MetaPartEditor.js (5596B)
1 /** 2 * @class PartKeepr.Components.Part.Editor.MetaPartEditor 3 4 * <p>The MetaPartEditor provides an editing form for meta parts</p> 5 */ 6 Ext.define('PartKeepr.Components.Part.Editor.MetaPartEditor', { 7 extend: 'PartKeepr.Editor', 8 9 // Assigned model 10 model: 'PartKeepr.PartBundle.Entity.Part', 11 bodyPadding: '0 0 0 0', 12 // Layout stuff 13 border: false, 14 editAfterSave: false, 15 16 ui: 'default-framed', 17 18 layout: { 19 type: 'vbox', 20 align: 'stretch', 21 pack: 'start' 22 }, 23 24 /** 25 * Initializes the editor fields 26 */ 27 initComponent: function () 28 { 29 this.operatorStore = Ext.create("PartKeepr.Data.store.OperatorStore"); 30 31 this.nameField = Ext.create("Ext.form.field.Text", { 32 name: 'name', 33 fieldLabel: i18n("Name"), 34 allowBlank: false, 35 labelWidth: 150, 36 height: 20 37 }); 38 39 this.parameterCriterias = Ext.create("Ext.grid.Panel", { 40 columns: [ 41 { 42 header: i18n("Parameter Name"), 43 dataIndex: 'partParameterName', 44 flex: 1 45 }, { 46 header: i18n("Operator"), 47 renderer: this.renderOperator, 48 scope: this, 49 flex: 0.5 50 }, { 51 header: i18n("Value"), 52 renderer: this.renderValue, 53 scope: this, 54 flex: 1 55 } 56 ], 57 bbar: [ 58 { 59 xtype: 'button', 60 itemId: 'addParameterCriteria', 61 handler: this.addParameterCriteriaClick, 62 iconCls: "fugue-icon eye--plus", 63 text: i18n("Add…"), 64 scope: this 65 }, { 66 xtype: 'button', 67 itemId: 'deleteParameterCriteria', 68 handler: this.onDeleteParameterCriteriaClick, 69 text: i18n("Delete"), 70 iconCls: "fugue-icon eye--minus", 71 scope: this 72 } 73 ] 74 }) 75 ; 76 77 this.items = [ 78 this.nameField, 79 { 80 xtype: 'CategoryComboBox', 81 fieldLabel: i18n("Category"), 82 name: 'category', 83 displayField: "name", 84 returnObject: true 85 }, 86 { 87 xtype: 'PartUnitComboBox', 88 fieldLabel: i18n("Measurement Unit"), 89 columnWidth: 0.5, 90 returnObject: true, 91 name: 'partUnit' 92 }, 93 { 94 xtype: 'fieldcontainer', 95 fieldLabel: i18n("Parameter Criterias"), 96 flex: 1, 97 layout: 'fit', 98 items: this.parameterCriterias 99 } 100 ]; 101 102 103 this.on("startEdit", this.onEditStart, this, {delay: 200}); 104 this.on("itemSaved", this._onItemSaved, this); 105 this.callParent(); 106 107 this.parameterCriterias.getSelectionModel().on('selectionchange', this.onSelectChange, this); 108 }, 109 onCancelEdit: function () { 110 this.record.metaPartParameterCriterias().rejectChanges(); 111 this.callParent(arguments); 112 }, 113 setTitle: function (title) 114 { 115 var tmpTitle; 116 117 if (this.record.phantom) { 118 tmpTitle = i18n("Add Meta-Part"); 119 } else { 120 tmpTitle = i18n("Edit Meta-Part"); 121 } 122 123 if (title !== "") { 124 tmpTitle = tmpTitle + ": " + title; 125 } 126 127 this.fireEvent("_titleChange", tmpTitle); 128 }, 129 _onItemSaved: function () 130 { 131 this.fireEvent("partSaved", this.record); 132 133 this.fireEvent("editorClose", this); 134 }, 135 onSelectChange: function (selModel, selections) 136 { 137 this.down("#deleteParameterCriteria").setDisabled(selections.length === 0); 138 }, 139 addParameterCriteriaClick: function () 140 { 141 var j = Ext.create("PartKeepr.Components.Widgets.PartParameterSearchWindow"); 142 143 j.on("apply", this.onAddParameterCriteria, this); 144 j.show(); 145 }, 146 onAddParameterCriteria: function (rec) 147 { 148 this.parameterCriterias.getStore().add(rec); 149 }, 150 onDeleteParameterCriteriaClick: function () 151 { 152 this.parameterCriterias.getStore().remove(this.parameterCriterias.getSelection()); 153 }, 154 renderValue: function (v, m, rec) 155 { 156 var unit = "", symbol = ""; 157 158 switch (rec.get("valueType")) { 159 case "string": 160 return rec.get("stringValue"); 161 break; 162 case "numeric": 163 if (rec.getUnit() !== null) { 164 unit = rec.getUnit().get("symbol"); 165 } 166 167 if (rec.getSiPrefix() !== null) { 168 symbol = rec.getSiPrefix().get("symbol"); 169 } 170 171 172 return rec.get("value") + symbol + unit; 173 break; 174 default: 175 return ""; 176 } 177 }, 178 renderOperator: function (v, m, rec) 179 { 180 var operator = this.operatorStore.findRecord("operator", rec.get("operator"), 0, false, true, true); 181 182 if (operator instanceof Ext.data.Model) { 183 return operator.get("symbol"); 184 } else { 185 return ""; 186 } 187 }, 188 onEditStart: function () 189 { 190 this.parameterCriterias.bindStore(this.record.metaPartParameterCriterias()); 191 this.nameField.focus(); 192 } 193 });