BatchJobEditor.js (9922B)
1 Ext.define('PartKeepr.BatchJobEditor', { 2 extend: 'PartKeepr.Editor', 3 alias: 'widget.BatchJobEditor', 4 5 defaults: { 6 anchor: '100%', 7 labelWidth: 110 8 }, 9 layout: { 10 type: 'vbox', 11 align: 'stretch', 12 pack: 'start' 13 }, 14 15 items: [ 16 { 17 xtype: 'textfield', 18 name: 'name', 19 fieldLabel: i18n("Batch Job Name") 20 }, 21 { 22 xtype: 'combo', 23 store: Ext.StoreManager.lookup("ModelStore"), 24 displayField: 'model', 25 queryMode: 'local', 26 itemId: 'baseEntity', 27 editable: false, 28 forceSelection: true, 29 valueField: 'model', 30 name: 'baseEntity', 31 fieldLabel: i18n("Base Entity") 32 }, 33 { 34 xtype: 'fieldcontainer', 35 fieldLabel: i18n("Query Fields"), 36 layout: 'fit', 37 flex: 1, 38 items: [ 39 { 40 xtype: 'grid', 41 itemId: 'batchJobQueryFields', 42 plugins: { 43 ptype: 'cellediting', 44 clicksToEdit: 1 45 }, 46 bbar: [ 47 { 48 xtype: 'button', 49 iconCls: 'fugue-icon database--plus', 50 itemId: 'addQueryFieldButton', 51 text: i18n("Add Query Field…") 52 }, { 53 xtype: 'button', 54 iconCls: 'fugue-icon database--minus', 55 text: i18n("Delete Query Field"), 56 itemId: 'deleteQueryFieldButton', 57 disabled: true 58 } 59 ], 60 columns: [ 61 { 62 header: i18n("Property"), 63 dataIndex: "property", 64 flex: 1 65 }, { 66 header: i18n("Operator"), 67 dataIndex: "operator", 68 flex: 0.5 69 }, { 70 header: i18n("Value"), 71 dataIndex: "value", 72 flex: 1 73 }, { 74 xtype: 'checkcolumn', 75 header: i18n("Dynamic"), 76 editable: true, 77 dataIndex: "dynamic", 78 flex: 0.5 79 }, { 80 header: i18n("Description"), 81 editable: true, 82 dataIndex: "description", 83 editor: { 84 xtype: 'textfield', 85 allowBlank: true 86 }, 87 flex: 2 88 } 89 ] 90 } 91 ] 92 }, 93 { 94 xtype: 'fieldcontainer', 95 fieldLabel: i18n("Update Fields"), 96 layout: 'fit', 97 flex: 1, 98 items: [ 99 { 100 xtype: 'grid', 101 itemId: 'batchJobUpdateFields', 102 plugins: { 103 ptype: 'cellediting', 104 pluginId: 'cellediting', 105 clicksToEdit: 1 106 }, 107 bbar: [ 108 { 109 xtype: 'button', 110 iconCls: 'fugue-icon database--plus', 111 itemId: 'addUpdateFieldButton', 112 text: i18n("Add Update Field…") 113 }, { 114 xtype: 'button', 115 iconCls: 'fugue-icon database--minus', 116 text: i18n("Delete Update Field"), 117 itemId: 'deleteUpdateFieldButton', 118 disabled: true 119 } 120 ], 121 columns: [ 122 { 123 header: i18n("Property"), 124 dataIndex: "property", 125 flex: 1 126 }, { 127 header: i18n("Value"), 128 dataIndex: "value", 129 flex: 1 130 }, { 131 xtype: 'checkcolumn', 132 header: i18n("Dynamic"), 133 editable: true, 134 dataIndex: "dynamic", 135 flex: 0.5 136 }, { 137 header: i18n("Description"), 138 editable: true, 139 dataIndex: "description", 140 editor: { 141 xtype: 'textfield', 142 allowBlank: true 143 }, 144 flex: 2 145 } 146 ] 147 } 148 ] 149 } 150 ], 151 saveText: i18n("Save Batch Job"), 152 153 initComponent: function () 154 { 155 this.on("startEdit", this.onEditStart, this, { delay: 50 }); 156 157 this.callParent(arguments); 158 159 this.down("#addQueryFieldButton").on("click", this.onAddQueryFieldButtonClick, this); 160 this.down("#deleteQueryFieldButton").on("click", this.onDeleteQueryFieldButtonClick, this); 161 this.down("#batchJobQueryFields").getSelectionModel().on("selectionchange", this.onSelectionChange, this); 162 this.down("#addUpdateFieldButton").on("click", this.onAddUpdateFieldButtonClick, this); 163 this.down("#deleteUpdateFieldButton").on("click", this.onDeleteUpdateFieldButtonClick, this); 164 this.down("#batchJobUpdateFields").getSelectionModel().on("selectionchange", this.onUpdateSelectionChange, 165 this); 166 167 168 }, 169 beforeFieldSelection: function (selectorField) 170 { 171 var sourceModel = Ext.ClassManager.get(this.down("#baseEntity").getValue()); 172 173 if (sourceModel === null) { 174 Ext.Msg.alert(i18n("Base Entity not selected"), 175 i18n("You need to select a base entity to perform the query against")); 176 return; 177 } 178 179 selectorField.setBaseEntity(sourceModel); 180 181 return true; 182 }, 183 /** 184 * Enables or disables the delete button, depending on the row selection 185 */ 186 onSelectionChange: function (selModel, selections) 187 { 188 this.down("#deleteQueryFieldButton").setDisabled(selections.length === 0); 189 }, 190 /** 191 * Enables or disables the delete button, depending on the row selection 192 */ 193 onUpdateSelectionChange: function (selModel, selections) 194 { 195 this.down("#deleteUpdateFieldButton").setDisabled(selections.length === 0); 196 }, 197 onAddQueryFieldButtonClick: function () 198 { 199 var sourceModel = Ext.ClassManager.get(this.down("#baseEntity").getValue()); 200 201 if (sourceModel === null) { 202 Ext.Msg.alert(i18n("Base Entity not selected"), 203 i18n("You need to select a base entity to perform the query against")); 204 return; 205 } 206 this.addFilterWindow = Ext.create("PartKeepr.Widgets.FilterExpressionWindow", { 207 sourceModel: sourceModel, 208 listeners: { 209 "applyfilter": this.onAddFilter, 210 scope: this 211 } 212 }); 213 this.addFilterWindow.show(); 214 }, 215 onAddUpdateFieldButtonClick: function () 216 { 217 var sourceModel = Ext.ClassManager.get(this.down("#baseEntity").getValue()); 218 219 if (sourceModel === null) { 220 Ext.Msg.alert(i18n("Base Entity not selected"), 221 i18n("You need to select a base entity to perform the query against")); 222 return; 223 } 224 225 var j = Ext.create("PartKeepr.Components.BatchJob.BatchJobUpdateExpressionWindow", { 226 sourceModel: sourceModel, 227 listeners: { 228 applyexpression: this.onApplyUpdateExpression, 229 scope: this 230 } 231 }); 232 j.show(); 233 }, 234 onApplyUpdateExpression: function (field, value) 235 { 236 this.down("#batchJobUpdateFields").getStore().add({ 237 property: field, 238 value: value 239 }); 240 }, 241 onAddFilter: function (filter) 242 { 243 this.down("#batchJobQueryFields").getStore().add({ 244 property: filter.getProperty(), 245 operator: filter.getOperator(), 246 value: filter.getValue() 247 }); 248 }, 249 onDeleteQueryFieldButtonClick: function () 250 { 251 var selection = this.down("#batchJobQueryFields").getSelectionModel().getSelection()[0]; 252 if (selection) { 253 this.down("#batchJobQueryFields").getStore().remove(selection); 254 } 255 }, 256 onDeleteUpdateFieldButtonClick: function () 257 { 258 var selection = this.down("#batchJobUpdateFields").getSelectionModel().getSelection()[0]; 259 if (selection) { 260 this.down("#batchJobUpdateFields").getStore().remove(selection); 261 } 262 }, 263 /** 264 * Re-bind the store after an item was saved 265 */ 266 _onItemSaved: function (record) 267 { 268 this.down("#batchJobQueryFields").bindStore(record.batchJobQueryFields()); 269 }, 270 /** 271 * Bind the store as soon as the view was rendered. 272 */ 273 onEditStart: function () 274 { 275 var store = this.record.batchJobQueryFields(); 276 this.down("#batchJobQueryFields").bindStore(store); 277 278 var store2 = this.record.batchJobUpdateFields(); 279 this.down("#batchJobUpdateFields").bindStore(store2); 280 } 281 });