PartParameterComboBox.js (2162B)
1 Ext.define("PartKeepr.PartParameterComboBox", { 2 extend: "Ext.form.field.ComboBox", 3 xtype: 'PartParameterComboBox', 4 displayField: 'name', 5 valueField: 'name', 6 autoSelect: false, 7 allowBlank: false, 8 queryMode: 'local', 9 triggerAction: 'all', 10 forceSelection: false, 11 editable: true, 12 tpl: Ext.create('Ext.XTemplate', 13 '<ul class="x-list-plain"><tpl for=".">', 14 '<li role="option" class="x-boundlist-item">', 15 '<span style="float: left;" class="web-icon fugue-icon ', 16 '<tpl if="valueType == \'numeric\'">', 17 'edit-number', 18 '<tpl else>', 19 'layer-shape-text', 20 '</tpl>', 21 '"></span>{name}', 22 '<tpl if="unitSymbol != null"> ({unitSymbol})</tpl>', 23 '<tpl if="description != \'\'"><br/><span style="margin-left: 16px;"><small>{description}</small></span></tpl>', 24 '</li>', 25 '</tpl></ul>' 26 ), 27 triggers: { 28 reload: { 29 cls: "x-form-reload-trigger", 30 weight: -1, 31 handler: function () 32 { 33 this.store.load(); 34 }, 35 scope: 'this' 36 } 37 }, 38 initComponent: function () 39 { 40 41 this.store = Ext.create("Ext.data.Store", { 42 fields: [{name: 'name'}, {name: 'description'}, {name: 'valueType'}, {name: 'unitName'},{name: 'unitSymbol'}], 43 autoLoad: false, 44 proxy: { 45 type: 'ajax', 46 url: PartKeepr.getBasePath() + "/api/parts/getPartParameterNames", 47 reader: { 48 type: 'json' 49 } 50 } 51 }); 52 53 /* Workaround to remember the value when loading */ 54 this.store.on("beforeload", function () 55 { 56 this._oldValue = this.getValue(); 57 }, this); 58 59 /* Set the old value when load is complete */ 60 this.store.on("load", function () 61 { 62 this.setValue(this._oldValue); 63 }, this); 64 65 this.callParent(); 66 this.store.load(); 67 }, 68 setValue: function (val) 69 { 70 this._oldValue = val; 71 this.callParent(arguments); 72 } 73 }); 74