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
|
5 |
|
public function __construct($selector="[data-field]",$event="dblclick",$hasButtons=true,$hasPopup=false,$updateCallback="",$identifierSelector="$(this).closest('tr').attr('data-ajax')"){ |
21
|
5 |
|
$this->selector=$selector; |
22
|
5 |
|
$this->event=$event; |
23
|
5 |
|
$this->hasButtons=$hasButtons; |
24
|
5 |
|
$this->hasPopup=$hasPopup; |
25
|
5 |
|
$this->updateCallback=$updateCallback; |
26
|
5 |
|
$this->identifierSelector=$identifierSelector; |
27
|
5 |
|
} |
28
|
|
|
|
29
|
5 |
|
private function getJsCallbackForEditMember(){ |
30
|
5 |
|
if($this->hasPopup){ |
31
|
1 |
|
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
|
5 |
|
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
|
2 |
|
public function getHasButtons() { |
55
|
2 |
|
return $this->hasButtons; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return boolean |
60
|
|
|
*/ |
61
|
2 |
|
public function getHasPopup() { |
62
|
2 |
|
return $this->hasPopup; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
2 |
|
public function getUpdateCallback() { |
69
|
2 |
|
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
|
5 |
|
public static function dataElement(){ |
121
|
5 |
|
return new EditMemberParams("#de td[data-field]","dblclick",true,true,"updateMemberDataElement","$(this).closest('table').attr('data-ajax')"); |
122
|
|
|
} |
123
|
|
|
|
124
|
5 |
|
public static function dataTable(){ |
125
|
5 |
|
return new EditMemberParams(); |
126
|
|
|
} |
127
|
|
|
|
128
|
5 |
|
public function compile($baseRoute,JsUtils $jquery,$part=null){ |
129
|
5 |
|
$part=(isset($part))?", part: '".$part."'":""; |
130
|
5 |
|
$jsCallback=$this->getJsCallbackForEditMember(); |
131
|
5 |
|
$element=null; |
132
|
5 |
|
if(!$this->hasPopup){ |
133
|
5 |
|
$element="\$(self)"; |
134
|
5 |
|
$before=$jsCallback; |
135
|
5 |
|
$jsCallback=""; |
136
|
|
|
}else{ |
137
|
1 |
|
$before=""; |
138
|
|
|
} |
139
|
5 |
|
$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
|
5 |
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|