Completed
Push — master ( dbc6d3...05c25a )
by Jean-Christophe
01:43
created

EditMemberParams::getIdentifierSelector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ubiquity\controllers\crud;
4
5
use Ajax\JsUtils;
6
7
class EditMemberParams {
8
	private $selector;
9
	private $event;
10
	private $hasButtons;
11
	private $hasPopup;
12
	private $updateCallback;
13
	private $identifierSelector;
14
	
15
	public function __construct($selector="[data-field]",$event="dblclick",$hasButtons=true,$hasPopup=true,$updateCallback="",$identifierSelector="$(this).closest('tr').attr('data-ajax')"){
16
		$this->selector=$selector;
17
		$this->event=$event;
18
		$this->hasButtons=$hasButtons;
19
		$this->hasPopup=$hasPopup;
20
		$this->updateCallback=$updateCallback;
21
		$this->identifierSelector=$identifierSelector;
22
	}
23
	
24
	private function getJsCallbackForEditMember(){
25
		if($this->hasPopup){
26
			return "$(self).popup({hideOnScroll: false,exclusive: true,delay:{show:50,hide: 5000},closable: false, variation: 'very wide',html: data, hoverable: true,className: {popup: 'ui popup'}}).popup('show');";
27
		}else{
28
			return "$(self).html(function(i,v){return $(this).data('originalText', v), '';});";
29
		}
30
	}
31
	
32
	/**
33
	 * @return string
34
	 */
35
	public function getSelector() {
36
		return $this->selector;
37
	}
38
39
	/**
40
	 * @return string
41
	 */
42
	public function getEvent() {
43
		return $this->event;
44
	}
45
46
	/**
47
	 * @return boolean
48
	 */
49
	public function getHasButtons() {
50
		return $this->hasButtons;
51
	}
52
53
	/**
54
	 * @return boolean
55
	 */
56
	public function getHasPopup() {
57
		return $this->hasPopup;
58
	}
59
60
	/**
61
	 * @return NULL
62
	 */
63
	public function getUpdateCallback() {
64
		return $this->updateCallback;
65
	}
66
67
	/**
68
	 * @param string $selector
69
	 */
70
	public function setSelector($selector) {
71
		$this->selector = $selector;
72
	}
73
74
	/**
75
	 * @param string $event
76
	 */
77
	public function setEvent($event) {
78
		$this->event = $event;
79
	}
80
81
	/**
82
	 * @param boolean $hasButtons
83
	 */
84
	public function setHasButtons($hasButtons) {
85
		$this->hasButtons = $hasButtons;
86
	}
87
88
	/**
89
	 * @param boolean $hasPopup
90
	 */
91
	public function setHasPopup($hasPopup) {
92
		$this->hasPopup = $hasPopup;
93
	}
94
95
	/**
96
	 * @param NULL $updateCallback
97
	 */
98
	public function setUpdateCallback($updateCallback) {
99
		$this->updateCallback = $updateCallback;
100
	}
101
	/**
102
	 * @return mixed
103
	 */
104
	public function getIdentifierSelector() {
105
		return $this->identifierSelector;
106
	}
107
108
	/**
109
	 * @param mixed $identifierSelector
110
	 */
111
	public function setIdentifierSelector($identifierSelector) {
112
		$this->identifierSelector = $identifierSelector;
113
	}
114
	
115
	public static function dataElement(){
116
		return new EditMemberParams("#de td[data-field]","dblclick",true,true,"updateMemberDataElement","$(this).closest('table').attr('data-ajax')");
117
	}
118
119
	public static function dataTable(){
120
		return new EditMemberParams();
121
	}
122
	
123
	public function compile($baseRoute,JsUtils $jquery,$part=null){
124
		$part=(isset($part))?", part: '".$part."'":"";
125
		$jsCallback=$this->getJsCallbackForEditMember();
126
		$element=null;
127
		if(!$this->hasPopup){
128
			$element="\$(self)";
129
			$before=$jsCallback;
130
			$jsCallback="";
131
		}else{
132
			$before="";
133
		}
134
		$jquery->postOn($this->event,$this->selector, $baseRoute."/editMember/","{id: ".$this->identifierSelector.",td:$(this).attr('id')".$part."}",$element,["attr"=>"data-field","hasLoader"=>false,"jqueryDone"=>"html","before"=>"$('._memberForm').trigger('endEdit');".$before,"jsCallback"=>$jsCallback]);
135
		
136
	}
137
	
138
}
139
140