Commit 86a636507247434b17f79723b38323be239cb90b
Committed by
Gabriela Navarro
1 parent
53303e03
Exists in
master
and in
5 other branches
Remove unused js code from software-catalog.js and fix clean up
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
1 changed file
with
10 additions
and
79 deletions
Show diff stats
public/software-catalog.js
| @@ -2,60 +2,10 @@ | @@ -2,60 +2,10 @@ | ||
| 2 | "use strict"; | 2 | "use strict"; |
| 3 | 3 | ||
| 4 | var AJAX_URL = { | 4 | var AJAX_URL = { |
| 5 | - get_categories: | ||
| 6 | - url_with_subdirectory("/plugin/mpog_software/get_categories"), | ||
| 7 | software_infos: | 5 | software_infos: |
| 8 | url_with_subdirectory("/search/software_infos") | 6 | url_with_subdirectory("/search/software_infos") |
| 9 | }; | 7 | }; |
| 10 | 8 | ||
| 11 | - function create_catalog_element(first, value, id) { | ||
| 12 | - var li_tag = document.createElement("li"); | ||
| 13 | - | ||
| 14 | - li_tag.className = "category_box"; | ||
| 15 | - li_tag.innerHTML = value + " <span class='catalog-remove-item' data-id='"+id+"'>x</span>"; | ||
| 16 | - | ||
| 17 | - return li_tag; | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - function add_item_to_catalog(value, id) { | ||
| 21 | - var already_has = false; | ||
| 22 | - | ||
| 23 | - $("#catalog-list ul li").each(function(i, li){ | ||
| 24 | - var regex = new RegExp(value, "g"); | ||
| 25 | - | ||
| 26 | - if( regex.test(li.innerHTML) ) { | ||
| 27 | - already_has = true; | ||
| 28 | - } | ||
| 29 | - }); | ||
| 30 | - | ||
| 31 | - if( !already_has ) { | ||
| 32 | - var catalog_list = $("#catalog-list ul li"); | ||
| 33 | - var current_ids = $("#filter").val(); | ||
| 34 | - var first = catalog_list.length == 0; | ||
| 35 | - | ||
| 36 | - current_ids += first ? id : ","+id; | ||
| 37 | - | ||
| 38 | - $("#filter").val(current_ids); | ||
| 39 | - | ||
| 40 | - $("#catalog-list ul").append(create_catalog_element(first, value, id)); | ||
| 41 | - } | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - function remote_catalog_item() { | ||
| 45 | - var current_id = this.getAttribute("data-id"); | ||
| 46 | - var filter_ids = $("#filter").val(); | ||
| 47 | - var id_list = []; | ||
| 48 | - | ||
| 49 | - filter_ids.split(",").forEach(function(id){ | ||
| 50 | - if( current_id != id ) { | ||
| 51 | - id_list.push(id); | ||
| 52 | - } | ||
| 53 | - }); | ||
| 54 | - | ||
| 55 | - $("#filter").val(id_list.join(",")); | ||
| 56 | - | ||
| 57 | - $(this).parent().remove(); | ||
| 58 | - } | ||
| 59 | 9 | ||
| 60 | function show_head_message() { | 10 | function show_head_message() { |
| 61 | if ($("#filter-categories-select-catalog").text().blank()){ | 11 | if ($("#filter-categories-select-catalog").text().blank()){ |
| @@ -67,29 +17,36 @@ | @@ -67,29 +17,36 @@ | ||
| 67 | } | 17 | } |
| 68 | } | 18 | } |
| 69 | 19 | ||
| 20 | + | ||
| 70 | function slideDowsCategoriesOptionAndHideOptionCatalog() { | 21 | function slideDowsCategoriesOptionAndHideOptionCatalog() { |
| 71 | $("#filter-categories-option").slideDown(); | 22 | $("#filter-categories-option").slideDown(); |
| 72 | $("#filter-option-catalog-software").hide(); | 23 | $("#filter-option-catalog-software").hide(); |
| 73 | } | 24 | } |
| 74 | 25 | ||
| 26 | + | ||
| 75 | function slideDownCategoriesOptionAndHideCategoriesSelect() { | 27 | function slideDownCategoriesOptionAndHideCategoriesSelect() { |
| 76 | $("#filter-categories-option").slideDown(); | 28 | $("#filter-categories-option").slideDown(); |
| 77 | $("#filter-categories-select-catalog").hide(); | 29 | $("#filter-categories-select-catalog").hide(); |
| 78 | } | 30 | } |
| 79 | 31 | ||
| 32 | + | ||
| 80 | function slideUpCategoriesAndShowHeadMessage() { | 33 | function slideUpCategoriesAndShowHeadMessage() { |
| 81 | $("#filter-categories-option").slideUp(); | 34 | $("#filter-categories-option").slideUp(); |
| 82 | show_head_message(); | 35 | show_head_message(); |
| 83 | } | 36 | } |
| 84 | 37 | ||
| 38 | + | ||
| 85 | function clearCatalogCheckbox(){ | 39 | function clearCatalogCheckbox(){ |
| 86 | $("#filter-categories-option").slideUp(); | 40 | $("#filter-categories-option").slideUp(); |
| 87 | $("#filter-option-catalog-software").show(); | 41 | $("#filter-option-catalog-software").show(); |
| 88 | $("#group-categories input:checked").each(function() { | 42 | $("#group-categories input:checked").each(function() { |
| 89 | $(this).prop('checked', false); | 43 | $(this).prop('checked', false); |
| 90 | }); | 44 | }); |
| 45 | + | ||
| 46 | + dispatch_search_ajax(update_search_page_on_ajax); | ||
| 91 | } | 47 | } |
| 92 | 48 | ||
| 49 | + | ||
| 93 | function selectCheckboxCategory() { | 50 | function selectCheckboxCategory() { |
| 94 | $("#filter-categories-option").slideUp(); | 51 | $("#filter-categories-option").slideUp(); |
| 95 | $("#filter-categories-select-catalog").show(); | 52 | $("#filter-categories-select-catalog").show(); |
| @@ -98,6 +55,7 @@ | @@ -98,6 +55,7 @@ | ||
| 98 | dispatch_search_ajax(update_search_page_on_ajax); | 55 | dispatch_search_ajax(update_search_page_on_ajax); |
| 99 | } | 56 | } |
| 100 | 57 | ||
| 58 | + | ||
| 101 | function dispatch_search_ajax(callback) { | 59 | function dispatch_search_ajax(callback) { |
| 102 | var query_text = $("#search-input").val(); | 60 | var query_text = $("#search-input").val(); |
| 103 | var selected_categories_ids = []; | 61 | var selected_categories_ids = []; |
| @@ -122,6 +80,7 @@ | @@ -122,6 +80,7 @@ | ||
| 122 | }); | 80 | }); |
| 123 | } | 81 | } |
| 124 | 82 | ||
| 83 | + | ||
| 125 | function update_search_page_on_ajax(response) { | 84 | function update_search_page_on_ajax(response) { |
| 126 | close_loading(); | 85 | close_loading(); |
| 127 | response = $(response); | 86 | response = $(response); |
| @@ -139,41 +98,15 @@ | @@ -139,41 +98,15 @@ | ||
| 139 | show_head_message(); | 98 | show_head_message(); |
| 140 | } | 99 | } |
| 141 | 100 | ||
| 101 | + | ||
| 142 | function selectProjectSoftwareCheckbox() { | 102 | function selectProjectSoftwareCheckbox() { |
| 143 | $("#filter-categories-option").slideUp(); | 103 | $("#filter-categories-option").slideUp(); |
| 144 | $("#filter-categories-select-catalog").show(); | 104 | $("#filter-categories-select-catalog").show(); |
| 145 | $("#filter-option-catalog-software").hide(); | 105 | $("#filter-option-catalog-software").hide(); |
| 146 | } | 106 | } |
| 147 | 107 | ||
| 148 | - function set_autocomplate() { | ||
| 149 | - $("#software-catalog").autocomplete({ | ||
| 150 | - source : function(request, response){ | ||
| 151 | - $.ajax({ | ||
| 152 | - type: "GET", | ||
| 153 | - url: AJAX_URL.get_categories, | ||
| 154 | - data: {query: request.term}, | ||
| 155 | - success: function(result){ | ||
| 156 | - response(result); | ||
| 157 | - } | ||
| 158 | - }) | ||
| 159 | - }, | ||
| 160 | - | ||
| 161 | - select : function (event, selected) { | ||
| 162 | - var value = selected.item.value; | ||
| 163 | - var id = selected.item.id; | ||
| 164 | - | ||
| 165 | - this.value = ""; | ||
| 166 | - | ||
| 167 | - add_item_to_catalog(value, id); | ||
| 168 | - set_events(); | ||
| 169 | - | ||
| 170 | - return false; | ||
| 171 | - } | ||
| 172 | - }); | ||
| 173 | - } | ||
| 174 | 108 | ||
| 175 | function set_events() { | 109 | function set_events() { |
| 176 | - $(".catalog-remove-item").click(remote_catalog_item); | ||
| 177 | $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog); | 110 | $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog); |
| 178 | $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect); | 111 | $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect); |
| 179 | $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage); | 112 | $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage); |
| @@ -184,10 +117,8 @@ | @@ -184,10 +117,8 @@ | ||
| 184 | 117 | ||
| 185 | 118 | ||
| 186 | $(document).ready(function(){ | 119 | $(document).ready(function(){ |
| 187 | - set_autocomplate(); | ||
| 188 | set_events(); | 120 | set_events(); |
| 189 | show_head_message(); | 121 | show_head_message(); |
| 190 | $("#filter-categories-option").hide(); | 122 | $("#filter-categories-option").hide(); |
| 191 | }); | 123 | }); |
| 192 | - | ||
| 193 | })(jQuery); | 124 | })(jQuery); |