|
1
|
|
|
<?php |
|
2
|
|
|
//------------------------------------------------------------------------- |
|
3
|
|
|
// OVIDENTIA http://www.ovidentia.org |
|
4
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify |
|
5
|
|
|
// it under the terms of the GNU General Public License as published by |
|
6
|
|
|
// the Free Software Foundation; either version 2, or (at your option) |
|
7
|
|
|
// any later version. |
|
8
|
|
|
// |
|
9
|
|
|
// This program is distributed in the hope that it will be useful, but |
|
10
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
12
|
|
|
// See the GNU General Public License for more details. |
|
13
|
|
|
// |
|
14
|
|
|
// You should have received a copy of the GNU General Public License |
|
15
|
|
|
// along with this program; if not, write to the Free Software |
|
16
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
17
|
|
|
// USA. |
|
18
|
|
|
//------------------------------------------------------------------------- |
|
19
|
|
|
/** |
|
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
|
21
|
|
|
* @copyright Copyright (c) 2009 by CANTICO ({@link http://www.cantico.fr}) |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* list of customfield of articles from back office |
|
29
|
|
|
* |
|
30
|
|
|
*/ |
|
31
|
|
|
class app_CustomFieldTableView extends app_TableModelView |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @param ORM_Record $record |
|
35
|
|
|
* @param string $fieldPath |
|
36
|
|
|
* @return Widget_Item |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function computeCellContent(ORM_Record $record, $fieldPath) |
|
39
|
|
|
{ |
|
40
|
|
|
$W = bab_Widgets(); |
|
41
|
|
|
$App = $record->App(); |
|
42
|
|
|
|
|
43
|
|
|
$editAction = $App->Controller()->CustomField()->edit($record->id); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
switch ($fieldPath) { |
|
46
|
|
|
|
|
47
|
|
|
case '_actions_': |
|
48
|
|
|
$box = $W->FlowItems(); |
|
49
|
|
|
if ($record->isUpdatable()) { |
|
50
|
|
|
$box->addItem( |
|
51
|
|
|
$W->Link('', $App->Controller()->CustomField()->edit($record->id)) |
|
|
|
|
|
|
52
|
|
|
->addClass('icon', Func_Icons::ACTIONS_DOCUMENT_EDIT) |
|
53
|
|
|
->setOpenMode(Widget_Link::OPEN_DIALOG_AND_RELOAD) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
if ($record->isDeletable()) { |
|
57
|
|
|
$box->addItem( |
|
58
|
|
|
$W->Link('', $App->Controller()->CustomField()->confirmDelete($record->id)) |
|
59
|
|
|
->addClass('icon', Func_Icons::ACTIONS_EDIT_DELETE) |
|
60
|
|
|
->setOpenMode(Widget_Link::OPEN_DIALOG_AND_RELOAD) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
return $box; |
|
64
|
|
|
|
|
65
|
|
|
case 'mandatory': |
|
66
|
|
|
case 'visible_in_shop': |
|
67
|
|
|
if (self::getRecordFieldValue($record, $fieldPath)) |
|
68
|
|
|
{ |
|
69
|
|
|
return $W->Label($App->translate('Yes')); |
|
|
|
|
|
|
70
|
|
|
} else { |
|
71
|
|
|
return $W->Label($App->translate('No')); |
|
72
|
|
|
} |
|
73
|
|
|
break; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return parent::computeCellContent($record, $fieldPath); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritDoc} |
|
83
|
|
|
* @see widget_TableModelView::addDefaultColumns() |
|
84
|
|
|
*/ |
|
85
|
|
|
public function addDefaultColumns(ORM_RecordSet $recordSet) |
|
86
|
|
|
{ |
|
87
|
|
|
$App = $this->App(); |
|
88
|
|
|
|
|
89
|
|
|
/* @var $recordSet app_CustomFieldSet */ |
|
90
|
|
|
$this->addColumn( |
|
91
|
|
|
app_TableModelViewColumn($recordSet->name) |
|
92
|
|
|
); |
|
93
|
|
|
$this->addColumn( |
|
94
|
|
|
app_TableModelViewColumn($recordSet->description) |
|
95
|
|
|
); |
|
96
|
|
|
$this->addColumn( |
|
97
|
|
|
app_TableModelViewColumn($recordSet->object) |
|
98
|
|
|
); |
|
99
|
|
|
// $this->addColumn( |
|
100
|
|
|
// app_TableModelViewColumn($recordSet->section) |
|
101
|
|
|
// ); |
|
102
|
|
|
$this->addColumn( |
|
103
|
|
|
app_TableModelViewColumn($recordSet->fieldtype) |
|
104
|
|
|
); |
|
105
|
|
|
$this->addColumn( |
|
106
|
|
|
widget_TableModelViewColumn($recordSet->mandatory, $App->translate('Mandatory')) |
|
107
|
|
|
->addClass('widget-10em') |
|
108
|
|
|
); |
|
109
|
|
|
$this->addColumn( |
|
110
|
|
|
app_TableModelViewColumn($recordSet->importable) |
|
|
|
|
|
|
111
|
|
|
->addClass('widget-10em') |
|
112
|
|
|
); |
|
113
|
|
|
$this->addColumn( |
|
114
|
|
|
widget_TableModelViewColumn($recordSet->searchable, $App->translate('Searchable')) |
|
|
|
|
|
|
115
|
|
|
->addClass('widget-10em') |
|
116
|
|
|
); |
|
117
|
|
|
$this->addColumn( |
|
118
|
|
|
widget_TableModelViewColumn($recordSet->visible, $App->translate('Visible in list')) |
|
|
|
|
|
|
119
|
|
|
->addClass('widget-10em') |
|
120
|
|
|
); |
|
121
|
|
|
$this->addColumn( |
|
122
|
|
|
widget_TableModelViewColumn('_actions_', '') |
|
123
|
|
|
->setSortable(false) |
|
124
|
|
|
->addClass('widget-column-thin', 'widget-nowrap', Func_Icons::ICON_LEFT_SYMBOLIC) |
|
125
|
|
|
); |
|
126
|
|
|
if ($App->onlineShop) { |
|
|
|
|
|
|
127
|
|
|
$this->addColumn(widget_TableModelViewColumn($recordSet->visible_in_shop, $App->translate('Visible in online shop'))); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$this->setDefaultSortField('name:up'); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* |
|
142
|
|
|
*/ |
|
143
|
|
|
class app_CustomFieldEditor extends app_Editor |
|
144
|
|
|
{ |
|
145
|
|
|
/** |
|
146
|
|
|
* |
|
147
|
|
|
* @var app_CustomField |
|
148
|
|
|
*/ |
|
149
|
|
|
protected $customfield = null; |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
public function __construct(Func_App $App, app_CustomField $customfield = null, $id = null, Widget_Layout $layout = null) |
|
153
|
|
|
{ |
|
154
|
|
|
$this->customfield = $customfield; |
|
155
|
|
|
|
|
156
|
|
|
parent::__construct($App, $id, $layout); |
|
157
|
|
|
$this->setName('customfield'); |
|
|
|
|
|
|
158
|
|
|
$this->colon(); |
|
159
|
|
|
|
|
160
|
|
|
$this->addFields(); |
|
161
|
|
|
$this->addButtons(); |
|
162
|
|
|
|
|
163
|
|
|
$this->setHiddenValue('tg', $App->controllerTg); |
|
164
|
|
|
|
|
165
|
|
|
if (isset($customfield)) { |
|
166
|
|
|
$this->setHiddenValue('customfield[id]', $customfield->id); |
|
167
|
|
|
$values = $customfield->getValues(); |
|
168
|
|
|
|
|
169
|
|
|
if (!empty($this->customfield->enumvalues)) { |
|
170
|
|
|
$values['enumvalues'] = unserialize($this->customfield->enumvalues); |
|
171
|
|
|
} else { |
|
172
|
|
|
$values['enumvalues'] = array('0' => ''); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$this->setValues($values, array('customfield')); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
protected function addFields() |
|
181
|
|
|
{ |
|
182
|
|
|
$App = $this->App(); |
|
183
|
|
|
|
|
184
|
|
|
$this->addItem($this->object()); |
|
185
|
|
|
$this->addItem($this->name()); |
|
186
|
|
|
$this->addItem($this->section()); |
|
187
|
|
|
$this->addItem($this->description()); |
|
188
|
|
|
$this->addItem($this->fieldtype()); |
|
189
|
|
|
$this->addItem($this->mandatory()); |
|
190
|
|
|
$this->addItem($this->searchable()); |
|
191
|
|
|
$this->addItem($this->visible()); |
|
192
|
|
|
$this->addItem($this->importable()); |
|
193
|
|
|
if ($App->onlineShop) { |
|
|
|
|
|
|
194
|
|
|
$this->addItem($this->visible_in_shop()); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
protected function addButtons() |
|
200
|
|
|
{ |
|
201
|
|
|
$App = $this->App(); |
|
202
|
|
|
$W = $this->widgets; |
|
203
|
|
|
|
|
204
|
|
|
$this->addButton( |
|
205
|
|
|
$W->SubmitButton() |
|
206
|
|
|
->setLabel($App->translate('Save')) |
|
207
|
|
|
->validate(true) |
|
|
|
|
|
|
208
|
|
|
->setAction($App->Controller()->CustomField()->save()) |
|
|
|
|
|
|
209
|
|
|
->setAjaxAction() |
|
210
|
|
|
); |
|
211
|
|
|
|
|
212
|
|
|
$this->addButton( |
|
213
|
|
|
$W->SubmitButton() |
|
214
|
|
|
->addClass('widget-close-dialog') |
|
215
|
|
|
->setLabel($App->translate('Cancel')) |
|
216
|
|
|
); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
|
|
protected function section() |
|
221
|
|
|
{ |
|
222
|
|
|
$App = $this->App(); |
|
223
|
|
|
$W = $this->widgets; |
|
224
|
|
|
|
|
225
|
|
|
return $this->labelledField( |
|
226
|
|
|
$App->translate('Section'), |
|
227
|
|
|
$W->LineEdit() |
|
228
|
|
|
->addClass('widget-100pc') |
|
229
|
|
|
->setMaxSize(255), |
|
230
|
|
|
'section' |
|
231
|
|
|
); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
protected function importable() |
|
235
|
|
|
{ |
|
236
|
|
|
$App = $this->App(); |
|
237
|
|
|
$W = $this->widgets; |
|
238
|
|
|
|
|
239
|
|
|
return $this->labelledField( |
|
240
|
|
|
$App->translate('Importable'), |
|
241
|
|
|
$W->Checkbox(), |
|
242
|
|
|
'importable' |
|
243
|
|
|
); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
protected function searchable() |
|
247
|
|
|
{ |
|
248
|
|
|
$App = $this->App(); |
|
249
|
|
|
$W = $this->widgets; |
|
250
|
|
|
|
|
251
|
|
|
return $this->labelledField( |
|
252
|
|
|
$App->translate('Searchable'), |
|
253
|
|
|
$W->Checkbox(), |
|
254
|
|
|
'searchable' |
|
255
|
|
|
); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
protected function visible() |
|
259
|
|
|
{ |
|
260
|
|
|
$App = $this->App(); |
|
261
|
|
|
$W = $this->widgets; |
|
262
|
|
|
|
|
263
|
|
|
return $this->labelledField( |
|
264
|
|
|
$App->translate('Visible in list'), |
|
265
|
|
|
$W->Checkbox(), |
|
266
|
|
|
'visible' |
|
267
|
|
|
); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
protected function name() |
|
271
|
|
|
{ |
|
272
|
|
|
$App = $this->App(); |
|
273
|
|
|
$W = $this->widgets; |
|
274
|
|
|
|
|
275
|
|
|
return $this->labelledField( |
|
276
|
|
|
$App->translate('Name'), |
|
277
|
|
|
$W->LineEdit() |
|
278
|
|
|
->addClass('widget-100pc') |
|
279
|
|
|
->setMandatory(true, $App->translate('The name is mandatory')), |
|
280
|
|
|
'name' |
|
281
|
|
|
); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
protected function description() |
|
285
|
|
|
{ |
|
286
|
|
|
$App = $this->App(); |
|
287
|
|
|
$W = $this->widgets; |
|
288
|
|
|
|
|
289
|
|
|
return $this->labelledField( |
|
290
|
|
|
$App->translate('Description'), |
|
291
|
|
|
$W->TextEdit() |
|
292
|
|
|
->setLines(2) |
|
293
|
|
|
->addClass('widget-100pc'), |
|
294
|
|
|
'description' |
|
295
|
|
|
); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
protected function fieldtype() |
|
299
|
|
|
{ |
|
300
|
|
|
$App = $this->App(); |
|
301
|
|
|
$W = $this->widgets; |
|
302
|
|
|
|
|
303
|
|
|
$select = $W->Select(); |
|
304
|
|
|
$select->setOptions($App->CustomFieldSet() |
|
305
|
|
|
->getFieldTypes()); |
|
306
|
|
|
|
|
307
|
|
|
$fieldTypeItem = $this->labelledField( |
|
308
|
|
|
$App->translate('Field type'), |
|
309
|
|
|
$select, |
|
310
|
|
|
'fieldtype' |
|
311
|
|
|
); |
|
312
|
|
|
|
|
313
|
|
|
$fieldValuesItem = $W->MultiField(); |
|
314
|
|
|
$fieldValuesItem->setName('enumvalues'); |
|
315
|
|
|
$fieldValuesItem->addItem($W->Label($App->translate('List of available values'))); |
|
316
|
|
|
$values = array(); |
|
317
|
|
|
|
|
318
|
|
|
if (isset($this->customfield) && !empty($this->customfield->enumvalues)) { |
|
319
|
|
|
$values = unserialize($this->customfield->enumvalues); |
|
320
|
|
|
|
|
321
|
|
|
foreach ($values as $name => $text) { |
|
322
|
|
|
$fieldValuesItem->addItem( |
|
323
|
|
|
$W->LineEdit()->setName((string) $name) |
|
324
|
|
|
); |
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
if (empty($values)) { |
|
329
|
|
|
$fieldValuesItem->addItem( |
|
330
|
|
|
$W->LineEdit()->setName('1') |
|
331
|
|
|
); |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
$select->setAssociatedDisplayable($fieldValuesItem, array('Enum', 'Set')); |
|
335
|
|
|
|
|
336
|
|
|
return $W->FlowItems($fieldTypeItem, $fieldValuesItem) |
|
337
|
|
|
->setHorizontalSpacing(2, 'em') |
|
338
|
|
|
->setVerticalAlign('top'); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
protected function object() |
|
343
|
|
|
{ |
|
344
|
|
|
$App = $this->App(); |
|
345
|
|
|
$W = $this->widgets; |
|
346
|
|
|
|
|
347
|
|
|
// if (isset($this->customfield)) { |
|
348
|
|
|
// $set = $this->customfield->getParentSet(); |
|
349
|
|
|
|
|
350
|
|
|
// $layout = $W->FlowLayout() |
|
351
|
|
|
// ->setSpacing(.4, 'em'); |
|
352
|
|
|
// $layout->addItem( |
|
353
|
|
|
// $W->Label($App->translate('This field will be used in')) |
|
354
|
|
|
// ->colon() |
|
355
|
|
|
// ); |
|
356
|
|
|
// $layout->addItem( |
|
357
|
|
|
// $W->Label($set->output($this->customfield->object())) |
|
358
|
|
|
// ); |
|
359
|
|
|
|
|
360
|
|
|
// return $layout; |
|
361
|
|
|
// } |
|
362
|
|
|
|
|
363
|
|
|
return $this->labelledField( |
|
364
|
|
|
$App->translate('This field will be used in'), |
|
365
|
|
|
$W->Select() |
|
366
|
|
|
->setOptions($App->CustomFieldSet() |
|
367
|
|
|
->getObjects()), |
|
368
|
|
|
'object' |
|
369
|
|
|
); |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
|
|
373
|
|
|
|
|
374
|
|
|
public function mandatory() |
|
375
|
|
|
{ |
|
376
|
|
|
$App = $this->App(); |
|
377
|
|
|
$W = $this->widgets; |
|
378
|
|
|
|
|
379
|
|
|
return $this->labelledField( |
|
380
|
|
|
$App->translate('Mandatory field'), |
|
381
|
|
|
$W->Checkbox(), |
|
382
|
|
|
__FUNCTION__ |
|
383
|
|
|
); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
public function visible_in_shop() |
|
387
|
|
|
{ |
|
388
|
|
|
$App = $this->App(); |
|
389
|
|
|
$W = $this->widgets; |
|
390
|
|
|
|
|
391
|
|
|
return $this->labelledField( |
|
392
|
|
|
$App->translate('Visible in online shop'), |
|
393
|
|
|
$W->Checkbox(), |
|
394
|
|
|
__FUNCTION__ |
|
395
|
|
|
); |
|
396
|
|
|
} |
|
397
|
|
|
} |
|
398
|
|
|
|