[open-ils-commits] r11792 - in trunk/Open-ILS/web: css/skin js/dojo/openils/widget

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Jan 9 16:52:55 EST 2009


Author: erickson
Date: 2009-01-09 16:52:50 -0500 (Fri, 09 Jan 2009)
New Revision: 11792

Added:
   trunk/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js
   trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js
Modified:
   trunk/Open-ILS/web/css/skin/default.css
Log:
added initial auto-widget class.  this takes an IDL class and optional fieldmapper object and builds a dojo widget for editing the object.  still lots to do, but currently handles text/bool/timestamp/org-unit, and money.  added editdialog class for auto-creating popup editor for a given fm object.

Modified: trunk/Open-ILS/web/css/skin/default.css
===================================================================
--- trunk/Open-ILS/web/css/skin/default.css	2009-01-09 21:50:57 UTC (rev 11791)
+++ trunk/Open-ILS/web/css/skin/default.css	2009-01-09 21:52:50 UTC (rev 11792)
@@ -63,3 +63,5 @@
 .dijitTooltipTable td {padding: 3px;} /* custom class for handling dialog tables */
 /* ----------------------------------------------------------------- */
 
+
+.oils-fm-edit-dialog td { padding: 5px; }

Added: trunk/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js	                        (rev 0)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoWidget.js	2009-01-09 21:52:50 UTC (rev 11792)
@@ -0,0 +1,112 @@
+if(!dojo._hasResource['openils.widget.AutoWidget']) {
+    dojo.provide('openils.widget.AutoWidget');
+    dojo.require('openils.Util');
+    dojo.require('openils.User');
+    dojo.require('fieldmapper.IDL');
+
+    dojo.declare('openils.widget.AutoWidget', null, {
+
+        async : false,
+
+        /**
+         * args:
+         *  idlField -- Field description object from fieldmapper.IDL.fmclasses
+         *  fmObject -- If available, the object being edited.  This will be used 
+         *      to set the value of the widget.
+         *  fmClass -- Class name (not required if idlField or fmObject is set)
+         *  fmField -- Field name (not required if idlField)
+         *  parentNode -- If defined, the widget will be appended to this DOM node
+         *  dijitArgs -- Optional parameters object, passed directly to the dojo widget
+         *  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
+         */
+        constructor : function(args) {
+            for(var k in args)
+                this[k] = args[k];
+
+            // find the field description in the IDL if not provided
+            if(!this.idlField) {
+                if(this.fmObject)
+                    this.fmClass = this.fmObject.classname;
+                var fields = fieldmapper.IDL.fmclasses[this.fmClass][fields];
+                for(var f in fields) 
+                    if(fields[f].name == this.fmField)
+                        this.idlField = fields[f];
+            }
+        },
+
+        build : function(onload) {
+            this.onload = onload;
+            this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null;
+
+            switch(this.idlField.datatype) {
+
+                case 'org_unit':
+                    this._buildOrgSelector();
+                    break;
+
+                case 'money':
+                    dojo.require('dijit.form.CurrencyTextBox');
+                    this.widget = new dijit.form.CurrencyTextBox(this.dijitArgs, this.parentNode);
+                    break;
+
+                case 'timestamp':
+                    dojo.require('dijit.form.DateTextBox');
+                    dojo.require('dojo.date.stamp');
+                    this.widget = new dijit.form.DateTextBox(this.dijitArgs, this.parentNode);
+                    if(this.widgetValue != null) 
+                        this.widgetValue = dojo.date.stamp.fromISOString(this.widgetValue);
+                    break;
+
+                case 'bool':
+                    dojo.require('dijit.form.CheckBox');
+                    this.widget = new dijit.form.CheckBox(this.dijitArgs, this.parentNode);
+                    this.widgetValue = openils.Util.isTrue(this.widgetValue);
+                    break;
+
+                default:
+                    dojo.require('dijit.form.TextBox');
+                    this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode);
+            }
+
+            if(!this.async) this._widgetLoaded();
+            return this.widget;
+        },
+
+        /**
+         * For widgets that run asynchronously, provide a callback for finishing up
+         */
+        _widgetLoaded : function(value) {
+            if(this.fmObject) 
+                this.widget.attr('value', this.widgetValue);
+            if(this.onload)
+                this.onload(this.widget, self);
+        },
+
+        _buildOrgSelector : function() {
+            dojo.require('fieldmapper.OrgUtils');
+            dojo.require('openils.widget.FilteringTreeSelect');
+            this.widget = new openils.widget.FilteringTreeSelect(this.dijitArgs, this.parentNode);
+            this.widget.searchAttr = 'shortname';
+
+            // if we have a limit perm, find the relevent orgs (async)
+            if(this.orgLimitPerms && this.orgLimitPerms.length > 0) {
+                this.async = true;
+                var user = new openils.User();
+                var self = this;
+                user.getPermOrgList(this.orgLimitPerms, 
+                    function(orgList) {
+                        self.widget.tree = orgList;
+                        self.widget.startup();
+                        self._widgetLoaded();
+                    }
+                );
+
+            } else {
+                this.widget.tree = fieldmapper.aou.globalOrgTree;
+            }
+        }
+    });
+}
+

Added: trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js	                        (rev 0)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/EditDialog.js	2009-01-09 21:52:50 UTC (rev 11792)
@@ -0,0 +1,67 @@
+if(!dojo._hasResource['openils.widget.EditDialog']) {
+    dojo.provide('openils.widget.EditDialog');
+    dojo.require('openils.widget.AutoWidget');
+    dojo.require('fieldmapper.Fieldmapper');
+    dojo.require('dijit.Dialog');
+    dojo.require('openils.Util');
+    dojo.require('openils.User');
+    dojo.require('fieldmapper.IDL');
+
+
+    /**
+     * Given a fieldmapper object, this builds a pop-up dialog used for editing the object
+     */
+
+    dojo.declare(
+        'openils.widget.EditDialog',
+        [dijit.Dialog],
+        {
+            fmClass : '',
+            fmObject : null,
+            mode : 'update',
+
+            /**
+             * Builds a basic table of key / value pairs.  Keys are IDL display labels.
+             * Values are dijit's, when values set
+             */
+            startup : function() {
+                this.inherited(arguments);
+                this.fmClass = (this.fmObject) ? this.fmObject.classname : this.fmClass;
+                fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
+
+                var table = document.createElement('table');
+                var tbody = document.createElement('tbody');
+                this.domNode.appendChild(table);
+                table.appendChild(tbody);
+
+                this.limitPerms = [];
+                if(fmIDL.permacrud && fmIDL.permacrud[this.mode])
+                    this.limitPerms = fmIDL.permacrud[this.mode].perms;
+
+                for(var f in fmIDL.fields) {
+                    var field = fmIDL.fields[f];
+                    if(field.virtual) continue;
+
+                    var row = document.createElement('tr');
+                    var nameTd = document.createElement('td');
+                    var valTd = document.createElement('td');
+
+                    nameTd.appendChild(document.createTextNode(field.label));
+                    row.appendChild(nameTd);
+                    row.appendChild(valTd);
+                    tbody.appendChild(row);
+
+                    new openils.widget.AutoWidget({
+                        idlField : field, 
+                        fmObject : this.fmObject,
+                        parentNode : valTd,
+                        orgLimitPerms : this.limitPerms
+                    }).build();
+                }
+
+                openils.Util.addCSSClass(table, 'oils-fm-edit-dialog');
+            },
+        }
+    );
+}
+



More information about the open-ils-commits mailing list