From 1cf306d11fa343c4f2e7370953a2013ac7a273bd Mon Sep 17 00:00:00 2001 From: lenovo Date: Wed, 16 Nov 2022 23:35:11 +0100 Subject: [PATCH] selection works in all cases --- .../map_prof/scripts/mp_filter_events.js | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/srcs/plugins/map_prof/scripts/mp_filter_events.js b/srcs/plugins/map_prof/scripts/mp_filter_events.js index 2b62433..82ca933 100644 --- a/srcs/plugins/map_prof/scripts/mp_filter_events.js +++ b/srcs/plugins/map_prof/scripts/mp_filter_events.js @@ -211,7 +211,40 @@ function toggle_menu_items(menu_name, x_abled) { } } -function disable_menus(menu_name_ori, menu_item_ori, is_menu_title) { +function disable_menus(menu_name_ori, menu_item_ori, reverse, menu_index) { + + // in case it's a menu title, like "Pays" or "Categories", + // or it's Mode menu, and both (irl and online) are abled or disabled, + // just act like Reset button + // it's too bas it will also go through this menu items even though it's unnecessary + if (menu_item_ori == null) { // it's a menu name + // "item" as a menu name will select all items in all menus + toggle_menu_items("item", "enable"); + return; + } + if (menu_name_ori === "mode") { + let mode_menus = document.getElementsByClassName("filter_menu_mode"); + let state = 0; + for (let mode_menu of mode_menus) { + if (mode_menu.checked) + state++; + else + state--; + } + if (state != 0) { // state equal 0 if both have a different state, because (0 + 1 - 1 = 0) and (0 - 1 + 1 = 0) + // "item" as a menu name will select all items in all menus + toggle_menu_items("item", "enable"); + return; + } + else if (reverse) { // menu is "mode" and only one item is selected and the action was to deselect one, so the action has trigered on item but really we want to see the options of the other item, so let's switch them + if (menu_index === 0) + menu_index++; + else + menu_index--; + menu_item_ori = filters[menu_name_ori][menu_index]; + } + } + let menu_item_name = menu_item_ori._name; let item_ori_html = html_item(menu_name_ori, menu_item_name); let is_enabled = item_ori_html.classList.contains('enable'); @@ -224,12 +257,8 @@ function disable_menus(menu_name_ori, menu_item_ori, is_menu_title) { continue; if (menu_name === "indexes") continue; - if (is_menu_title) { - // true == enable - toggle_menu_items(menu_name, "enable"); - } else if (! is_enabled) { - // false == disable + // it's too bad it will disable all to then enable certains, it would be better to check each time toggle_menu_items(menu_name, "disable"); // loop through items in menu names (ex. for "pays" : france, chili, cuba) for (let item of menu_item_ori[menu_name]) { @@ -246,11 +275,10 @@ function filter_show_only(element, menu_name) { g_infowindow.close(); let menu_index = element.getAttribute("data-menu_index"); - let menu_item = filters[menu_name][menu_index]; - let is_menu_title = true; + let menu_item = null; let indexes = []; if (menu_index != "menu_name") { - is_menu_title = false; + menu_item = filters[menu_name][menu_index]; indexes = menu_item.indexes; } @@ -261,15 +289,13 @@ function filter_show_only(element, menu_name) { add = true; } - disable_menus(menu_name, menu_item, is_menu_title); + disable_menus(menu_name, menu_item, reverse, menu_index); let index_array = filter_selection_indexes(menu_name, indexes, reverse, add); redraw_clusters(index_array); } - - function filter_show_all() { g_infowindow.close();