partkeepr

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

ImporterFieldConfiguration.js (4263B)


      1 Ext.define("PartKeepr.Importer.ImporterFieldConfiguration", {
      2     extend: "Ext.form.Panel",
      3     layout: 'vbox',
      4     scrollable: 'y',
      5     xtype: 'importerFieldConfiguration',
      6     importerField: null,
      7     defaultListenerScope: true,
      8     defaultConfig: {
      9         fieldConfiguration: "ignore",
     10         copyFromField: "",
     11         setToValue: ""
     12     },
     13     loading: false,
     14     items: [
     15         {
     16             xtype: 'radio',
     17             boxLabel: i18n("Ignore"),
     18             itemId: "ignore",
     19             name: "fieldConfiguration",
     20             inputValue: 'ignore',
     21             checked: true,
     22             listeners: {
     23                 change: "onChange"
     24             }
     25         },
     26 
     27         {
     28             xtype: 'fieldcontainer',
     29             layout: {
     30                 type: 'hbox',
     31                 align: "stretch"
     32             },
     33             items: [
     34                 {
     35                     xtype: 'radio',
     36                     boxLabel: i18n("Copy contents from:"),
     37                     itemId: "copyContentsFrom",
     38                     name: "fieldConfiguration",
     39                     inputValue: 'copyFrom',
     40                     listeners: {
     41                         change: "onChange"
     42                     }
     43                 },
     44                 {
     45                     xtype: 'combo',
     46                     forceSelection: true,
     47                     editable: false,
     48                     itemId: 'importFieldSelector',
     49                     name: 'copyFromField',
     50                     queryMode: "local",
     51                     displayField: "headerName",
     52                     valueField: "headerIndex",
     53                     listeners: {
     54                         change: "onChange"
     55                     }
     56                 },
     57             ]
     58         },
     59         {
     60             xtype: 'fieldcontainer',
     61             layout: {
     62                 type: 'hbox',
     63                 align: "stretch"
     64             },
     65             items: [
     66                 {
     67                     xtype: 'radio',
     68                     boxLabel: i18n("Set to fixed value"),
     69                     itemId: "setToFixedValue",
     70                     name: "fieldConfiguration",
     71                     inputValue: 'fixedValue',
     72                     listeners: {
     73                         change: "onChange"
     74                     }
     75                 },
     76                 {
     77                     xtype: 'textfield',
     78                     itemId: "fixedValue",
     79                     name: "setToValue",
     80                     disabled: true,
     81                     listeners: {
     82                         change: "onChange"
     83                     }
     84                 }
     85             ]
     86         }
     87     ],
     88     initComponent: function ()
     89     {
     90         this.callParent(arguments);
     91         this.down("#copyContentsFrom").on("change", this.onFieldConfigurationChange, this);
     92         this.down("#setToFixedValue").on("change", this.onFieldConfigurationChange, this);
     93     },
     94     onChange: function ()
     95     {
     96         this.onFieldConfigurationChange();
     97 
     98         if (!this.loading) {
     99             Ext.apply(this.importerConfig, this.getForm().getValues());
    100         }
    101         this.fireEvent("configChanged");
    102 
    103     },
    104     onFieldConfigurationChange: function ()
    105     {
    106         var fieldValues = this.getForm().getFieldValues();
    107 
    108         switch (fieldValues.fieldConfiguration) {
    109             case "copyFrom":
    110                 this.down("#importFieldSelector").enable();
    111                 this.down("#fixedValue").disable();
    112                 break;
    113             case "fixedValue":
    114                 this.down("#importFieldSelector").disable();
    115                 this.down("#fixedValue").enable();
    116                 break;
    117             default:
    118                 this.down("#importFieldSelector").disable();
    119                 this.down("#fixedValue").disable();
    120         }
    121     },
    122     setModel: function (model)
    123     {
    124         this.down("importFieldMatcherGrid").setModel(model);
    125     },
    126     setImporterConfig: function (config)
    127     {
    128         this.importerConfig = config;
    129         Ext.applyIf(this.importerConfig, this.defaultConfig);
    130         this.loading = true;
    131         this.getForm().setValues(this.importerConfig);
    132         this.loading = false;
    133 
    134         this.onFieldConfigurationChange();
    135     },
    136     reconfigureColumns: function (columnsStore)
    137     {
    138         this.down("#importFieldSelector").setStore(columnsStore);
    139     }
    140 });