Passed
Push — master ( 42337f...468e47 )
by Jean-Christophe
02:24
created

TableTrait   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 24

19 Methods

Rating   Name   Duplication   Size   Complexity  
A setSingleLine() 0 2 1
A setSortable() 0 6 3
A onRow() 0 2 1
A addEventsOnRun() 0 7 2
A onPageChange() 0 3 1
A addToPropertyTable() 0 2 1
A setDefinition() 0 2 1
A setBasic() 0 5 2
A setStriped() 0 2 1
A getEventsScript() 0 2 1
A setSelectable() 0 2 1
A setCelled() 0 2 1
A onSearchTerminate() 0 3 1
A getOnRow() 0 3 1
A setCollapsing() 0 2 1
A setStructured() 0 2 1
A setCompact() 0 5 2
A onRowClick() 0 2 1
A setFixed() 0 2 1
1
<?php
2
namespace Ajax\semantic\html\collections\table\traits;
3
4
5
use Ajax\JsUtils;
6
7
/**
8
 * @author jc
9
 * @property HtmlTable $_self
10
 */
11
trait TableTrait{
12
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){
17
		return $this->_self->addToProperty($property, $value);
18
	}
19
20
	public function setCelled() {
21
		return $this->addToPropertyTable("class", "celled");
22
	}
23
24
	public function setBasic($very=false) {
25
		$table=$this->_self;
26
		if ($very)
27
			$table->addToPropertyCtrl("class", "very", array ("very" ));
28
		return $table->addToPropertyCtrl("class", "basic", array ("basic" ));
29
	}
30
31
	public function setCompact($very=false) {
32
		$table=$this->_self;
33
		if ($very)
34
			$table->addToPropertyCtrl("class", "very", array ("very" ));
35
		return $table->addToPropertyCtrl("class", "compact", array ("compact" ));
36
	}
37
38
	public function setCollapsing() {
39
		return $this->addToPropertyTable("class", "collapsing");
40
	}
41
42
	public function setDefinition() {
43
		return $this->addToPropertyTable("class", "definition");
44
	}
45
46
	public function setStructured() {
47
		return $this->addToPropertyTable("class", "structured");
48
	}
49
50
	public function setSortable($colIndex=NULL) {
51
		$table=$this->_self;
52
		if (isset($colIndex) && $table->hasPart("thead")) {
53
			$table->getHeader()->sort($colIndex);
54
		}
55
		return $table->addToProperty("class", "sortable");
56
	}
57
58
	public function setSingleLine() {
59
		return $this->addToPropertyTable("class", "single line");
60
	}
61
62
	public function setFixed() {
63
		return $this->addToPropertyTable("class", "fixed");
64
	}
65
66
	public function setSelectable() {
67
		return $this->addToPropertyTable("class", "selectable");
68
	}
69
70
	public function setStriped() {
71
		return $this->addToPropertyTable("class", "striped");
72
	}
73
74
	public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false){
75
		return $this->onRow("click", $jsCode,$stopPropagation,$preventDefault);
76
	}
77
78
	public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){
79
		return $this->_self->addEvent($event."{{tr}}",$jsCode,$stopPropagation,$preventDefault);
80
	}
81
82
	public function getOnRow($event, $url, $responseElement="", $parameters=array()){
83
		$parameters=\array_merge($parameters,["stopPropagation"=>false,"preventDefault"=>false]);
84
		return $this->_self->getOn($event."{{tbody tr}}", $url,$responseElement,$parameters);
85
	}
86
	
87
	public function onPageChange($jsCode){
88
		$this->_self->_addEvent("pageChange", $jsCode);
89
		return $this;
90
	}
91
	
92
	public function onSearchTerminate($jsCode){
93
		$this->_self->_addEvent("searchTerminate", $jsCode);
94
		return $this;
95
	}
96
	
97
	public function getEventsScript(){
98
		return $this->_self->getBsComponent()->getScript();
99
	}
100
	
101
	public function addEventsOnRun(JsUtils $js=NULL) {
102
		$script=parent::addEventsOnRun($js);
103
		$innerScript=$this->_self->getInnerScript();
104
		if(!isset($innerScript)){
105
			$this->_self->setInnerScript($script);
106
		}
107
		return $script;
108
	}
109
}
110