software-catalog.js
4.14 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
(function(){
"use strict";
var AJAX_URL = {
get_categories:
url_with_subdirectory("/plugin/mpog_software/get_categories")
};
function create_catalog_element(first, value, id) {
var li_tag = document.createElement("li");
li_tag.className = "category_box";
li_tag.innerHTML = value + " <span class='catalog-remove-item' data-id='"+id+"'>x</span>";
return li_tag;
}
function add_item_to_catalog(value, id) {
var already_has = false;
jQuery("#catalog-list ul li").each(function(i, li){
var regex = new RegExp(value, "g");
if( regex.test(li.innerHTML) ) {
already_has = true;
}
});
if( !already_has ) {
var catalog_list = jQuery("#catalog-list ul li");
var current_ids = jQuery("#filter").val();
var first = catalog_list.length == 0;
current_ids += first ? id : ","+id;
jQuery("#filter").val(current_ids);
jQuery("#catalog-list ul").append(create_catalog_element(first, value, id));
}
}
function remote_catalog_item() {
var current_id = this.getAttribute("data-id");
var filter_ids = jQuery("#filter").val();
var id_list = [];
filter_ids.split(",").forEach(function(id){
if( current_id != id ) {
id_list.push(id);
}
});
jQuery("#filter").val(id_list.join(","));
jQuery(this).parent().remove();
}
function show_head_message() {
if (jQuery("#filter-categories-select-catalog").text().blank()){
jQuery("#filter-categories-select-catalog").hide();
jQuery("#filter-option-catalog-software").show();
}else{
jQuery("#filter-categories-select-catalog").show();
jQuery("#filter-option-catalog-software").hide();
}
}
function slideDowsCategoriesOptionAndHideOptionCatalog() {
jQuery("#filter-categories-option").slideDown();
jQuery("#filter-option-catalog-software").hide();
}
function slideDownCategoriesOptionAndHideCategoriesSelect() {
jQuery("#filter-categories-option").slideDown();
jQuery("#filter-categories-select-catalog").hide();
}
function slideUpCategoriesAndShowHeadMessage() {
jQuery("#filter-categories-option").slideUp();
show_head_message();
}
function clearCatalogCheckbox(){
jQuery("#filter-categories-option").slideUp();
jQuery("#filter-option-catalog-software").show();
jQuery("#group-categories input:checked").each(function() {
jQuery(this).prop('checked', false);
});
}
function selectCheckboxCategory() {
jQuery("#filter-categories-option").slideUp();
jQuery("#filter-categories-select-catalog").show();
jQuery("#filter-option-catalog-software").hide();
}
function selectProjectSoftwareCheckbox() {
jQuery("#filter-categories-option").slideUp();
jQuery("#filter-categories-select-catalog").show();
jQuery("#filter-option-catalog-software").hide();
}
function set_autocomplate() {
jQuery("#software-catalog").autocomplete({
source : function(request, response){
jQuery.ajax({
type: "GET",
url: AJAX_URL.get_categories,
data: {query: request.term},
success: function(result){
response(result);
}
})
},
select : function (event, selected) {
var value = selected.item.value;
var id = selected.item.id;
this.value = "";
add_item_to_catalog(value, id);
set_events();
return false;
}
});
}
function set_events() {
jQuery(".catalog-remove-item").click(remote_catalog_item);
jQuery("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
jQuery("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect);
jQuery("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage);
jQuery("#cleanup-filter-catalg").click(clearCatalogCheckbox);
jQuery(".categories-catalog").click(selectCheckboxCategory);
jQuery(".project-software").click(selectProjectSoftwareCheckbox);
}
jQuery(document).ready(function(){
set_autocomplate();
set_events();
show_head_message();
jQuery("#filter-categories-option").hide();
});
})();