partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 5033e523bba3cb3c8c5fccdd90106c15e73d8a9b
parent ef731e125d9f5ac640789ae7971e653abbb04cac
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri,  4 Sep 2015 20:05:23 +0200

Reworked Part Manufacturer Grid to operate on objects only

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartManufacturerGrid.js | 194++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 104 insertions(+), 90 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartManufacturerGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/Editor/PartManufacturerGrid.js @@ -1,99 +1,113 @@ Ext.define('PartKeepr.PartManufacturerGrid', { - extend: 'PartKeepr.BaseGrid', - alias: 'widget.PartManufacturerGrid', - border: false, - initComponent: function () { - this.store = Ext.create("Ext.data.Store", { - model: 'PartKeepr.PartBundle.Entity.PartManufacturer', - proxy: { - type: 'memory', - reader: { - type: 'json' - } - } - - }); - - this.editing = Ext.create('Ext.grid.plugin.RowEditing', { + extend: 'PartKeepr.BaseGrid', + alias: 'widget.PartManufacturerGrid', + border: false, + initComponent: function () + { + this.store = Ext.create("Ext.data.Store", { + model: 'PartKeepr.PartBundle.Entity.PartManufacturer', + proxy: { + type: 'memory', + reader: { + type: 'json' + } + } + + }); + + this.editing = Ext.create('Ext.grid.plugin.RowEditing', { clicksToEdit: 1 }); - - this.plugins = [ this.editing ]; - - this.deleteButton = Ext.create("Ext.button.Button", { - text: 'Delete', - disabled: true, - itemId: 'delete', - scope: this, - icon: 'resources/silkicons/building_delete.png', - handler: this.onDeleteClick - }); - - this.dockedItems = [{ - xtype: 'toolbar', - items: [{ - text: 'Add', - scope: this, - icon: 'resources/silkicons/building_add.png', - handler: this.onAddClick - }, this.deleteButton] - }]; - - this.columns = [ - { - header: i18n("Manufacturer"), - dataIndex: 'manufacturer_id', - xtype: 'templatecolumn', - tpl: '{manufacturer_name}', - flex: 0.4, - editor: { - xtype:'ManufacturerComboBox', - allowBlank:true - } - }, - { - header: i18n("Part Number"), - dataIndex: 'partNumber', - flex: 0.4, - editor: { - xtype:'textfield', - allowBlank:true - } - } - ]; - - this.callParent(); - - this.getSelectionModel().on('selectionchange', this.onSelectChange, this); - this.on("edit", this.onEdit, this); - }, - onEdit: function (editor, data) { - var id = data.record.get("manufacturer_id"); - - var rec = PartKeepr.getApplication().getManufacturerStore().findRecord("id", id); - - if (rec) { - data.record.set("manufacturer_name", rec.get("name")); - } - }, - onAddClick: function () { - this.editing.cancelEdit(); - - var rec = new PartKeepr.PartBundle.Entity.PartManufacturer({ - packagingUnit: 1 - }); - - this.store.insert(0, rec); - - this.editing.startEdit(0,0); - }, - onDeleteClick: function () { - var selection = this.getView().getSelectionModel().getSelection()[0]; + + this.plugins = [this.editing]; + + this.deleteButton = Ext.create("Ext.button.Button", { + text: 'Delete', + disabled: true, + itemId: 'delete', + scope: this, + icon: 'resources/silkicons/building_delete.png', + handler: this.onDeleteClick + }); + + this.dockedItems = [ + { + xtype: 'toolbar', + items: [ + { + text: 'Add', + scope: this, + icon: 'resources/silkicons/building_add.png', + handler: this.onAddClick + }, this.deleteButton + ] + } + ]; + + this.columns = [ + { + header: i18n("Manufacturer"), + dataIndex: 'manufacturer', + flex: 0.4, + renderer: function (val, p, rec) + { + if (rec.getManufacturer() !== null) { + return rec.getManufacturer().get("name"); + } else { + return null; + } + }, + editor: { + xtype: 'ManufacturerComboBox', + allowBlank: true, + returnObject: true + } + }, + { + header: i18n("Part Number"), + dataIndex: 'partNumber', + flex: 0.4, + editor: { + xtype: 'textfield', + allowBlank: true + } + } + ]; + + this.callParent(); + + this.getSelectionModel().on('selectionchange', this.onSelectChange, this); + this.on("edit", this.onEdit, this); + }, + onEdit: function (editor, data) + { + var id = data.record.get("manufacturer_id"); + + var rec = PartKeepr.getApplication().getManufacturerStore().findRecord("id", id); + + if (rec) { + data.record.set("manufacturer_name", rec.get("name")); + } + }, + onAddClick: function () + { + this.editing.cancelEdit(); + + var rec = Ext.create("PartKeepr.PartBundle.Entity.PartManufacturer"); + + this.store.insert(0, rec); + + this.editing.startEdit(0, 0); + }, + onDeleteClick: function () + { + var selection = this.getView().getSelectionModel().getSelection()[0]; if (selection) { this.store.remove(selection); } - }, - onSelectChange: function(selModel, selections){ + }, + onSelectChange: function (selModel, selections) + { this.deleteButton.setDisabled(selections.length === 0); } }); \ No newline at end of file