|
224 | 224 | //----------------------------//
|
225 | 225 | // Modal Events
|
226 | 226 | $(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); |
231 | 230 |
|
232 | 231 | //fixing a jQuery bug on clone
|
233 | 232 | $('option', this).removeAttr('selected');
|
234 | 233 | option.attr('selected', 'selected');
|
235 | 234 |
|
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 |
| - |
241 | 235 | var value = option.attr('data-default');
|
242 | 236 | var label = option.attr('data-label');
|
243 | 237 | var name = option.attr('data-name');
|
244 | 238 | var searchable = option.attr('data-searchable');
|
245 | 239 | var filterable = option.attr('data-filterable');
|
246 | 240 | var sortable = option.attr('data-sortable');
|
247 |
| - var index = $(this).getModelIndex(); |
248 |
| - |
249 | 241 | var validation = option.attr('data-validation');
|
250 | 242 |
|
| 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 | + |
251 | 327 | //reset
|
252 | 328 | $('select.field-list optgroup', target).show();
|
253 | 329 | $('select.field-detail optgroup', target).show();
|
|
256 | 332 | $('input.field-sortable', target).attr('disabled', false);
|
257 | 333 |
|
258 | 334 | //remove all fieldsets
|
259 |
| - select.parent().find('div.input-fieldset').remove(); |
| 335 | + select.parent() |
| 336 | + .find('div.input-fieldset') |
| 337 | + .remove(); |
260 | 338 |
|
261 | 339 | fieldsets.forEach(function(field) {
|
262 | 340 | var data = [];
|
|
342 | 420 | }
|
343 | 421 | });
|
344 | 422 |
|
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(); |
415 | 424 | });
|
416 | 425 |
|
417 | 426 | //list format change
|
|
566 | 575 |
|
567 | 576 | row.doon();
|
568 | 577 | });
|
| 578 | + |
| 579 | + setModalState(); |
569 | 580 | });
|
570 | 581 |
|
571 | 582 | $(window).on('modal-cancel-click', function(e, trigger) {
|
|
0 commit comments