1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2015 ublaboo <[email protected]> |
5
|
|
|
* @author Pavel Janda <[email protected]> |
6
|
|
|
* @package Ublaboo |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Ublaboo\DataGrid\InlineEdit; |
10
|
|
|
|
11
|
|
|
use Nette; |
12
|
|
|
use Nette\Application\UI\Form; |
13
|
|
|
use Ublaboo\DataGrid\DataGrid; |
14
|
|
|
use Nette\Utils\Html; |
15
|
|
|
use Ublaboo\DataGrid\Traits; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @method onSubmit($id, Nette\Utils\ArrayHash $values) |
19
|
|
|
* @method onSubmit(Nette\Utils\ArrayHash $values) |
20
|
|
|
* @method onControlAdd(Nette\Forms\Container $container) |
21
|
|
|
* @method onSetDefaults(Nette\Forms\Container $container, $item) |
22
|
|
|
*/ |
23
|
|
|
class InlineEdit extends Nette\Object |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
use Traits\ButtonIconTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var callable[] |
30
|
|
|
*/ |
31
|
|
|
public $onSubmit; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var callable[] |
35
|
|
|
*/ |
36
|
|
|
public $onControlAdd; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var callable[] |
40
|
|
|
*/ |
41
|
|
|
public $onSetDefaults; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var mixed |
45
|
|
|
*/ |
46
|
|
|
protected $item_id; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $title = 'edit'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
protected $class = 'btn btn-xs btn-default ajax'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
protected $icon = 'pencil'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
protected $text = ''; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var DataGrid |
70
|
|
|
*/ |
71
|
|
|
protected $grid; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var string|NULL |
75
|
|
|
*/ |
76
|
|
|
protected $primary_where_column; |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param DataGrid $grid |
81
|
|
|
* @param string|NULL $primary_where_column |
82
|
|
|
*/ |
83
|
|
|
public function __construct(DataGrid $grid, $primary_where_column = NULL) |
84
|
|
|
{ |
85
|
|
|
$this->grid = $grid; |
86
|
|
|
$this->primary_where_column = $primary_where_column; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param mixed $id |
92
|
|
|
*/ |
93
|
|
|
public function setItemId($id) |
94
|
|
|
{ |
95
|
|
|
$this->item_id = $id; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function getItemId() |
103
|
|
|
{ |
104
|
|
|
return $this->item_id; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getPrimaryWhereColumn() |
112
|
|
|
{ |
113
|
|
|
return $this->primary_where_column; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Render row item detail button |
119
|
|
|
* @param Row $row |
120
|
|
|
* @return Html |
121
|
|
|
*/ |
122
|
|
|
public function renderButton($row) |
123
|
|
|
{ |
124
|
|
|
$a = Html::el('a') |
125
|
|
|
->href($this->grid->link('inlineEdit!', ['id' => $row->getId()])); |
126
|
|
|
|
127
|
|
|
$this->tryAddIcon($a, $this->getIcon(), $this->getText()); |
128
|
|
|
|
129
|
|
|
$a->add($this->text); |
130
|
|
|
|
131
|
|
|
if ($this->title) { $a->title($this->title); } |
132
|
|
|
if ($this->class) { $a->class($this->class); } |
133
|
|
|
|
134
|
|
|
return $a; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Render row item detail button |
140
|
|
|
* @return Html |
141
|
|
|
*/ |
142
|
|
|
public function renderButtonAdd() |
143
|
|
|
{ |
144
|
|
|
$a = Html::el('a')->data('datagrid-toggle-inline-add', TRUE); |
145
|
|
|
|
146
|
|
|
$this->tryAddIcon($a, $this->getIcon(), $this->getText()); |
147
|
|
|
|
148
|
|
|
$a->add($this->text); |
149
|
|
|
|
150
|
|
|
if ($this->title) { $a->title($this->title); } |
151
|
|
|
if ($this->class) { $a->class($this->class); } |
152
|
|
|
|
153
|
|
|
return $a; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set attribute title |
159
|
|
|
* @param string $title |
160
|
|
|
*/ |
161
|
|
|
public function setTitle($title) |
162
|
|
|
{ |
163
|
|
|
$this->title = $title; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Get attribute title |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getTitle() |
174
|
|
|
{ |
175
|
|
|
return $this->title; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Set attribute class |
181
|
|
|
* @param string $class |
182
|
|
|
*/ |
183
|
|
|
public function setClass($class) |
184
|
|
|
{ |
185
|
|
|
$this->class = $class; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get attribute class |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function getClass() |
196
|
|
|
{ |
197
|
|
|
return $this->class; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Set icon |
203
|
|
|
* @param string $icon |
204
|
|
|
*/ |
205
|
|
|
public function setIcon($icon) |
206
|
|
|
{ |
207
|
|
|
$this->icon = $icon; |
208
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Get icon |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
public function getIcon() |
218
|
|
|
{ |
219
|
|
|
return $this->icon; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Set text |
225
|
|
|
* @param string $text |
226
|
|
|
*/ |
227
|
|
|
public function setText($text) |
228
|
|
|
{ |
229
|
|
|
$this->text = $text; |
230
|
|
|
|
231
|
|
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Get text |
237
|
|
|
* @return string |
238
|
|
|
*/ |
239
|
|
|
public function getText() |
240
|
|
|
{ |
241
|
|
|
return $this->text; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
} |
245
|
|
|
|