diff --git a/etemplate/js/et2_checkbox.js b/etemplate/js/et2_checkbox.js new file mode 100644 index 0000000000..477f61a57b --- /dev/null +++ b/etemplate/js/et2_checkbox.js @@ -0,0 +1,83 @@ +/** + * eGroupWare eTemplate2 - JS Checkbox object + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link http://www.egroupware.org + * @author Nathan Gray + * @copyright Nathan Gray 2011 + * @version $Id$ + */ + +"use strict"; + +/*egw:uses + jquery.jquery; + et2_inputWidget; +*/ + +/** + * Class which implements the "checkbox" XET-Tag + */ +var et2_checkbox = et2_inputWidget.extend({ + + attributes: { + "set_value": { + "name": "Set value", + "type": "string", + "default": "true", + "description": "Value when checked" + }, + "unset_value": { + "name": "Unset value", + "type": "string", + "default": "false", + "description": "Value when not checked" + } + }, + + init: function(_parent) { + this._super.apply(this, arguments); + + this.input = null; + this.id = ""; + + this.createInputWidget(); + + }, + + createInputWidget: function() { + this.input = $j(document.createElement("input")).attr("type", "checkbox"); + + this.input.addClass("et2_checkbox"); + + this.setDOMNode(this.input[0]); + }, + + /** + * Override default to match against set/unset value + */ + set_value: function(_value) { + if(_value != this.value) { + if(_value == this.set_value) { + this.input.attr("checked", true); + } else { + this.input.removeAttr("checked"); + } + } + }, + + /** + * Override default to return unchecked value + */ + getValue: function() { + if(this.input.attr("checked")) { + return this.set_value; + } else { + return this.unset_value; + } + } +}); + +et2_register_widget(et2_checkbox, ["checkbox"]); diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 1136923cf2..4ba974b624 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -21,6 +21,7 @@ et2_textbox; et2_number; et2_selectbox; + et2_checkbox; et2_styles; et2_html; et2_tabs;