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
|
|
|
class InlineEdit extends Nette\Object |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
use Traits\ButtonIconTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var callable[] |
24
|
|
|
*/ |
25
|
|
|
public $onSubmit; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var callable[] |
29
|
|
|
*/ |
30
|
|
|
public $onControlAdd; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var callable[] |
34
|
|
|
*/ |
35
|
|
|
public $onSetDefaults; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var mixed |
39
|
|
|
*/ |
40
|
|
|
protected $item_id; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $title; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $class = 'btn btn-xs btn-default ajax'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $icon = 'pencil'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $text = ''; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var DataGrid |
64
|
|
|
*/ |
65
|
|
|
protected $grid; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
protected $primary_where_column; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param DataGrid $grid |
75
|
|
|
* @param string $primary_where_column |
76
|
|
|
*/ |
77
|
|
|
public function __construct(DataGrid $grid, $primary_where_column) |
78
|
|
|
{ |
79
|
|
|
$this->grid = $grid; |
80
|
|
|
$this->primary_where_column = $primary_where_column; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param mixed $id |
86
|
|
|
*/ |
87
|
|
|
public function setItemId($id) |
88
|
|
|
{ |
89
|
|
|
$this->item_id = $id; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return mixed |
95
|
|
|
*/ |
96
|
|
|
public function getItemId() |
97
|
|
|
{ |
98
|
|
|
return $this->item_id; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getPrimaryWhereColumn() |
106
|
|
|
{ |
107
|
|
|
return $this->primary_where_column; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Render row item detail button |
113
|
|
|
* @param Row $row |
114
|
|
|
* @return Html |
115
|
|
|
*/ |
116
|
|
|
public function renderButton($row) |
117
|
|
|
{ |
118
|
|
|
$a = Html::el('a') |
119
|
|
|
->href($this->grid->link('inlineEdit!', ['id' => $row->getId()])); |
120
|
|
|
|
121
|
|
|
$this->tryAddIcon($a, $this->getIcon(), $this->getText()); |
122
|
|
|
|
123
|
|
|
$a->add($this->text); |
124
|
|
|
|
125
|
|
|
if ($this->title) { $a->title($this->title); } |
126
|
|
|
if ($this->class) { $a->class($this->class); } |
127
|
|
|
|
128
|
|
|
return $a; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set attribute title |
134
|
|
|
* @param string $title |
135
|
|
|
*/ |
136
|
|
|
public function setTitle($title) |
137
|
|
|
{ |
138
|
|
|
$this->title = $title; |
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get attribute title |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getTitle() |
149
|
|
|
{ |
150
|
|
|
return $this->title; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Set attribute class |
156
|
|
|
* @param string $class |
157
|
|
|
*/ |
158
|
|
|
public function setClass($class) |
159
|
|
|
{ |
160
|
|
|
$this->class = $class; |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get attribute class |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getClass() |
171
|
|
|
{ |
172
|
|
|
return $this->class; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Set icon |
178
|
|
|
* @param string $icon |
179
|
|
|
*/ |
180
|
|
|
public function setIcon($icon) |
181
|
|
|
{ |
182
|
|
|
$this->icon = $icon; |
183
|
|
|
|
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Get icon |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
public function getIcon() |
193
|
|
|
{ |
194
|
|
|
return $this->icon; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Set text |
200
|
|
|
* @param string $text |
201
|
|
|
*/ |
202
|
|
|
public function setText($text) |
203
|
|
|
{ |
204
|
|
|
$this->text = $text; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Get text |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
public function getText() |
215
|
|
|
{ |
216
|
|
|
return $this->text; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
|