Passed
Push — master ( f477f5...1a8de4 )
by Jean-Christophe
04:14
created

EditMemberParams::getJsCallbackForEditMember()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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