Completed
Push — master ( 8d4c2e...08f984 )
by Pavel
03:16
created

InlineEdit::isPositionTop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
	 * Inline adding - render on the top or in the bottom?
80
	 * @var bool
81
	 */
82
	protected $position_top = FALSE;
83
84
85
	/**
86
	 * @param DataGrid $grid
87
	 * @param string|NULL   $primary_where_column
88
	 */
89
	public function __construct(DataGrid $grid, $primary_where_column = NULL)
90
	{
91
		$this->grid = $grid;
92
		$this->primary_where_column = $primary_where_column;
93
	}
94
95
96
	/**
97
	 * @param mixed $id
98
	 */
99
	public function setItemId($id)
100
	{
101
		$this->item_id = $id;
102
	}
103
104
105
	/**
106
	 * @return mixed
107
	 */
108
	public function getItemId()
109
	{
110
		return $this->item_id;
111
	}
112
113
114
	/**
115
	 * @return string
116
	 */
117
	public function getPrimaryWhereColumn()
118
	{
119
		return $this->primary_where_column;
120
	}
121
122
123
	/**
124
	 * Render row item detail button
125
	 * @param  Row $row
126
	 * @return Html
127
	 */
128
	public function renderButton($row)
129
	{
130
		$a = Html::el('a')
131
			->href($this->grid->link('inlineEdit!', ['id' => $row->getId()]));
132
133
		$this->tryAddIcon($a, $this->getIcon(), $this->getText());
134
135
		$a->add($this->text);
136
137
		if ($this->title) { $a->title($this->title); }
138
		if ($this->class) { $a->class($this->class); }
139
140
		return $a;
141
	}
142
143
144
	/**
145
	 * Render row item detail button
146
	 * @return Html
147
	 */
148
	public function renderButtonAdd()
149
	{
150
		$a = Html::el('a')->data('datagrid-toggle-inline-add', TRUE);
151
152
		$this->tryAddIcon($a, $this->getIcon(), $this->getText());
153
154
		$a->add($this->text);
155
156
		if ($this->title) { $a->title($this->title); }
157
		if ($this->class) { $a->class($this->class); }
158
159
		return $a;
160
	}
161
162
163
	/**
164
	 * Set attribute title
165
	 * @param string $title
166
	 */
167
	public function setTitle($title)
168
	{
169
		$this->title = $title;
170
171
		return $this;
172
	}
173
174
175
	/**
176
	 * Get attribute title
177
	 * @return string
178
	 */
179
	public function getTitle()
180
	{
181
		return $this->title;
182
	}
183
184
185
	/**
186
	 * Set attribute class
187
	 * @param string $class
188
	 */
189
	public function setClass($class)
190
	{
191
		$this->class = $class;
192
193
		return $this;
194
	}
195
196
197
	/**
198
	 * Get attribute class
199
	 * @return string
200
	 */
201
	public function getClass()
202
	{
203
		return $this->class;
204
	}
205
206
207
	/**
208
	 * Set icon
209
	 * @param string $icon
210
	 */
211
	public function setIcon($icon)
212
	{
213
		$this->icon = $icon;
214
215
		return $this;
216
	}
217
218
219
	/**
220
	 * Get icon
221
	 * @return string
222
	 */
223
	public function getIcon()
224
	{
225
		return $this->icon;
226
	}
227
228
229
	/**
230
	 * Set text
231
	 * @param string $text
232
	 */
233
	public function setText($text)
234
	{
235
		$this->text = $text;
236
237
		return $this;
238
	}
239
240
241
	/**
242
	 * Get text
243
	 * @return string
244
	 */
245
	public function getText()
246
	{
247
		return $this->text;
248
	}
249
250
251
	/**
252
	 * Setter for inline adding position
253
	 * @param bool $position_top
254
	 * @return static
255
	 */
256
	public function setPositionTop($position_top = TRUE)
257
	{
258
		$this->position_top = (bool) $position_top;
259
260
		return $this;
261
	}
262
263
264
	/**
265
	 * Getter for inline adding
266
	 * @return bool
267
	 */
268
	public function isPositionTop()
269
	{
270
		return $this->position_top;
271
	}
272
273
274
	/**
275
	 * @return bool
276
	 */
277
	public function isPositionBottom()
278
	{
279
		return !$this->position_top;
280
	}
281
282
}
283