Remoto - VFS: groupWidget.js Source File
Remoto - VFS
groupWidget.js
Go to the documentation of this file.
1 
2 define( [
3  'remoto!stdlib:js/widgets/widget.js',
4  'remoto!stdlib:js/widgets/widgetFactory.js',
5  'remoto!stdlib:js/include/utils.js',
6  ],
7  function(widget,widgetFactory,utils)
8  {
9  'use strict';
10 
35  groupWidget.prototype = new widget;
36  function groupWidget( dd )
37  {
38  var value = dd.value || {};
39  this._children = {};
40 
41  dd.value = null;
42  dd.defaultValue = undefined;
43 
44  widget.call(this,dd);
45 
46  this._fixed = this._options.equal || false;
47  this._useValue = this._options.useValue === false ? false : true;
48 
49  var valueSorted = utils.sortObjectByMemberAttribute(value,"index");
50 
51  var v,c,d;
52  for (var __i=0;__i < valueSorted.length; __i++)
53  {
54  v = valueSorted[__i].__key;
55  c = value[v];
56 
57  d = utils.copyObject(c);
58  d.variable = v;
59  d.change = this.changeField.bind(this, d.change);
60 
61  var w = widgetFactory( d );
62 
63  if (w)
64  this._children[v] = w;
65  else
66  {
67  console.dir(d);
68  throw "Bad Widget: "+v;
69  }
70  }
71  }
72 
82  groupWidget.prototype.createWidget = function()
83  {
84  if (this._widgetJq) return this._widgetJq;
85 
86  var g = $("<div class='widgetGroup' id='"+this._id+"'/>");
87  var r = $("<div class='widgetGroupRow'/>").appendTo(g);
88 
89  if (this._fixed)
90  g.css("table-layout","fixed");
91 
92  var k,w,f;
93  for (var c in this._children)
94  {
95  k = this._children[c];
96 
97  /*
98  if (!k._options.hideLabel)
99  k.createLabel().appendTo(r);
100 
101  w = k._html = k.createWidget();
102  f = $("<div class='widgetField'>").append(w).appendTo(r);
103  f.attr("title",k._tip);
104  */
105  r.append( k.createHTML() );
106  }
107 
108  this._widgetJq = g;
109 
110  return this._widgetJq;
111  }
112 
128  groupWidget.prototype.changeField = function(childChange,variable,value,widget)
129  {
130  //console.error("FIELD CHANGE!",arguments);
131 
132  if (this._change)
133  {
134  var u = {};
135  if (this._useValue)
136  u[variable] = { value:value };
137  else
138  u[variable] = value;
139 
140  if (childChange)
141  childChange(variable,value,widget);
142 
143  this._change( this._variable, u, widget );
144  //this._change( this._variable+"."+variable, value, widget );
145  }
146  }
147 
156  groupWidget.prototype.activate = function()
157  {
158  //widget.prototype.activate.call(this);
159 
160  for (var c in this._children)
161  this._children[c].activate();
162 
163  //FIXME: should assign change to children so they trigger this change
164 
165  //if (this._widgetJq && this._change)
166  // this._widgetJq.bind("change input", this.sync.bind(this));
167  }
168 
177  groupWidget.prototype.deactivate = function()
178  {
179  //widget.prototype.deactivate.call(this);
180 
181  for (var c in this._children)
182  this._children[c].deactivate();
183 
184  //if (this._widgetJq)
185  // this._widget.unbind("change input");
186  }
187 
196  groupWidget.prototype.destroy = function()
197  {
198  for (var c in this._children)
199  this._children[c].destroy();
200 
201  widget.prototype.destroy.call(this);
202  }
203 
215  groupWidget.prototype.__defineGetter__( "value", function()
216  {
217  //return this._children;
218  /*
219  var v = {};
220  for (var c in this._children)
221  v[c] = this._children[c];
222 
223  return v;
224  */
225 
226  var v = {};
227  for (var c in this._children)
228  {
229  if (this._useValue)
230  { v[c] = { "value": this._children[c].value };
231  }
232  else
233  v[c] = this._children[c].value;
234  }
235  return v;
236  } );
237 
244  groupWidget.prototype.__defineSetter__( "value", function(v)
245  {
246  for (var c in v)
247  {
248  if (c in this._children)
249  {
250  this._children[c].activeUser = this._activeUser;
251 
252  if (this._immediate) this._children[c].immediateValue = (this._useValue && (typeof(v[c]) == "object") && ("value" in v[c])) ? v[c].value : v[c];
253  else this._children[c].value = (this._useValue && (typeof(v[c]) == "object") && ("value" in v[c])) ? v[c].value : v[c];
254  }
255  else
256  {
257  console.error("FIXME: need a group value setter that creates new attributes as needed.");
258  console.log(v);
259  }
260  }
261 
262  this._activeUser = null;
263 
264  return v;
265  } );
266 
273  groupWidget.prototype.__defineGetter__( "isDefault", function()
274  {
275  for (var c in this._children)
276  if (!this._children[c].isDefault)
277  return false;
278 
279  return true;
280  } );
281 
288  groupWidget.prototype.__defineGetter__( "nonDefaultValue", function()
289  {
290  var v = {};
291  var f = false;
292  var d = undefined;
293  for (var c in this._children)
294  { d = this._children[c].nonDefaultValue;
295  if (d !== undefined)
296  { v[c] = d;
297  f = true;
298  }
299  }
300 
301  return f ? {value:v} : undefined;
302  } );
303 
306  return groupWidget;
307  }
308 );
309 
310 
setter value
a setter DOCME
changeField(variable, value, widget)
A grouping widget which will put child widgets in a row instead of the normal form column.
changeField(childChange, variable, value, widget)
A change callback for widgets created within this group.
setter widget
a setter DOCME
Utility functions for javascript clients.
copyObject(source, dest)
Create a deep copy of a JSON object, extending the destination object recursively.
sortObjectByMemberAttribute(o, attr)
Sort an object by the value of an attribute of members of the object.
A factory and registry for loaded widget definitions.
widgetFactory(d)
Create a widget, if possible, or return a widgetLoader.
Base class for GUI form widgets.
getter isDefault
Return whether or not this widget's value is its default value.
destroy()
Destroy this widget.