ActionsConfiguration.js (5654B)
1 Ext.define('PartKeepr.Components.SystemPreferences.Preferences.ActionsConfiguration', { 2 extend: 'PartKeepr.Components.Preferences.PreferenceEditor', 3 4 initComponent: function () 5 { 6 7 this.batchJobStore = Ext.create("Ext.data.Store", { 8 model: 'PartKeepr.BatchJobBundle.Entity.BatchJob', 9 autoLoad: true 10 }); 11 12 this.actionsStore = Ext.create("Ext.data.Store", { 13 fields: [ 14 {name: 'baseEntity'}, 15 {name: 'action'}, 16 {name: 'batchJob'}, 17 {name: 'batchJobName'} 18 ] 19 }); 20 21 this.items = [ 22 { 23 xtype: 'fieldcontainer', 24 fieldLabel: i18n("Actions"), 25 items: [ 26 { 27 xtype: 'grid', 28 height: 200, 29 itemId: 'actionGrid', 30 plugins: { 31 ptype: 'cellediting', 32 clicksToEdit: 1, 33 pluginId: 'editing' 34 }, 35 listeners: { 36 selectionchange: this.onSelectionChange, 37 edit: this.onGridEdit, 38 scope: this 39 }, 40 store: this.actionsStore, 41 columns: [ 42 { 43 header: i18n("Entity"), 44 flex: 1, 45 dataIndex: "baseEntity", 46 editor: { 47 xtype: 'combo', 48 store: Ext.StoreManager.lookup("ModelStore"), 49 displayField: 'model', 50 queryMode: 'local', 51 editable: false, 52 forceSelection: true, 53 valueField: 'model' 54 } 55 }, { 56 header: i18n("Action"), 57 dataIndex: "action", 58 flex: 1, 59 editor: { 60 xtype: 'textfield' 61 } 62 }, { 63 header: i18n("Batch Job"), 64 dataIndex: "batchJob", 65 flex: 1, 66 editor: { 67 xtype: 'combo', 68 store: this.batchJobStore, 69 displayField: 'name', 70 editable: false, 71 forceSelection: true, 72 valueField: '@id' 73 }, 74 renderer: this.renderBatchJob, 75 scope: this 76 } 77 ], 78 bbar: [ 79 { 80 xtype: 'button', 81 text: i18n("Add Action"), 82 itemId: 'actionAdd', 83 handler: this.onAddAction, 84 scope: this 85 }, { 86 xtype: 'button', 87 text: i18n("Delete Action"), 88 disabled: true, 89 itemId: 'actionDelete' 90 } 91 ] 92 } 93 ] 94 } 95 ]; 96 97 this.callParent(arguments); 98 99 var actions = PartKeepr.getApplication().getSystemPreference("partkeepr.actions", []); 100 101 for (var i = 0; i < actions.length; i++) { 102 this.actionsStore.add(actions[i]); 103 } 104 105 }, 106 onGridEdit: function (editor, e) { 107 if (e.field === "batchJob") { 108 var batchJob = this.batchJobStore.getById(e.value); 109 110 if (batchJob !== null) { 111 e.record.set("batchJobName", batchJob.get("name")); 112 } 113 } 114 }, 115 renderBatchJob: function (value, metaData, record) 116 { 117 return record.get("batchJobName"); 118 }, 119 onAddAction: function () 120 { 121 var grid = this.down("#actionGrid"); 122 grid.getPlugin("editing").cancelEdit(); 123 124 grid.getStore().insert(0, {}); 125 126 grid.getPlugin("editing").startEdit(0, 0); 127 }, 128 onSelectionChange: function (grid, selection) 129 { 130 if (selection.length === 1) { 131 this.down("#actionDelete").setDisabled(false); 132 } else { 133 this.down("#actionDelete").setDisabled(true); 134 } 135 }, 136 onSave: function () 137 { 138 var data = this.down("#actionGrid").getStore().getData(); 139 var actions = []; 140 141 for (var i = 0; i < data.length; i++) { 142 var item = data.getAt(i); 143 144 actions.push({ 145 baseEntity: item.get("baseEntity"), 146 action: item.get("action"), 147 batchJob: item.get("batchJob"), 148 batchJobName: item.get("batchJobName") 149 }); 150 } 151 152 PartKeepr.getApplication().setSystemPreference("partkeepr.actions", actions); 153 }, 154 statics: { 155 iconCls: 'fugue-icon task--arrow', 156 title: i18n('Actions'), 157 menuPath: [] 158 } 159 });