partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

RendererConfigurationForm.js (3023B)


      1 Ext.define("PartKeepr.Components.Widgets.ColumnConfigurator.RendererConfigurationForm", {
      2     extend: "Ext.form.Panel",
      3 
      4     renderer: null,
      5     rendererConfiguration: null,
      6 
      7     scrollable: true,
      8 
      9     bbar: {
     10         items: [{
     11             xtype: 'button',
     12             itemId: "apply",
     13             text: i18n("Apply")
     14         }, {
     15             xtype: 'button',
     16             itemId: "cancel",
     17             text: i18n("Cancel")
     18         }]
     19     },
     20     defaults: {
     21         labelWidth: 200
     22     },
     23     initComponent: function ()
     24     {
     25         var renderer = PartKeepr.Components.Grid.Renderers.RendererRegistry.lookupRenderer(this.renderer);
     26 
     27 
     28         if (typeof(renderer) !== undefined)
     29         {
     30             this.items = this.createFormConfig(renderer);
     31 
     32         }
     33 
     34         if (typeof(this.rendererConfiguration) === "string") {
     35             this.rendererConfiguration = Ext.decode(this.rendererConfiguration);
     36         }
     37 
     38         this.callParent(arguments);
     39         this.getForm().setValues(this.rendererConfiguration);
     40 
     41     },
     42     createFormConfig: function (renderer)
     43     {
     44         var configIterator, config, field, fields = [], useDescriptionElemement;
     45 
     46         for (configIterator in renderer.rendererConfigs)
     47         {
     48             config = renderer.rendererConfigs[configIterator];
     49 
     50             Ext.applyIf(config, {
     51                 type: "",
     52                 description: ""
     53             });
     54 
     55             useDescriptionElemement = false;
     56 
     57             switch (config.type)
     58             {
     59                 case "boolean":
     60                     field = {
     61                         xtype: 'checkbox',
     62                         name: configIterator,
     63                         boxLabel: config.description,
     64                         fieldLabel: config.title
     65                     };
     66 
     67                     break;
     68                 case "string":
     69                     field = {
     70                         xtype: 'textfield',
     71                         name: configIterator,
     72                         fieldLabel: config.title,
     73                         title: config.description
     74                     };
     75 
     76                     useDescriptionElemement = true;
     77                     break;
     78                 case "partParameter":
     79                     field = {
     80                         xtype: 'PartParameterComboBox',
     81                         name: configIterator,
     82                         fieldLabel: config.title
     83                     };
     84                     break;
     85                 default:
     86                     field = {};
     87             }
     88 
     89             fields.push(field);
     90 
     91             if (useDescriptionElemement)
     92             {
     93                 fields.push({
     94                     xtype: 'displayfield',
     95                     value: config.description,
     96                     hideEmptyLabel: false
     97                 });
     98             }
     99         }
    100 
    101         if (fields.length === 0) {
    102             fields.push({
    103                     xtype: 'displayfield',
    104                     value: i18n("The selected renderer cannot be configured")
    105                 });
    106         }
    107 
    108         return fields;
    109     }
    110 });