|
1 | 1 | function showElementsType() { |
2 | | - var value = $('select#form-widgets-type_template').val(); |
3 | | - |
4 | | - switch(value) { |
5 | | - case '--NOVALUE--': |
6 | | - $('#formfield-form-widgets-accordion_open_multiple').hide(); |
7 | | - $('#formfield-form-widgets-accordion_items_expanded').hide(); |
8 | | - break; |
9 | | - case 'accordion': |
10 | | - $('#formfield-form-widgets-accordion_open_multiple').show(); |
11 | | - $('#formfield-form-widgets-accordion_items_expanded').show(); |
12 | | - break; |
13 | | - case 'nav': |
14 | | - $('#formfield-form-widgets-accordion_open_multiple').hide(); |
15 | | - $('#formfield-form-widgets-accordion_items_expanded').hide(); |
16 | | - break; |
17 | | - } |
| 2 | + var value = $('select#form-widgets-type_template').val(); |
| 3 | + |
| 4 | + switch(value) { |
| 5 | + case '--NOVALUE--': |
| 6 | + $('#formfield-form-widgets-accordion_open_multiple').hide(); |
| 7 | + $('#formfield-form-widgets-accordion_open_first').hide(); |
| 8 | + $('#formfield-form-widgets-accordion_items_expanded').hide(); |
| 9 | + break; |
| 10 | + case 'accordion': |
| 11 | + $('#formfield-form-widgets-accordion_open_multiple').show(); |
| 12 | + $('#formfield-form-widgets-accordion_open_first').show(); |
| 13 | + $('#formfield-form-widgets-accordion_items_expanded').show(); |
| 14 | + break; |
| 15 | + case 'nav': |
| 16 | + $('#formfield-form-widgets-accordion_open_multiple').hide(); |
| 17 | + $('#formfield-form-widgets-accordion_open_first').hide(); |
| 18 | + $('#formfield-form-widgets-accordion_items_expanded').hide(); |
| 19 | + break; |
| 20 | + } |
18 | 21 | } |
19 | 22 |
|
20 | 23 | function showCollectionSelector() { |
21 | | - var value = $('select#form-widgets-content').val(); |
22 | | - |
23 | | - switch(value) { |
24 | | - case 'inside': |
25 | | - if ($('body.template-edit').length > 0) { |
26 | | - $('#formfield-form-widgets-content .form-text').show(); |
27 | | - } else { |
28 | | - $('#formfield-form-widgets-content .form-text').hide(); |
29 | | - } |
30 | | - $('#formfield-form-widgets-collection').hide(); |
31 | | - break; |
32 | | - default: |
33 | | - $('#formfield-form-widgets-content .form-text').hide(); |
34 | | - $('#formfield-form-widgets-collection').show(); |
35 | | - break; |
| 24 | + var value = $('select#form-widgets-content').val(); |
| 25 | + |
| 26 | + switch(value) { |
| 27 | + case 'inside': |
| 28 | + if ($('body.template-edit').length > 0) { |
| 29 | + $('#formfield-form-widgets-content .form-text').show(); |
| 30 | + } else { |
| 31 | + $('#formfield-form-widgets-content .form-text').hide(); |
| 32 | + } |
| 33 | + $('#formfield-form-widgets-collection').hide(); |
| 34 | + break; |
| 35 | + default: |
| 36 | + $('#formfield-form-widgets-content .form-text').hide(); |
| 37 | + $('#formfield-form-widgets-collection').show(); |
| 38 | + break; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +function disableSecondaryCheckboxIfPrincipalIsChecked(principal_checkbox, secondary_checkbox, enable_secondary_checkbox = false) { |
| 43 | + if (principal_checkbox.length === 0 || secondary_checkbox.length === 0) { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + var isOpenFirstChecked = principal_checkbox.is(':checked'); |
| 48 | + if (isOpenFirstChecked) { |
| 49 | + secondary_checkbox.prop('disabled', true); |
| 50 | + if (enable_secondary_checkbox) { |
| 51 | + secondary_checkbox.prop('checked', true); |
| 52 | + } else { |
| 53 | + secondary_checkbox.prop('checked', false); |
36 | 54 | } |
| 55 | + } else { |
| 56 | + secondary_checkbox.prop('disabled', false); |
| 57 | + } |
37 | 58 | } |
38 | 59 |
|
39 | 60 | $(document).ready(function(){ |
40 | 61 |
|
| 62 | + showElementsType(); |
| 63 | + showCollectionSelector(); |
| 64 | + disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_open_first input[type="checkbox"]'), $('#form-widgets-accordion_items_expanded input[type="checkbox"]')); |
| 65 | + disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_first input[type="checkbox"]')); |
| 66 | + disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_multiple input[type="checkbox"]'), true); |
| 67 | + |
| 68 | + $('select#form-widgets-type_template').on('change', function(){ |
41 | 69 | showElementsType(); |
| 70 | + }); |
| 71 | + |
| 72 | + $('select#form-widgets-content').on('change', function(){ |
42 | 73 | showCollectionSelector(); |
| 74 | + }); |
43 | 75 |
|
44 | | - $('select#form-widgets-type_template').on('change', function(){ |
45 | | - showElementsType(); |
46 | | - }); |
| 76 | + $('#form-widgets-accordion_open_first input[type="checkbox"]').on('change', function(){ |
| 77 | + disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_open_first input[type="checkbox"]'), $('#form-widgets-accordion_items_expanded input[type="checkbox"]')); |
| 78 | + }); |
47 | 79 |
|
48 | | - $('select#form-widgets-content').on('change', function(){ |
49 | | - showCollectionSelector(); |
50 | | - }); |
| 80 | + $('#form-widgets-accordion_items_expanded input[type="checkbox"]').on('change', function(){ |
| 81 | + disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_first input[type="checkbox"]')); |
| 82 | + disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_multiple input[type="checkbox"]'), true); |
| 83 | + }); |
| 84 | + |
51 | 85 | }); |
0 commit comments