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];
40 * Turn the value from the dojo widget into a value oils understands
42 getFormattedValue : function() {
43 var value = this.widget.attr('value');
44 switch(this.idlField.datatype) {
46 return (value) ? 't' : 'f'
48 return dojo.date.stamp.toISOString(value);
54 build : function(onload) {
56 this.widgetValue = (this.fmObject) ? this.fmObject[this.idlField.name]() : null;
58 switch(this.idlField.datatype) {
61 dojo.require('dijit.form.TextBox');
62 this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode);
63 this.widget.setDisabled(true); // never allow editing of IDs
67 this._buildOrgSelector();
71 dojo.require('dijit.form.CurrencyTextBox');
72 this.widget = new dijit.form.CurrencyTextBox(this.dijitArgs, this.parentNode);
76 dojo.require('dijit.form.DateTextBox');
77 dojo.require('dojo.date.stamp');
78 this.widget = new dijit.form.DateTextBox(this.dijitArgs, this.parentNode);
79 if(this.widgetValue != null)
80 this.widgetValue = dojo.date.stamp.fromISOString(this.widgetValue);
84 dojo.require('dijit.form.CheckBox');
85 this.widget = new dijit.form.CheckBox(this.dijitArgs, this.parentNode);
86 this.widgetValue = openils.Util.isTrue(this.widgetValue);
90 dojo.require('dijit.form.TextBox');
91 this.widget = new dijit.form.TextBox(this.dijitArgs, this.parentNode);
94 if(!this.async) this._widgetLoaded();
99 * For widgets that run asynchronously, provide a callback for finishing up
101 _widgetLoaded : function(value) {
103 this.widget.attr('value', this.widgetValue);
105 this.onload(this.widget, self);
108 _buildOrgSelector : function() {
109 dojo.require('fieldmapper.OrgUtils');
110 dojo.require('openils.widget.FilteringTreeSelect');
111 this.widget = new openils.widget.FilteringTreeSelect(this.dijitArgs, this.parentNode);
112 this.widget.searchAttr = 'shortname';
114 // if we have a limit perm, find the relevent orgs (async)
115 if(this.orgLimitPerms && this.orgLimitPerms.length > 0) {
117 var user = new openils.User();
119 user.getPermOrgList(this.orgLimitPerms,
121 self.widget.tree = orgList;
122 self.widget.startup();
123 self._widgetLoaded();
128 this.widget.tree = fieldmapper.aou.globalOrgTree;