partkeepr

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

commit d07294558e040bb2e1af1c1e4bc46676ae170dbd
parent 936ea9d92b18b06d7c6be24f46543c2545b51f12
Author: Felicitus <felicitus@felicitus.org>
Date:   Thu,  3 Sep 2015 20:37:55 +0200

Added support for direct association editing

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Bugfixes/Ext.data.Model-EXTJS-15037.js | 12++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.grid.plugin.CellEditing-associationSupport.js | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.grid.plugin.Editing-associationSupport.js | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Bugfixes/Ext.data.Model-EXTJS-15037.js b/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Bugfixes/Ext.data.Model-EXTJS-15037.js @@ -6,6 +6,18 @@ Ext.define("PartKeepr.data.Model", { override: 'Ext.data.Model', + hasField: function (fieldName) { + var fields = this.getFields(); + + + for (var i in fields) { + if (fields[i].name == fieldName && fields[i].reference === null) { + return true; + } + } + + return false; + }, /** * Saves the model instance using the configured proxy. * @param {Object} [options] Options to pass to the proxy. Config object for {@link Ext.data.operation.Operation}. diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.grid.plugin.CellEditing-associationSupport.js b/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.grid.plugin.CellEditing-associationSupport.js @@ -0,0 +1,51 @@ +/** + * Overrides the editing plugin to support editing of associations. + */ +Ext.define('PartKeepr.grid.plugin.CellEditing', { + alias: 'plugin.cellediting', + extend: 'Ext.grid.plugin.Editing', + override: 'Ext.grid.plugin.CellEditing', + requires: ['Ext.grid.CellEditor', 'Ext.util.DelayedTask'], + + onEditComplete: function (ed, value, startValue) + { + var me = this, + context = ed.context, + view, record; + + view = context.view; + record = context.record; + context.value = value; + if (!me.validateEdit(context)) { + me.editing = false; + return; + } + + // Only update the record if the new value is different than the + // startValue. When the view refreshes its el will gain focus + if (!record.isEqual(value, startValue)) { + if (record.hasField(context.column.dataIndex)) { + record.set(context.column.dataIndex, value); + } else { + if (record.associations[context.column.dataIndex]) { + var setterName = record.associations[context.column.dataIndex].setterName; + + record[setterName](value); + } + } + // Changing the record may impact the position + context.rowIdx = view.indexOf(record); + } + + me.fireEvent('edit', me, context); + + // We clear down our context here in response to the CellEditor completing. + // We only do this if we have not already started editing a new context. + if (me.context === context) { + me.setActiveEditor(null); + me.setActiveColumn(null); + me.setActiveRecord(null); + me.editing = false; + } + }, +}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.grid.plugin.Editing-associationSupport.js b/src/PartKeepr/FrontendBundle/Resources/public/js/ExtJS/Enhancements/Ext.grid.plugin.Editing-associationSupport.js @@ -0,0 +1,109 @@ +/** + * Overrides the editing plugin to support editing of associations. + */ +Ext.define('PartKeepr.grid.plugin.Editing', { + override: 'Ext.grid.plugin.Editing', + extend: 'Ext.plugin.Abstract', + alias: 'editing.editing', + + /** + * @private + * Collects all information necessary for any subclasses to perform their editing functions. + * @param {Ext.data.Model/Number} record The record or record index to edit. + * @param {Ext.grid.column.Column/Number} columnHeader The column of column index to edit. + * @return {Ext.grid.CellContext/undefined} The editing context based upon the passed record and column + */ + getEditingContext: function (record, columnHeader) + { + var me = this, + grid = me.grid, + colMgr = grid.visibleColumnManager, + view, + gridRow, + rowIdx, colIdx, + result, + layoutView = me.grid.lockable ? me.grid : me.view; + + // The view must have had a layout to show the editor correctly, defer until that time. + // In case a grid's startup code invokes editing immediately. + if (!layoutView.componentLayoutCounter) { + layoutView.on({ + boxready: Ext.Function.bind(me.startEdit, me, [record, columnHeader]), + single: true + }); + return; + } + + // If disabled or grid collapsed, or view not truly visible, don't calculate a context - we cannot edit + if (me.disabled || me.grid.collapsed || !me.grid.view.isVisible(true)) { + return; + } + + // They've asked to edit by column number. + // Note that in a locked grid, the columns are enumerated in a unified set for this purpose. + if (Ext.isNumber(columnHeader)) { + columnHeader = colMgr.getHeaderAtIndex(columnHeader); + } + + // No corresponding column. Possible if all columns have been moved to the other side of a lockable grid pair + if (!columnHeader) { + return; + } + + // Coerce the column to the closest visible column + if (columnHeader.hidden) { + columnHeader = columnHeader.next(':not([hidden])') || columnHeader.prev(':not([hidden])'); + } + + // Navigate to the view and grid which the column header relates to. + view = columnHeader.getView(); + grid = view.ownerCt; + + gridRow = view.getRow(record); + + // An intervening listener may have deleted the Record. + if (!gridRow) { + return; + } + + colIdx = colMgr.getHeaderIndex(columnHeader); + + if (Ext.isNumber(record)) { + // look up record if numeric row index was passed + rowIdx = record; + record = view.getRecord(gridRow); + } else { + rowIdx = view.indexOf(gridRow); + } + + // The record may be removed from the store but the view + // not yet updated, so check it exists + if (!record) { + return; + } + + // Create a new CellContext + result = new Ext.grid.CellContext(view).setAll(view, rowIdx, colIdx, record, columnHeader); + + // Add extra Editing information + result.grid = grid; + result.store = view.dataSource; + result.field = columnHeader.dataIndex; + + if (record.hasField(columnHeader.dataIndex)) { + result.value = result.originalValue = record.get(columnHeader.dataIndex); + } else { + if (record.associations[columnHeader.dataIndex]) { + var getterName = record.associations[columnHeader.dataIndex].getterName; + + result.value = result.originalValue = record[getterName](); + } + } + + result.row = gridRow; + result.node = view.getNode(record); + result.cell = view.getCellByPosition(result, true); + + return result; + }, +});+ \ No newline at end of file