1 if(!dojo._hasResource['openils.widget.AutoWidget']) {
2 dojo.provide('openils.widget.AutoWidget');
3 dojo.require('openils.Util');
4 dojo.require('openils.User');
5 dojo.require('fieldmapper.IDL');
7 dojo.declare('openils.widget.AutoWidget', null, {
13 * idlField -- Field description object from fieldmapper.IDL.fmclasses
14 * fmObject -- If available, the object being edited. This will be used
15 * to set the value of the widget.
16 * fmClass -- Class name (not required if idlField or fmObject is set)
17 * fmField -- Field name (not required if idlField)
18 * parentNode -- If defined, the widget will be appended to this DOM node
19 * dijitArgs -- Optional parameters object, passed directly to the dojo widget
20 * orgLimitPerms -- If this field defines a set of org units and an orgLimitPerms
21 * is defined, the code will limit the org units in the set to those
22 * allowed by the permission
24 constructor : function(args) {
28 // find the field description in the IDL if not provided
31 this.fmClass = this.fmObject.classname;
32 var fields = fieldmapper.IDL.fmclasses[this.fmClass][fields];
34 if(fields[f].name == this.fmField)
35 this.idlField = fields[f];
39 build : function(onload) {
41 this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null;
43 switch(this.idlField.datatype) {
46 dojo.require('dijit.form.TextBox');
47 this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode);
48 this.widget.setDisabled(true); // never allow editing of IDs
52 this._buildOrgSelector();
56 dojo.require('dijit.form.CurrencyTextBox');
57 this.widget = new dijit.form.CurrencyTextBox(this.dijitArgs, this.parentNode);
61 dojo.require('dijit.form.DateTextBox');
62 dojo.require('dojo.date.stamp');
63 this.widget = new dijit.form.DateTextBox(this.dijitArgs, this.parentNode);
64 if(this.widgetValue != null)
65 this.widgetValue = dojo.date.stamp.fromISOString(this.widgetValue);
69 dojo.require('dijit.form.CheckBox');
70 this.widget = new dijit.form.CheckBox(this.dijitArgs, this.parentNode);
71 this.widgetValue = openils.Util.isTrue(this.widgetValue);
75 dojo.require('dijit.form.TextBox');
76 this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode);
79 if(!this.async) this._widgetLoaded();
84 * For widgets that run asynchronously, provide a callback for finishing up
86 _widgetLoaded : function(value) {
88 this.widget.attr('value', this.widgetValue);
90 this.onload(this.widget, self);
93 _buildOrgSelector : function() {
94 dojo.require('fieldmapper.OrgUtils');
95 dojo.require('openils.widget.FilteringTreeSelect');
96 this.widget = new openils.widget.FilteringTreeSelect(this.dijitArgs, this.parentNode);
97 this.widget.searchAttr = 'shortname';
99 // if we have a limit perm, find the relevent orgs (async)
100 if(this.orgLimitPerms && this.orgLimitPerms.length > 0) {
102 var user = new openils.User();
104 user.getPermOrgList(this.orgLimitPerms,
106 self.widget.tree = orgList;
107 self.widget.startup();
108 self._widgetLoaded();
113 this.widget.tree = fieldmapper.aou.globalOrgTree;