/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. (function() {
  17. function CheckboxControl(delegate, name, config) {
  18. CheckboxControl.$super.call(this, delegate, name, config);
  19. this.init();
  20. }
  21. CheckboxControl.lastEditorId = 0;
  22. Global.Utils.extend(CheckboxControl).from(Global.BaseControl);
  23. CheckboxControl.prototype.init = function() {
  24. var self = this,
  25. name = "checkbox-" + this.name + (CheckboxControl.lastEditorId++);
  26. this.ctrl = $("<input type='checkbox' />")
  27. .attr("id", name)
  28. .attr("name", name);
  29. this.ctrlLabel = $("<label />").attr("for", name).html("&nbsp;");
  30. this.ctrlParent = $("<div >").append(this.ctrl).append(this.ctrlLabel);
  31. this.ctrl.bind("change blur", function () { self._onChange(); });
  32. }
  33. CheckboxControl.prototype._onChange = function() {
  34. var val = this.ctrl.attr("checked") == "checked";
  35. this.setValue(val ? 1 : 0, false);
  36. };
  37. CheckboxControl.prototype._updateControls = function() {
  38. var value = this.getValue();
  39. if (!value)
  40. this.ctrl.removeAttr("checked");
  41. else
  42. this.ctrl.attr("checked", "checked");
  43. }
  44. CheckboxControl.prototype.pushControls = function(parent) {
  45. this.pushTableColumns(parent, this.ctrlParent);
  46. }
  47. Global.Controls.register("checkbox", CheckboxControl);
  48. })();