partkeepr

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

BatchJobExecutionWindow.js (9112B)


      1 Ext.define("PartKeepr.Components.BatchJob.BatchJobExecutionWindow", {
      2     extend: "Ext.window.Window",
      3 
      4     width: 800,
      5     height: 400,
      6     layout: 'fit',
      7     title: i18n("Execute Batch Job"),
      8     items: [
      9         {
     10             xtype: 'form',
     11             items: [
     12                 {
     13                     xtype: 'fieldcontainer',
     14                     fieldLabel: i18n("Query Fields"),
     15                     items: [
     16                         {
     17                             xtype: 'grid',
     18                             height: 100,
     19                             itemId: 'queryFields',
     20                             viewConfig: {
     21                                 markDirty: false
     22                             },
     23                             columns: []
     24                         }
     25                     ]
     26                 },
     27                 {
     28                     xtype: 'fieldcontainer',
     29                     fieldLabel: i18n("Update Fields"),
     30                     items: [
     31                         {
     32                             xtype: 'grid',
     33                             height: 100,
     34                             itemId: 'updateFields',
     35                             viewConfig: {
     36                                 markDirty: false
     37                             },
     38                             columns: [
     39                                 {
     40                                     header: '',
     41                                     width: 32,
     42                                     renderer: function (val, metaData, record)
     43                                     {
     44                                         if (record.get("value") == "") {
     45                                             return '<span title="OK" style="vertical-align: top;" class="web-icon error"></span>';
     46                                         } else {
     47                                             return '<span title="OK" style="vertical-align: top;" class="web-icon accept"></span>';
     48                                         }
     49 
     50                                     }
     51                                 },
     52                                 {
     53                                     header: i18n("Property"),
     54                                     flex: 1,
     55                                     dataIndex: "property"
     56                                 }, {
     57                                     header: i18n("Description"),
     58                                     flex: 2,
     59                                     dataIndex: "description"
     60                                 },
     61                                 {
     62                                     header: i18n("Value"),
     63                                     flex: 1,
     64                                     dataIndex: "value"
     65                                 }
     66                             ]
     67                         }
     68                     ]
     69                 }
     70             ]
     71         }
     72     ],
     73 
     74     bbar: [
     75         {
     76             xtype: 'button',
     77             text: i18n("Execute Batch Job"),
     78             disabled: true,
     79             itemId: 'executeBatchJob'
     80         }
     81     ],
     82 
     83     batchJob: null,
     84 
     85     initComponent: function ()
     86     {
     87         var i;
     88 
     89         this.callParent(arguments);
     90 
     91         var batchJobQueryFields = this.batchJob.batchJobQueryFields();
     92         batchJobQueryFields.setRemoteFilter(false);
     93         batchJobQueryFields.filter({property: 'dynamic', operator: '=', value: true});
     94 
     95         for (i = 0; i < batchJobQueryFields.getCount(); i++) {
     96             batchJobQueryFields.getAt(i).set("value", "");
     97         }
     98 
     99         this.down("#queryFields").setStore(batchJobQueryFields);
    100 
    101         var batchJobUpdateFields = this.batchJob.batchJobUpdateFields();
    102         batchJobUpdateFields.setRemoteFilter(false);
    103         batchJobUpdateFields.filter({property: 'dynamic', operator: '=', value: true});
    104 
    105         for (i = 0; i < batchJobUpdateFields.getCount(); i++) {
    106             batchJobUpdateFields.getAt(i).set("value", "");
    107         }
    108 
    109         this.down("#updateFields").setStore(batchJobUpdateFields);
    110 
    111         var columns = [
    112             {
    113                 header: '',
    114                 width: 32,
    115                 renderer: function (val, metaData, record)
    116                 {
    117                     if (record.get("value") == "") {
    118                         return '<span title="OK" style="vertical-align: top;" class="web-icon error"></span>';
    119                     } else {
    120                         return '<span title="OK" style="vertical-align: top;" class="web-icon accept"></span>';
    121                     }
    122 
    123                 }
    124             },
    125             {
    126                 header: i18n("Property"),
    127                 flex: 1,
    128                 dataIndex: "property"
    129             }, {
    130                 header: i18n("Description"),
    131                 flex: 2,
    132                 dataIndex: "description"
    133             }, {
    134                 header: i18n("Value"),
    135                 flex: 1,
    136                 dataIndex: "value"
    137             }, {
    138                 width: 100,
    139                 xtype: 'widgetcolumn',
    140                 itemId: 'foobar',
    141                 widget: {
    142 
    143                     xtype: 'button',
    144                     text: i18n("Set Value…"),
    145                     handler: this.onSetValueClick,
    146                     scope: this
    147                 }
    148             }
    149         ];
    150 
    151         this.down("#updateFields").reconfigure(null, columns);
    152         this.down("#queryFields").reconfigure(null, columns);
    153 
    154         this.validateExecuteBatchJobButton();
    155         this.down("#executeBatchJob").on("click", this.onExecuteBatchJob, this);
    156     },
    157     onExecuteBatchJob: function ()
    158     {
    159         this.down("#executeBatchJob").setDisabled();
    160 
    161         var i, queryFieldConfig = [], updateFieldConfig = [];
    162 
    163         for (i = 0; i < this.batchJob.batchJobQueryFields().getCount(); i++) {
    164             queryFieldConfig.push({
    165                 property: this.batchJob.batchJobQueryFields().getAt(i).get("property"),
    166                 value: this.batchJob.batchJobQueryFields().getAt(i).get("value")
    167             });
    168         }
    169 
    170         for (i = 0; i < this.batchJob.batchJobUpdateFields().getCount(); i++) {
    171             updateFieldConfig.push({
    172                 property: this.batchJob.batchJobUpdateFields().getAt(i).get("property"),
    173                 value: this.batchJob.batchJobUpdateFields().getAt(i).get("value")
    174             });
    175         }
    176 
    177         this.batchJob.callPutAction("execute", {
    178             queryFields: Ext.encode(queryFieldConfig),
    179             updateFields: Ext.encode(updateFieldConfig)
    180         }, Ext.bind(this.onBatchJobExecuted, this));
    181     },
    182     /**
    183      * Displays a message as soon as the batch job is completed successfully.
    184      */
    185     onBatchJobExecuted: function (options, success)
    186     {
    187         if (success) {
    188             Ext.MessageBox.alert(i18n("Batch Job Completed Successfully"),
    189                 i18n("The batch job has been executed successfully"));
    190         }
    191 
    192         this.down("#executeBatchJob").setEnabled();
    193     },
    194     validateExecuteBatchJobButton: function ()
    195     {
    196         var valid = true, i;
    197 
    198         var batchJobQueryFields = this.batchJob.batchJobQueryFields();
    199 
    200         for (i = 0; i < batchJobQueryFields.getCount(); i++) {
    201             if (batchJobQueryFields.getAt(i).get("value") == "") {
    202                 valid = false;
    203             }
    204         }
    205 
    206         var batchJobUpdateFields = this.batchJob.batchJobUpdateFields();
    207 
    208         for (i = 0; i < batchJobUpdateFields.getCount(); i++) {
    209             if (batchJobUpdateFields.getAt(i).get("value") == "") {
    210                 valid = false;
    211             }
    212         }
    213 
    214         this.down("#executeBatchJob").setDisabled(!valid);
    215     },
    216     onSetValueClick: function (widgetColumn)
    217     {
    218         this.editingRecord = widgetColumn.getWidgetRecord();
    219 
    220 
    221         var baseEntity = this.batchJob.get("baseEntity");
    222 
    223         var baseModel = Ext.create(baseEntity);
    224 
    225         var type = baseModel.getFieldType(this.editingRecord.get("property"));
    226 
    227         if (type.type === "field") {
    228             Ext.Msg.prompt(i18n("Enter the value"), this.editingRecord.get("description"), this.onValueEntered, this);
    229         } else {
    230             this.entitySelector = Ext.create("Ext.window.Window", {
    231                 items: Ext.create("PartKeepr.Widgets.EntityPicker", {
    232                     model: Ext.ClassManager.get(type.reference),
    233                     listeners: {
    234                         entityselect: this.onEntitySelect,
    235                         scope: this
    236                     },
    237                     ittemId: "entitySelectorPanel"
    238                 }),
    239                 title: i18n("Select entity"),
    240                 width: "80%",
    241                 height: "80%",
    242                 modal: true,
    243                 layout: 'fit',
    244                 maximizable: true,
    245                 closeAction: 'destroy'
    246             });
    247 
    248             this.entitySelector.show();
    249         }
    250 
    251 
    252     },
    253     onValueEntered: function (btn, value)
    254     {
    255         if (btn === "ok") {
    256             this.editingRecord.set("value", value);
    257         }
    258 
    259         this.validateExecuteBatchJobButton();
    260     },
    261     onEntitySelect: function (entity)
    262     {
    263         this.editingRecord.set("value", entity.getId());
    264         this.entitySelector.close();
    265         this.validateExecuteBatchJobButton();
    266     }
    267 });