From: erickson Date: Wed, 4 Feb 2009 16:43:03 +0000 (+0000) Subject: auto-grid now has the ability to pop up an edit dialog for the given fieldmapper... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a74c3a726da835582ce87c9421b0ff7adab5172f;p=evergreen%2Ftadl.git auto-grid now has the ability to pop up an edit dialog for the given fieldmapper object git-svn-id: svn://svn.open-ils.org/ILS/trunk@12063 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 2031309f8b..0fab1bc5de 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -3,12 +3,21 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { dojo.require('dojox.grid.DataGrid'); dojo.require('openils.widget.AutoWidget'); dojo.require('openils.widget.AutoFieldWidget'); + dojo.require('openils.widget.EditDialog'); dojo.require('openils.Util'); dojo.declare( 'openils.widget.AutoGrid', [dojox.grid.DataGrid, openils.widget.AutoWidget], { + + /* if true, pop up an edit dialog when user hits Enter on a give row */ + editOnEnter : false, + + /* maps dojo store items to fieldmapper objects, since the + * grid may not have access to all fm objects */ + storeItemObjectMapper : null, + startup : function() { this.inherited(arguments); this.initAutoEnv(); @@ -27,7 +36,43 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } this.setStructure([{cells: [fields]}]); this.setStore(this.buildAutoStore()); + if(this.editOnEnter) + this._applyEditOnEnter(); }, + + /* capture keydown and launch edit dialog on enter */ + _applyEditOnEnter : function() { + dojo.connect(this, 'onKeyDown', + function(e) { + if(e.keyCode == dojo.keys.ENTER) { + this.selection.deselectAll(); + this.selection.select(this.focus.rowIndex); + this._drawEditDialog(this.selection.getFirstSelected()); + } + } + ); + }, + + _drawEditDialog : function(storeItem) { + var grid = this; + var fmObject = this.storeItemObjectMapper(storeItem); + var idents = grid.store.getIdentityAttributes(); + var dialog = new openils.widget.EditDialog({ + fmObject:fmObject, + onPostApply : function() { + // update the grid store + for(var i in fmObject._fields) { + var field = fmObject._fields[i]; + if(idents.filter(function(j){return (j == field)})[0]) + continue; // don't try to edit an identifier field + grid.store.setValue(storeItem, field, fmObject[field]()); + } + } + }); + dialog.editPane.fieldOrder = this.fieldOrder; + dialog.startup(); + dialog.show(); + } } ); openils.widget.AutoGrid.markupFactory = dojox.grid.DataGrid.markupFactory;