[open-ils-commits] r12172 - trunk/Open-ILS/web/js/dojo/openils/widget (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Feb 13 11:16:00 EST 2009


Author: erickson
Date: 2009-02-13 11:15:58 -0500 (Fri, 13 Feb 2009)
New Revision: 12172

Modified:
   trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
Log:
when no field order is defined but fields existin in the markup, start there with the order

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js	2009-02-13 16:15:14 UTC (rev 12171)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js	2009-02-13 16:15:58 UTC (rev 12172)
@@ -19,36 +19,61 @@
             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() {
 



More information about the open-ils-commits mailing list