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 | 2 | "use strict"; |
| 3 | 3 | |
| 4 | 4 | var AJAX_URL = { |
| 5 | - get_categories: | |
| 6 | - url_with_subdirectory("/plugin/mpog_software/get_categories"), | |
| 7 | 5 | software_infos: |
| 8 | 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 | 10 | function show_head_message() { |
| 61 | 11 | if ($("#filter-categories-select-catalog").text().blank()){ |
| ... | ... | @@ -67,29 +17,36 @@ |
| 67 | 17 | } |
| 68 | 18 | } |
| 69 | 19 | |
| 20 | + | |
| 70 | 21 | function slideDowsCategoriesOptionAndHideOptionCatalog() { |
| 71 | 22 | $("#filter-categories-option").slideDown(); |
| 72 | 23 | $("#filter-option-catalog-software").hide(); |
| 73 | 24 | } |
| 74 | 25 | |
| 26 | + | |
| 75 | 27 | function slideDownCategoriesOptionAndHideCategoriesSelect() { |
| 76 | 28 | $("#filter-categories-option").slideDown(); |
| 77 | 29 | $("#filter-categories-select-catalog").hide(); |
| 78 | 30 | } |
| 79 | 31 | |
| 32 | + | |
| 80 | 33 | function slideUpCategoriesAndShowHeadMessage() { |
| 81 | 34 | $("#filter-categories-option").slideUp(); |
| 82 | 35 | show_head_message(); |
| 83 | 36 | } |
| 84 | 37 | |
| 38 | + | |
| 85 | 39 | function clearCatalogCheckbox(){ |
| 86 | 40 | $("#filter-categories-option").slideUp(); |
| 87 | 41 | $("#filter-option-catalog-software").show(); |
| 88 | 42 | $("#group-categories input:checked").each(function() { |
| 89 | 43 | $(this).prop('checked', false); |
| 90 | 44 | }); |
| 45 | + | |
| 46 | + dispatch_search_ajax(update_search_page_on_ajax); | |
| 91 | 47 | } |
| 92 | 48 | |
| 49 | + | |
| 93 | 50 | function selectCheckboxCategory() { |
| 94 | 51 | $("#filter-categories-option").slideUp(); |
| 95 | 52 | $("#filter-categories-select-catalog").show(); |
| ... | ... | @@ -98,6 +55,7 @@ |
| 98 | 55 | dispatch_search_ajax(update_search_page_on_ajax); |
| 99 | 56 | } |
| 100 | 57 | |
| 58 | + | |
| 101 | 59 | function dispatch_search_ajax(callback) { |
| 102 | 60 | var query_text = $("#search-input").val(); |
| 103 | 61 | var selected_categories_ids = []; |
| ... | ... | @@ -122,6 +80,7 @@ |
| 122 | 80 | }); |
| 123 | 81 | } |
| 124 | 82 | |
| 83 | + | |
| 125 | 84 | function update_search_page_on_ajax(response) { |
| 126 | 85 | close_loading(); |
| 127 | 86 | response = $(response); |
| ... | ... | @@ -139,41 +98,15 @@ |
| 139 | 98 | show_head_message(); |
| 140 | 99 | } |
| 141 | 100 | |
| 101 | + | |
| 142 | 102 | function selectProjectSoftwareCheckbox() { |
| 143 | 103 | $("#filter-categories-option").slideUp(); |
| 144 | 104 | $("#filter-categories-select-catalog").show(); |
| 145 | 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 | 109 | function set_events() { |
| 176 | - $(".catalog-remove-item").click(remote_catalog_item); | |
| 177 | 110 | $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog); |
| 178 | 111 | $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect); |
| 179 | 112 | $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage); |
| ... | ... | @@ -184,10 +117,8 @@ |
| 184 | 117 | |
| 185 | 118 | |
| 186 | 119 | $(document).ready(function(){ |
| 187 | - set_autocomplate(); | |
| 188 | 120 | set_events(); |
| 189 | 121 | show_head_message(); |
| 190 | 122 | $("#filter-categories-option").hide(); |
| 191 | 123 | }); |
| 192 | - | |
| 193 | 124 | })(jQuery); | ... | ... |