Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/content_translation/content_translation.admin.es6.js @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 /** | 1 /** |
2 * @file | 2 * @file |
3 * Content Translation admin behaviors. | 3 * Content Translation admin behaviors. |
4 */ | 4 */ |
5 | 5 |
6 (function ($, Drupal, drupalSettings) { | 6 (function($, Drupal, drupalSettings) { |
7 /** | 7 /** |
8 * Forces applicable options to be checked as translatable. | 8 * Forces applicable options to be checked as translatable. |
9 * | 9 * |
10 * @type {Drupal~behavior} | 10 * @type {Drupal~behavior} |
11 * | 11 * |
17 const $context = $(context); | 17 const $context = $(context); |
18 const options = drupalSettings.contentTranslationDependentOptions; | 18 const options = drupalSettings.contentTranslationDependentOptions; |
19 let $fields; | 19 let $fields; |
20 | 20 |
21 function fieldsChangeHandler($fields, dependentColumns) { | 21 function fieldsChangeHandler($fields, dependentColumns) { |
22 return function (e) { | 22 return function(e) { |
23 Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns, $(e.target)); | 23 Drupal.behaviors.contentTranslationDependentOptions.check( |
24 $fields, | |
25 dependentColumns, | |
26 $(e.target), | |
27 ); | |
24 }; | 28 }; |
25 } | 29 } |
26 | 30 |
27 // We're given a generic name to look for so we find all inputs containing | 31 // We're given a generic name to look for so we find all inputs containing |
28 // that name and copy over the input values that require all columns to be | 32 // that name and copy over the input values that require all columns to be |
29 // translatable. | 33 // translatable. |
30 if (options && options.dependent_selectors) { | 34 if (options && options.dependent_selectors) { |
31 Object.keys(options.dependent_selectors).forEach((field) => { | 35 Object.keys(options.dependent_selectors).forEach(field => { |
32 $fields = $context.find(`input[name^="${field}"]`); | 36 $fields = $context.find(`input[name^="${field}"]`); |
33 const dependentColumns = options.dependent_selectors[field]; | 37 const dependentColumns = options.dependent_selectors[field]; |
34 | 38 |
35 $fields.on('change', fieldsChangeHandler($fields, dependentColumns)); | 39 $fields.on('change', fieldsChangeHandler($fields, dependentColumns)); |
36 Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns); | 40 Drupal.behaviors.contentTranslationDependentOptions.check( |
41 $fields, | |
42 dependentColumns, | |
43 ); | |
37 }); | 44 }); |
38 } | 45 } |
39 }, | 46 }, |
40 check($fields, dependentColumns, $changed) { | 47 check($fields, dependentColumns, $changed) { |
41 let $element = $changed; | 48 let $element = $changed; |
45 return $(field).val() === column; | 52 return $(field).val() === column; |
46 } | 53 } |
47 | 54 |
48 // A field that has many different translatable parts can also define one | 55 // A field that has many different translatable parts can also define one |
49 // or more columns that require all columns to be translatable. | 56 // or more columns that require all columns to be translatable. |
50 Object.keys(dependentColumns || {}).forEach((index) => { | 57 Object.keys(dependentColumns || {}).forEach(index => { |
51 column = dependentColumns[index]; | 58 column = dependentColumns[index]; |
52 | 59 |
53 if (!$changed) { | 60 if (!$changed) { |
54 $element = $fields.filter(filterFieldsList); | 61 $element = $fields.filter(filterFieldsList); |
55 } | 62 } |
56 | 63 |
57 if ($element.is(`input[value="${column}"]:checked`)) { | 64 if ($element.is(`input[value="${column}"]:checked`)) { |
58 $fields.prop('checked', true) | 65 $fields |
59 .not($element).prop('disabled', true); | 66 .prop('checked', true) |
60 } | 67 .not($element) |
61 else { | 68 .prop('disabled', true); |
69 } else { | |
62 $fields.prop('disabled', false); | 70 $fields.prop('disabled', false); |
63 } | 71 } |
64 }); | 72 }); |
65 }, | 73 }, |
66 }; | 74 }; |
75 */ | 83 */ |
76 Drupal.behaviors.contentTranslation = { | 84 Drupal.behaviors.contentTranslation = { |
77 attach(context) { | 85 attach(context) { |
78 // Initially hide all field rows for non translatable bundles and all | 86 // Initially hide all field rows for non translatable bundles and all |
79 // column rows for non translatable fields. | 87 // column rows for non translatable fields. |
80 $(context).find('table .bundle-settings .translatable :input').once('translation-entity-admin-hide').each(function () { | 88 $(context) |
81 const $input = $(this); | 89 .find('table .bundle-settings .translatable :input') |
82 const $bundleSettings = $input.closest('.bundle-settings'); | 90 .once('translation-entity-admin-hide') |
83 if (!$input.is(':checked')) { | 91 .each(function() { |
84 $bundleSettings.nextUntil('.bundle-settings').hide(); | 92 const $input = $(this); |
85 } | 93 const $bundleSettings = $input.closest('.bundle-settings'); |
86 else { | 94 if (!$input.is(':checked')) { |
87 $bundleSettings | 95 $bundleSettings.nextUntil('.bundle-settings').hide(); |
88 .nextUntil('.bundle-settings', '.field-settings') | 96 } else { |
89 .find('.translatable :input:not(:checked)') | 97 $bundleSettings |
90 .closest('.field-settings') | 98 .nextUntil('.bundle-settings', '.field-settings') |
91 .nextUntil(':not(.column-settings)') | 99 .find('.translatable :input:not(:checked)') |
92 .hide(); | 100 .closest('.field-settings') |
93 } | 101 .nextUntil(':not(.column-settings)') |
94 }); | 102 .hide(); |
103 } | |
104 }); | |
95 | 105 |
96 // When a bundle is made translatable all of its fields should inherit | 106 // When a bundle is made translatable all of its fields should inherit |
97 // this setting. Instead when it is made non translatable its fields are | 107 // this setting. Instead when it is made non translatable its fields are |
98 // hidden, since their translatability no longer matters. | 108 // hidden, since their translatability no longer matters. |
99 $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', (e) => { | 109 $('body') |
100 const $target = $(e.target); | 110 .once('translation-entity-admin-bind') |
101 const $bundleSettings = $target.closest('.bundle-settings'); | 111 .on('click', 'table .bundle-settings .translatable :input', e => { |
102 const $settings = $bundleSettings.nextUntil('.bundle-settings'); | 112 const $target = $(e.target); |
103 const $fieldSettings = $settings.filter('.field-settings'); | 113 const $bundleSettings = $target.closest('.bundle-settings'); |
104 if ($target.is(':checked')) { | 114 const $settings = $bundleSettings.nextUntil('.bundle-settings'); |
105 $bundleSettings.find('.operations :input[name$="[language_alterable]"]').prop('checked', true); | 115 const $fieldSettings = $settings.filter('.field-settings'); |
106 $fieldSettings.find('.translatable :input').prop('checked', true); | 116 if ($target.is(':checked')) { |
107 $settings.show(); | 117 $bundleSettings |
108 } | 118 .find('.operations :input[name$="[language_alterable]"]') |
109 else { | 119 .prop('checked', true); |
110 $settings.hide(); | 120 $fieldSettings.find('.translatable :input').prop('checked', true); |
111 } | 121 $settings.show(); |
112 }) | 122 } else { |
113 .on('click', 'table .field-settings .translatable :input', (e) => { | 123 $settings.hide(); |
124 } | |
125 }) | |
126 .on('click', 'table .field-settings .translatable :input', e => { | |
114 const $target = $(e.target); | 127 const $target = $(e.target); |
115 const $fieldSettings = $target.closest('.field-settings'); | 128 const $fieldSettings = $target.closest('.field-settings'); |
116 const $columnSettings = $fieldSettings.nextUntil('.field-settings, .bundle-settings'); | 129 const $columnSettings = $fieldSettings.nextUntil( |
130 '.field-settings, .bundle-settings', | |
131 ); | |
117 if ($target.is(':checked')) { | 132 if ($target.is(':checked')) { |
118 $columnSettings.show(); | 133 $columnSettings.show(); |
119 } | 134 } else { |
120 else { | |
121 $columnSettings.hide(); | 135 $columnSettings.hide(); |
122 } | 136 } |
123 }); | 137 }); |
124 }, | 138 }, |
125 }; | 139 }; |
126 }(jQuery, Drupal, drupalSettings)); | 140 })(jQuery, Drupal, drupalSettings); |