phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
AbstractCheckbox.php
Go to the documentation of this file.
1<?php
3
7
8abstract class AbstractCheckbox extends HtmlSemDoubleElement {
9
10 protected $_params = [];
11
12 public function __construct($identifier, $name = NULL, $label = NULL, $value = NULL, $inputType = "checkbox", $type = "checkbox") {
13 parent::__construct("ck-" . $identifier, "div", "ui " . $type);
14 $this->_identifier = $identifier;
15 $field = new \Ajax\common\html\html5\HtmlInput($identifier, $inputType, $value);
16 $field->setProperty("name", $name);
17 $this->setField($field);
18 if (isset($label))
19 $this->setLabel($label, $value);
21 }
22
23 public function setChecked($value = true) {
24 if ($value === true) {
25 $this->getField()->setProperty("checked", "checked");
26 } else {
27 $this->getField()->removeProperty("checked");
28 }
29 return $this;
30 }
31
32 public function forceValue($value = 'true') {
33 $this->getField()->forceValue($value);
34 return $this;
35 }
36
37 public function setType($checkboxType) {
38 return $this->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
39 }
40
41 public function setLabel($label, $value = null) {
42 $labelO = $label;
43 if (\is_string($label)) {
44 $labelO = new HtmlSemDoubleElement("", "label", "");
45 $labelO->setContent($label);
46 $labelO->setProperty("for", $this->getField()
47 ->getIdentifier());
48 if (isset($value))
49 $labelO->setProperty("data-value", $value);
50 }
51 $this->content["label"] = $labelO;
52 }
53
54 public function setField($field) {
55 $this->content["field"] = $field;
56 }
57
63 public function getLabel() {
64 if (\array_key_exists("label", $this->content))
65 return $this->content["label"];
66 }
67
73 public function getField() {
74 return $this->content["field"];
75 }
76
80 public function swapLabel() {
81 $label = $this->getLabel();
82 unset($this->content["label"]);
83 $this->content["label"] = $label;
84 }
85
86 public function setReadonly() {
87 $this->getField()->setProperty("disabled", "disabled");
88 return $this->addToProperty("class", "read-only");
89 }
90
100 public function attachEvent($selector, $action = NULL) {
101 if (isset($action) || \is_numeric($action) === true) {
102 $js = '$("#%identifier%").checkbox("attach events", "' . $selector . '", "' . $action . '");';
103 } else {
104 $js = '$("#%identifier%").checkbox("attach events", "' . $selector . '");';
105 }
106 $js = \str_replace("%identifier%", $this->identifier, $js);
107 return $this->executeOnRun($js);
108 }
109
117 public function attachEvents($events = array()) {
118 if (\is_array($events)) {
119 foreach ($events as $action => $selector) {
120 $this->attachEvent($selector, $action);
121 }
122 }
123 return $this;
124 }
125
126 public function setFitted() {
127 return $this->addToProperty("class", "fitted");
128 }
129
130 public function setOnChecked($jsCode) {
131 $this->_params["onChecked"] = $jsCode;
132 return $this;
133 }
134
135 public function setOnUnchecked($jsCode) {
136 $this->_params["onUnchecked"] = $jsCode;
137 return $this;
138 }
139
140 public function setOnChange($jsCode) {
141 $this->_params["onChange"] = $jsCode;
142 return $this;
143 }
144
145 public function run(JsUtils $js) {
146 if (! isset($this->_bsComponent))
147 $this->_bsComponent = $js->semantic()->checkbox("#" . $this->identifier, $this->_params);
148 return parent::run($js);
149 }
150}
JQuery PHP library.
Definition JsUtils.php:23
semantic(Semantic $semantic=NULL)
getter or setter of the Semantic-UI variable
Definition JsUtils.php:158
Base class for Semantic double elements.
addToProperty($name, $value, $separator=" ")
addToPropertyCtrl($name, $value, $typeCtrl)
run(JsUtils $js)
{{SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()}HtmlDoubleElement:...
attachEvent($selector, $action=NULL)
Attach $this to $selector and fire $action.
attachEvents($events=array())
Attach $this to an array of $action=>$selector.
__construct($identifier, $name=NULL, $label=NULL, $value=NULL, $inputType="checkbox", $type="checkbox")