Remoto - VFS: booleanWidget.js Source File
Remoto - VFS
booleanWidget.js
Go to the documentation of this file.
1 
2 
3 define( [
4  'remoto!stdlib:js/widgets/widget.js',
5  ],
6  function(widget)
7  {
8  'use strict';
9 
33  booleanWidget.prototype = new widget;
34  function booleanWidget( d )
35  {
36  d.value = (d.value === "true" || d.value === true);
37 
38  widget.call(this,d);
39 
40  this._arrowAt = "left-2 bottom+3";
41  }
42 
54  booleanWidget.prototype.createWidget = function()
55  {
56  if (this._widgetJq) return this._widgetJq;
57 
58  this._widgetJq = $("<input class='widgetInputField' id='"+this._id+"' type='checkbox' value='"+(this._value?"true":"false")+"' "+(this._value?"checked":"")+" />");
59 
60  if (this._options["enabled"]!==true || !this._enabled)
61  this.enabled = false;
62 
63  if (this._options.text)
64  { var d = $("<div style='white-space: nowrap;'>").append(this._widgetJq);
65  var t = $("<span>").addClass("widgetLabel").text(this._options.text).appendTo(d);
66  t.css( { display: "inline-block",
67  //text-overflow: "ellipsis",
68  //overflow: "hidden",
69  width: "unset",
70  "white-space": "normal",
71  "text-align": "left",
72  } );
73  return d;
74  }
75  else
76  return this._widgetJq;
77  }
78 
86  booleanWidget.prototype.activate = function()
87  {
88  if (this._widgetJq && this._change)
89  { this._widgetJq.bind("change", this.sync.bind(this));
90  this._widgetJq.bind("click", function(e) { e.stopPropagation(); } ); //don't preventDefault() here, which would effectively disable the widget
91  }
92 
93  //this.validate();
94  }
95 
102  booleanWidget.prototype.sync = function()
103  {
104  var v = this._widgetJq.val();
105 
106  this.value = (v === "true") ? false : true; //toggler
107 
108  return false;
109  }
110 
122  booleanWidget.prototype.__defineGetter__("value", function()
123  {
124  return this._value === true;
125  } );
126 
133  booleanWidget.prototype.__defineSetter__("value", function(v)
134  {
135  if (v === true || v === "true") v = true;
136  else v = false;
137 
138  if (v)
139  this._widgetJq[0].checked = true;
140  else
141  this._widgetJq[0].checked = false;
142 
143  return widget.prototype.__lookupSetter__("value").call(this,v);
144  } );
145 
148  return booleanWidget;
149  }
150 );
151 
A checkbox/boolean widget.
sync()
Sync the visible value with the internal value.
activate()
Activate the widget, which will cause changes to propagate to the form, and therefore the submit() me...
createWidget()
Create the widget jQuery object.
setter value
a setter DOCME
setter widget
a setter DOCME
Base class for GUI form widgets.
getter enabled
Return true or false based on _enabled state.
sync()
Sync the visible value with the internal value.