UnitEditor.js (1767B)
1 Ext.define('PartKeepr.UnitEditor', { 2 extend: 'PartKeepr.Editor', 3 alias: 'widget.UnitEditor', 4 saveText: i18n("Save Unit"), 5 initComponent: function () { 6 7 var sm = Ext.create('Ext.selection.CheckboxModel',{ 8 checkOnly: true 9 }); 10 11 this.gridPanel = Ext.create("PartKeepr.BaseGrid", { 12 store: PartKeepr.getApplication().getSiPrefixStore(), 13 selModel: sm, 14 columnLines: true, 15 columns: [ 16 { text: i18n("Prefix"), dataIndex: "prefix", width: 60 }, 17 { text: i18n("Symbol"), dataIndex: "symbol", width: 60 }, 18 { text: i18n("Power"), dataIndex: "exponent", flex: 1, renderer: function (value,m,rec) { return rec.get("base")+"<sup>"+value+"</sup>"; } } 19 ] 20 }); 21 22 var container = Ext.create("Ext.form.FieldContainer", { 23 fieldLabel: i18n("Allowed SI-Prefixes"), 24 labelWidth: 150, 25 items: this.gridPanel 26 }); 27 28 this.items = [{ 29 xtype: 'textfield', 30 name: 'name', 31 fieldLabel: i18n("Unit Name") 32 },{ 33 xtype: 'textfield', 34 name: 'symbol', 35 fieldLabel: i18n("Symbol") 36 }, 37 container]; 38 39 this.callParent(); 40 41 this.on("startEdit", this.onStartEdit, this); 42 this.on("itemSave", this.onItemSave, this); 43 }, 44 onStartEdit: function () { 45 var records = this.record.prefixes().getRange(); 46 var toSelect = []; 47 var pfxStore = PartKeepr.getApplication().getSiPrefixStore(); 48 49 for (var i=0;i<records.length;i++) { 50 toSelect.push(pfxStore.getById(records[i].getId())); 51 } 52 53 this.gridPanel.getSelectionModel().select(toSelect); 54 }, 55 onItemSave: function () { 56 var selection = this.gridPanel.getSelectionModel().getSelection(); 57 58 this.record.prefixes().removeAll(true); 59 60 for (var i=0;i<selection.length;i++) { 61 this.record.prefixes().add(selection[i]); 62 } 63 } 64 });