94 lines
3.4 KiB
JavaScript
94 lines
3.4 KiB
JavaScript
/**
|
|
* DO NOT EDIT THIS FILE.
|
|
* See the following change record for more information,
|
|
* https://www.drupal.org/node/2815083
|
|
* @preserve
|
|
**/
|
|
|
|
(function ($, Drupal, drupalSettings) {
|
|
Drupal.behaviors.contentTranslationDependentOptions = {
|
|
attach(context) {
|
|
const $context = $(context);
|
|
const options = drupalSettings.contentTranslationDependentOptions;
|
|
let $fields;
|
|
|
|
function fieldsChangeHandler($fields, dependentColumns) {
|
|
return function (e) {
|
|
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns, $(e.target));
|
|
};
|
|
}
|
|
|
|
if (options && options.dependent_selectors) {
|
|
Object.keys(options.dependent_selectors).forEach(field => {
|
|
$fields = $context.find(`input[name^="${field}"]`);
|
|
const dependentColumns = options.dependent_selectors[field];
|
|
$fields.on('change', fieldsChangeHandler($fields, dependentColumns));
|
|
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns);
|
|
});
|
|
}
|
|
},
|
|
|
|
check($fields, dependentColumns, $changed) {
|
|
let $element = $changed;
|
|
let column;
|
|
|
|
function filterFieldsList(index, field) {
|
|
return field.value === column;
|
|
}
|
|
|
|
Object.keys(dependentColumns || {}).forEach(index => {
|
|
column = dependentColumns[index];
|
|
|
|
if (!$changed) {
|
|
$element = $fields.filter(filterFieldsList);
|
|
}
|
|
|
|
if ($element.is(`input[value="${column}"]:checked`)) {
|
|
$fields.prop('checked', true).not($element).prop('disabled', true);
|
|
} else {
|
|
$fields.prop('disabled', false);
|
|
}
|
|
});
|
|
}
|
|
|
|
};
|
|
Drupal.behaviors.contentTranslation = {
|
|
attach(context) {
|
|
once('translation-entity-admin-hide', $(context).find('table .bundle-settings .translatable :input')).forEach(input => {
|
|
const $input = $(input);
|
|
const $bundleSettings = $input.closest('.bundle-settings');
|
|
|
|
if (!$input.is(':checked')) {
|
|
$bundleSettings.nextUntil('.bundle-settings').hide();
|
|
} else {
|
|
$bundleSettings.nextUntil('.bundle-settings', '.field-settings').find('.translatable :input:not(:checked)').closest('.field-settings').nextUntil(':not(.column-settings)').hide();
|
|
}
|
|
});
|
|
$(once('translation-entity-admin-bind', 'body')).on('click', 'table .bundle-settings .translatable :input', e => {
|
|
const $target = $(e.target);
|
|
const $bundleSettings = $target.closest('.bundle-settings');
|
|
const $settings = $bundleSettings.nextUntil('.bundle-settings');
|
|
const $fieldSettings = $settings.filter('.field-settings');
|
|
|
|
if ($target.is(':checked')) {
|
|
$bundleSettings.find('.operations :input[name$="[language_alterable]"]').prop('checked', true);
|
|
$fieldSettings.find('.translatable :input').prop('checked', true);
|
|
$settings.show();
|
|
} else {
|
|
$settings.hide();
|
|
}
|
|
}).on('click', 'table .field-settings .translatable :input', e => {
|
|
const $target = $(e.target);
|
|
const $fieldSettings = $target.closest('.field-settings');
|
|
const $columnSettings = $fieldSettings.nextUntil('.field-settings, .bundle-settings');
|
|
|
|
if ($target.is(':checked')) {
|
|
$columnSettings.show();
|
|
} else {
|
|
$columnSettings.hide();
|
|
}
|
|
});
|
|
}
|
|
|
|
};
|
|
})(jQuery, Drupal, drupalSettings); |