partkeepr

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

ImporterEntityConfiguration.js (3907B)


      1 Ext.define("PartKeepr.Importer.ImporterEntityConfiguration", {
      2     extend: "Ext.form.Panel",
      3     layout: {
      4         type: 'vbox',
      5         align: 'stretch'
      6     },
      7     scrollable: 'y',
      8     defaultListenerScope: true,
      9     importerField: null,
     10     xtype: 'importerEntityConfiguration',
     11 
     12     items: [
     13         {
     14             xtype: 'radio',
     15             boxLabel: i18n("Always import"),
     16             name: 'importBehaviour',
     17             inputValue: 'alwaysImport',
     18             checked: true,
     19             itemId: 'alwaysImport'
     20         },
     21         {
     22             xtype: 'radio',
     23             boxLabel: i18n("Match import data with existing data using:"),
     24             name: 'importBehaviour',
     25             checked: false,
     26             inputValue: 'matchData',
     27             itemId: 'matchData'
     28         },
     29         {
     30             disabled: true,
     31             xtype: 'importFieldMatcherGrid',
     32             itemId: 'importFieldMatcherGrid',
     33             listeners: {
     34                 change: "onImportBehaviourChange"
     35             },
     36             height: 100
     37         },
     38         {
     39             xtype: 'radio',
     40             boxLabel: i18n("Don't update data if an item exists"),
     41             disabled: true,
     42             inputValue: 'dontUpdate',
     43             itemId: 'dontUpdateData',
     44             name: 'updateBehaviour'
     45         },
     46         {
     47             xtype: 'radio',
     48             boxLabel: i18n("Update data if an item exists"),
     49             disabled: true,
     50             checked: true,
     51             inputValue: 'update',
     52             itemId: 'updateData',
     53             name: 'updateBehaviour'
     54         }
     55     ],
     56     initComponent: function ()
     57     {
     58         this.defaults = {
     59             listeners: {
     60                 change: function ()
     61                 {
     62                     this.fireEvent("configChanged");
     63                 },
     64                 scope: this
     65             }
     66         };
     67 
     68         this.callParent(arguments);
     69 
     70         this.down("#alwaysImport").on("change", this.onImportBehaviourChange, this);
     71         this.down("#matchData").on("change", this.onImportBehaviourChange, this);
     72     },
     73     onImportBehaviourChange: function ()
     74     {
     75         var fieldValues = this.getForm().getFieldValues();
     76 
     77         if (fieldValues.importBehaviour === "matchData") {
     78             this.down("#importFieldMatcherGrid").enable();
     79             this.down("#dontUpdateData").enable();
     80             this.down("#updateData").enable();
     81         } else {
     82             this.down("#importFieldMatcherGrid").disable();
     83             this.down("#dontUpdateData").disable();
     84             this.down("#updateData").disable();
     85         }
     86 
     87         Ext.apply(this.importerConfig, this.getImporterConfig());
     88     },
     89     setModel: function (model)
     90     {
     91         this.down("importFieldMatcherGrid").setModel(model);
     92 
     93     },
     94     getImporterConfig: function ()
     95     {
     96         var config = this.getForm().getFieldValues();
     97 
     98         config.matchers = this.down("#importFieldMatcherGrid").getImporterConfig();
     99         return config;
    100     },
    101     setImporterConfig: function (config)
    102     {
    103         this.importerConfig = config;
    104 
    105         this.getForm().setValues(this.importerConfig);
    106 
    107         if (this.importerConfig === {}) {
    108             this.getForm().reset();
    109             this.down("#importFieldMatcherGrid").setImporterConfig({});
    110             return;
    111         }
    112 
    113         if (config.hasOwnProperty("matchers")) {
    114             this.down("#importFieldMatcherGrid").setImporterConfig(this.importerConfig.matchers);
    115         } else {
    116             this.down("#importFieldMatcherGrid").setImporterConfig({});
    117         }
    118 
    119         Ext.apply(this.importerConfig, this.getImporterConfig());
    120     },
    121     reconfigureColumns: function (columnsStore)
    122     {
    123         this.down("#importFieldMatcherGrid").reconfigureColumns(columnsStore);
    124     },
    125     setImporterField: function (field)
    126     {
    127         this.importerField = field;
    128     },
    129     getImporterField: function ()
    130     {
    131         return this.importerField;
    132     }
    133 
    134 });