added feauture to org unit settings interface to display friendly values and selector...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 29 Oct 2009 18:55:18 +0000 (18:55 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 29 Oct 2009 18:55:18 +0000 (18:55 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@14681 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Open-ILS/xul/staff_client/server/admin/org_unit_settings.js
Open-ILS/xul/staff_client/server/admin/org_unit_settings.xhtml

index 1d56b17..7283f0a 100644 (file)
@@ -22,6 +22,11 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
          *  orgLimitPerms -- If this field defines a set of org units and an orgLimitPerms 
          *      is defined, the code will limit the org units in the set to those
          *      allowed by the permission
+         *  selfReference -- The primary purpose of an AutoFieldWidget is to render the value
+         *      or widget for a field on an object (that may or may not link to another object).
+         *      selfReference allows you to sidestep the indirection and create a selector widget
+         *      based purely on an fmClass.  To get a dropdown of all of the 'abc'
+         *      objects, pass in {selfReference : true, fmClass : 'abc'}.  
          */
         constructor : function(args) {
             for(var k in args)
@@ -33,12 +38,27 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             this.fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
             this.suppressLinkedFields = args.suppressLinkedFields || [];
 
-            if(!this.idlField) {
-                this.fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
-                var fields = this.fmIDL.fields;
-                for(var f in fields) 
-                    if(fields[f].name == this.fmField)
-                        this.idlField = fields[f];
+            if(this.selfReference) {
+                this.fmField = fieldmapper.IDL.fmclasses[this.fmClass].pkey;
+                
+                // create a mock-up of the idlField object.  
+                this.idlField = {
+                    datatype : 'link',
+                    'class' : this.fmClass,
+                    reltype : 'has_a',
+                    key : this.fmField,
+                    name : this.fmField
+                };
+
+            } else {
+
+                if(!this.idlField) {
+                    this.fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
+                    var fields = this.fmIDL.fields;
+                    for(var f in fields) 
+                        if(fields[f].name == this.fmField)
+                            this.idlField = fields[f];
+                }
             }
 
             if(!this.idlField) 
@@ -355,7 +375,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             } else {
 
                 this.baseWidgetValue(this.widgetValue);
-                if(this.idlField.name == this.fmIDL.pkey && this.fmIDL.pkey_sequence)
+                if(this.idlField.name == this.fmIDL.pkey && this.fmIDL.pkey_sequence && !this.selfReference)
                     this.widget.attr('disabled', true); 
                 if(this.disableWidgetTest && this.disableWidgetTest(this.idlField.name, this.fmObject))
                     this.widget.attr('disabled', true); 
index f7a2152..fae50a1 100644 (file)
@@ -1,3 +1,4 @@
+dojo.require('fieldmapper.AutoIDL');
 dojo.require("dijit.layout.LayoutContainer");
 dojo.require("dijit.layout.ContentPane");
 dojo.require('dijit.form.FilteringSelect');
@@ -12,17 +13,20 @@ dojo.require('openils.User');
 dojo.require('openils.Event');
 dojo.require('openils.widget.OrgUnitFilteringSelect');
 dojo.require('openils.PermaCrud');
+dojo.require('openils.widget.AutoFieldWidget');
 
 var authtoken;
 var contextOrg;
 var user;
 var workOrgs;
 var osSettings = {};
+var osEditAutoWidget;
 
 function osInit(data) {
-    authtoken = dojo.cookie('ses') || new openils.CGI().param('ses');
+    authtoken = new openils.CGI().param('ses') || dojo.cookie('ses');
     user = new openils.User({authtoken:authtoken});
     contextOrg = user.user.ws_ou();
+    openils.User.authtoken = authtoken;
 
     fieldmapper.standardRequest(
         [   'open-ils.actor',
@@ -149,6 +153,7 @@ function osGetGridData(rowIdx) {
     var setting = osSettings[data.name];
     var value = setting[this.field];
     if(value == null) return '';
+
     switch(this.field) {
         case 'context':
             return fieldmapper.aou.findOrgUnit(value).shortname();
@@ -157,6 +162,21 @@ function osGetGridData(rowIdx) {
                 return value + ' *';
             return value;
         case 'value':
+            if(setting.fm_class) {
+                var autoWidget = new openils.widget.AutoFieldWidget(
+                    {
+                        fmClass : setting.fm_class,
+                        selfReference : true,
+                        widgetValue : value,
+                        forceSync : true,
+                        readOnly : true
+                    }
+                );
+                autoWidget.build();
+                if(autoWidget.getDisplayString())
+                    return autoWidget.getDisplayString();
+            }
+
             if(setting.type == 'bool') {
                 if(value) 
                     return dojo.byId('os-true').innerHTML;
@@ -192,51 +212,86 @@ function osLaunchEditor(name) {
     dojo.style(osEditNumberTextBox.domNode, 'display', 'none');
     dojo.style(osEditBoolSelect.domNode, 'display', 'none');
 
-    var widget;
-    switch(osSettings[name].type) {
-        case 'number':
-            widget = osEditNumberTextBox; 
-            break;
-        case 'currency':
-            widget = osEditCurrencyTextBox; 
-            break;
-        case 'bool':
-            widget = osEditBoolSelect; 
-            break;
-        default:
-            widget = osEditTextBox;
-    }
+    var fmClass = osSettings[name].fm_class;
 
-    dojo.style(widget.domNode, 'display', 'block');
-    widget.setValue(osSettings[name].value);
-}
+    if(fmClass) {
 
-function osEditSetting(deleteMe) {
-    osEditDialog.hide();
-    var name = osEditDialog._osattr;
+        if(osEditAutoWidget) {
+            osEditAutoWidget.domNode.parentNode.removeChild(osEditAutoWidget.domNode);
+            osEditAutoWidget.destroy();
+        }
 
-    var obj = {};
-    if(deleteMe) {
-        obj[name] = null;
+        var autoWidget = new openils.widget.AutoFieldWidget(
+            {
+                fmClass : fmClass,
+                selfReference : true,
+                parentNode : dojo.create('div', null, dojo.byId('os-edit-auto-widget')),
+                widgetValue : osSettings[name].value
+            }
+        );
+        autoWidget.build(
+            function(w) {
+                osEditAutoWidget = w;
+            }
+        );
 
     } else {
-
+        var widget;
         switch(osSettings[name].type) {
             case 'number':
-                obj[name] = osEditNumberTextBox.getValue();
-                if(obj[name] == null) return;
+                widget = osEditNumberTextBox; 
                 break;
             case 'currency':
-                obj[name] = osEditCurrencyTextBox.getValue();
-                if(obj[name] == null) return;
+                widget = osEditCurrencyTextBox; 
                 break;
             case 'bool':
-                var val = osEditBoolSelect.getValue();
-                obj[name] = (val == 'true') ? true : false;
+                widget = osEditBoolSelect; 
                 break;
             default:
-                obj[name] = osEditTextBox.getValue();
-                if(obj[name] == null) return;
+                widget = osEditTextBox;
+        }
+
+        dojo.style(widget.domNode, 'display', 'block');
+        widget.setValue(osSettings[name].value);
+    }
+}
+
+function osEditSetting(deleteMe) {
+    osEditDialog.hide();
+    var name = osEditDialog._osattr;
+
+    var obj = {};
+    if(deleteMe) {
+        obj[name] = null;
+
+    } else {
+
+        if(osSettings[name].fm_class) {
+            var val = osEditAutoWidget.attr('value');
+            osEditAutoWidget.domNode.parentNode.removeChild(osEditAutoWidget.domNode);
+            osEditAutoWidget.destroy();
+            osEditAutoWidget = null;
+            if(val == null || val == '') return;
+            obj[name] = val;
+
+        } else {
+            switch(osSettings[name].type) {
+                case 'number':
+                    obj[name] = osEditNumberTextBox.getValue();
+                    if(obj[name] == null) return;
+                    break;
+                case 'currency':
+                    obj[name] = osEditCurrencyTextBox.getValue();
+                    if(obj[name] == null) return;
+                    break;
+                case 'bool':
+                    var val = osEditBoolSelect.getValue();
+                    obj[name] = (val == 'true') ? true : false;
+                    break;
+                default:
+                    obj[name] = osEditTextBox.getValue();
+                    if(obj[name] == null) return;
+            }
         }
     }
 
index b054959..e8ad6a0 100644 (file)
@@ -85,6 +85,7 @@
                                 <option value='true'>&common.true;</option>
                                 <option value='false'>&common.false;</option>
                             </select>
+                            <div id='os-edit-auto-widget'></div>
                         </td>
                     </tr>
                     <tr>