[open-ils-commits] r11941 - trunk/Open-ILS/web/js/dojo/openils/widget

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Jan 23 18:33:12 EST 2009


Author: erickson
Date: 2009-01-23 18:33:07 -0500 (Fri, 23 Jan 2009)
New Revision: 11941

Modified:
   trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
   trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
   trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
Log:
added a default gettier for common fieldmapper datatypes

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2009-01-23 22:20:49 UTC (rev 11940)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2009-01-23 23:33:07 UTC (rev 11941)
@@ -29,7 +29,7 @@
             if(!this.idlField) {
                 if(this.fmObject)
                     this.fmClass = this.fmObject.classname;
-                var fields = fieldmapper.IDL.fmclasses[this.fmClass][fields];
+                var fields = fieldmapper.IDL.fmclasses[this.fmClass].fields;
                 for(var f in fields) 
                     if(fields[f].name == this.fmField)
                         this.idlField = fields[f];
@@ -50,17 +50,35 @@
                     return value;
             }
         },
+        
+        getDisplayString : function() {
+            var value = this.widgetValue;
+            switch(this.idlField.datatype) {
+                case 'bool':
+                    return (value) ? 'True' : 'False'; // XXX i18n!
+                case 'timestamp':
+                    dojo.require('dojo.date.locale');
+                    dojo.require('dojo.date.stamp');
+                    var date = dojo.date.stamp.fromISOString(value);
+                    return dojo.date.locale.format(date, {formatLength:'short'});
+                case 'org_unit':
+                    return fieldmapper.aou.findOrgUnit(value).shortname();
+                default:
+                    return value;
+            }
+        },
 
         build : function(onload) {
             this.onload = onload;
-            this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null;
+            if(this.widgetValue == null)
+                this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null;
 
             switch(this.idlField.datatype) {
                 
                 case 'id':
                     dojo.require('dijit.form.TextBox');
                     this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode);
-                    this.widget.setDisabled(true); // never allow editing of IDs
+                    this.widget.attr('disabled', true); // never allow editing of IDs
                     break;
 
                 case 'org_unit':
@@ -99,7 +117,7 @@
          * For widgets that run asynchronously, provide a callback for finishing up
          */
         _widgetLoaded : function(value) {
-            if(this.fmObject) 
+            if(this.widgetValue != null) 
                 this.widget.attr('value', this.widgetValue);
             if(this.onload)
                 this.onload(this.widget, self);

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js	2009-01-23 22:20:49 UTC (rev 11940)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js	2009-01-23 23:33:07 UTC (rev 11941)
@@ -2,6 +2,7 @@
     dojo.provide('openils.widget.AutoGrid');
     dojo.require('dojox.grid.DataGrid');
     dojo.require('openils.widget.AutoWidget');
+    dojo.require('openils.widget.AutoFieldWidget');
     dojo.require('openils.Util');
 
     dojo.declare(
@@ -20,12 +21,26 @@
                     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
                 }
                 this.setStructure([{cells: [fields]}]);
                 this.setStore(this.buildAutoStore());
             },
+
         }
     );
     openils.widget.AutoGrid.markupFactory = dojox.grid.DataGrid.markupFactory;
+
+    openils.widget.AutoGrid.defaultGetter = function(rowIndex, item) {
+        if(!item) return '';
+        var val = this.grid.store.getValue(item, this.field);
+        var autoWidget = new openils.widget.AutoFieldWidget({
+            fmClass: this.grid.fmClass,
+            fmField: this.field,
+            widgetValue : val,
+        });
+        return autoWidget.getDisplayString();
+    }
 }
 

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js	2009-01-23 22:20:49 UTC (rev 11940)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js	2009-01-23 23:33:07 UTC (rev 11941)
@@ -42,7 +42,7 @@
                 this.inherited(arguments);
             },
 
-            // Compile the tree down to a dept-first list of nodes
+            // Compile the tree down to a depth-first list of nodes
             _makeNodeList : function(node) {
                 this.dataList.push(node);
                 for(var i in node[this.childField]()) 



More information about the open-ils-commits mailing list