software-catalog.js
5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
(function($){
"use strict";
var AJAX_URL = {
software_infos:
url_with_subdirectory("/search/software_infos")
};
function show_head_message() {
if ($("#filter-categories-select-catalog").text().blank()){
$("#filter-categories-select-catalog").hide();
$("#filter-option-catalog-software").show();
}else{
$("#filter-categories-select-catalog").show();
$("#filter-option-catalog-software").hide();
}
}
function slideDowsCategoriesOptionAndHideOptionCatalog() {
$("#filter-categories-option").slideDown();
$("#filter-option-catalog-software").hide();
}
function slideDownCategoriesOptionAndHideCategoriesSelect() {
$("#filter-categories-option").slideDown();
$("#filter-categories-select-catalog").hide();
}
function slideUpCategoriesAndShowHeadMessage() {
$("#filter-categories-option").slideUp();
show_head_message();
}
function clearCatalogCheckbox(){
$("#filter-categories-option").slideUp();
$("#filter-option-catalog-software").show();
$("#group-categories input:checked").each(function() {
$(this).prop('checked', false);
});
dispatch_search_ajax(update_search_page_on_ajax, true);
}
function selectCheckboxCategory() {
$("#filter-categories-option").slideUp();
$("#filter-categories-select-catalog").show();
$("#filter-option-catalog-software").hide();
dispatch_search_ajax(update_search_page_on_ajax, true);
}
function dispatch_search_ajax(callback, enable_load) {
var search_params = get_search_params();
if(enable_load) {
open_loading("Loading");
}
$.ajax({
url: AJAX_URL.software_infos,
type: "GET",
data: search_params,
success: callback,
error: function(){
close_loading();
}
});
}
function get_search_params() {
var params = {};
params.query = $("#search-input").val();
params.selected_categories = [];
$(".categories-catalog:checked").each(function(index, element) {
params.selected_categories.push(element.value);
});
params.software_display = $("#software_display").val();
params.sort = $("#sort").val();
params.include_non_public = $("#include_non_public").is(":checked");
return params;
}
function update_search_page_on_ajax(response) {
response = $(response);
var search_list = $("#search-results");
var selected_categories_field = $("#filter-categories-select-catalog");
var pagination = $("#software-pagination");
var software_count = $("#software-count");
var result_list = response.find("#search-results").html();
var result_categories = response.find("#filter-categories-select-catalog").html();
var result_pagination = response.find("#software-pagination").html();
var result_software_count = response.find("#software-count").html();
search_list.html(result_list);
selected_categories_field.html(result_categories);
pagination.html(result_pagination);
software_count.html(result_software_count);
show_head_message();
highlight_searched_terms();
hide_load_after_ajax();
}
function hide_load_after_ajax() {
if ($("#overlay_loading_modal").is(":visible")) {
close_loading();
setTimeout(hide_load_after_ajax, 1000);
}
}
function highlight_searched_terms() {
var searched_terms = $("#search-input").val();
if( searched_terms.length === 0 ) {
return undefined;
}
var content_result = $(".search-content-result");
var regex = new RegExp("("+searched_terms.replace(/\s/g, "|")+")", "gi");
content_result.each(function(i, e){
var element = $(e);
var new_text = element.text().replace(regex, function(text) {
return "<strong>"+text+"</strong>";
});
element.html(new_text);
});
}
function selectProjectSoftwareCheckbox() {
$("#filter-categories-option").slideUp();
$("#filter-categories-select-catalog").show();
$("#filter-option-catalog-software").hide();
dispatch_search_ajax(update_search_page_on_ajax, true);
show_head_message();
}
function update_page_by_ajax_on_select_change() {
dispatch_search_ajax(update_search_page_on_ajax, true);
}
function update_page_by_text_filter() {
var text = this.value;
dispatch_search_ajax(update_search_page_on_ajax, false);
}
function search_input_keyup() {
var timer = null;
$("#search-input").keyup(function() {
timer = setTimeout(update_page_by_text_filter, 400);
}).keydown(function() {
clearTimeout(timer);
});
}
function set_events() {
$("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
$("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect);
$("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage);
$("#cleanup-filter-catalg").click(clearCatalogCheckbox);
$(".categories-catalog").click(selectCheckboxCategory);
$(".project-software").click(selectProjectSoftwareCheckbox);
$("#software_display").change(update_page_by_ajax_on_select_change);
$("#sort").change(update_page_by_ajax_on_select_change);
search_input_keyup();
}
$(document).ready(function(){
set_events();
show_head_message();
$("#filter-categories-option").hide();
});
})(jQuery);