Skip to content

Commit c387528

Browse files
author
Christian Blanquera
committed
Active, Created, Updated showing regular field form on update CradlePHP/Cradle#199
1 parent 26fcc2d commit c387528

File tree

1 file changed

+93
-82
lines changed

1 file changed

+93
-82
lines changed

src/Schema/template/_scripts.html

+93-82
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,106 @@
224224
//----------------------------//
225225
// Modal Events
226226
$(window).on('modal-form-init', function(e, target) {
227-
//field type change
228-
$('select.field-type', target).change(function() {
229-
var select = $(this);
230-
var option = $('option[value="' + select.val() + '"]', this);
227+
var setModalState = function () {
228+
var select = $('select.field-type', target);
229+
var option = $('option[value="' + select.val() + '"]', select);
231230

232231
//fixing a jQuery bug on clone
233232
$('option', this).removeAttr('selected');
234233
option.attr('selected', 'selected');
235234

236-
//configuration
237-
var fieldsets = (option.attr('data-fieldset') || '').split('|');
238-
var formats = (option.attr('data-format') || '').split('|');
239-
var indexes = (option.attr('data-index') || '').split('|');
240-
241235
var value = option.attr('data-default');
242236
var label = option.attr('data-label');
243237
var name = option.attr('data-name');
244238
var searchable = option.attr('data-searchable');
245239
var filterable = option.attr('data-filterable');
246240
var sortable = option.attr('data-sortable');
247-
var index = $(this).getModelIndex();
248-
249241
var validation = option.attr('data-validation');
250242

243+
//determine label
244+
if(label && label.length) {
245+
$('input.field-label', target).val(label);
246+
$('div.form-group-label', target).hide();
247+
} else {
248+
$('div.form-group-label', target).show();
249+
}
250+
251+
//determine name
252+
if(name && name.length) {
253+
$('input.field-name', target).val(name);
254+
$('div.form-group-name', target).hide();
255+
select.parent().find('div.input-fieldset').remove();
256+
} else {
257+
$('div.form-group-name', target).show();
258+
}
259+
260+
//determine validation
261+
if(parseInt(validation) === 0) {
262+
$('div.validation-row', target).remove();
263+
$('div.form-group-validation', target).hide();
264+
} else if(validation && validation.length) {
265+
$('div.form-group-validation', target).show();
266+
}
267+
268+
//determine default
269+
if(value && value.length) {
270+
$('input.field-default', target).val(value);
271+
$('div.form-group-default', target).hide();
272+
} else {
273+
$('div.form-group-default', target).show();
274+
}
275+
276+
//determine searchable
277+
if(searchable && searchable.length) {
278+
if(searchable == 1) {
279+
$('input.field-searchable', target).prop('checked', true);
280+
} else {
281+
$('input.field-searchable', target).prop('checked', false);
282+
}
283+
284+
$('input.field-searchable', target).parent().hide();
285+
} else {
286+
$('input.field-searchable', target).parent().show();
287+
}
288+
289+
//determine filterable
290+
if(filterable && filterable.length) {
291+
if(filterable == 1) {
292+
$('input.field-filterable', target).prop('checked', true);
293+
} else {
294+
$('input.field-filterable', target).prop('checked', false);
295+
}
296+
297+
$('input.field-filterable', target).parent().hide();
298+
} else {
299+
$('input.field-filterable', target).parent().show();
300+
}
301+
302+
//determine sortable
303+
if(sortable && sortable.length) {
304+
if(sortable == 1) {
305+
$('input.field-sortable', target).prop('checked', true);
306+
} else {
307+
$('input.field-sortable', target).prop('checked', false);
308+
}
309+
310+
$('input.field-sortable', target).parent().hide();
311+
} else {
312+
$('input.field-sortable', target).parent().show();
313+
}
314+
};
315+
316+
//field type change
317+
$('select.field-type', target).change(function() {
318+
var select = $(this);
319+
var option = $('option[value="' + select.val() + '"]', this);
320+
321+
//configuration
322+
var fieldsets = (option.attr('data-fieldset') || '').split('|');
323+
var formats = (option.attr('data-format') || '').split('|');
324+
var indexes = (option.attr('data-index') || '').split('|');
325+
var index = $(this).getModelIndex();
326+
251327
//reset
252328
$('select.field-list optgroup', target).show();
253329
$('select.field-detail optgroup', target).show();
@@ -256,7 +332,9 @@
256332
$('input.field-sortable', target).attr('disabled', false);
257333

258334
//remove all fieldsets
259-
select.parent().find('div.input-fieldset').remove();
335+
select.parent()
336+
.find('div.input-fieldset')
337+
.remove();
260338

261339
fieldsets.forEach(function(field) {
262340
var data = [];
@@ -342,76 +420,7 @@
342420
}
343421
});
344422

345-
//determine label
346-
if(label && label.length) {
347-
$('input.field-label', target).val(label);
348-
$('div.form-group-label', target).hide();
349-
} else {
350-
$('div.form-group-label', target).show();
351-
}
352-
353-
//determine name
354-
if(name && name.length) {
355-
$('input.field-name', target).val(name);
356-
$('div.form-group-name', target).hide();
357-
} else {
358-
$('div.form-group-name', target).show();
359-
}
360-
361-
//determine validation
362-
if(parseInt(validation) === 0) {
363-
$('div.validation-row', target).remove();
364-
$('div.form-group-validation', target).hide();
365-
} else if(validation && validation.length) {
366-
$('div.form-group-validation', target).show();
367-
}
368-
369-
//determine default
370-
if(value && value.length) {
371-
$('input.field-default', target).val(value);
372-
$('div.form-group-default', target).hide();
373-
} else {
374-
$('div.form-group-default', target).show();
375-
}
376-
377-
//determine searchable
378-
if(searchable && searchable.length) {
379-
if(searchable == 1) {
380-
$('input.field-searchable', target).prop('checked', true);
381-
} else {
382-
$('input.field-searchable', target).prop('checked', false);
383-
}
384-
385-
$('input.field-searchable', target).parent().hide();
386-
} else {
387-
$('input.field-searchable', target).parent().show();
388-
}
389-
390-
//determine filterable
391-
if(filterable && filterable.length) {
392-
if(filterable == 1) {
393-
$('input.field-filterable', target).prop('checked', true);
394-
} else {
395-
$('input.field-filterable', target).prop('checked', false);
396-
}
397-
398-
$('input.field-filterable', target).parent().hide();
399-
} else {
400-
$('input.field-filterable', target).parent().show();
401-
}
402-
403-
//determine sortable
404-
if(sortable && sortable.length) {
405-
if(sortable == 1) {
406-
$('input.field-sortable', target).prop('checked', true);
407-
} else {
408-
$('input.field-sortable', target).prop('checked', false);
409-
}
410-
411-
$('input.field-sortable', target).parent().hide();
412-
} else {
413-
$('input.field-sortable', target).parent().show();
414-
}
423+
setModalState();
415424
});
416425

417426
//list format change
@@ -566,6 +575,8 @@
566575

567576
row.doon();
568577
});
578+
579+
setModalState();
569580
});
570581

571582
$(window).on('modal-cancel-click', function(e, trigger) {

0 commit comments

Comments
 (0)