Completed
Push — master ( da7bd7...a4feba )
by Jean-Christophe
03:22
created

TableTrait::onRowClick()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace Ajax\semantic\html\collections\table\traits;
3
4
trait TableTrait{
5
	/**
6
	 * @return HtmlTable
7
	 */
8
	abstract protected function getTable();
9
	abstract public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false);
10
	abstract public function getOn($event, $url, $responseElement="", $parameters=array());
11
12
	protected function addToPropertyTable($property,$value){
13
		return $this->getTable()->addToProperty($property, $value);
14
	}
15
16
	public function setCelled() {
17
		return $this->addToPropertyTable("class", "celled");
18
	}
19
20
	public function setBasic($very=false) {
21
		$table=$this->getTable();
22
		if ($very)
23
			$table->addToPropertyCtrl("class", "very", array ("very" ));
24
		return $table->addToPropertyCtrl("class", "basic", array ("basic" ));
25
	}
26
27
	public function setCompact($very=false) {
28
		$table=$this->getTable();
29
		if ($very)
30
			$table->addToPropertyCtrl("class", "very", array ("very" ));
31
		return $table->addToPropertyCtrl("class", "compact", array ("compact" ));
32
	}
33
34
	public function setCollapsing() {
35
		return $this->addToPropertyTable("class", "collapsing");
36
	}
37
38
	public function setDefinition() {
39
		return $this->addToPropertyTable("class", "definition");
40
	}
41
42
	public function setStructured() {
43
		return $this->addToPropertyTable("class", "structured");
44
	}
45
46
	public function setSortable($colIndex=NULL) {
47
		$table=$this->getTable();
48
		if (isset($colIndex) && $table->hasPart("thead")) {
49
			$table->getHeader()->sort($colIndex);
50
		}
51
		return $table->addToProperty("class", "sortable");
52
	}
53
54
	public function setSingleLine() {
55
		return $this->addToPropertyTable("class", "single line");
56
	}
57
58
	public function setFixed() {
59
		return $this->addToPropertyTable("class", "fixed");
60
	}
61
62
	public function setSelectable() {
63
		return $this->addToPropertyTable("class", "selectable");
64
	}
65
66
	public function setStriped() {
67
		return $this->addToPropertyTable("class", "striped");
68
	}
69
70
	public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false){
71
		$this->onRowClick($jsCode,$stopPropagation,$preventDefault);
72
	}
73
74
	public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){
75
		$this->getTable()->addEvent($event,"{{tr}}".$jsCode,$stopPropagation,$preventDefault);
76
	}
77
78
	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);
81
	}
82
}