From dc3160190580ce9985e8c10d45b9ea06d16355fe Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 13 Feb 2009 16:15:58 +0000 Subject: [PATCH] when no field order is defined but fields existin in the markup, start there with the order git-svn-id: svn://svn.open-ils.org/ILS/trunk@12172 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/dojo/openils/widget/AutoGrid.js | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 63ea180081..7607726e9f 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -19,36 +19,61 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { showSequenceFields : false, startup : function() { - this.selectionMode = 'single'; this.inherited(arguments); this.initAutoEnv(); + this.setStructure(this._compileStructure()); + this.setStore(this.buildAutoStore()); + if(this.editOnEnter) + this._applyEditOnEnter(); + }, + + _compileStructure : function() { var existing = (this.structure && this.structure[0].cells[0]) ? this.structure[0].cells[0] : []; var fields = []; + var self = this; + function pushEntry(entry) { + if(!entry.get) + entry.get = openils.widget.AutoGrid.defaultGetter + if(!entry.width && self.defaultCellWidth) + entry.width = self.defaultCellWidth; + fields.push(entry); + } + + if(!this.fieldOrder) { + /* no order defined, start with any explicit grid fields */ + for(var e in existing) { + var entry = existing[e]; + var field = this.fmIDL.fields.filter( + function(i){return (i.name == entry.field)})[0]; + if(field) entry.name = entry.name || field.label; + pushEntry(entry); + } + } + for(var f in this.sortedFieldList) { var field = this.sortedFieldList[f]; if(!field || field.virtual) continue; + + // field was already added above + if(fields.filter(function(i){return (i.field == field.name)})[0]) + continue; + + if(!this.showSequenceFields && field.name == this.fmIDL.pkey && this.fmIDL.pkey_sequence) continue; - var entry = existing.filter( - function(i){return (i.field == field.name)})[0]; + var entry = existing.filter(function(i){return (i.field == field.name)})[0]; if(entry) entry.name = field.label; else entry = {field:field.name, name:field.label}; - fields.push(entry); - if(!entry.get) - entry.get = openils.widget.AutoGrid.defaultGetter - if(!entry.width && this.defaultCellWidth) - entry.width = this.defaultCellWidth; + pushEntry(entry); } - this.setStructure([{cells: [fields]}]); - this.setStore(this.buildAutoStore()); - if(this.editOnEnter) - this._applyEditOnEnter(); + return [{cells: [fields]}]; }, + /* capture keydown and launch edit dialog on enter */ _applyEditOnEnter : function() { -- 2.43.2