PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/controls/checkbox_control.js

https://github.com/ajanthanm/cssfilterlab
JavaScript | 61 lines | 33 code | 13 blank | 15 comment | 3 complexity | d72f6a7499d9ef01a147f4097c6cab82 MD5 | raw file
 1/*
 2 * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
 3 * 
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 * 
 8 *     http://www.apache.org/licenses/LICENSE-2.0
 9 * 
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17(function() {
18
19    function CheckboxControl(delegate, name, config) {
20        CheckboxControl.$super.call(this, delegate, name, config);
21        this.init();
22    }
23
24    CheckboxControl.lastEditorId = 0;
25
26    Global.Utils.extend(CheckboxControl).from(Global.BaseControl);
27
28    CheckboxControl.prototype.init = function() {
29        var self = this,
30            name = "checkbox-" + this.name + (CheckboxControl.lastEditorId++);
31        this.ctrl = $("<input type='checkbox' />")
32                    .attr("id", name)
33                    .attr("name", name);
34        this.ctrlLabel = $("<label />").attr("for", name).html("&nbsp;");
35
36        this.ctrlParent = $("<div >").append(this.ctrl).append(this.ctrlLabel);
37
38        this.ctrl.bind("change blur", function () { self._onChange(); });
39    }
40
41    CheckboxControl.prototype._onChange = function() {
42        var val = this.ctrl.attr("checked") == "checked";
43        this.setValue(val ? 1 : 0, false);
44    };
45
46    CheckboxControl.prototype._updateControls = function() {
47        var value = this.getValue();
48        if (!value)
49            this.ctrl.removeAttr("checked");
50        else    
51            this.ctrl.attr("checked", "checked");
52    }
53
54    CheckboxControl.prototype.pushControls = function(parent) {
55        this.pushTableColumns(parent, this.ctrlParent);
56    }
57
58    Global.Controls.register("checkbox", CheckboxControl);
59
60
61})();