Skip to content

Commit 3ad5ef1

Browse files
committed
ActiveRow on Tables + itemSelector on event
1 parent a4feba4 commit 3ad5ef1

File tree

7 files changed

+82
-19
lines changed

7 files changed

+82
-19
lines changed

Ajax/common/components/SimpleComponent.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function __construct(JsUtils $js=NULL) {
2424

2525
protected function compileEvents() {
2626
foreach ( $this->events as $event => $jsCode ) {
27-
$itemSelector=JString::getValueBetween($jsCode);
27+
$itemSelector=JString::getValueBetween($event);
28+
//echo $itemSelector.":::".$jsCode."<br>";
2829
if($event=="execute"){
2930
$this->jquery_code_for_compile []=$jsCode;
3031
}else if($event=="beforeExecute"){
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Ajax\semantic\html\collections\table;
4+
5+
/**
6+
* A class for row selection in Table or DataTable
7+
* @author jc
8+
* @since 2.2.2
9+
*/
10+
class ActiveRow {
11+
/**
12+
* @var HtmlTable
13+
*/
14+
private $table;
15+
private $class;
16+
private $event;
17+
private $multiple;
18+
/**
19+
* @param HtmlTable $table
20+
* @param string $class
21+
* @param string $event
22+
* @param boolean $multiple
23+
*/
24+
public function __construct($table,$class="active",$event="click",$multiple=false){
25+
$this->table=$table;
26+
$this->class=$class;
27+
$this->event=$event;
28+
$this->multiple=$multiple;
29+
}
30+
31+
public function getClass() {
32+
return $this->class;
33+
}
34+
35+
public function setClass($class) {
36+
$this->class=$class;
37+
return $this;
38+
}
39+
40+
public function getEvent() {
41+
return $this->event;
42+
}
43+
44+
public function setEvent($event) {
45+
$this->event=$event;
46+
return $this;
47+
}
48+
49+
public function getMultiple() {
50+
return $this->multiple;
51+
}
52+
53+
public function setMultiple($multiple) {
54+
$this->multiple=$multiple;
55+
return $this;
56+
}
57+
58+
public function compile(){
59+
$multiple="";
60+
if(!$this->multiple){
61+
$multiple="$(this).closest('tbody').children('tr').removeClass('".$this->class."');";
62+
}
63+
$this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');",false,false);
64+
}
65+
66+
}

Ajax/semantic/html/collections/table/HtmlTable.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class HtmlTable extends HtmlSemDoubleElement {
2323
private $_compileParts;
2424
private $_footer;
2525
private $_afterCompileEvents;
26-
private $_activeClass="warning";
27-
private $_activeRowEvent="click";
26+
private $_activeRowSelector;
2827

2928
public function __construct($identifier, $rowCount, $colCount) {
3029
parent::__construct($identifier, "table", "ui table");
@@ -252,8 +251,8 @@ protected function compile_once(JsUtils $js=NULL, &$view=NULL) {
252251
if ($this->propertyContains("class", "sortable")) {
253252
$this->addEvent("execute", "$('#" . $this->identifier . "').tablesort().data('tablesort').sort($('th.default-sort'));");
254253
}
255-
if(isset($this->_activeClass)){
256-
$this->onRow($this->_activeRowEvent, "$(this).toggleClass('".$this->_activeClass."');");
254+
if(isset($this->_activeRowSelector)){
255+
$this->_activeRowSelector->compile();
257256
}
258257
}
259258

@@ -309,15 +308,8 @@ public function onNewRow($callback) {
309308
return $this;
310309
}
311310

312-
public function setActiveClass($_activeClass) {
313-
$this->_activeClass=$_activeClass;
311+
public function setActiveRowSelector($class="active",$event="click",$multiple=false){
312+
$this->_activeRowSelector=new ActiveRow($this,$class,$event,$multiple);
314313
return $this;
315314
}
316-
317-
public function setActiveRowEvent($_activeRowEvent) {
318-
$this->_activeRowEvent=$_activeRowEvent;
319-
return $this;
320-
}
321-
322-
323315
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=fals
7272
}
7373

7474
public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){
75-
$this->getTable()->addEvent($event,"{{tr}}".$jsCode,$stopPropagation,$preventDefault);
75+
$this->getTable()->addEvent($event."{{tr}}",$jsCode,$stopPropagation,$preventDefault);
7676
}
7777

7878
public function getOnRow($event, $url, $responseElement="", $parameters=array()){
79-
$parameters=\array_merge($parameters,["eventItemSelector"=>"tbody tr","stopPropagation"=>false,"preventDefault"=>false]);
80-
return $this->getTable()->getOn($event, $url,$responseElement,$parameters);
79+
$parameters=\array_merge($parameters,["stopPropagation"=>false,"preventDefault"=>false]);
80+
return $this->getTable()->getOn($event."{{tbody tr}}", $url,$responseElement,$parameters);
8181
}
8282
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,9 @@ public function setSortable($colIndex=NULL) {
397397
return $this;
398398
}
399399

400+
public function setActiveRowSelector($class="active",$event="click",$multiple=false){
401+
$this->getTable()->setActiveRowSelector($class,$event,$multiple);
402+
return $this;
403+
}
404+
400405
}

Ajax/service/AjaxCall.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function compile(JsUtils $js=null) {
4545
$result.=$js->jsonArrayDeferred($modelSelector, $url,$method,$params,$jsCallback);
4646
break;
4747
}
48-
if(isset($eventItemSelector))
49-
$result="{{".$eventItemSelector."}}".$result;
5048
return $result;
5149
}
5250

Ajax/service/JString.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static function replaceAtFirstAndLast($subject,$fromFirst,$toFirst,$fromL
5353

5454
public static function getValueBetween(&$str,$before="{{",$after="}}"){
5555
$matches=[];
56+
$result=null;
5657
$_before=\preg_quote($before);
5758
$_after=\preg_quote($after);
5859
if(\preg_match('/'.$_before.'(.*?)'.$_after.'/s', $str, $matches)===1){

0 commit comments

Comments
 (0)