contrib_todo_list-1.1.1/js/admin-todo.js
js/admin-todo.js
(function ($, Drupal, once) {
Drupal.behaviors.todoListFilters = {
attach: function (context, settings) {
once('todo-filters-init', 'body', context).forEach(function () {
const currentFilters = settings.todoList.currentFilters;
if (currentFilters) {
if (currentFilters.state) {
$('.todo-filters .form-select').eq(0).val(currentFilters.state);
}
if (currentFilters.share) {
$('.todo-filters .form-select').eq(1).val(currentFilters.share);
}
}
});
once('todo-filters', '.todo-filters .form-submit', context).forEach(function (button) {
$(button).on('click', function(e) {
e.preventDefault();
if ($(this).val() === Drupal.t('Réinitialiser')) {
window.location.href = window.location.pathname;
return;
}
const state = $('.todo-filters .form-select').eq(0).val();
const share = $('.todo-filters .form-select').eq(1).val();
let params = new URLSearchParams();
if (state) {
params.append('state', state);
}
if (share) {
params.append('share', share);
}
const queryString = params.toString();
const url = window.location.pathname + (queryString ? '?' + queryString : '');
window.location.href = url;
});
});
}
};
})(jQuery, Drupal, once);
