Skip to content

Commit e046eb2

Browse files
committed
Fix jsCondition pb in TableTrait getOnRow evt
1 parent feb86ec commit e046eb2

File tree

2 files changed

+59
-40
lines changed

2 files changed

+59
-40
lines changed

Ajax/semantic/html/collections/table/traits/TableTrait.php

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
<?php
22
namespace Ajax\semantic\html\collections\table\traits;
33

4-
54
use Ajax\JsUtils;
65

76
/**
7+
*
88
* @author jc
99
* @property HtmlTable $_self
1010
*/
11-
trait TableTrait{
11+
trait TableTrait {
12+
13+
abstract public function addEvent($event, $jsCode, $stopPropagation = false, $preventDefault = false);
1214

13-
abstract public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false);
14-
abstract public function getOn($event, $url, $responseElement="", $parameters=array());
15-
16-
protected function addToPropertyTable($property,$value){
15+
abstract public function getOn($event, $url, $responseElement = "", $parameters = array());
16+
17+
protected function addToPropertyTable($property, $value) {
1718
return $this->_self->addToProperty($property, $value);
1819
}
1920

2021
public function setCelled() {
2122
return $this->addToPropertyTable("class", "celled");
2223
}
2324

24-
public function setBasic($very=false) {
25-
$table=$this->_self;
25+
public function setBasic($very = false) {
26+
$table = $this->_self;
2627
if ($very)
27-
$table->addToPropertyCtrl("class", "very", array ("very" ));
28-
return $table->addToPropertyCtrl("class", "basic", array ("basic" ));
28+
$table->addToPropertyCtrl("class", "very", array(
29+
"very"
30+
));
31+
return $table->addToPropertyCtrl("class", "basic", array(
32+
"basic"
33+
));
2934
}
3035

31-
public function setCompact($very=false) {
32-
$table=$this->_self;
36+
public function setCompact($very = false) {
37+
$table = $this->_self;
3338
if ($very)
34-
$table->addToPropertyCtrl("class", "very", array ("very" ));
35-
return $table->addToPropertyCtrl("class", "compact", array ("compact" ));
39+
$table->addToPropertyCtrl("class", "very", array(
40+
"very"
41+
));
42+
return $table->addToPropertyCtrl("class", "compact", array(
43+
"compact"
44+
));
3645
}
3746

3847
public function setCollapsing() {
@@ -47,8 +56,8 @@ public function setStructured() {
4756
return $this->addToPropertyTable("class", "structured");
4857
}
4958

50-
public function setSortable($colIndex=NULL) {
51-
$table=$this->_self;
59+
public function setSortable($colIndex = NULL) {
60+
$table = $this->_self;
5261
if (isset($colIndex) && $table->hasPart("thead")) {
5362
$table->getHeader()->sort($colIndex);
5463
}
@@ -71,41 +80,49 @@ public function setStriped() {
7180
return $this->addToPropertyTable("class", "striped");
7281
}
7382

74-
public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false){
75-
return $this->onRow("click", $jsCode,$stopPropagation,$preventDefault);
83+
public function onRowClick($jsCode, $stopPropagation = false, $preventDefault = false) {
84+
return $this->onRow("click", $jsCode, $stopPropagation, $preventDefault);
7685
}
7786

78-
public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){
79-
return $this->_self->addEvent($event."{{tbody tr}}",$jsCode,$stopPropagation,$preventDefault);
87+
public function onRow($event, $jsCode, $stopPropagation = false, $preventDefault = false) {
88+
return $this->_self->addEvent($event . "{{tbody tr}}", $jsCode, $stopPropagation, $preventDefault);
8089
}
8190

82-
public function getOnRow($event, $url, $responseElement="", $parameters=array()){
83-
$parameters=\array_merge($parameters,["stopPropagation"=>false,"preventDefault"=>false,"jsCondition"=>'!$(this).closest("tr").hasClass("active")']);
84-
$selector="tbody tr";
85-
if(isset($parameters["selector"])){
86-
$selector=$parameters["selector"];
91+
public function getOnRow($event, $url, $responseElement = "", $parameters = array()) {
92+
$jsCondition = '!$(this).closest("tr").hasClass("active")';
93+
if (isset($parameters['jsCondition'])) {
94+
$jsCondition = '(' . $parameters['jsCondition'] . ' && ' . $jsCondition . ')';
95+
}
96+
$parameters = \array_merge($parameters, [
97+
"stopPropagation" => false,
98+
"preventDefault" => false,
99+
"jsCondition" => $jsCondition
100+
]);
101+
$selector = "tbody tr";
102+
if (isset($parameters["selector"])) {
103+
$selector = $parameters["selector"];
87104
}
88-
return $this->_self->getOn($event."{{".$selector."}}", $url,$responseElement,$parameters);
105+
return $this->_self->getOn($event . "{{" . $selector . "}}", $url, $responseElement, $parameters);
89106
}
90-
91-
public function onPageChange($jsCode){
107+
108+
public function onPageChange($jsCode) {
92109
$this->_self->_addEvent("pageChange", $jsCode);
93110
return $this;
94111
}
95-
96-
public function onSearchTerminate($jsCode){
112+
113+
public function onSearchTerminate($jsCode) {
97114
$this->_self->_addEvent("searchTerminate", $jsCode);
98115
return $this;
99116
}
100-
101-
public function getEventsScript(){
117+
118+
public function getEventsScript() {
102119
return $this->_self->getBsComponent()->getScript();
103120
}
104-
105-
public function addEventsOnRun(JsUtils $js=NULL) {
106-
$script=parent::addEventsOnRun($js);
107-
$innerScript=$this->_self->getInnerScript();
108-
if(!isset($innerScript)){
121+
122+
public function addEventsOnRun(JsUtils $js = NULL) {
123+
$script = parent::addEventsOnRun($js);
124+
$innerScript = $this->_self->getInnerScript();
125+
if (! isset($innerScript)) {
109126
$this->_self->setInnerScript($script);
110127
}
111128
return $script;

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @version 1.0
2222
* @author jc
2323
* @since 2.2
24-
*
24+
*
2525
*/
2626
class DataTable extends Widget {
2727
use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait;
@@ -281,7 +281,7 @@ protected function _generateRow($instance, $fields, &$table, $checkedClass = nul
281281
$checked = $func($instance);
282282
}
283283
$ck->setChecked($checked);
284-
$ck->setOnChange("event.stopPropagation();");
284+
// $ck->setOnChange("event.stopPropagation();");
285285
$field = $ck->getField();
286286
$field->setProperty("value", $dataAjax);
287287
$field->setProperty("name", "selection[]");
@@ -475,7 +475,9 @@ public function autoPaginate($page = 1, $items_per_page = 10, $pages_visibles =
475475
* @param array $compileParts
476476
* @return DataTable
477477
*/
478-
public function refresh($compileParts = ["tbody"]) {
478+
public function refresh($compileParts = [
479+
"tbody"
480+
]) {
479481
$this->_compileParts = $compileParts;
480482
return $this;
481483
}

0 commit comments

Comments
 (0)