$(function() { $(".selectBox").on("click", function (e) { if($(this).siblings(".checkboxes").find("label").css("display") == "block") { if($(this).siblings(".checkboxes").css("display") == "none") { $(".checkboxes").css("display", "none"); $(this).siblings(".checkboxes").css("display", "block"); } else { $(".checkboxes").css("display", "none"); } } }); $("body").on("click", function (event) { if (!$(event.target).hasClass("overSelect")) { if (($(event.target).closest(".checkboxes").length == 0)) { $(".checkboxes").css("display", "none"); } } }); $(".multiselect #category-any").on("change", function() { $("#notes").slideUp(200); if(this.checked) { search_data["category"] = get_value_list_by_key(db_table["category"], null, -1, "category_id"); search_data["project"] = get_value_list_by_key(db_table["project"], null, -1, "project_id"); search_data["type"] = get_value_list_by_key(db_table["type"], null, -1, "type_id"); $(".category-option").prop("checked", true); show_select_option("project", search_data["project"], "p", true); $("#project-any").prop("checked", true); show_select_option("type", search_data["type"], "t", true); $("#type-any").prop("checked", true); } else { search_data["category"] = []; search_data["project"] = []; search_data["type"] = []; $(".category-option").prop("checked", false); show_select_option("project", search_data["project"], "p", true); show_select_option("type", search_data["type"], "t", true); } search_data["notes"] = []; search_data["project"].forEach(element => { search_data["notes"] = search_data["notes"].concat(db_table["notes"][element]); }); notes_show_id_list = []; search_data["notes"].forEach(element => { for(i=0; i { if(element != "any") { category_id_list.push(element.split("-")[0].replace("c", "")); list_id_list.push(element.split("-")[1].replace("l", "")); } }); search_data["category"] = category_id_list; search_data["project"] = get_value_list_by_key(db_table["project"], "category_id", category_id_list, "project_id"); target_type_id_list = get_value_list_by_key(db_table["category_type"], "list_id", list_id_list, "category_list"); search_data["type"] = merge_string_to_list(target_type_id_list); } //set view show_select_option("project", search_data["project"], "p", true); $("#project-any").prop("checked", true); show_select_option("type", search_data["type"], "t", true); $("#type-any").prop("checked", true); if(category_id_list.length < db_table["category"].length) { $("#category-any").prop("checked", false); } else { $("#category-any").prop("checked", true); } search_data["notes"] = []; search_data["project"].forEach(element => { search_data["notes"] = search_data["notes"].concat(db_table["notes"][element]); }); notes_show_id_list = []; search_data["notes"].forEach(element => { for(i=0; i { search_data["notes"] = search_data["notes"].concat(db_table["notes"][element]); }); notes_show_id_list = []; search_data["notes"].forEach(element => { for(i=0; i { output = output.concat(element.split(",")); }); return output; } function string_concat_list(name, target_list) { output_list = []; target_list.forEach(element => { output_list.push(name + element); }); return output_list; } function get_multi_checkbox_check_list(checkbox_class, name_replace) { output = []; var $select_option = $("."+checkbox_class+":checked"); $select_option.each(function(){ if(checkbox_class == "notes-option") { output.push($(this).attr('value')); } else { output.push($(this).attr('id').replace(name_replace, "")); } }); return output; } function set_select_text(address, lock) { //unlock select bar $("#"+address+" select").prop("disabled", false); //get check number check_length = $("."+address+"-option:checked").length; //get option name that show on select bar show_list = []; $("."+address+"-option:checked").each(function() { show_list = show_list.concat($(this).attr("value")); }); //set select bar text if(check_length == 0){ if(lock) { $("#"+address+" select option").text("無符合條件選項"); $("#"+address+" select").prop("disabled", true); } else { $("#"+address+" select option").text("未選擇任何專案"); } } else { if(check_length > 2) { $("#"+address+" select option").text("已選擇 "+check_length+" 項"); } else { $("#"+address+" select option").text(show_list); } } } function show_select_option(address, show_list, id_name, lock) { //init option $("#" + address + " .checkboxes input").prop("checked", false); $("#" + address + " .checkboxes label").css("display", "none"); //show option show_list.forEach(element => { $("#"+id_name+element).prop("checked", true); $("#"+id_name+element).parent().css("display", "block"); }); if(show_list.length) { $("#" + address + " #" + address + "-any").prop("checked", true); $("#" + address + " #" + address + "-any").parent().css("display", "block"); } set_select_text(address, lock); } function reset_checkbox(checkbox_class, id_name, lock) { search_data[checkbox_class] = []; $("#"+checkbox_class+" ." + checkbox_class + "-button").each(function() { if($(this).css("display") == "block") { $(this).find("input").prop("checked", true); if(checkbox_class == "notes") { search_data[checkbox_class] = search_data[checkbox_class].concat($(this).find("input").attr("value")); } else { search_data[checkbox_class] = search_data[checkbox_class].concat($(this).find("input").attr("id").replace(id_name, "")); } } }); $("#"+checkbox_class+" #" + checkbox_class + "-any").prop("checked", true); set_select_text(checkbox_class, lock) }