phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HasCheckboxesTrait.php
Go to the documentation of this file.
1<?php
3
8
16 protected $_hasCheckboxes;
17 protected $_hasCheckedMessage=false;
19 protected $_checkedClass;
21
22 abstract public function addInToolbar($element,$callback=NULL);
23
24 protected function _runCheckboxes(JsUtils $js){
25 $js->execOn("change", "#".$this->identifier." [name='selection[]']:not(._jsonArrayChecked)", $this->_getCheckedChange($js));
26 if(JArray::count($this->_compileParts)<3){
27 $js->trigger("#".$this->identifier." [name='selection[]']","change",true);
28 }
29 }
30
31 protected function _getCheckedChange(JsUtils $js=NULL){
32 $callback="var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true;
33 \$checkbox.each(function() {if($(this).prop('checked')){allUnchecked = false;}else{allChecked = false;}});
34 if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$this->_getCheckedMessageCall($js);
35 return $callback;
36 }
37
38 protected function _getCheckedMessageFunction(){
39 $msg=$this->getCheckedMessage();
40 $checkedMessageFunction="$('#{$this->identifier}').bind('updateChecked',function() {var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length;
41 if(count==1) msg='".$msg[1]."';
42 else if(count>1) msg='".$msg["other"]."';
43 \$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);});
44 \$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);});\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();";
45 return $checkedMessageFunction;
46 }
47
48 protected function _getCheckedMessageCall(JsUtils $js=NULL){
49 $checkedMessageCall="";
50 if($this->_hasCheckedMessage){
51 $checkedMessageCall="$('#{$this->identifier}').trigger('updateChecked');";
52 if(isset($this->_checkedClass)){
53 $checkedMessageCall.="$(this).closest('tr').toggleClass('".$this->_checkedClass."',$(this).prop('checked'));";
54 }
55 if(isset($js))
56 $js->exec($this->_getCheckedMessageFunction(),true);
57 }
58 return $checkedMessageCall;
59 }
60
61 protected function _generateMainCheckbox(&$captions){
62 $ck=new HtmlCheckbox("main-ck-".$this->identifier,"");
63 $checkedMessageCall="";
64 if($this->_hasCheckedMessage)
65 $checkedMessageCall="$('#{$this->identifier}').trigger('updateChecked');";
66
67 $ck->setOnChecked($this->_setAllChecked("true").$checkedMessageCall);
68 $ck->setOnUnchecked($this->_setAllChecked("false").$checkedMessageCall);
69 \array_unshift($captions, $ck);
70 }
71
72 protected function _setAllChecked($checked){
73 $result="$('#".$this->identifier." [name=%quote%selection[]%quote%]:not(._jsonArrayChecked)').prop('checked',".$checked.");";
74 if(isset($this->_checkedClass)){
75 $result.="$('#".$this->identifier." tr').toggleClass('".$this->_checkedClass."',".$checked.");";
76 }
77 return $result;
78 }
79
80 public function getHasCheckboxes() {
82 }
83
85 $this->_hasCheckboxes=$_hasCheckboxes;
86 return $this;
87 }
88
89 protected function getCheckedMessage() {
91 if(!isset($result)){
92 $result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"];
93 }
94 return $result;
95 }
96
103 public function setCheckedMessage(array $_checkedMessage) {
104 $this->_checkedMessage=$_checkedMessage;
105 return $this;
106 }
107
112 public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){
113 if(isset($checkedMessage))
114 $this->_checkedMessage=$checkedMessage;
115 $checkedMessage=$this->getCheckedMessage();
116 $this->_hasCheckboxes=true;
117 $this->_hasCheckedMessage=true;
118 $element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]);
119 $this->addInToolbar($element,$callback);
120 }
121
123 $this->_checkedClass=$_checkedClass;
124 return $this;
125 }
130 public function setCheckedCallback($checkedCallback) {
131 $this->_checkedCallback = $checkedCallback;
132 }
133
134}
JQuery PHP library.
Definition JsUtils.php:23
trigger($element='this', $event='click', $immediatly=false)
Execute all handlers and behaviors attached to the matched elements for the given event.
execOn($event, $element, $js, $parameters=array())
Executes the javascript code $js when $event fires on $element.
Semantic Label component.
Definition HtmlLabel.php:20
setCheckedMessage(array $_checkedMessage)
Defines the message displayed when checkboxes are checked or unchecked with an associative array 0=>n...
setCheckedCallback($checkedCallback)
Set the callback function that determines whether the checkbox should be checked for an object.
addCountCheckedInToolbar(array $checkedMessage=null, $callback=null)