summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js
Unidiff
Diffstat (limited to 'frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js b/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js
new file mode 100644
index 0000000..681b847
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/grid/editor/CheckboxEditor.js
@@ -0,0 +1,60 @@
1/**
2 * @class YAHOO.ext.grid.CheckboxEditor
3 * @extends YAHOO.ext.grid.CellEditor
4Provides a checkbox for editing boolean values. It currently has no configuration options.<br><br>
5For more information on using this editor, see <a href="http://www.jackslocum.com/yui/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/">this blog post</a>.
6* @constructor
7* Create a new CheckboxEditor
8 */
9YAHOO.ext.grid.CheckboxEditor = function(){
10 var div = document.createElement('span');
11 div.className = 'ygrid-editor ygrid-checkbox-editor';
12 var cb = document.createElement('input');
13 cb.type = 'checkbox';
14 cb.setAttribute('autocomplete', 'off');
15 div.appendChild(cb);
16 document.body.appendChild(div);
17 YAHOO.ext.grid.CheckboxEditor.superclass.constructor.call(this, div);
18 div.tabIndex = '';
19 cb.tabIndex = 1;
20 this.cb = getEl(cb, true);
21};
22
23YAHOO.extendX(YAHOO.ext.grid.CheckboxEditor, YAHOO.ext.grid.CellEditor);
24
25YAHOO.ext.grid.CheckboxEditor.prototype.fitToCell = function(box){
26 this.element.setBox(box, true);
27};
28
29YAHOO.ext.grid.CheckboxEditor.prototype.setValue = function(value){
30 this.cb.dom.checked = (value === true || value === 'true' || value === 1 || value === '1');
31};
32
33YAHOO.ext.grid.CheckboxEditor.prototype.getValue = function(){
34 return this.cb.dom.checked;
35};
36
37YAHOO.ext.grid.CheckboxEditor.prototype.show = function(){
38 this.element.show();
39 this.cb.focus();
40};
41
42YAHOO.ext.grid.CheckboxEditor.prototype.initEvents = function(){
43 var stopOnEnter = function(e){
44 if(e.browserEvent.keyCode == e.RETURN){
45 this.stopEditing(true);
46 }else if(e.browserEvent.keyCode == e.ESC){
47 this.setValue(this.originalValue);
48 this.stopEditing(true);
49 }
50 }
51 this.cb.mon('keydown', stopOnEnter, this, true);
52 this.cb.on('blur', this.stopEditing, this, true);
53};
54
55YAHOO.ext.grid.CheckboxEditor.prototype.hide = function(){
56 try{
57 this.cb.dom.blur();
58 }catch(e){}
59 this.element.hide();
60};