1 if(!dojo._hasResource['openils.widget.AutoGrid']) {
2 dojo.provide('openils.widget.AutoGrid');
3 dojo.require('dojox.grid.DataGrid');
4 dojo.require('openils.widget.AutoWidget');
5 dojo.require('openils.widget.AutoFieldWidget');
6 dojo.require('openils.widget.EditDialog');
7 dojo.require('openils.Util');
10 'openils.widget.AutoGrid',
11 [dojox.grid.DataGrid, openils.widget.AutoWidget],
14 /* if true, pop up an edit dialog when user hits Enter on a give row */
17 startup : function() {
19 this.selectionMode = 'single';
20 this.inherited(arguments);
22 var existing = (this.structure && this.structure[0].cells[0]) ?
23 this.structure[0].cells[0] : [];
26 for(var f in this.sortedFieldList) {
27 var field = this.sortedFieldList[f];
28 if(!field || field.virtual) continue;
29 var entry = existing.filter(function(i){return (i.field == field.name)})[0];
30 if(entry) entry.name = field.label;
31 else entry = {field:field.name, name:field.label};
34 entry.get = openils.widget.AutoGrid.defaultGetter
37 this.setStructure([{cells: [fields]}]);
38 this.setStore(this.buildAutoStore());
40 this._applyEditOnEnter();
43 /* capture keydown and launch edit dialog on enter */
44 _applyEditOnEnter : function() {
46 this.onMouseOverRow = function(e) {};
47 this.onMouseOutRow = function(e) {};
48 this.onCellFocus = function(cell, rowIndex) {
49 this.selection.deselectAll();
50 this.selection.select(this.focus.rowIndex);
53 dojo.connect(this, 'onKeyDown',
55 if(e.keyCode == dojo.keys.ENTER) {
56 this.selection.deselectAll();
57 this.selection.select(this.focus.rowIndex);
58 this._drawEditDialog(this.selection.getFirstSelected(), this.focus.rowIndex);
64 _drawEditDialog : function(storeItem, rowIndex) {
66 var fmObject = new fieldmapper[this.fmClass]().fromStoreItem(storeItem);
67 var idents = grid.store.getIdentityAttributes();
68 var dialog = new openils.widget.EditDialog({
70 onPostApply : function() {
71 for(var i in fmObject._fields) {
72 var field = fmObject._fields[i];
73 if(idents.filter(function(j){return (j == field)})[0])
74 continue; // don't try to edit an identifier field
75 grid.store.setValue(storeItem, field, fmObject[field]());
81 dialog.editPane.fieldOrder = this.fieldOrder;
87 openils.widget.AutoGrid.markupFactory = dojox.grid.DataGrid.markupFactory;
89 openils.widget.AutoGrid.defaultGetter = function(rowIndex, item) {
91 var val = this.grid.store.getValue(item, this.field);
92 var autoWidget = new openils.widget.AutoFieldWidget({
93 fmClass: this.grid.fmClass,
97 return autoWidget.getDisplayString();