feat(Rule): add new rules
This commit is contained in:
37
admin/js/rule-admin.js
Normal file
37
admin/js/rule-admin.js
Normal file
@@ -0,0 +1,37 @@
|
||||
(function () {
|
||||
function nextIndex(container) {
|
||||
return container.querySelectorAll('[data-row]').length;
|
||||
}
|
||||
|
||||
function addRow(target) {
|
||||
const container = document.getElementById(target === 'actions' ? 'sodino-actions' : 'sodino-conditions');
|
||||
const template = document.getElementById(target === 'actions' ? 'sodino-action-template' : 'sodino-condition-template');
|
||||
if (!container || !template) {
|
||||
return;
|
||||
}
|
||||
|
||||
const index = nextIndex(container);
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.innerHTML = template.innerHTML.replaceAll('__INDEX__', String(index)).trim();
|
||||
container.appendChild(wrapper.firstElementChild);
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
const addButton = event.target.closest('.sodino-add-row');
|
||||
if (addButton) {
|
||||
event.preventDefault();
|
||||
addRow(addButton.dataset.target);
|
||||
return;
|
||||
}
|
||||
|
||||
const removeButton = event.target.closest('.sodino-remove-row');
|
||||
if (removeButton) {
|
||||
event.preventDefault();
|
||||
const row = removeButton.closest('[data-row]');
|
||||
const container = row ? row.parentElement : null;
|
||||
if (container && container.querySelectorAll('[data-row]').length > 1) {
|
||||
row.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user