mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 03:26:51 +03:00
feat: return community list change handler
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
'require form';
|
||||
'require baseclass';
|
||||
'require ui';
|
||||
'require tools.widgets as widgets';
|
||||
'require view.podkop.main as main';
|
||||
|
||||
@@ -231,6 +232,81 @@ function createSectionContent(section) {
|
||||
o.value(key, _(label));
|
||||
});
|
||||
o.rmempty = true;
|
||||
let lastValues = [];
|
||||
let isProcessing = false;
|
||||
|
||||
o.onchange = function (ev, section_id, value) {
|
||||
if (isProcessing) return;
|
||||
isProcessing = true;
|
||||
|
||||
try {
|
||||
const values = Array.isArray(value) ? value : [value];
|
||||
let newValues = [...values];
|
||||
let notifications = [];
|
||||
|
||||
const selectedRegionalOptions = main.REGIONAL_OPTIONS.filter((opt) =>
|
||||
newValues.includes(opt),
|
||||
);
|
||||
|
||||
if (selectedRegionalOptions.length > 1) {
|
||||
const lastSelected =
|
||||
selectedRegionalOptions[selectedRegionalOptions.length - 1];
|
||||
const removedRegions = selectedRegionalOptions.slice(0, -1);
|
||||
newValues = newValues.filter(
|
||||
(v) => v === lastSelected || !main.REGIONAL_OPTIONS.includes(v),
|
||||
);
|
||||
notifications.push(
|
||||
E('p', { class: 'alert-message warning' }, [
|
||||
E('strong', {}, _('Regional options cannot be used together')),
|
||||
E('br'),
|
||||
_(
|
||||
'Warning: %s cannot be used together with %s. Previous selections have been removed.',
|
||||
).format(removedRegions.join(', '), lastSelected),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
if (newValues.includes('russia_inside')) {
|
||||
const removedServices = newValues.filter(
|
||||
(v) => !main.ALLOWED_WITH_RUSSIA_INSIDE.includes(v),
|
||||
);
|
||||
if (removedServices.length > 0) {
|
||||
newValues = newValues.filter((v) =>
|
||||
main.ALLOWED_WITH_RUSSIA_INSIDE.includes(v),
|
||||
);
|
||||
notifications.push(
|
||||
E('p', { class: 'alert-message warning' }, [
|
||||
E('strong', {}, _('Russia inside restrictions')),
|
||||
E('br'),
|
||||
_(
|
||||
'Warning: Russia inside can only be used with %s. %s already in Russia inside and have been removed from selection.',
|
||||
).format(
|
||||
main.ALLOWED_WITH_RUSSIA_INSIDE.map(
|
||||
(key) => main.DOMAIN_LIST_OPTIONS[key],
|
||||
)
|
||||
.filter((label) => label !== 'Russia inside')
|
||||
.join(', '),
|
||||
removedServices.join(', '),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(newValues.sort()) !== JSON.stringify(values.sort())) {
|
||||
this.getUIElement(section_id).setValue(newValues);
|
||||
}
|
||||
|
||||
notifications.forEach((notification) =>
|
||||
ui.addNotification(null, notification),
|
||||
);
|
||||
lastValues = newValues;
|
||||
} catch (e) {
|
||||
console.error('Error in onchange handler:', e);
|
||||
} finally {
|
||||
isProcessing = false;
|
||||
}
|
||||
};
|
||||
|
||||
o = section.option(
|
||||
form.ListValue,
|
||||
|
||||
Reference in New Issue
Block a user