BatchJobUpdateExpression.js (4519B)
1 Ext.define("PartKeepr.Components.BatchJob.BatchJobUpdateExpression", { 2 extend: "Ext.form.Panel", 3 4 xtype: 'partkeepr.batchjobupdateexpression', 5 6 layout: { 7 type: 'vbox', 8 align: 'stretch', 9 pack: 'start' 10 }, 11 12 minHeight: 150, 13 minWidth: 400, 14 width: 400, 15 height: 150, 16 requires: [], 17 18 bbar: [ 19 { 20 xtype: 'button', 21 itemId: 'apply', 22 disabled: true, 23 text: i18n("Apply") 24 } 25 ], 26 items: [ 27 { 28 xtype: 'fieldcontainer', 29 fieldLabel: i18n("Field"), 30 layout: 'hbox', 31 items: [ 32 { 33 flex: 1, 34 xtype: 'textfield', 35 itemId: "field", 36 emptyText: i18n("Select a field"), 37 readOnly: true 38 }, 39 { 40 width: 100, 41 xtype: 'button', 42 itemId: "selectField", 43 text: i18n("Select field") 44 } 45 ] 46 }, 47 { 48 xtype: 'fieldcontainer', 49 fieldLabel: i18n("Value"), 50 flex: 1, 51 itemId: 'value', 52 layout: 'hbox', 53 border: false, 54 items: [ 55 { 56 disabled: true, 57 itemId: "valueField", 58 xtype: 'textfield', 59 flex: 1 60 }, 61 { 62 width: 100, 63 xtype: 'button', 64 hidden: true, 65 itemId: "selectEntity", 66 text: i18n("Select Entity") 67 } 68 ] 69 }, 70 ], 71 72 sourceModel: null, 73 objectFilter: null, 74 75 initComponent: function () 76 { 77 this.callParent(arguments); 78 79 this.down("#selectField").on("click", this.onFieldSelectClick, this); 80 this.down("#selectEntity").on("click", this.onEntitySelectClick, this); 81 this.down("#apply").on("click", this.onApplyClick, this); 82 }, 83 onApplyClick: function () 84 { 85 this.fireEvent("applyexpression", this.selectedField.data.data.name, this.down("#valueField").getValue()); 86 }, 87 validateApplyButton: function () 88 { 89 var applyButton = this.down("#apply"); 90 91 if (this.selectedField.data.data.type == "manytoone") { 92 if (this.down("#valueField").getValue() === "") { 93 applyButton.setDisabled(true); 94 return; 95 } 96 } 97 98 applyButton.setDisabled(false); 99 }, 100 onFieldSelectClick: function () 101 { 102 this.modelFieldSelectorWindow = Ext.create("PartKeepr.Components.Widgets.FieldSelectorWindow", { 103 sourceModel: this.sourceModel 104 }); 105 this.modelFieldSelectorWindow.on("fieldSelect", function (field) 106 { 107 this.updateValueFieldState(field); 108 this.down("#field").setValue(field.data.data.name); 109 }, this); 110 this.modelFieldSelectorWindow.show(); 111 }, 112 updateValueFieldState: function (record) 113 { 114 this.selectedField = record; 115 116 117 if (record.data.data.type == "manytoone") { 118 this.down("#selectEntity").show(); 119 this.down("#valueField").setReadOnly(true); 120 } else { 121 this.down("#selectEntity").hide(); 122 this.down("#valueField").setReadOnly(false); 123 } 124 125 this.down("#valueField").setDisabled(false); 126 127 this.validateApplyButton(); 128 }, 129 onEntitySelectClick: function () 130 { 131 this.entitySelector = Ext.create("Ext.window.Window", { 132 items: Ext.create("PartKeepr.Widgets.EntityPicker", { 133 model: this.selectedField.data.data.reference, 134 listeners: { 135 entityselect: this.onEntitySelect, 136 scope: this 137 }, 138 ittemId: "entitySelectorPanel" 139 }), 140 title: i18n("Select entity"), 141 width: "80%", 142 height: "80%", 143 modal: true, 144 layout: 'fit', 145 maximizable: true, 146 closeAction: 'destroy' 147 }); 148 149 this.entitySelector.show(); 150 }, 151 /** 152 * @param entity {Ext.data.Model} The entity 153 */ 154 onEntitySelect: function (entity) 155 { 156 this.down("#valueField").setValue(entity.getId()); 157 158 this.entitySelector.close(); 159 this.validateApplyButton(); 160 }, 161 });