-
Notifications
You must be signed in to change notification settings - Fork 146
/
field.php
executable file
·395 lines (341 loc) · 13.6 KB
/
field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
/**
* Modal window for extend field creation / edition
*
* @receives :
* - Extend definitions fields in case of existing extend definition edition
* - $parents : List of potential extend parents
*/
?>
<?php if (Authority::can('delete', 'admin/extend') && $id_extend_field != '') :?>
<a id="bDeleteextendfield<?php echo $id_extend_field; ?>" class="button red right" ><?php echo lang('ionize_button_delete'); ?></a>
<?php endif ;?>
<h2 id="mainTitleExtend<?php echo $id_extend_field ?>" class="main extends">
<?php echo lang('ionize_title_extend_field') ?>
</h2>
<div class="main subtitle">
<p>
<?php if ($id_extend_field) :?>
<span class="lite"><?php echo lang('ionize_label_id') ?>: </span>
<?php echo $id_extend_field; ?>
<?php endif ;?>
<?php if ($id_extend_field != '' && $limit_to_parent) :?>
<span class="lite"> | </span>
<?php endif ;?>
<?php if ($limit_to_parent) :?>
<span class="lite"><?php echo lang('ionize_label_extend_field_parent') ?>: </span>
<?php echo ucfirst($limit_to_parent) ?>
<?php if ($id_parent) :?>
<span class="lite"> | <?php echo lang('ionize_label_parent_id') ?>: </span>
<?php echo $id_parent ?>
<?php endif ;?>
<?php endif ;?>
<?php if ( ! empty($context)) :?>
<span class="lite"> | <?php echo ucfirst($context) ?></span>
<?php if ( ! empty($id_context)) :?>
<span class="lite"> : </span>
<?php echo $id_context ?>
<?php endif ;?>
<?php endif ;?>
</p>
</div>
<form name="extendfieldForm" id="extendfieldForm<?php echo $id_extend_field; ?>" action="<?php echo admin_url(); ?>extend_field/save">
<!-- Hidden fields -->
<input id="id_extend_field" name="id_extend_field" type="hidden" value="<?php echo $id_extend_field; ?>" />
<input id="ordering" name="ordering" type="hidden" value="<?php echo $ordering; ?>" />
<input type="hidden" name="id_parent" value="<?php echo $id_parent ?>" />
<input id="article_types" type="hidden" name="article_types" value="<?php echo implode(',', $_article_types) ?>" />
<?php if ( ! empty($context)) :?>
<input type="hidden" name="context" value="<?php echo $context ?>" />
<?php endif ;?>
<?php if ( ! empty($id_context)) :?>
<input type="hidden" name="id_context" value="<?php echo $id_context ?>" />
<?php endif ;?>
<!-- Parent -->
<?php if ($limit_to_parent) :?>
<input type="hidden" name="parent" value="<?php echo $limit_to_parent ?>" />
<?php else :?>
<dl class="small">
<dt>
<label for="parent<?php echo $id_extend_field; ?>" title="<?php echo lang('ionize_help_ef_parent'); ?>"><?php echo lang('ionize_label_extend_field_parent'); ?></label>
</dt>
<dd>
<select id="parent<?php echo $id_extend_field; ?>" name="parent" class="select">
<?php foreach ($parents as $_parent) :?>
<option value="<?php echo $_parent ?>" <?php if ($parent==$_parent) :?> selected="selected" <?php endif ;?>><?php echo ucfirst($_parent); ?></option>
<?php endforeach; ?>
</select>
</dd>
</dl>
<?php endif ;?>
<!-- Article extend field (only): article type -->
<dl class="small" id="dl_article_type_<?php echo $id_extend_field; ?>"<?php if($parent !== 'article') : ?> style="display:none"<?php endif; ?>>
<dt>
<label for="article_type_<?php echo $id_extend_field; ?>" title="<?php echo lang('ionize_help_ef_article_type'); ?>"><?php echo lang('ionize_label_extend_field_article_type'); ?></label>
</dt>
<dd>
<select size="<?php echo count($article_types); ?>" multiple="multiple" id="article_type_<?php echo $id_extend_field; ?>" name="article_type" class="select">
<?php foreach ($article_types as $article_type) :?>
<option value="<?php echo $article_type['id_type'] ?>" <?php if ( count($_article_types) === 0 || in_array($article_type['id_type'], $_article_types)) :?> selected="selected" <?php endif ;?>><?php echo $article_type['type']; ?></option>
<?php endforeach; ?>
</select>
</dd>
</dl>
<!-- Label -->
<dl class="small">
<dt class="mt10"><label><?php echo lang('ionize_label_label'); ?></label></dt>
<dd>
<!-- Tabs -->
<div id="extendFieldTab<?php echo $id_extend_field; ?>" class="mainTabs small">
<ul class="tab-menu">
<?php foreach(Settings::get_languages() as $language) :?>
<li class="tab_extend<?php if($language['def'] == '1') :?> dl<?php endif ;?>" rel="<?php echo $language['lang']; ?>"><a><?php echo ucfirst($language['name']); ?></a></li>
<?php endforeach ;?>
</ul>
<div class="clear"></div>
</div>
<div id="extendFieldTabContent<?php echo $id_extend_field; ?>">
<?php foreach(Settings::get_languages() as $language) :?>
<?php $lang = $language['lang']; ?>
<div class="tabcontent <?php echo $lang; ?>">
<!-- Label -->
<input id="label_<?php echo $lang; ?><?php echo $id_extend_field; ?>" onblur="if ($('nameExtend<?php echo $id_extend_field; ?>').value=='') { $('nameExtend<?php echo $id_extend_field; ?>').value=this.value.replace(' ', '-').toLowerCase(); }" name="label_<?php echo $lang; ?>" class="inputtext title w96p" type="text" value="<?php echo $languages[$lang]['label']; ?>"/>
</div>
<?php endforeach ;?>
</div>
</dd>
</dl>
<!-- Key -->
<dl class="small">
<dt>
<label for="nameExtend<?php echo $id_extend_field; ?>" title="<?php echo lang('ionize_help_ef_name'); ?>"><?php echo lang('ionize_label_key'); ?></label>
</dt>
<dd>
<input id="nameExtend<?php echo $id_extend_field; ?>" name="name" class="inputtext required w240" type="text" value="<?php echo $name; ?>" />
</dd>
</dl>
<!-- description -->
<dl class="small">
<dt>
<label for="description<?php echo $id_extend_field; ?>" title="<?php echo lang('ionize_help_ef_description'); ?>"><?php echo lang('ionize_label_description'); ?></label>
</dt>
<dd>
<textarea id="description<?php echo $id_extend_field; ?>" name="description" class="inputtext autogrow" type="text"><?php echo $description; ?></textarea>
</dd>
</dl>
<h3 class="mt20 extend<?php echo $id_extend_field; ?>"><?php echo lang('ionize_label_extend_field_definition') ?></h3>
<div class="element extend<?php echo $id_extend_field; ?>">
<!-- Type -->
<dl class="small">
<dt>
<label for="type<?php echo $id_extend_field; ?>"><?php echo lang('ionize_label_extend_field_type'); ?></label>
</dt>
<dd>
<?php echo $type_select ?>
</dd>
</dl>
<!-- Can be translated ? -->
<dl id="translate_block<?php echo $id_extend_field; ?>" class="small">
<dt>
<label for="translated<?php echo $id_extend_field; ?>"><?php echo lang('ionize_label_extend_field_translated'); ?></label>
</dt>
<dd>
<input id="translated<?php echo $id_extend_field; ?>" name="translated" class="inputcheckbox" type="checkbox" value="1" <?php if ($translated=='1') :?> checked="checked" <?php endif ;?> />
</dd>
</dl>
<!-- Values : For select, radio, checkboxes -->
<dl id="value_block<?php echo $id_extend_field; ?>" class="small">
<dt>
<label for="value<?php echo $id_extend_field; ?>"><?php echo lang('ionize_label_values'); ?></label>
</dt>
<dd>
<textarea id="value<?php echo $id_extend_field; ?>" name="value" class="inputtext autogrow warn-checkListFormat" type="text"><?php echo $value; ?></textarea>
<p class="lite"><?php echo lang('ionize_help_ef_values'); ?></p>
</dd>
</dl>
<!-- default_value -->
<dl id="default_value_block<?php echo $id_extend_field; ?>" class="small">
<dt>
<label for="default_value<?php echo $id_extend_field; ?>"><?php echo lang('ionize_label_default_value'); ?></label>
</dt>
<dd>
<textarea id="default_value<?php echo $id_extend_field; ?>" name="default_value" class="inputtext autogrow" type="text"><?php echo $default_value; ?></textarea>
<p id="efListHelp" class="lite"><?php echo lang('ionize_help_ef_default_value') ?></p>
</dd>
</dl>
</div>
<?php if ($limit_to_parent && TRUE == FALSE) :?>
<h3 class="toggler extend<?php echo $id_extend_field; ?>"><?php echo lang('ionize_title_advanced') ?></h3>
<div class="element extend<?php echo $id_extend_field; ?>">
<dl class="small">
<dt>
<label for="copy_in<?php echo $id_extend_field; ?>" title="<?php echo lang('ionize_help_ef_copy_in'); ?>"><?php echo lang('ionize_label_extend_field_copy_in'); ?></label>
</dt>
<dd>
<input id="copy_in<?php echo $id_extend_field; ?>" name="copy_in" class="inputtext w96p" type="text" value="<?php echo $copy_in; ?>" />
</dd>
</dl>
<dl class="small">
<dt>
<label for="copy_in<?php echo $id_extend_field; ?>" title="<?php echo lang('ionize_help_ef_copy_in_pk'); ?>"><?php echo lang('ionize_label_extend_field_copy_in_pk'); ?></label>
</dt>
<dd>
<input id="copy_in_pk<?php echo $id_extend_field; ?>" name="copy_in_pk" class="inputtext w96p" type="text" value="<?php echo $copy_in_pk; ?>" />
</dd>
</dl>
</div>
<?php endif ;?>
</form>
<div class="buttons">
<button id="bSaveextendfield<?php echo $id_extend_field; ?>" type="button" class="button yes right"><?php echo lang('ionize_button_save_close'); ?></button>
<button id="bCancelextendfield<?php echo $id_extend_field; ?>" type="button" class="button no right"><?php echo lang('ionize_button_cancel'); ?></button>
</div>
<script type="text/javascript">
var id = '<?php echo $id_extend_field; ?>';
var id_type = '<?php echo $type; ?>';
var extend_types = JSON.decode('<?php echo $extend_types; ?>', false);
var default_lang_code = '<?php echo Settings::get_lang("default") ?>';
/**
* @param {String} id_type
*/
function get_extend_type(id_type)
{
var type = null;
Array.each(extend_types, function(item)
{
if (item.id_extend_field_type == id_type)
{
type = item;
}
});
return type;
}
/**
* Update value of hidden field for article type IDs
*/
function updateArticleTypes() {
$('article_types').setProperty('value', '');
if($('parent<?php echo $id_extend_field; ?>').value === 'article') {
$('article_type_<?php echo $id_extend_field; ?>').getSelected().each(function(option){
var elArticleTypes = $('article_types');
elArticleTypes.setProperty(
'value',
elArticleTypes.get('value') + parseInt(option.value, 10) + ','
);
});
}
}
/**
* @param {String} id_type
*/
function display_value_block(id_type)
{
var type = get_extend_type(id_type);
var value_block = $('value_block' + id);
var default_value_block = $('default_value_block' + id);
var translate_block = $('translate_block' + id);
if (type.values == 1) value_block.show(); else value_block.hide();
if (type.default_values == 1) default_value_block.show(); else default_value_block.hide();
if (['radio','checkbox','select','select-multiple'].contains(type.html_element_type)) $('efListHelp').show(); else $('efListHelp').hide();
if (type.translated == 1) translate_block.show(); else translate_block.hide();
}
var elTypeById = $('type' + id);
elTypeById.addEvent('change', function()
{
var id_type = this.get('value');
display_value_block(id_type);
});
display_value_block(elTypeById.value);
// Install parent kind select observer: show article type select only for article
$('parent<?php echo $id_extend_field; ?>').addEvent('change', function()
{
var parent_type = $('parent<?php echo $id_extend_field; ?>').value;
$('dl_article_type_<?php echo $id_extend_field; ?>')[parent_type === 'article' ? 'show' : 'hide']();
});
// Install article type change observer: select all when none selected, update IDs value field
var elArticleTypeSelect = $('article_type_<?php echo $id_extend_field; ?>');
elArticleTypeSelect.addEvent('change', function(e)
{
var selected = elArticleTypeSelect.getSelected();
if(selected.length === 0) {
var allOptions = $$('#article_type_<?php echo $id_extend_field; ?> option');
allOptions.each(function(option){
option.set('selected', true);
});
}
updateArticleTypes();
});
// Form Validation
Form.Validator.add('checkListFormat', {
errorMsg: Lang.get('ionize_form_validator_warning_format_corrected'),
test: function(element)
{
var v = element.value,
newVal = '',
passed = true
;
// v = v.replace(/ /g, '');
v = v.trim();
v = v.split(/\r\n|\r|\n/g);
Object.each(v, function(row)
{
var kv = row.split(':');
if (Object.getLength(kv) == 2)
{
row = kv[0].charTrim(' ,;') + ':' + kv[1].trim(' ,;');
newVal += newVal == '' ? row : '\n' + row;
}
else passed = false;
});
element.setProperty('value', newVal);
return passed;
}
});
// Auto-generate Main title
var elNameExtend = $('nameExtend' + id);
elNameExtend.addEvent('keyup', function()
{
$('mainTitleExtend' + id).set('text', this.value);
});
if (id) elNameExtend.fireEvent('keyup');
ION.initFormAutoGrow('extendfieldForm' + id);
// Auto generates the name of the field
if (id == '')
ION.initCorrectUrl('label_' + default_lang_code + id, 'nameExtend' + id);
// Tabs
var extendFieldTab<?php echo $id_extend_field; ?> = new TabSwapper({
tabsContainer : 'extendFieldTab<?php echo $id_extend_field; ?>',
sectionsContainer : 'extendFieldTabContent<?php echo $id_extend_field; ?>',
selectedClass : 'selected',
deselectedClass : '',
tabs : 'li',
clickers : 'li a',
sections : 'div.tabcontent'
});
// Delete Action
var elBDeleteExtendField = $('bDeleteextendfield' + id);
if (elBDeleteExtendField != null)
{
elBDeleteExtendField.addEvent('click', function()
{
ION.confirmation(
'wConfirmDelete' + id,
function()
{
ION.JSON(
ION.adminUrl + 'extend_field/delete/' + id,
{},
{
onSuccess: function()
{
$('bCancelextendfield' + id).click();
}
}
);
},
Lang.get('ionize_confirm_extend_delete')
);
});
}
updateArticleTypes();
</script>