Passed
Push — master ( bd3cb9...127ddb )
by Jean-Christophe
17:45
created

EditMemberParams::getUpdateCallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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