-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnillrik_wpjb_af_import-main.js
237 lines (205 loc) · 7.08 KB
/
snillrik_wpjb_af_import-main.js
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
jQuery(document).ready(function ($) {
//$("#snimp_joblist").find('input[type="checkbox"]');
// Usage: $form.find('input[type="checkbox"]').shiftSelectable();
// replace input[type="checkbox"] with the selector to match your list of checkboxes
let selected_arr = $(".snimp_selected");
let count_delete_times = 0;
$("#snimp-selected-categories").html("<strong>Selected categories:</strong> ");
$.each(selected_arr, function (index, item) {
$("#snimp-selected-categories").append("<div class='snimp-selected-infobox'>" + $(this).text() + "</div>");
});
$.fn.shiftSelectable = function () {
var lastChecked,
$boxes = this;
$boxes.click(function (evt) {
//console.log("wat");
if (!lastChecked) {
lastChecked = this;
return;
}
if (evt.shiftKey) {
var start = $boxes.index(this),
end = $boxes.index(lastChecked);
$boxes.slice(Math.min(start, end), Math.max(start, end) + 1)
.attr('checked', lastChecked.checked)
.trigger('change');
}
lastChecked = this;
});
};
$(".snimp_selectbox").on("click", function () {
let ths = $(this);
let ths_id = $(this).attr("id");
let ths_name = $(this).text();
if (ths.hasClass("snimp_selected"))
ths.removeClass("snimp_selected");
else
ths.addClass("snimp_selected");
//console.log(ths_name);
let selected_arr = $(".snimp_selected");
$("#snimp-selected-categories").html("<strong>Valda kategorier:</strong> ");
$.each(selected_arr, function (index, item) {
$("#snimp-selected-categories").append("<div class='snimp-selected-infobox'>" + $(this).text() + "</div>");
});
});
$("#snimp-showallbutton").on("click", function (e) {
if ($(".snimp_selectmain").hasClass("fullbox")) {
e.stopPropagation();
$(".snimp_selectmain").removeClass("fullbox");
$("#snimp-showallbutton").text("Show All");
}
else {
$(".snimp_selectmain").addClass("fullbox");
$("#snimp-showallbutton").text("Hide");
}
});
$("#snimp_emptyselected").on("click", function () {
$(".snimp_selected").removeClass("snimp_selected");
$("#snimp-selected-categories").html("");
});
$("#snimp-favouritesbutton").on("click", function () {
let selected_arr = $(".snimp_selected");
let listout = [];
$.each(selected_arr, function (index, item) {
//console.log(this.id.split("-")[2]);
listout.push(this.id.split("-")[2])
//alert( index + ": " + value );
});
var data = { 'action': 'snaf_save_favourites', 'occupations': listout };
console.log(snillrik_impadmin.ajaxurl);
$.post(
snillrik_impadmin.ajaxurl,
data,
function (response) {
alert("Saved");
}
);
});
$("#delete_expired_jobs").on("click", function () {
let untildate = $("#delete_expired_jobs_until").val();
//alert(untildate);
$("#delete_info").append("Starting delete process.");
deleteTilDate(untildate);
});
$("body").on("click", ".snimp-pagebutton", function () {
let thisid = $(this).attr("id");
//console.log(thisid);
$("#snimp_joblist_offset").val(thisid);
fetchfrominputs();
});
$("#snimp-fetchbutton").on("click", function () {
$("#snimp_joblist_offset").val(0);
fetchfrominputs();
});
$("#snimp-changeselected").on("click", function () {
let selected = $("#snaf_change_cats").val();
//alert(selected);
let selected_arr = $("#snimp_joblist").find('input[type=checkbox]:checked').parent().parent().find('.snaf_cat_selected');
selected_arr.val(selected);
});
$("#snimp-saveselected").on("click", function () {
console.log("selected saving");
let selected_arr = $("#snimp_joblist").find('input[type=checkbox]:checked');
//let changed_categories = $(".snaf_cat_selected");
$("#snimp_joblist").slideUp("fast");
let selected = [];
let selected_cats = {};
$.each(selected_arr, function (index, item) {
let thisid = this.id;
//console.log(thisid);
/* let category_selected = $("#snaf_cat_selected_"+thisid+" option:selected" );
selected.push(thisid);
selected_cats[thisid] = category_selected.val() ? category_selected.text() : ""; */
let category_selected = $("#snaf_cat_selected_" + thisid + " option:selected");
selected.push(thisid);
let all_selected_cats = "";
category_selected.each(function () {
//console.log("Val gjorda: "+$(this).val());
all_selected_cats += ($(this).val() ? $(this).text() : "") + "|";
});
selected_cats[thisid] = all_selected_cats;
});
console.log(selected_cats);
let offset = $("#snimp_joblist_offset").val();
let selected_arr2 = $(".snimp_selected");
$(".snimp-loader").fadeIn().css("display", "inline-block");
let listout = [];
$.each(selected_arr2, function (index, item) {
//console.log(this.id.split("-")[2]);
listout.push(this.id.split("-")[2])
//alert( index + ": " + value );
});
//let occupations = $("#snimp_joblist_selected").val();
let search_string = $("#snillrik-wpjb-q").val();
var data = {
'action': 'snaf_save_to_wpjb',
'selected': selected,
'selected_cats': selected_cats,
'occupations': listout,
'offset': offset,
'q': search_string
};
console.log(data);
$.post(
snillrik_impadmin.ajaxurl,
data,
function (response) {
console.log(response);
$("#snimp_saverespons").html(response);
$("#snimp_joblist_offset").val(0);
fetchfrominputs();
$("#snimp_joblist").slideDown("fast");
}
);
});
function deleteTilDate(todate) {
var data = { 'action': 'snaf_delete_to_date', 'todate': todate };
//console.log(data);
var currentdate = new Date();
var datetime = "(" + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds()+")";
$.post(
snillrik_impadmin.ajaxurl,
data,
function (response) {
console.log(response);
if (response.result != "done") {// && count_delete_times<3){
//console.log(response.result);
deleteTilDate(todate);
$("#delete_info").append("Deleting turn: " + (parseInt(count_delete_times) - 1) + " (" + response.info + ") "+datetime+"<br />");
}
else { //if done
console.log("stopp!");
$("#delete_info").append("Deleting turn: " + (parseInt(count_delete_times)) + " (" + response.info + ") "+datetime+"<br />");
}
//$("#snimp_joblist_offset").val(parseInt(offset)+1);
}
);
count_delete_times++;
}
function fetchfrominputs() {
let selected_arr = $(".snimp_selected");
$(".snimp-loader").fadeIn().css("display", "inline-block");;
let offset = $("#snimp_joblist_offset").val();
let search_string = $("#snillrik-wpjb-q").val();
let listout = [];
$.each(selected_arr, function (index, item) {
//console.log(this.id.split("-")[2]);
listout.push(this.id.split("-")[2])
//alert( index + ": " + value );
});
$("#snimp_joblist_selected").val(listout);
var data = { 'action': 'snaf_get_occupations', 'occupations': listout, 'offset': offset, 'q': search_string };
//console.log(snillrik_impadmin.ajaxurl);
$.post(
snillrik_impadmin.ajaxurl,
data,
function (response) {
console.log(response);
$(".snimp-loader").fadeOut();
$("#snimp_joblist").html(response.html_out);
$("#snimp_joblist").find('input[type="checkbox"]').shiftSelectable();
//$("#snimp_joblist_offset").val(parseInt(offset)+1);
}
);
}
});