/* -------------------------------------------------------------------------- */ /* LIST JS */ /* -------------------------------------------------------------------------- */ // Constants var choices_values = null; var plugins = null; var themes = null; var options = { item: null, page: wpdbt_admin_vars.data.pagination, pagination: true, indexAsync: true, searchDelay: 250, }; if (wpdbt_admin_vars.data.current_page == "tables" ) { options.item = function (values) { return get_table_template(values); }; } if (wpdbt_admin_vars.data.current_page == "cronjobs") { options.item = function (values) { return get_cronjob_template(values); }; } if (wpdbt_admin_vars.data.current_page == "options") { options.item = function (values) { return get_option_template(values); }; } if (wpdbt_admin_vars.data.current_page == "transients") { options.item = function (values) { return get_transient_template(values); }; } // Create list var list = new List("list-display", options); /* -------------------------------------------------------------------------- */ /* CHOICES */ /* -------------------------------------------------------------------------- */ // Choices element var element = document.getElementById("choices"); // Choices create obj const select_choice = new Choices(element, { searchEnabled: true, placeholder: true, placeholderValue: "Please Choose…", removeItems: true, removeItemButton: true, searchPlaceholderValue: "Buscar", classNames: { containerOuter: "choices select-choices", }, }); select_choice.passedElement.element.addEventListener( "change", function (event) { let current_element = select_choice._currentState.items.find( (selection) => selection.active === true ); if(current_element !== undefined ){ let current_value = current_element.value.split("$"); let current_name = current_value[0]; let current_type = current_value[1]; let current_warning = current_value[2]; if( current_warning == 'yes'){ let element_filter = document.querySelector("#filters #uncategorized"); resetFiltersSelection(element_filter); } if ( (current_type == "plugin" || current_type == "theme") && current_warning == 'no') { console.log('entre en no'); let element_filter = document.querySelector("#filters #" + current_type); resetFiltersSelection(element_filter); } } filterAll(); }, false ); /* -------------------------------------------------------------------------- */ /* CHOICES UNCATEGORIZED */ /* -------------------------------------------------------------------------- */ let choice_options = { searchEnabled: true, placeholder: true, placeholderValue: "Please Choose…", removeItems: false, removeItemButton: false, searchPlaceholderValue: "Buscar", classNames: { containerOuter: "choices select-choices uncategorized", }, }; // Choices element var el_uncategorized_group = document.getElementById( "choices-origin-uncategorized-group" ); // Choices create obj const choice_group_uncategorized = new Choices( el_uncategorized_group, choice_options ); var el_uncategorized_individual = document.getElementById( "choices-origin-uncategorized-individual" ); // Choices create obj const choice_individual_uncategorized = new Choices( el_uncategorized_individual, choice_options ); /* -------------------------------------------------------------------------- */ /* RADIO STATUS */ /* -------------------------------------------------------------------------- */ function changeStatus() { filterAll(); } function changeAutoload() { filterAll(); } // Create elements filters var btn_all = document.querySelector('button[data-type="all"]'); var btn_uncategorized = document.querySelector( 'button[data-type="uncategorized"]' ); var btn_plugin = document.querySelector('button[data-type="plugin"]'); var btn_theme = document.querySelector('button[data-type="theme"]'); var btn_core = document.querySelector('button[data-type="core"]'); function filterList(element) { resetFiltersSelection(element); filterAll(); } /* * Using calback when the filter is completed updates the pagination of the page number selector. */ list.on("filterComplete", function (list) { current_elements.innerHTML = list.matchingItems.length; }); function resetFiltersSelection(element) { let filters = document.querySelectorAll("#filters button"); filters.forEach(function (filterItem) { filterItem.classList.remove("active"); }); element.classList.add("active"); } function filterChoiceSelection(item) { let current_element = select_choice._currentState.items.find( (selection) => selection.active === true ); $_GET_origin = encodeString(current_element.value); let current_value = current_element.value.split("$"); current_value = current_value[0]; if((item._values.multiple == true) && current_value == wpdbt_admin_vars.data.translations.multiple){ return true; } if (current_value == "placeholder") { return true; } let multiple_search = false; if((item._values.multiple == true)){ item._values.origin.forEach(function(origin) { if(origin.name == current_value){ multiple_search = true; } }); } if(multiple_search == true) return true; if (item._values.origin.name == current_value) { return true; } else { return false; } } function filterListSelection(item) { let element = document.querySelectorAll("#filters button.active")[0]; $_GET_category = element.id; if (element.id == "all") return true; if(item._values.origin.warning === 'yes'){ if (element.id == "uncategorized") return true; } if(item._values.multiple === true){ let multiple_type = false; item._values.origin.forEach(function(origin) { if(origin.type == element.id){ multiple_type = true; } }); return multiple_type; } if (item._values.origin.type == element.id) { return true; } else { return false; } } function filterStatus(item) { let checked = document.querySelector("input[name=status]:checked"); let filter_status = checked.value; $_GET_status = filter_status; if (filter_status == "all") { return true; } if(item._values.multiple === true){ let multiple_status = false; item._values.origin.forEach(function(origin) { if(origin.status == filter_status){ multiple_status = true; } }); return multiple_status; } return filter_status == item._values.origin.status; } function filterAutoload(item){ if( wpdbt_admin_vars.data.current_page !== 'options' && wpdbt_admin_vars.data.current_page !== 'transients' ){ return true; } let checked = document.querySelector("input[name=autoload]:checked"); let filter_autoload = checked.value; $_GET_autoload = filter_autoload; if (filter_autoload == "all") { return true; } return filter_autoload == item._values.autoload; } function filterAll() { handleLoader(true); fetch( wpdbt_admin_vars.data.admin_url + "/wp-database-tools-admin-fetch.json" ).then(function (response) { resetCheck(); list.filter(function (item) { return ( filterChoiceSelection(item) && filterListSelection(item) && filterStatus(item) && filterSearchName(item) && filterAutoload(item) ); }); // Set sleep for hidden loading sleep(200).then(() => { handleLoader(false); }); }); } function sleep(time) { return new Promise((resolve) => setTimeout(resolve, time)); } /* -------------------------------------------------------------------------- */ /* SORT LIST */ /* -------------------------------------------------------------------------- */ function sortList(el) { // Class active change let sorts = document.querySelectorAll(".svg-sort"); sorts.forEach(function (current_sort, index) { current_sort.classList.remove("active"); }); let svg_sort = el.querySelector(".svg-sort"); svg_sort.classList.add("active"); // Sort by atributte let order = el.dataset.order; let row = el.dataset.row; if(row == 'origin'){ list.sort('', { order: order, sortFunction: function (a, b) { return a._values.origin.name > b._values.origin.name ? 1 : a._values.origin.name < b._values.origin.name ? -1 : 0; } }); }else{ list.sort(row, { order: order }); } }