PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.3
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.3
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / asset / js / admin.js

admin.js in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.3, at asset/js/admin.js

6,413 lines 165.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Get ticket list
3 */
4 function wpsc_get_ticket_list(is_humbargar = false) {
5 supportcandy.current_section = "ticket-list";
6
7 if (is_humbargar) {
8 wpsc_toggle_humbargar();
9 }
10
11 if (wpsc_is_description_text()) {
12 if (!confirm(supportcandy.translations.warning_message)) {
13 return;
14 } else {
15 var is_tinymce =
16 typeof tinyMCE != "undefined" &&
17 tinyMCE.activeEditor &&
18 !tinyMCE.activeEditor.isHidden();
19 if (is_tinymce && tinymce.get("description")) {
20 var description = tinyMCE.get("description").setContent("");
21 } else {
22 var description = jQuery("#description").val("");
23 }
24 ticket_id = jQuery("#wpsc-current-ticket").val();
25 wpsc_clear_saved_draft_reply(ticket_id);
26 }
27 }
28
29 var id = supportcandy.current_ticket_id;
30 if (id) {
31 delete supportcandy.current_ticket_id;
32 wpsc_get_individual_ticket(id);
33 return;
34 }
35
36 wpsc_update_live_agents();
37
38 // set flag to differenciate between ticket list and individual ticket.
39 supportcandy.ticketListIsIndividual = false;
40
41 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
42 jQuery(
43 ".wpsc-tickets-nav.ticket-list, .wpsc-humbargar-menu-item.ticket-list"
44 ).addClass("active");
45 jQuery(".wpsc-humbargar-title").html(
46 supportcandy.humbargar_titles.ticket_list
47 );
48
49 window.history.replaceState(
50 {},
51 null,
52 "admin.php?page=wpsc-tickets&section=ticket-list"
53 );
54 jQuery(".wpsc-body").html(supportcandy.loader_html);
55
56 wpsc_scroll_top();
57
58 var data = {
59 action: "wpsc_get_ticket_list",
60 _ajax_nonce: supportcandy.nonce,
61 is_frontend: supportcandy.is_frontend,
62 };
63 if (
64 typeof supportcandy.ticketList != "undefined" &&
65 typeof supportcandy.ticketList.filters != "undefined"
66 ) {
67 data.filters = supportcandy.ticketList.filters;
68 }
69 jQuery.post(supportcandy.ajax_url, data, function (response) {
70 jQuery(".wpsc-body").html(response);
71 wpsc_reset_responsive_style();
72 });
73 wpsc_delete_auto_draft();
74 }
75
76 /**
77 * Get individual ticket
78 */
79 function wpsc_get_individual_ticket(id) {
80 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
81 jQuery(
82 ".wpsc-tickets-nav.ticket-list, .wpsc-humbargar-menu-item.ticket-list"
83 ).addClass("active");
84 jQuery(".wpsc-humbargar-title").html(
85 supportcandy.humbargar_titles.ticket_list
86 );
87
88 window.history.replaceState(
89 {},
90 null,
91 "admin.php?page=wpsc-tickets&section=ticket-list&id=" + id
92 );
93 jQuery(".wpsc-body").html(supportcandy.loader_html);
94
95 wpsc_scroll_top();
96
97 // set flag to differenciate between ticket list and individual ticket.
98 supportcandy.ticketListIsIndividual = true;
99
100 var data = {
101 action: "wpsc_get_individual_ticket",
102 ticket_id: id,
103 };
104 jQuery.post(supportcandy.ajax_url, data, function (response) {
105 jQuery(".wpsc-body").html(response);
106 wpsc_reset_responsive_style();
107 });
108 }
109
110 /**
111 * Get create ticket form
112 */
113 function wpsc_get_ticket_form(is_humbargar = false) {
114 supportcandy.current_section = "new-ticket";
115
116 if (is_humbargar) {
117 wpsc_toggle_humbargar();
118 }
119
120 if (wpsc_is_description_text()) {
121 if (confirm(supportcandy.translations.warning_message)) {
122 current_ticket = jQuery("#wpsc-current-ticket").val();
123 wpsc_clear_saved_draft_reply(current_ticket);
124 } else {
125 return;
126 }
127 }
128
129 wpsc_update_live_agents();
130
131 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
132 jQuery(
133 ".wpsc-tickets-nav.new-ticket, .wpsc-humbargar-menu-item.new-ticket"
134 ).addClass("active");
135 jQuery(".wpsc-humbargar-title").html(
136 supportcandy.humbargar_titles.new_ticket
137 );
138
139 // set url.
140 var url = new URL(window.location.href);
141 var search_params = url.searchParams;
142 search_params.set("section", "new-ticket");
143 search_params.delete("id");
144 url.search = search_params.toString();
145 window.history.replaceState({}, null, url.toString());
146 jQuery(".wpsc-body").html(supportcandy.loader_html);
147
148 wpsc_scroll_top();
149
150 var data = {
151 action: "wpsc_get_ticket_form",
152 _ajax_nonce: supportcandy.nonce,
153 };
154 search_params.forEach(function (value, key) {
155 data[key] = value;
156 });
157 jQuery.post(supportcandy.ajax_url, data, function (response) {
158 jQuery(".wpsc-body").html(response);
159 wpsc_reset_responsive_style();
160 });
161 }
162
163 /**
164 * Get agent settings
165 */
166 function wpsc_get_user_profile(is_humbargar = false) {
167 supportcandy.current_section = "my-profile";
168
169 if (is_humbargar) {
170 wpsc_toggle_humbargar();
171 }
172
173 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
174 jQuery(
175 ".wpsc-tickets-nav.my-profile, .wpsc-humbargar-menu-item.my-profile"
176 ).addClass("active");
177 jQuery(".wpsc-humbargar-title").html(
178 supportcandy.humbargar_titles.my_profile
179 );
180
181 wpsc_update_live_agents();
182
183 window.history.replaceState(
184 {},
185 null,
186 "admin.php?page=wpsc-tickets&section=my-profile"
187 );
188 jQuery(".wpsc-body").html(supportcandy.loader_html);
189
190 wpsc_scroll_top();
191
192 var data = { action: "wpsc_get_user_profile" };
193 jQuery.post(supportcandy.ajax_url, data, function (response) {
194 jQuery(".wpsc-body").html(response);
195 wpsc_reset_responsive_style();
196 });
197 }
198
199 /**
200 * Get agent settings
201 */
202 function wpsc_get_agent_profile(is_humbargar = false) {
203 supportcandy.current_section = "agent-profile";
204
205 if (is_humbargar) {
206 wpsc_toggle_humbargar();
207 }
208
209 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
210 jQuery(
211 ".wpsc-tickets-nav.agent-profile, .wpsc-humbargar-menu-item.agent-profile"
212 ).addClass("active");
213 jQuery(".wpsc-humbargar-title").html(
214 supportcandy.humbargar_titles.agent_profile
215 );
216
217 wpsc_update_live_agents();
218
219 window.history.replaceState(
220 {},
221 null,
222 "admin.php?page=wpsc-tickets&section=agent-profile"
223 );
224 jQuery(".wpsc-body").html(supportcandy.loader_html);
225
226 wpsc_scroll_top();
227
228 var data = { action: "wpsc_get_agent_profile" };
229 jQuery.post(supportcandy.ajax_url, data, function (response) {
230 jQuery(".wpsc-body").html(response);
231 wpsc_reset_responsive_style();
232 jQuery(".wpsc-ap-nav.general").trigger("click");
233 });
234 }
235
236 /**
237 * Get agent dashboard
238 */
239 function wpsc_get_agent_dashboard(is_humbargar = false) {
240 supportcandy.current_section = "dashboard";
241
242 if (is_humbargar) {
243 wpsc_toggle_humbargar();
244 }
245
246 wpsc_update_live_agents();
247
248 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
249 jQuery(
250 ".wpsc-tickets-nav.dashboard, .wpsc-humbargar-menu-item.dashboard"
251 ).addClass("active");
252 jQuery(".wpsc-humbargar-title").html(supportcandy.humbargar_titles.dashboard);
253
254 window.history.replaceState(
255 {},
256 null,
257 "admin.php?page=wpsc-tickets&section=dashboard"
258 );
259 jQuery(".wpsc-body").html(supportcandy.loader_html);
260
261 wpsc_scroll_top();
262
263 var data = { action: "wpsc_get_agent_dashboard" };
264 jQuery.post(supportcandy.ajax_url, data, function (response) {
265 jQuery(".wpsc-body").html(response);
266 wpsc_reset_responsive_style();
267 jQuery(".wpsc-ap-nav.general").trigger("click");
268 });
269 }
270
271 /**
272 * Show other actions popover
273 */
274 function wpsc_show_tl_other_actions() {
275 jQuery("#wpsc-more-actions").gpopover("show");
276 }
277
278 /**
279 * Get agent list
280 */
281 function wpsc_get_agent_list(is_humbargar = false) {
282 if (is_humbargar) {
283 wpsc_toggle_humbargar();
284 }
285
286 var id = supportcandy.current_id;
287 if (id) {
288 delete supportcandy.current_id;
289 wpsc_get_individual_agent(id);
290 return;
291 }
292
293 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
294 jQuery(".wpsc-setting-nav.agents, .wpsc-humbargar-menu-item.agents").addClass(
295 "active"
296 );
297 jQuery(".wpsc-humbargar-title").html(supportcandy.humbargar_titles.agents);
298
299 window.history.replaceState(
300 {},
301 null,
302 "admin.php?page=wpsc-support-agents&section=agents"
303 );
304 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
305
306 wpsc_scroll_top();
307
308 var data = { action: "wpsc_get_agent_list" };
309 jQuery.post(supportcandy.ajax_url, data, function (response) {
310 jQuery(".wpsc-setting-body").html(response);
311 wpsc_reset_responsive_style();
312 });
313 }
314
315 /**
316 * Create an agent
317 */
318 function wpsc_set_add_agent(el) {
319 var user = jQuery(".wpsc-frm-add-agent #wpsc-select-user-input").val();
320 if (!user) {
321 alert(supportcandy.translations.req_fields_missing);
322 return;
323 }
324 var form = jQuery(".wpsc-frm-add-agent")[0];
325 var dataform = new FormData(form);
326
327 var users = dataform.getAll("users[]");
328 if (!users.length) {
329 alert(supportcandy.translations.req_fields_missing);
330 return;
331 }
332
333 jQuery(".wpsc-modal-footer button").attr("disabled", true);
334 jQuery(el).text(supportcandy.translations.please_wait);
335 jQuery
336 .ajax({
337 url: supportcandy.ajax_url,
338 type: "POST",
339 data: dataform,
340 processData: false,
341 contentType: false,
342 })
343 .done(function (res) {
344 wpsc_close_modal();
345 wpsc_get_agent_list();
346 });
347 }
348
349 /**
350 * Get edit agent modal popup
351 */
352 function wpsc_get_edit_agent(id, _ajax_nonce) {
353 wpsc_show_modal();
354 var data = {
355 action: "wpsc_get_edit_agent",
356 id,
357 _ajax_nonce,
358 };
359 jQuery.post(supportcandy.ajax_url, data, function (response) {
360 // Set to modal.
361 jQuery(".wpsc-modal-header").text(response.title);
362 jQuery(".wpsc-modal-body").html(response.body);
363 jQuery(".wpsc-modal-footer").html(response.footer);
364 // Display modal.
365 wpsc_show_modal_inner_container();
366 });
367 }
368
369 /**
370 * Submit changes made to an agent
371 */
372 function wpsc_set_edit_agent(el) {
373 var form = jQuery(".wpsc-frm-edit-agent")[0];
374 var dataform = new FormData(form);
375 jQuery(".wpsc-modal-footer button").attr("disabled", true);
376 jQuery(el).text(supportcandy.translations.please_wait);
377 jQuery
378 .ajax({
379 url: supportcandy.ajax_url,
380 type: "POST",
381 data: dataform,
382 processData: false,
383 contentType: false,
384 })
385 .done(function (res) {
386 wpsc_close_modal();
387 wpsc_get_agent_list();
388 });
389 }
390
391 /**
392 * Get delete agent modal popup
393 */
394 function wpsc_get_delete_agent(id, nonce) {
395 var flag = confirm(supportcandy.translations.confirm);
396 if (!flag) {
397 return;
398 }
399
400 var data = {
401 action: "wpsc_delete_agent",
402 id,
403 _ajax_nonce: nonce,
404 };
405 jQuery.post(supportcandy.ajax_url, data, function (res) {
406 wpsc_get_agent_list();
407 });
408 }
409
410 /**
411 * Submit delete an agent request
412 */
413 function wpsc_set_delete_agent(el) {
414 jQuery(".wpsc-modal-footer button").attr("disabled", true);
415 jQuery(el).text(supportcandy.translations.please_wait);
416 setTimeout(function () {
417 wpsc_close_modal();
418 wpsc_get_agent_list();
419 }, 500);
420 }
421
422 /**
423 * Get agent roles
424 */
425 function wpsc_get_agent_roles(is_humbargar = false) {
426 if (is_humbargar) {
427 wpsc_toggle_humbargar();
428 }
429
430 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
431 jQuery(
432 ".wpsc-setting-nav.agent-roles, .wpsc-humbargar-menu-item.agent-roles"
433 ).addClass("active");
434 jQuery(".wpsc-humbargar-title").html(
435 supportcandy.humbargar_titles.agent_roles
436 );
437
438 window.history.replaceState(
439 {},
440 null,
441 "admin.php?page=wpsc-support-agents&section=agent-roles"
442 );
443 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
444
445 wpsc_scroll_top();
446
447 var data = { action: "wpsc_get_agent_roles" };
448 jQuery.post(supportcandy.ajax_url, data, function (response) {
449 jQuery(".wpsc-setting-body").html(response);
450 wpsc_reset_responsive_style();
451 });
452 }
453
454 /**
455 * Create an agent
456 */
457 function wpsc_set_add_agent_role(el) {
458 var label = jQuery(".frm-add-agent-role #label").val().trim();
459 if (!label) {
460 alert(supportcandy.translations.req_fields_missing);
461 return;
462 }
463 jQuery("#wpsc_add_agent_role").DataTable().search("").draw();
464 var form = jQuery(".frm-add-agent-role")[0];
465 var dataform = new FormData(form);
466 jQuery(".wpsc-modal-footer button").attr("disabled", true);
467 jQuery(el).text(supportcandy.translations.please_wait);
468 jQuery
469 .ajax({
470 url: supportcandy.ajax_url,
471 type: "POST",
472 data: dataform,
473 processData: false,
474 contentType: false,
475 })
476 .done(function (res) {
477 wpsc_get_agent_roles();
478 });
479 }
480
481 /**
482 * Get clone agent role
483 */
484 function wpsc_get_clone_agent_role(id, nonce) {
485 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
486 var data = { action: "wpsc_get_clone_agent_role", id, _ajax_nonce: nonce };
487 jQuery.post(supportcandy.ajax_url, data, function (response) {
488 wpsc_get_agent_roles();
489 });
490 }
491
492 /**
493 * Get edit agent roles
494 */
495 function wpsc_get_edit_agent_role(id, nonce) {
496 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
497 var data = {
498 action: "wpsc_get_edit_agent_role",
499 role_id: id,
500 _ajax_nonce: nonce,
501 };
502 jQuery.post(supportcandy.ajax_url, data, function (response) {
503 jQuery(".wpsc-setting-section-body").html(response);
504 });
505 }
506
507 /**
508 * Submit changes made to an agent
509 */
510 function wpsc_set_edit_agent_role(el) {
511 var label = jQuery(".frm-edit-agent-role #label").val().trim();
512 if (!label) {
513 alert(supportcandy.translations.req_fields_missing);
514 return;
515 }
516 jQuery("#wpsc_edit_agent_role").DataTable().search("").draw();
517 var form = jQuery(".frm-edit-agent-role")[0];
518 var dataform = new FormData(form);
519 jQuery(".wpsc-modal-footer button").attr("disabled", true);
520 jQuery(el).text(supportcandy.translations.please_wait);
521 jQuery
522 .ajax({
523 url: supportcandy.ajax_url,
524 type: "POST",
525 data: dataform,
526 processData: false,
527 contentType: false,
528 })
529 .done(function (res) {
530 wpsc_get_agent_roles();
531 });
532 }
533
534 /**
535 * Delete agent role
536 */
537 function wpsc_delete_agent_role(id, nonce) {
538 if (!confirm(supportcandy.translations.confirm)) {
539 return;
540 }
541
542 var data = {
543 action: "wpsc_delete_agent_role",
544 role_id: id,
545 _ajax_nonce: nonce,
546 };
547 jQuery
548 .post(supportcandy.ajax_url, data, function (res) {
549 wpsc_get_agent_roles();
550 })
551 .fail(function (xhr) {
552 var response = JSON.parse(xhr.responseText);
553 alert(response.data);
554 });
555 }
556
557 /**
558 * Get general settings
559 */
560 function wpsc_get_general_settings(is_humbargar = false) {
561 if (is_humbargar) {
562 wpsc_toggle_humbargar();
563 }
564
565 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
566 jQuery(
567 ".wpsc-setting-nav.general-settings, .wpsc-humbargar-menu-item.general-settings"
568 ).addClass("active");
569 jQuery(".wpsc-humbargar-title").html(
570 supportcandy.humbargar_titles.general_settings
571 );
572
573 if (supportcandy.current_section !== "general-settings") {
574 supportcandy.current_section = "general-settings";
575 supportcandy.current_tab = "general";
576 }
577
578 window.history.replaceState(
579 {},
580 null,
581 "admin.php?page=wpsc-settings&section=" +
582 supportcandy.current_section +
583 "&tab=" +
584 supportcandy.current_tab
585 );
586 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
587
588 wpsc_scroll_top();
589
590 var data = {
591 action: "wpsc_get_general_settings",
592 tab: supportcandy.current_tab,
593 };
594 jQuery.post(supportcandy.ajax_url, data, function (response) {
595 jQuery(".wpsc-setting-body").html(response);
596 wpsc_reset_responsive_style();
597 jQuery(
598 ".wpsc-setting-tab-container button." + supportcandy.current_tab
599 ).trigger("click");
600 });
601 }
602
603 /**
604 * Load general tab ui
605 */
606 function wpsc_get_gs_general() {
607 supportcandy.current_tab = "general";
608 jQuery(".wpsc-setting-tab-container button").removeClass("active");
609 jQuery(
610 ".wpsc-setting-tab-container button." + supportcandy.current_tab
611 ).addClass("active");
612
613 window.history.replaceState(
614 {},
615 null,
616 "admin.php?page=wpsc-settings&section=" +
617 supportcandy.current_section +
618 "&tab=" +
619 supportcandy.current_tab
620 );
621 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
622
623 wpsc_scroll_top();
624
625 var data = { action: "wpsc_get_gs_general" };
626 jQuery.post(supportcandy.ajax_url, data, function (response) {
627 jQuery(".wpsc-setting-section-body").html(response);
628 wpsc_reset_responsive_style();
629 });
630 }
631
632 /**
633 * Save general settings
634 */
635 function wpsc_set_gs_general(el) {
636 var form = jQuery(".wpsc-frm-gs-general")[0];
637 var dataform = new FormData(form);
638 jQuery(el).text(supportcandy.translations.please_wait);
639 jQuery
640 .ajax({
641 url: supportcandy.ajax_url,
642 type: "POST",
643 data: dataform,
644 processData: false,
645 contentType: false,
646 })
647 .done(function (res) {
648 wpsc_get_gs_general();
649 });
650 }
651
652 /**
653 * Reset general settings
654 */
655 function wpsc_reset_gs_general(el, nonce) {
656 jQuery(".wpsc-modal-footer button").attr("disabled", true);
657 jQuery(el).text(supportcandy.translations.please_wait);
658 var data = { action: "wpsc_reset_gs_general", _ajax_nonce: nonce };
659 jQuery.post(supportcandy.ajax_url, data, function (response) {
660 wpsc_get_gs_general();
661 });
662 }
663
664 /**
665 * Load page settings tab ui
666 */
667 function wpsc_get_gs_page_settings() {
668 supportcandy.current_tab = "page-settings";
669 jQuery(".wpsc-setting-tab-container button").removeClass("active");
670 jQuery(
671 ".wpsc-setting-tab-container button." + supportcandy.current_tab
672 ).addClass("active");
673
674 window.history.replaceState(
675 {},
676 null,
677 "admin.php?page=wpsc-settings&section=" +
678 supportcandy.current_section +
679 "&tab=" +
680 supportcandy.current_tab
681 );
682 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
683
684 wpsc_scroll_top();
685
686 var data = { action: "wpsc_get_gs_page_settings" };
687 jQuery.post(supportcandy.ajax_url, data, function (response) {
688 jQuery(".wpsc-setting-section-body").html(response);
689 wpsc_reset_responsive_style();
690 });
691 }
692
693 /**
694 * Save page settings
695 */
696 function wpsc_set_gs_page_settings(el) {
697 var form = jQuery(".wpsc-frm-gs-ps")[0];
698 var dataform = new FormData(form);
699 jQuery(".wpsc-modal-footer button").attr("disabled", true);
700 jQuery(el).text(supportcandy.translations.please_wait);
701 jQuery
702 .ajax({
703 url: supportcandy.ajax_url,
704 type: "POST",
705 data: dataform,
706 processData: false,
707 contentType: false,
708 })
709 .done(function (res) {
710 wpsc_get_gs_page_settings();
711 });
712 }
713
714 /**
715 * Reset page settings
716 */
717 function wpsc_reset_gs_page_settings(el, nonce) {
718 jQuery(".wpsc-modal-footer button").attr("disabled", true);
719 jQuery(el).text(supportcandy.translations.please_wait);
720 var data = { action: "wpsc_reset_gs_page_settings", _ajax_nonce: nonce };
721 jQuery.post(supportcandy.ajax_url, data, function (response) {
722 wpsc_get_gs_page_settings();
723 });
724 }
725
726 /**
727 * Get category settings
728 */
729 function wpsc_get_ticket_categories(is_humbargar = false) {
730 if (is_humbargar) {
731 wpsc_toggle_humbargar();
732 }
733
734 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
735 jQuery(
736 ".wpsc-setting-nav.ticket-categories, .wpsc-humbargar-menu-item.ticket-categories"
737 ).addClass("active");
738 jQuery(".wpsc-humbargar-title").html(
739 supportcandy.humbargar_titles.ticket_categories
740 );
741
742 window.history.replaceState(
743 {},
744 null,
745 "admin.php?page=wpsc-settings&section=ticket-categories"
746 );
747 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
748
749 wpsc_scroll_top();
750
751 var data = { action: "wpsc_get_ticket_categories" };
752 jQuery.post(supportcandy.ajax_url, data, function (response) {
753 jQuery(".wpsc-setting-body").html(response);
754 wpsc_reset_responsive_style();
755 });
756 }
757
758 /**
759 * Get working hrs settings
760 */
761 function wpsc_get_working_hrs_settings(is_humbargar = false) {
762 if (is_humbargar) {
763 wpsc_toggle_humbargar();
764 }
765
766 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
767 jQuery(
768 ".wpsc-setting-nav.working-hrs, .wpsc-humbargar-menu-item.working-hrs"
769 ).addClass("active");
770 jQuery(".wpsc-humbargar-title").html(
771 supportcandy.humbargar_titles.working_hrs
772 );
773
774 if (supportcandy.current_section !== "working-hrs") {
775 supportcandy.current_section = "working-hrs";
776 supportcandy.current_tab = "working-hrs";
777 }
778
779 window.history.replaceState(
780 {},
781 null,
782 "admin.php?page=wpsc-settings&section=" +
783 supportcandy.current_section +
784 "&tab=" +
785 supportcandy.current_tab
786 );
787 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
788
789 wpsc_scroll_top();
790
791 var data = {
792 action: "wpsc_get_working_hrs_settings",
793 tab: supportcandy.current_tab,
794 };
795 jQuery.post(supportcandy.ajax_url, data, function (response) {
796 jQuery(".wpsc-setting-body").html(response);
797 wpsc_reset_responsive_style();
798 jQuery(
799 ".wpsc-setting-tab-container button." + supportcandy.current_tab
800 ).trigger("click");
801 });
802 }
803
804 /**
805 * Get working hrs
806 */
807 function wpsc_get_working_hrs() {
808 supportcandy.current_tab = "working-hrs";
809 jQuery(".wpsc-setting-tab-container button").removeClass("active");
810 jQuery(
811 ".wpsc-setting-tab-container button." + supportcandy.current_tab
812 ).addClass("active");
813
814 window.history.replaceState(
815 {},
816 null,
817 "admin.php?page=wpsc-settings&section=" +
818 supportcandy.current_section +
819 "&tab=" +
820 supportcandy.current_tab
821 );
822 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
823
824 wpsc_scroll_top();
825 var data = { action: "wpsc_get_working_hrs" };
826 jQuery.post(supportcandy.ajax_url, data, function (response) {
827 jQuery(".wpsc-setting-section-body").html(response);
828 wpsc_reset_responsive_style();
829 });
830 }
831
832 /**
833 * Get working hrs
834 */
835 function wpsc_set_working_hrs(el) {
836 var form = jQuery("form.wpsc-wh-settings")[0];
837 var dataform = new FormData(form);
838 jQuery(el).text(supportcandy.translations.please_wait);
839 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
840 jQuery
841 .ajax({
842 url: supportcandy.ajax_url,
843 type: "POST",
844 data: dataform,
845 processData: false,
846 contentType: false,
847 })
848 .done(function (res) {
849 wpsc_get_working_hrs();
850 });
851 }
852
853 /**
854 * Get holidays
855 */
856 function wpsc_get_holidays() {
857 supportcandy.current_tab = "holidays";
858 jQuery(".wpsc-setting-tab-container button").removeClass("active");
859 jQuery(
860 ".wpsc-setting-tab-container button." + supportcandy.current_tab
861 ).addClass("active");
862
863 window.history.replaceState(
864 {},
865 null,
866 "admin.php?page=wpsc-settings&section=" +
867 supportcandy.current_section +
868 "&tab=" +
869 supportcandy.current_tab
870 );
871 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
872
873 wpsc_scroll_top();
874 var data = { action: "wpsc_get_holidays" };
875 jQuery.post(supportcandy.ajax_url, data, function (response) {
876 jQuery(".wpsc-setting-section-body").html(response);
877 wpsc_reset_responsive_style();
878 });
879 }
880
881 /**
882 * Get company holiday actions
883 */
884 function wpsc_get_company_holiday_actions(dateSelected, nonce) {
885 supportcandy.temp.dateSelected = dateSelected;
886 wpsc_show_modal();
887 var data = {
888 action: "wpsc_get_company_holiday_actions",
889 dateSelected,
890 _ajax_nonce: nonce,
891 };
892 jQuery.post(supportcandy.ajax_url, data, function (response) {
893 // Set to modal.
894 jQuery(".wpsc-modal-header").text(response.title);
895 jQuery(".wpsc-modal-body").html(response.body);
896 jQuery(".wpsc-modal-footer").html(response.footer);
897 // Display modal.
898 wpsc_show_modal_inner_container();
899 });
900 }
901
902 /**
903 * Set company holiday actions
904 */
905 function wpsc_set_company_holiday_actions(el) {
906 const form = jQuery(".wpsc-frm-comp-holiday-actions")[0];
907 const dataform = new FormData(form);
908 dataform.append("dateSelected", supportcandy.temp.dateSelected);
909 jQuery(el).text(supportcandy.translations.please_wait);
910 jQuery
911 .ajax({
912 url: supportcandy.ajax_url,
913 type: "POST",
914 data: dataform,
915 processData: false,
916 contentType: false,
917 })
918 .done(function (response) {
919 jQuery.each(supportcandy.temp.dateSelected, function (index, value) {
920 if (response.action == "add" && response.is_recurring == 1) {
921 jQuery("td")
922 .find("[data-date=" + value + "]")
923 .css({ "background-color": "#eb4d4b" });
924 } else if (response.action == "add" && response.is_recurring == 0) {
925 jQuery("td")
926 .find("[data-date=" + value + "]")
927 .css({ "background-color": "#f0932b" });
928 } else {
929 jQuery("td")
930 .find("[data-date=" + value + "]")
931 .css("background-color", "unset");
932 }
933 });
934 supportcandy.temp.holidayList = response.holidayList;
935 wpsc_close_modal();
936 });
937 }
938
939 /**
940 * Get working hrs exceptions
941 */
942 function wpsc_get_wh_exceptions() {
943 supportcandy.current_tab = "exceptions";
944 jQuery(".wpsc-setting-tab-container button").removeClass("active");
945 jQuery(
946 ".wpsc-setting-tab-container button." + supportcandy.current_tab
947 ).addClass("active");
948
949 window.history.replaceState(
950 {},
951 null,
952 "admin.php?page=wpsc-settings&section=" +
953 supportcandy.current_section +
954 "&tab=" +
955 supportcandy.current_tab
956 );
957 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
958
959 wpsc_scroll_top();
960 var data = { action: "wpsc_get_wh_exceptions" };
961 jQuery.post(supportcandy.ajax_url, data, function (response) {
962 jQuery(".wpsc-setting-section-body").html(response);
963 wpsc_reset_responsive_style();
964 });
965 }
966
967 /**
968 * Add company holiday
969 */
970 function wpsc_set_add_holiday(el) {
971 var title = jQuery("input[name=title]").val().trim();
972 if (title.length === 0) {
973 return;
974 }
975
976 var startDate = jQuery("input.start_date").val().trim();
977 if (startDate.length === 0) {
978 return;
979 }
980
981 jQuery(".wpsc-modal-footer button").attr("disabled", true);
982 jQuery(el).text(supportcandy.translations.please_wait);
983 var form = jQuery(".wpsc-frm-add-holiday")[0];
984 var dataform = new FormData(form);
985 jQuery
986 .ajax({
987 url: supportcandy.ajax_url,
988 type: "POST",
989 data: dataform,
990 processData: false,
991 contentType: false,
992 })
993 .done(function (res) {
994 wpsc_close_modal();
995 wpsc_get_holidays();
996 });
997 }
998
999 /**
1000 * Add company holiday
1001 */
1002 function wpsc_set_edit_holiday(el) {
1003 var title = jQuery("input[name=title]").val().trim();
1004 if (title.length === 0) {
1005 return;
1006 }
1007
1008 var startDate = jQuery("input.start_date").val().trim();
1009 if (startDate.length === 0) {
1010 return;
1011 }
1012
1013 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1014 jQuery(el).text(supportcandy.translations.please_wait);
1015 var form = jQuery(".wpsc-frm-edit-holiday")[0];
1016 var dataform = new FormData(form);
1017 jQuery
1018 .ajax({
1019 url: supportcandy.ajax_url,
1020 type: "POST",
1021 data: dataform,
1022 processData: false,
1023 contentType: false,
1024 })
1025 .done(function (res) {
1026 wpsc_close_modal();
1027 wpsc_get_holidays();
1028 });
1029 }
1030
1031 /**
1032 * Add company holiday
1033 */
1034 function wpsc_set_add_wh_exception(el) {
1035 var title = jQuery("input[name=title]").val().trim();
1036 if (title.length === 0) {
1037 return;
1038 }
1039
1040 var startDate = jQuery("input.exception_date").val().trim();
1041 if (startDate.length === 0) {
1042 return;
1043 }
1044
1045 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1046 jQuery(el).text(supportcandy.translations.please_wait);
1047 var form = jQuery(".wpsc-frm-add-exception")[0];
1048 var dataform = new FormData(form);
1049 jQuery
1050 .ajax({
1051 url: supportcandy.ajax_url,
1052 type: "POST",
1053 data: dataform,
1054 processData: false,
1055 contentType: false,
1056 })
1057 .done(function (res) {
1058 wpsc_close_modal();
1059 wpsc_get_wh_exceptions();
1060 });
1061 }
1062
1063 /**
1064 * Add company holiday
1065 */
1066 function wpsc_set_edit_wh_exception(el) {
1067 var title = jQuery("input[name=title]").val().trim();
1068 if (title.length === 0) {
1069 return;
1070 }
1071
1072 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1073 jQuery(el).text(supportcandy.translations.please_wait);
1074 var form = jQuery(".wpsc-frm-edit-exception")[0];
1075 var dataform = new FormData(form);
1076 jQuery
1077 .ajax({
1078 url: supportcandy.ajax_url,
1079 type: "POST",
1080 data: dataform,
1081 processData: false,
1082 contentType: false,
1083 })
1084 .done(function (res) {
1085 wpsc_close_modal();
1086 wpsc_get_wh_exceptions();
1087 });
1088 }
1089
1090 /**
1091 * Get working hrs settings
1092 */
1093 function wpsc_get_wh_settings() {
1094 supportcandy.current_tab = "settings";
1095 jQuery(".wpsc-setting-tab-container button").removeClass("active");
1096 jQuery(
1097 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1098 ).addClass("active");
1099
1100 window.history.replaceState(
1101 {},
1102 null,
1103 "admin.php?page=wpsc-settings&section=" +
1104 supportcandy.current_section +
1105 "&tab=" +
1106 supportcandy.current_tab
1107 );
1108 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
1109
1110 wpsc_scroll_top();
1111 var data = { action: "wpsc_get_wh_settings" };
1112 jQuery.post(supportcandy.ajax_url, data, function (response) {
1113 jQuery(".wpsc-setting-section-body").html(response);
1114 wpsc_reset_responsive_style();
1115 });
1116 }
1117
1118 /**
1119 * Set working hrs setting
1120 */
1121 function wpsc_set_wh_settings(el) {
1122 var form = jQuery(".wpsc-frm-wh-settings")[0];
1123 var dataform = new FormData(form);
1124 jQuery(el).text(supportcandy.translations.please_wait);
1125 jQuery
1126 .ajax({
1127 url: supportcandy.ajax_url,
1128 type: "POST",
1129 data: dataform,
1130 processData: false,
1131 contentType: false,
1132 })
1133 .done(function (res) {
1134 wpsc_get_wh_settings();
1135 });
1136 }
1137
1138 /**
1139 * Set working hrs setting
1140 */
1141 function wpsc_reset_wh_settings(el, nonce) {
1142 jQuery(el).text(supportcandy.translations.please_wait);
1143 var data = { action: "wpsc_reset_wh_settings", _ajax_nonce: nonce };
1144 jQuery.post(supportcandy.ajax_url, data, function (res) {
1145 wpsc_get_wh_settings();
1146 });
1147 }
1148
1149 /**
1150 * Get appearence settings
1151 */
1152 function wpsc_get_appearence_settings(is_humbargar = false) {
1153 if (is_humbargar) {
1154 wpsc_toggle_humbargar();
1155 }
1156
1157 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
1158 jQuery(
1159 ".wpsc-setting-nav.appearence, .wpsc-humbargar-menu-item.appearence"
1160 ).addClass("active");
1161 jQuery(".wpsc-humbargar-title").html(
1162 supportcandy.humbargar_titles.appearence
1163 );
1164
1165 if (supportcandy.current_section !== "appearence") {
1166 supportcandy.current_section = "appearence";
1167 supportcandy.current_tab = "general";
1168 }
1169
1170 window.history.replaceState(
1171 {},
1172 null,
1173 "admin.php?page=wpsc-settings&section=" +
1174 supportcandy.current_section +
1175 "&tab=" +
1176 supportcandy.current_tab
1177 );
1178 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
1179
1180 wpsc_scroll_top();
1181
1182 var data = {
1183 action: "wpsc_get_appearence_settings",
1184 tab: supportcandy.current_tab,
1185 };
1186 jQuery.post(supportcandy.ajax_url, data, function (response) {
1187 jQuery(".wpsc-setting-body").html(response);
1188 wpsc_reset_responsive_style();
1189 jQuery(
1190 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1191 ).trigger("click");
1192 });
1193 }
1194
1195 /**
1196 * Get general appearence settings
1197 */
1198 function wpsc_get_ap_general() {
1199 supportcandy.current_tab = "general";
1200 jQuery(".wpsc-setting-tab-container button").removeClass("active");
1201 jQuery(
1202 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1203 ).addClass("active");
1204
1205 window.history.replaceState(
1206 {},
1207 null,
1208 "admin.php?page=wpsc-settings&section=" +
1209 supportcandy.current_section +
1210 "&tab=" +
1211 supportcandy.current_tab
1212 );
1213 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
1214
1215 wpsc_scroll_top();
1216 var data = { action: "wpsc_get_ap_general" };
1217 jQuery.post(supportcandy.ajax_url, data, function (response) {
1218 jQuery(".wpsc-setting-section-body").html(response);
1219 wpsc_reset_responsive_style();
1220 });
1221 }
1222
1223 /**
1224 * Set general appearence settings
1225 */
1226 function wpsc_set_ap_general(el) {
1227 var form = jQuery(".wpsc-frm-ap-general")[0];
1228 var dataform = new FormData(form);
1229 jQuery(el).text(supportcandy.translations.please_wait);
1230 jQuery
1231 .ajax({
1232 url: supportcandy.ajax_url,
1233 type: "POST",
1234 data: dataform,
1235 processData: false,
1236 contentType: false,
1237 })
1238 .done(function (res) {
1239 wpsc_get_ap_general();
1240 });
1241 }
1242
1243 /**
1244 * Reset appearence general settings
1245 */
1246 function wpsc_reset_ap_general(el, nonce) {
1247 jQuery(el).text(supportcandy.translations.please_wait);
1248 var data = { action: "wpsc_reset_ap_general", _ajax_nonce: nonce };
1249 jQuery.post(supportcandy.ajax_url, data, function (res) {
1250 wpsc_get_ap_general();
1251 });
1252 }
1253
1254 /**
1255 * Get appearence ticket list settings
1256 */
1257 function wpsc_get_ap_ticket_list() {
1258 supportcandy.current_tab = "ticket-list";
1259 jQuery(".wpsc-setting-tab-container button").removeClass("active");
1260 jQuery(
1261 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1262 ).addClass("active");
1263
1264 window.history.replaceState(
1265 {},
1266 null,
1267 "admin.php?page=wpsc-settings&section=" +
1268 supportcandy.current_section +
1269 "&tab=" +
1270 supportcandy.current_tab
1271 );
1272 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
1273
1274 wpsc_scroll_top();
1275 var data = { action: "wpsc_get_ap_ticket_list" };
1276 jQuery.post(supportcandy.ajax_url, data, function (response) {
1277 jQuery(".wpsc-setting-section-body").html(response);
1278 wpsc_reset_responsive_style();
1279 });
1280 }
1281
1282 /**
1283 * Set appearence ticket list settings
1284 */
1285 function wpsc_set_ap_ticket_list(el) {
1286 var form = jQuery(".wpsc-frm-ap-tl")[0];
1287 var dataform = new FormData(form);
1288 jQuery(el).text(supportcandy.translations.please_wait);
1289 jQuery
1290 .ajax({
1291 url: supportcandy.ajax_url,
1292 type: "POST",
1293 data: dataform,
1294 processData: false,
1295 contentType: false,
1296 })
1297 .done(function (res) {
1298 wpsc_get_ap_ticket_list();
1299 });
1300 }
1301
1302 /**
1303 * Reset appearence ticket list settings
1304 */
1305 function wpsc_reset_ap_ticket_list(el, nonce) {
1306 jQuery(el).text(supportcandy.translations.please_wait);
1307 var data = { action: "wpsc_reset_ap_ticket_list", _ajax_nonce: nonce };
1308 jQuery.post(supportcandy.ajax_url, data, function (res) {
1309 wpsc_get_ap_ticket_list();
1310 });
1311 }
1312
1313 /**
1314 * Get appearence individual ticket settings
1315 */
1316 function wpsc_get_ap_individual_ticket() {
1317 supportcandy.current_tab = "individual-ticket";
1318 jQuery(".wpsc-setting-tab-container button").removeClass("active");
1319 jQuery(
1320 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1321 ).addClass("active");
1322
1323 window.history.replaceState(
1324 {},
1325 null,
1326 "admin.php?page=wpsc-settings&section=" +
1327 supportcandy.current_section +
1328 "&tab=" +
1329 supportcandy.current_tab
1330 );
1331 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
1332
1333 wpsc_scroll_top();
1334 var data = { action: "wpsc_get_ap_individual_ticket" };
1335 jQuery.post(supportcandy.ajax_url, data, function (response) {
1336 jQuery(".wpsc-setting-section-body").html(response);
1337 wpsc_reset_responsive_style();
1338 });
1339 }
1340
1341 /**
1342 * Set appearence individual ticket settings
1343 */
1344 function wpsc_set_ap_individual_ticket(el) {
1345 var form = jQuery(".wpsc-frm-ap-it")[0];
1346 var dataform = new FormData(form);
1347 jQuery(el).text(supportcandy.translations.please_wait);
1348 jQuery
1349 .ajax({
1350 url: supportcandy.ajax_url,
1351 type: "POST",
1352 data: dataform,
1353 processData: false,
1354 contentType: false,
1355 })
1356 .done(function (res) {
1357 wpsc_get_ap_individual_ticket();
1358 });
1359 }
1360
1361 /**
1362 * Reset appearence individual ticket settings
1363 */
1364 function wpsc_reset_ap_individual_ticket(el, nonce) {
1365 jQuery(el).text(supportcandy.translations.please_wait);
1366 var data = { action: "wpsc_reset_ap_individual_ticket", _ajax_nonce: nonce };
1367 jQuery.post(supportcandy.ajax_url, data, function (res) {
1368 wpsc_get_ap_individual_ticket();
1369 });
1370 }
1371
1372 /**
1373 * Get appearence modal popup settigns
1374 */
1375 function wpsc_get_ap_modal_popup() {
1376 supportcandy.current_tab = "modal-popup";
1377 jQuery(".wpsc-setting-tab-container button").removeClass("active");
1378 jQuery(
1379 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1380 ).addClass("active");
1381
1382 window.history.replaceState(
1383 {},
1384 null,
1385 "admin.php?page=wpsc-settings&section=" +
1386 supportcandy.current_section +
1387 "&tab=" +
1388 supportcandy.current_tab
1389 );
1390 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
1391
1392 wpsc_scroll_top();
1393 var data = { action: "wpsc_get_ap_modal_popup" };
1394 jQuery.post(supportcandy.ajax_url, data, function (response) {
1395 jQuery(".wpsc-setting-section-body").html(response);
1396 wpsc_reset_responsive_style();
1397 });
1398 }
1399
1400 /**
1401 * Set appearence modal settings
1402 */
1403 function wpsc_set_ap_modal_popup(el) {
1404 var form = jQuery(".wpsc-frm-ap-modal")[0];
1405 var dataform = new FormData(form);
1406 jQuery(el).text(supportcandy.translations.please_wait);
1407 jQuery
1408 .ajax({
1409 url: supportcandy.ajax_url,
1410 type: "POST",
1411 data: dataform,
1412 processData: false,
1413 contentType: false,
1414 })
1415 .done(function (res) {
1416 wpsc_get_ap_modal_popup();
1417 });
1418 }
1419
1420 /**
1421 * Reset appearence modal settings
1422 */
1423 function wpsc_reset_ap_modal_popup(el, nonce) {
1424 jQuery(el).text(supportcandy.translations.please_wait);
1425 var data = { action: "wpsc_reset_ap_modal_popup", _ajax_nonce: nonce };
1426 jQuery.post(supportcandy.ajax_url, data, function (res) {
1427 wpsc_get_ap_modal_popup();
1428 });
1429 }
1430
1431 /**
1432 * Get appearence agent collision settigns
1433 */
1434 function wpsc_get_ap_agent_collision() {
1435 supportcandy.current_tab = "agent-collision";
1436 jQuery(".wpsc-setting-tab-container button").removeClass("active");
1437 jQuery(
1438 ".wpsc-setting-tab-container button." + supportcandy.current_tab
1439 ).addClass("active");
1440
1441 window.history.replaceState(
1442 {},
1443 null,
1444 "admin.php?page=wpsc-settings&section=" +
1445 supportcandy.current_section +
1446 "&tab=" +
1447 supportcandy.current_tab
1448 );
1449 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
1450
1451 wpsc_scroll_top();
1452 var data = { action: "wpsc_get_ap_agent_collision" };
1453 jQuery.post(supportcandy.ajax_url, data, function (response) {
1454 jQuery(".wpsc-setting-section-body").html(response);
1455 wpsc_reset_responsive_style();
1456 });
1457 }
1458
1459 /**
1460 * Set appearence agent collision settings
1461 */
1462 function wpsc_set_ap_agent_collision(el) {
1463 var form = jQuery(".wpsc-frm-ap-agent-collision")[0];
1464 var dataform = new FormData(form);
1465 jQuery(el).text(supportcandy.translations.please_wait);
1466 jQuery
1467 .ajax({
1468 url: supportcandy.ajax_url,
1469 type: "POST",
1470 data: dataform,
1471 processData: false,
1472 contentType: false,
1473 })
1474 .done(function (res) {
1475 wpsc_get_ap_agent_collision();
1476 });
1477 }
1478
1479 /**
1480 * Reset appearence agent collision settings
1481 */
1482 function wpsc_reset_ap_agent_collision(el, nonce) {
1483 jQuery(el).text(supportcandy.translations.please_wait);
1484 var data = { action: "wpsc_reset_ap_agent_collision", _ajax_nonce: nonce };
1485 jQuery.post(supportcandy.ajax_url, data, function (res) {
1486 wpsc_get_ap_agent_collision();
1487 });
1488 }
1489
1490 /**
1491 * Set add new category
1492 */
1493 function wpsc_set_add_category(el) {
1494 var form = jQuery(".wpsc-frm-add-category")[0];
1495 var dataform = new FormData(form);
1496
1497 if (dataform.get("label").trim() == "") {
1498 alert(supportcandy.translations.req_fields_missing);
1499 return;
1500 }
1501
1502 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1503 jQuery(el).text(supportcandy.translations.please_wait);
1504
1505 jQuery
1506 .ajax({
1507 url: supportcandy.ajax_url,
1508 type: "POST",
1509 data: dataform,
1510 processData: false,
1511 contentType: false,
1512 })
1513 .done(function (res) {
1514 wpsc_close_modal();
1515 wpsc_get_ticket_categories();
1516 });
1517 }
1518
1519 /**
1520 * Get edit category modal
1521 */
1522 function wpsc_get_edit_category(id, nonce) {
1523 wpsc_show_modal();
1524 var data = { action: "wpsc_get_edit_category", id, _ajax_nonce: nonce };
1525 jQuery.post(supportcandy.ajax_url, data, function (response) {
1526 // Set to modal.
1527 jQuery(".wpsc-modal-header").text(response.title);
1528 jQuery(".wpsc-modal-body").html(response.body);
1529 jQuery(".wpsc-modal-footer").html(response.footer);
1530 // Display modal.
1531 wpsc_show_modal_inner_container();
1532 });
1533 }
1534
1535 /**
1536 * Update category
1537 */
1538 function wpsc_set_edit_category(el) {
1539 var form = jQuery(".wpsc-frm-edit-category")[0];
1540 var dataform = new FormData(form);
1541
1542 if (dataform.get("label").trim() == "") {
1543 alert(supportcandy.translations.req_fields_missing);
1544 return;
1545 }
1546
1547 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1548 jQuery(el).text(supportcandy.translations.please_wait);
1549
1550 jQuery
1551 .ajax({
1552 url: supportcandy.ajax_url,
1553 type: "POST",
1554 data: dataform,
1555 processData: false,
1556 contentType: false,
1557 })
1558 .done(function (res) {
1559 wpsc_close_modal();
1560 wpsc_get_ticket_categories();
1561 });
1562 }
1563
1564 /**
1565 * Delete category modal
1566 */
1567 function wpsc_get_delete_category(id, nonce) {
1568 var flag = confirm(supportcandy.translations.confirm);
1569 if (!flag) {
1570 return;
1571 }
1572
1573 wpsc_show_modal();
1574 var data = { action: "wpsc_get_delete_category", id, _ajax_nonce: nonce };
1575 jQuery.post(supportcandy.ajax_url, data, function (response) {
1576 // Set to modal.
1577 jQuery(".wpsc-modal-header").text(response.title);
1578 jQuery(".wpsc-modal-body").html(response.body);
1579 jQuery(".wpsc-modal-footer").html(response.footer);
1580 // Display modal.
1581 wpsc_show_modal_inner_container();
1582 });
1583 }
1584
1585 /**
1586 * Delete category
1587 */
1588 function wpsc_set_delete_category(el) {
1589 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1590 jQuery(el).text(supportcandy.translations.please_wait);
1591
1592 var form = jQuery(".wpsc-frm-delete-category")[0];
1593 var dataform = new FormData(form);
1594 jQuery
1595 .ajax({
1596 url: supportcandy.ajax_url,
1597 type: "POST",
1598 data: dataform,
1599 processData: false,
1600 contentType: false,
1601 })
1602 .done(function (res) {
1603 wpsc_close_modal();
1604 wpsc_get_ticket_categories();
1605 });
1606 }
1607
1608 /**
1609 * Get status settings
1610 */
1611 function wpsc_get_ticket_statuses(is_humbargar = false) {
1612 if (is_humbargar) {
1613 wpsc_toggle_humbargar();
1614 }
1615
1616 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
1617 jQuery(
1618 ".wpsc-setting-nav.ticket-statuses, .wpsc-humbargar-menu-item.ticket-statuses"
1619 ).addClass("active");
1620 jQuery(".wpsc-humbargar-title").html(
1621 supportcandy.humbargar_titles.ticket_statuses
1622 );
1623
1624 window.history.replaceState(
1625 {},
1626 null,
1627 "admin.php?page=wpsc-settings&section=ticket-statuses"
1628 );
1629 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
1630
1631 wpsc_scroll_top();
1632
1633 var data = { action: "wpsc_get_ticket_statuses" };
1634 jQuery.post(supportcandy.ajax_url, data, function (response) {
1635 jQuery(".wpsc-setting-body").html(response);
1636 wpsc_reset_responsive_style();
1637 });
1638 }
1639
1640 /**
1641 * Set add new status
1642 */
1643 function wpsc_set_add_status(el) {
1644 var form = jQuery(".wpsc-frm-add-status")[0];
1645 var dataform = new FormData(form);
1646
1647 if (dataform.get("name").trim() == "") {
1648 alert(supportcandy.translations.req_fields_missing);
1649 return;
1650 }
1651
1652 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1653 jQuery(el).text(supportcandy.translations.please_wait);
1654
1655 jQuery
1656 .ajax({
1657 url: supportcandy.ajax_url,
1658 type: "POST",
1659 data: dataform,
1660 processData: false,
1661 contentType: false,
1662 })
1663 .done(function (res) {
1664 wpsc_close_modal();
1665 wpsc_get_ticket_statuses();
1666 });
1667 }
1668
1669 /**
1670 * Get edit status modal
1671 */
1672 function wpsc_get_edit_status(id, nonce) {
1673 wpsc_show_modal();
1674 var data = { action: "wpsc_get_edit_status", id, _ajax_nonce: nonce };
1675 jQuery.post(supportcandy.ajax_url, data, function (response) {
1676 // Set to modal.
1677 jQuery(".wpsc-modal-header").text(response.title);
1678 jQuery(".wpsc-modal-body").html(response.body);
1679 jQuery(".wpsc-modal-footer").html(response.footer);
1680 // Display modal.
1681 wpsc_show_modal_inner_container();
1682 });
1683 }
1684
1685 /**
1686 * Update status
1687 */
1688 function wpsc_set_edit_status(el) {
1689 var form = jQuery(".wpsc-frm-edit-status")[0];
1690 var dataform = new FormData(form);
1691
1692 if (dataform.get("name").trim() == "") {
1693 alert(supportcandy.translations.req_fields_missing);
1694 return;
1695 }
1696
1697 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1698 jQuery(el).text(supportcandy.translations.please_wait);
1699
1700 jQuery
1701 .ajax({
1702 url: supportcandy.ajax_url,
1703 type: "POST",
1704 data: dataform,
1705 processData: false,
1706 contentType: false,
1707 })
1708 .done(function (res) {
1709 wpsc_close_modal();
1710 wpsc_get_ticket_statuses();
1711 });
1712 }
1713
1714 /**
1715 * Delete status modal
1716 */
1717 function wpsc_get_delete_status(id, nonce) {
1718 var flag = confirm(supportcandy.translations.confirm);
1719 if (!flag) {
1720 return;
1721 }
1722
1723 wpsc_show_modal();
1724 var data = { action: "wpsc_get_delete_status", id, _ajax_nonce: nonce };
1725 jQuery.post(supportcandy.ajax_url, data, function (response) {
1726 // Set to modal.
1727 jQuery(".wpsc-modal-header").text(response.title);
1728 jQuery(".wpsc-modal-body").html(response.body);
1729 jQuery(".wpsc-modal-footer").html(response.footer);
1730 // Display modal.
1731 wpsc_show_modal_inner_container();
1732 });
1733 }
1734
1735 /**
1736 * Delete status
1737 */
1738 function wpsc_set_delete_status(el) {
1739 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1740 jQuery(el).text(supportcandy.translations.please_wait);
1741
1742 var form = jQuery(".wpsc-frm-delete-status")[0];
1743 var dataform = new FormData(form);
1744 jQuery
1745 .ajax({
1746 url: supportcandy.ajax_url,
1747 type: "POST",
1748 data: dataform,
1749 processData: false,
1750 contentType: false,
1751 })
1752 .done(function (res) {
1753 wpsc_close_modal();
1754 wpsc_get_ticket_statuses();
1755 });
1756 }
1757
1758 /**
1759 * Get priority settings
1760 */
1761 function wpsc_get_ticket_priorities(is_humbargar = false) {
1762 if (is_humbargar) {
1763 wpsc_toggle_humbargar();
1764 }
1765
1766 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
1767 jQuery(
1768 ".wpsc-setting-nav.ticket-priorities, .wpsc-humbargar-menu-item.ticket-priorities"
1769 ).addClass("active");
1770 jQuery(".wpsc-humbargar-title").html(
1771 supportcandy.humbargar_titles.ticket_priorities
1772 );
1773
1774 window.history.replaceState(
1775 {},
1776 null,
1777 "admin.php?page=wpsc-settings&section=ticket-priorities"
1778 );
1779 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
1780
1781 wpsc_scroll_top();
1782
1783 var data = { action: "wpsc_get_ticket_priorities" };
1784 jQuery.post(supportcandy.ajax_url, data, function (response) {
1785 jQuery(".wpsc-setting-body").html(response);
1786 wpsc_reset_responsive_style();
1787 });
1788 }
1789
1790 /**
1791 * Set add new priority
1792 */
1793 function wpsc_set_add_priority(el) {
1794 var form = jQuery(".wpsc-frm-add-priority")[0];
1795 var dataform = new FormData(form);
1796
1797 if (dataform.get("name").trim() == "") {
1798 alert(supportcandy.translations.req_fields_missing);
1799 return;
1800 }
1801
1802 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1803 jQuery(el).text(supportcandy.translations.please_wait);
1804
1805 jQuery
1806 .ajax({
1807 url: supportcandy.ajax_url,
1808 type: "POST",
1809 data: dataform,
1810 processData: false,
1811 contentType: false,
1812 })
1813 .done(function (res) {
1814 wpsc_close_modal();
1815 wpsc_get_ticket_priorities();
1816 });
1817 }
1818
1819 /**
1820 * Get edit priority modal
1821 */
1822 function wpsc_get_edit_priority(id, nonce) {
1823 wpsc_show_modal();
1824 var data = { action: "wpsc_get_edit_priority", id, _ajax_nonce: nonce };
1825 jQuery.post(supportcandy.ajax_url, data, function (response) {
1826 // Set to modal.
1827 jQuery(".wpsc-modal-header").text(response.title);
1828 jQuery(".wpsc-modal-body").html(response.body);
1829 jQuery(".wpsc-modal-footer").html(response.footer);
1830 // Display modal.
1831 wpsc_show_modal_inner_container();
1832 });
1833 }
1834
1835 /**
1836 * Update an priority
1837 */
1838 function wpsc_set_edit_priority(el) {
1839 var form = jQuery(".wpsc-frm-edit-priority")[0];
1840 var dataform = new FormData(form);
1841
1842 if (dataform.get("name").trim() == "") {
1843 alert(supportcandy.translations.req_fields_missing);
1844 return;
1845 }
1846
1847 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1848 jQuery(el).text(supportcandy.translations.please_wait);
1849
1850 jQuery
1851 .ajax({
1852 url: supportcandy.ajax_url,
1853 type: "POST",
1854 data: dataform,
1855 processData: false,
1856 contentType: false,
1857 })
1858 .done(function (res) {
1859 wpsc_close_modal();
1860 wpsc_get_ticket_priorities();
1861 });
1862 }
1863
1864 /**
1865 * Delete priority modal
1866 */
1867 function wpsc_get_delete_priority(id, nonce) {
1868 var flag = confirm(supportcandy.translations.confirm);
1869 if (!flag) {
1870 return;
1871 }
1872
1873 wpsc_show_modal();
1874 var data = { action: "wpsc_get_delete_priority", id, _ajax_nonce: nonce };
1875 jQuery.post(supportcandy.ajax_url, data, function (response) {
1876 // Set to modal.
1877 jQuery(".wpsc-modal-header").text(response.title);
1878 jQuery(".wpsc-modal-body").html(response.body);
1879 jQuery(".wpsc-modal-footer").html(response.footer);
1880 // Display modal.
1881 wpsc_show_modal_inner_container();
1882 });
1883 }
1884
1885 /**
1886 * Delete priority
1887 */
1888 function wpsc_set_delete_priority(el) {
1889 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1890 jQuery(el).text(supportcandy.translations.please_wait);
1891
1892 var form = jQuery(".wpsc-frm-delete-priority")[0];
1893 var dataform = new FormData(form);
1894 jQuery
1895 .ajax({
1896 url: supportcandy.ajax_url,
1897 type: "POST",
1898 data: dataform,
1899 processData: false,
1900 contentType: false,
1901 })
1902 .done(function (res) {
1903 wpsc_close_modal();
1904 wpsc_get_ticket_priorities();
1905 });
1906 }
1907
1908 /**
1909 * Get ticket form fields
1910 */
1911 function wpsc_get_tff(is_humbargar = false) {
1912 if (is_humbargar) {
1913 wpsc_toggle_humbargar();
1914 }
1915
1916 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
1917 jQuery(
1918 ".wpsc-setting-nav.ticket-form-fields, .wpsc-humbargar-menu-item.ticket-form-fields"
1919 ).addClass("active");
1920 jQuery(".wpsc-humbargar-title").html(
1921 supportcandy.humbargar_titles.ticket_form_fields
1922 );
1923
1924 window.history.replaceState(
1925 {},
1926 null,
1927 "admin.php?page=wpsc-ticket-form&section=ticket-form-fields"
1928 );
1929 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
1930
1931 wpsc_scroll_top();
1932
1933 var data = { action: "wpsc_get_tff" };
1934 jQuery.post(supportcandy.ajax_url, data, function (response) {
1935 jQuery(".wpsc-setting-body").html(response);
1936 wpsc_reset_responsive_style();
1937 });
1938 }
1939
1940 /**
1941 * Set add new ticket form field
1942 */
1943 function wpsc_set_add_new_tff(el) {
1944 if (!jQuery("#wpsc-select-ticket-form-field").val()) {
1945 alert(supportcandy.translations.req_fields_missing);
1946 return;
1947 }
1948
1949 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1950 jQuery(el).text(supportcandy.translations.please_wait);
1951
1952 var form = jQuery(".frm-add-new-ticket-form-field")[0];
1953 var dataform = new FormData(form);
1954
1955 dataform.append(
1956 "visibility",
1957 JSON.stringify(wpsc_get_condition_json("visibility"))
1958 );
1959
1960 jQuery
1961 .ajax({
1962 url: supportcandy.ajax_url,
1963 type: "POST",
1964 data: dataform,
1965 processData: false,
1966 contentType: false,
1967 })
1968 .done(function (res) {
1969 wpsc_close_modal();
1970 wpsc_get_tff();
1971 });
1972 }
1973
1974 /**
1975 * Get edit ticket form field modal
1976 */
1977 function wpsc_get_edit_tff(id, nonce) {
1978 wpsc_show_modal();
1979 var data = { action: "wpsc_get_edit_tff", id, _ajax_nonce: nonce };
1980 jQuery.post(supportcandy.ajax_url, data, function (response) {
1981 // Set to modal.
1982 jQuery(".wpsc-modal-header").text(response.title);
1983 jQuery(".wpsc-modal-body").html(response.body);
1984 jQuery(".wpsc-modal-footer").html(response.footer);
1985 // Display modal.
1986 wpsc_show_modal_inner_container();
1987 });
1988 }
1989
1990 /**
1991 * Update ticket form field
1992 */
1993 function wpsc_set_edit_tff(el) {
1994 jQuery(".wpsc-modal-footer button").attr("disabled", true);
1995 jQuery(el).text(supportcandy.translations.please_wait);
1996
1997 var form = jQuery(".frm-edit-ticket-form-field")[0];
1998 var dataform = new FormData(form);
1999
2000 dataform.append(
2001 "visibility",
2002 JSON.stringify(wpsc_get_condition_json("visibility"))
2003 );
2004
2005 jQuery
2006 .ajax({
2007 url: supportcandy.ajax_url,
2008 type: "POST",
2009 data: dataform,
2010 processData: false,
2011 contentType: false,
2012 })
2013 .done(function (res) {
2014 wpsc_close_modal();
2015 wpsc_get_tff();
2016 });
2017 }
2018
2019 /**
2020 * Delete ticket form field
2021 */
2022 function wpsc_delete_tff(id, nonce) {
2023 var flag = confirm(supportcandy.translations.confirm);
2024 if (!flag) {
2025 return;
2026 }
2027
2028 var data = { action: "wpsc_delete_tff", id, _ajax_nonce: nonce };
2029 jQuery.post(supportcandy.ajax_url, data, function (res) {
2030 wpsc_get_tff();
2031 });
2032 }
2033
2034 /**
2035 * Get ticket fields
2036 */
2037 function wpsc_get_ticket_fields(is_humbargar = false) {
2038 if (is_humbargar) {
2039 wpsc_toggle_humbargar();
2040 }
2041
2042 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
2043 jQuery(
2044 ".wpsc-setting-nav.ticket-fields, .wpsc-humbargar-menu-item.ticket-fields"
2045 ).addClass("active");
2046 jQuery(".wpsc-humbargar-title").html(
2047 supportcandy.humbargar_titles.ticket_fields
2048 );
2049
2050 window.history.replaceState(
2051 {},
2052 null,
2053 "admin.php?page=wpsc-ticket-form&section=ticket-fields"
2054 );
2055 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2056
2057 wpsc_scroll_top();
2058
2059 var data = { action: "wpsc_get_ticket_fields" };
2060 jQuery.post(supportcandy.ajax_url, data, function (response) {
2061 jQuery(".wpsc-setting-body").html(response);
2062 wpsc_reset_responsive_style();
2063 });
2064 }
2065
2066 /**
2067 * Get customer fields
2068 */
2069 function wpsc_get_customer_fields(is_humbargar = false) {
2070 if (is_humbargar) {
2071 wpsc_toggle_humbargar();
2072 }
2073
2074 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
2075 jQuery(
2076 ".wpsc-setting-nav.customer-fields, .wpsc-humbargar-menu-item.customer-fields"
2077 ).addClass("active");
2078 jQuery(".wpsc-humbargar-title").html(
2079 supportcandy.humbargar_titles.customer_fields
2080 );
2081
2082 window.history.replaceState(
2083 {},
2084 null,
2085 "admin.php?page=wpsc-ticket-form&section=customer-fields"
2086 );
2087 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2088
2089 wpsc_scroll_top();
2090
2091 var data = { action: "wpsc_get_customer_fields" };
2092 jQuery.post(supportcandy.ajax_url, data, function (response) {
2093 jQuery(".wpsc-setting-body").html(response);
2094 wpsc_reset_responsive_style();
2095 });
2096 }
2097
2098 /**
2099 * Get agent only fields
2100 */
2101 function wpsc_get_agent_only_fields(is_humbargar = false) {
2102 if (is_humbargar) {
2103 wpsc_toggle_humbargar();
2104 }
2105
2106 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
2107 jQuery(
2108 ".wpsc-setting-nav.agent-only-fields, .wpsc-humbargar-menu-item.agent-only-fields"
2109 ).addClass("active");
2110 jQuery(".wpsc-humbargar-title").html(
2111 supportcandy.humbargar_titles.agent_only_fields
2112 );
2113
2114 window.history.replaceState(
2115 {},
2116 null,
2117 "admin.php?page=wpsc-ticket-form&section=agent-only-fields"
2118 );
2119 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2120
2121 wpsc_scroll_top();
2122
2123 var data = { action: "wpsc_get_agent_only_fields" };
2124 jQuery.post(supportcandy.ajax_url, data, function (response) {
2125 jQuery(".wpsc-setting-body").html(response);
2126 wpsc_reset_responsive_style();
2127 });
2128 }
2129
2130 /**
2131 * Get add new ticket field
2132 */
2133 function wpsc_get_add_new_custom_field(field, nonce) {
2134 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2135 var data = {
2136 action: "wpsc_get_add_new_custom_field",
2137 field,
2138 _ajax_nonce: nonce,
2139 };
2140 jQuery.post(supportcandy.ajax_url, data, function (response) {
2141 jQuery(".wpsc-setting-section-body").html(response);
2142 });
2143 }
2144
2145 /**
2146 * Get edit ticket field modal
2147 */
2148 function wpsc_get_edit_custom_field(id, nonce) {
2149 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2150 var data = {
2151 action: "wpsc_get_edit_custom_field",
2152 cf_id: id,
2153 _ajax_nonce: nonce,
2154 };
2155 jQuery.post(supportcandy.ajax_url, data, function (response) {
2156 jQuery(".wpsc-setting-section-body").html(response);
2157 });
2158 }
2159
2160 /**
2161 * Submit delete an ticket form field
2162 */
2163 function wpsc_delete_custom_field(id, nonce) {
2164 var flag = confirm(supportcandy.translations.confirm);
2165 if (!flag) {
2166 return;
2167 }
2168
2169 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2170
2171 var data = {
2172 action: "wpsc_delete_custom_field",
2173 cf_id: id,
2174 _ajax_nonce: nonce,
2175 };
2176 jQuery.post(supportcandy.ajax_url, data, function (res) {
2177 jQuery(".wpsc-setting-nav.active").trigger("click");
2178 });
2179 }
2180
2181 /**
2182 * Get agent ticket list settings
2183 */
2184 function wpsc_get_agent_tl_settings(is_humbargar = false) {
2185 if (is_humbargar) {
2186 wpsc_toggle_humbargar();
2187 }
2188
2189 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
2190 jQuery(
2191 ".wpsc-setting-nav.agent-ticket-list, .wpsc-humbargar-menu-item.agent-ticket-list"
2192 ).addClass("active");
2193 jQuery(".wpsc-humbargar-title").html(
2194 supportcandy.humbargar_titles.agent_ticket_list
2195 );
2196
2197 if (supportcandy.current_section !== "agent-ticket-list") {
2198 supportcandy.current_section = "agent-ticket-list";
2199 supportcandy.current_tab = "list-items";
2200 }
2201
2202 window.history.replaceState(
2203 {},
2204 null,
2205 "admin.php?page=wpsc-ticket-list&section=" +
2206 supportcandy.current_section +
2207 "&tab=" +
2208 supportcandy.current_tab
2209 );
2210 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2211
2212 wpsc_scroll_top();
2213
2214 var data = {
2215 action: "wpsc_get_agent_tl_settings",
2216 tab: supportcandy.current_tab,
2217 };
2218 jQuery.post(supportcandy.ajax_url, data, function (response) {
2219 jQuery(".wpsc-setting-body").html(response);
2220 wpsc_reset_responsive_style();
2221 jQuery(
2222 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2223 ).trigger("click");
2224 });
2225 }
2226
2227 /**
2228 * Get customer ticket list
2229 */
2230 function wpsc_get_customer_tl_settings(is_humbargar = false) {
2231 if (is_humbargar) {
2232 wpsc_toggle_humbargar();
2233 }
2234
2235 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
2236 jQuery(
2237 ".wpsc-setting-nav.customer-ticket-list, .wpsc-humbargar-menu-item.customer-ticket-list"
2238 ).addClass("active");
2239 jQuery(".wpsc-humbargar-title").html(
2240 supportcandy.humbargar_titles.customer_ticket_list
2241 );
2242
2243 if (supportcandy.current_section !== "customer-ticket-list") {
2244 supportcandy.current_section = "customer-ticket-list";
2245 supportcandy.current_tab = "list-items";
2246 }
2247
2248 window.history.replaceState(
2249 {},
2250 null,
2251 "admin.php?page=wpsc-ticket-list&section=" +
2252 supportcandy.current_section +
2253 "&tab=" +
2254 supportcandy.current_tab
2255 );
2256 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2257
2258 wpsc_scroll_top();
2259
2260 var data = {
2261 action: "wpsc_get_customer_tl_settings",
2262 tab: supportcandy.current_tab,
2263 };
2264 jQuery.post(supportcandy.ajax_url, data, function (response) {
2265 jQuery(".wpsc-setting-body").html(response);
2266 wpsc_reset_responsive_style();
2267 jQuery(
2268 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2269 ).trigger("click");
2270 });
2271 }
2272
2273 /**
2274 * Get ticket list more settings
2275 */
2276 function wpsc_get_tl_more_settigns(is_humbargar = false) {
2277 if (is_humbargar) {
2278 wpsc_toggle_humbargar();
2279 }
2280
2281 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
2282 jQuery(
2283 ".wpsc-setting-nav.more-settings, .wpsc-humbargar-menu-item.more-settings"
2284 ).addClass("active");
2285 jQuery(".wpsc-humbargar-title").html(
2286 supportcandy.humbargar_titles.more_settings
2287 );
2288
2289 if (supportcandy.current_section !== "more-settings") {
2290 supportcandy.current_section = "more-settings";
2291 supportcandy.current_tab = "agent-view";
2292 }
2293
2294 window.history.replaceState(
2295 {},
2296 null,
2297 "admin.php?page=wpsc-ticket-list&section=more-settings"
2298 );
2299 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
2300
2301 wpsc_scroll_top();
2302
2303 var data = { action: "wpsc_get_tl_more_settigns" };
2304 jQuery.post(supportcandy.ajax_url, data, function (response) {
2305 jQuery(".wpsc-setting-body").html(response);
2306 wpsc_reset_responsive_style();
2307 jQuery(
2308 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2309 ).trigger("click");
2310 });
2311 }
2312
2313 /**
2314 * Get agent ticket list items
2315 */
2316 function wpsc_get_agent_tl_items() {
2317 supportcandy.current_tab = "list-items";
2318 jQuery(".wpsc-setting-tab-container button").removeClass("active");
2319 jQuery(
2320 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2321 ).addClass("active");
2322
2323 window.history.replaceState(
2324 {},
2325 null,
2326 "admin.php?page=wpsc-ticket-list&section=" +
2327 supportcandy.current_section +
2328 "&tab=" +
2329 supportcandy.current_tab
2330 );
2331 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2332
2333 wpsc_scroll_top();
2334
2335 var data = { action: "wpsc_get_agent_tl_items" };
2336 jQuery.post(supportcandy.ajax_url, data, function (response) {
2337 jQuery(".wpsc-setting-section-body").html(response);
2338 wpsc_reset_responsive_style();
2339 });
2340 }
2341
2342 /**
2343 * Set add new agent list items
2344 */
2345 function wpsc_set_add_agent_tl_item(el) {
2346 var form = jQuery(".frm-add-agent-tl-items")[0];
2347 var dataform = new FormData(form);
2348
2349 var cf_id = dataform.getAll("cf_id[]");
2350 if (!cf_id.length) {
2351 alert(supportcandy.translations.req_fields_missing);
2352 return;
2353 }
2354
2355 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2356 jQuery(el).text(supportcandy.translations.please_wait);
2357
2358 jQuery
2359 .ajax({
2360 url: supportcandy.ajax_url,
2361 type: "POST",
2362 data: dataform,
2363 processData: false,
2364 contentType: false,
2365 })
2366 .done(function (res) {
2367 wpsc_close_modal();
2368 wpsc_get_agent_tl_items();
2369 });
2370 }
2371
2372 /**
2373 * Set delete agent ticket list item
2374 */
2375 function wpsc_delete_agent_tl_item(slug, nonce) {
2376 if (confirm(supportcandy.translations.confirm)) {
2377 var data = {
2378 action: "wpsc_delete_agent_tl_item",
2379 slug: slug,
2380 _ajax_nonce: nonce,
2381 };
2382
2383 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2384 jQuery(slug).text(supportcandy.translations.please_wait);
2385 jQuery.post(supportcandy.ajax_url, data, function (res) {
2386 wpsc_get_agent_tl_items();
2387 });
2388 } else {
2389 return false;
2390 }
2391 }
2392
2393 /**
2394 * Get agent filter items
2395 */
2396 function wpsc_get_agent_filter_items() {
2397 supportcandy.current_tab = "filter-items";
2398 jQuery(".wpsc-setting-tab-container button").removeClass("active");
2399 jQuery(
2400 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2401 ).addClass("active");
2402
2403 window.history.replaceState(
2404 {},
2405 null,
2406 "admin.php?page=wpsc-ticket-list&section=" +
2407 supportcandy.current_section +
2408 "&tab=" +
2409 supportcandy.current_tab
2410 );
2411 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2412
2413 wpsc_scroll_top();
2414
2415 var data = { action: "wpsc_get_agent_filter_items" };
2416 jQuery.post(supportcandy.ajax_url, data, function (response) {
2417 jQuery(".wpsc-setting-section-body").html(response);
2418 wpsc_reset_responsive_style();
2419 });
2420 }
2421
2422 /**
2423 * Set add new agent list items
2424 */
2425 function wpsc_set_add_atl_filter_item(el) {
2426 var form = jQuery(".frm-add-agent-tl-filter-items")[0];
2427 var dataform = new FormData(form);
2428
2429 var cf_id = dataform.getAll("agent-tl-filter-id[]");
2430 if (!cf_id.length) {
2431 alert(supportcandy.translations.req_fields_missing);
2432 return;
2433 }
2434
2435 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2436 jQuery(el).text(supportcandy.translations.please_wait);
2437 jQuery
2438 .ajax({
2439 url: supportcandy.ajax_url,
2440 type: "POST",
2441 data: dataform,
2442 processData: false,
2443 contentType: false,
2444 })
2445 .done(function (res) {
2446 wpsc_close_modal();
2447 wpsc_get_agent_filter_items();
2448 });
2449 }
2450
2451 /**
2452 * Get delete agent ticket list item
2453 *
2454 * @param {*} slug
2455 */
2456 function wpsc_delete_atl_filter_item(slug, nonce) {
2457 if (confirm(supportcandy.translations.confirm)) {
2458 var data = {
2459 action: "wpsc_delete_atl_filter_item",
2460 slug: slug,
2461 _ajax_nonce: nonce,
2462 };
2463 jQuery.post(supportcandy.ajax_url, data, function (res) {
2464 wpsc_get_agent_filter_items();
2465 });
2466 }
2467 }
2468
2469 /**
2470 * Get agent default filters
2471 */
2472 function wpsc_get_atl_default_filters() {
2473 supportcandy.current_tab = "default-filters";
2474 jQuery(".wpsc-setting-tab-container button").removeClass("active");
2475 jQuery(
2476 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2477 ).addClass("active");
2478
2479 window.history.replaceState(
2480 {},
2481 null,
2482 "admin.php?page=wpsc-ticket-list&section=" +
2483 supportcandy.current_section +
2484 "&tab=" +
2485 supportcandy.current_tab
2486 );
2487 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2488
2489 wpsc_scroll_top();
2490
2491 var data = { action: "wpsc_get_atl_default_filters" };
2492 jQuery.post(supportcandy.ajax_url, data, function (response) {
2493 jQuery(".wpsc-setting-section-body").html(response);
2494 wpsc_reset_responsive_style();
2495 });
2496 }
2497
2498 /**
2499 * Add agent default filter
2500 */
2501 function wpsc_get_add_atl_default_filter() {
2502 wpsc_show_modal();
2503 var data = { action: "wpsc_get_add_atl_default_filter" };
2504 jQuery.post(supportcandy.ajax_url, data, function (response) {
2505 jQuery(".wpsc-modal-header").text(response.title);
2506 jQuery(".wpsc-modal-body").html(response.body);
2507 jQuery(".wpsc-modal-footer").html(response.footer);
2508 jQuery(".wpsc-form-filter-container").append(
2509 jQuery(".wpsc-form-filter-snippet").html()
2510 );
2511 jQuery(".wpsc-form-filter-container select").selectWoo();
2512 wpsc_show_modal_inner_container();
2513 });
2514 }
2515
2516 /**
2517 * Set add agent default filters
2518 */
2519 function wpsc_set_add_atl_default_filter(el) {
2520 var label = jQuery("#wpsc-atl-df-label").val().trim();
2521 if (!label) {
2522 alert(supportcandy.translations.req_fields_missing);
2523 return;
2524 }
2525
2526 var filters = wpsc_get_condition_json("default_filters");
2527 if (
2528 filters.length === 0 ||
2529 (filters.length === 1 && filters[0].length === 0)
2530 ) {
2531 alert(supportcandy.translations.req_fields_missing);
2532 return;
2533 }
2534
2535 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2536 jQuery(el).text(supportcandy.translations.please_wait);
2537
2538 var form = jQuery(".wpsc-frm-add-atl-default-filter")[0];
2539 var dataform = new FormData(form);
2540 dataform.append("filters", JSON.stringify(filters));
2541
2542 jQuery
2543 .ajax({
2544 url: supportcandy.ajax_url,
2545 type: "POST",
2546 data: dataform,
2547 processData: false,
2548 contentType: false,
2549 })
2550 .done(function (res) {
2551 wpsc_close_modal();
2552 wpsc_get_atl_default_filters();
2553 });
2554 }
2555
2556 /**
2557 * Get edit agent defualt filter
2558 */
2559 function wpsc_get_edit_atl_default_filter(slug, nonce) {
2560 wpsc_show_modal();
2561 var data = {
2562 action: "wpsc_get_edit_atl_default_filter",
2563 slug,
2564 _ajax_nonce: nonce,
2565 };
2566 jQuery.post(supportcandy.ajax_url, data, function (response) {
2567 jQuery(".wpsc-modal-header").text(response.title);
2568 jQuery(".wpsc-modal-body").html(response.body);
2569 jQuery(".wpsc-modal-footer").html(response.footer);
2570 wpsc_show_modal_inner_container();
2571 });
2572 }
2573
2574 /**
2575 * Set edit agent default filter
2576 */
2577 function wpsc_set_edit_atl_default_filter(el, flag) {
2578 var label = jQuery("#wpsc-atl-df-label").val().trim();
2579 if (!label) {
2580 alert(supportcandy.translations.req_fields_missing);
2581 return;
2582 }
2583
2584 var form = jQuery(".wpsc-frm-edit-atl-default-filter")[0];
2585 var dataform = new FormData(form);
2586
2587 if (flag) {
2588 var filters = wpsc_get_condition_json("default_filters");
2589 if (
2590 filters.length === 0 ||
2591 (filters.length === 1 && filters[0].length === 0)
2592 ) {
2593 alert(supportcandy.translations.req_fields_missing);
2594 return;
2595 }
2596 dataform.append("filters", JSON.stringify(filters));
2597 }
2598
2599 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2600 jQuery(el).text(supportcandy.translations.please_wait);
2601
2602 jQuery
2603 .ajax({
2604 url: supportcandy.ajax_url,
2605 type: "POST",
2606 data: dataform,
2607 processData: false,
2608 contentType: false,
2609 })
2610 .done(function (res) {
2611 wpsc_close_modal();
2612 wpsc_get_atl_default_filters();
2613 });
2614 }
2615
2616 /**
2617 * Delete agent default filter
2618 */
2619 function wpsc_delete_atl_default_filter(slug, nonce) {
2620 var flag = confirm(supportcandy.translations.confirm);
2621 if (!flag) {
2622 return;
2623 }
2624
2625 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2626
2627 var data = {
2628 action: "wpsc_delete_atl_default_filter",
2629 slug,
2630 _ajax_nonce: nonce,
2631 };
2632 jQuery.post(supportcandy.ajax_url, data, function (response) {
2633 wpsc_get_atl_default_filters();
2634 });
2635 }
2636
2637 /**
2638 * Toggle enable/disable status of a single default filter.
2639 * Note: the currently active default filter can't be disabled - if the
2640 * server refuses the disable, it sends back is_enable: 1 and we resync
2641 * the checkbox/row to reflect that.
2642 */
2643 function wpsc_toggle_atl_default_filter_status(el, slug, nonce) {
2644 var checkbox = jQuery(el);
2645 var is_enable = checkbox.is(":checked") ? 1 : 0;
2646 var filter = checkbox.closest(".wpsc-setting-card");
2647
2648 var data = {
2649 action: "wpsc_toggle_atl_default_filter_status",
2650 slug,
2651 is_enable,
2652 _ajax_nonce: nonce,
2653 };
2654 jQuery.post(supportcandy.ajax_url, data, function (response) {
2655 var saved_enable = response.data.is_enable;
2656 checkbox.prop("checked", !!saved_enable);
2657 filter.attr(
2658 "style",
2659 saved_enable ? "" : "background-color:#eec7ca;color:#dc2222"
2660 );
2661 var total = jQuery(".wpsc-toggle-atl-default-filter").length;
2662 var checked = jQuery(".wpsc-toggle-atl-default-filter:checked").length;
2663 jQuery(".wpsc-toggle-all-atl-default-filters").prop(
2664 "checked",
2665 total > 0 && total === checked
2666 );
2667 }).fail(function () {
2668 // Revert checkbox on failure.
2669 checkbox.prop("checked", !is_enable);
2670 });
2671 }
2672
2673 /**
2674 * Get customer ticket list items
2675 */
2676 function wpsc_get_customer_tl_items() {
2677 supportcandy.current_tab = "list-items";
2678 jQuery(".wpsc-setting-tab-container button").removeClass("active");
2679 jQuery(
2680 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2681 ).addClass("active");
2682
2683 window.history.replaceState(
2684 {},
2685 null,
2686 "admin.php?page=wpsc-ticket-list&section=" +
2687 supportcandy.current_section +
2688 "&tab=" +
2689 supportcandy.current_tab
2690 );
2691 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2692
2693 wpsc_scroll_top();
2694
2695 var data = { action: "wpsc_get_customer_tl_items" };
2696 jQuery.post(supportcandy.ajax_url, data, function (response) {
2697 jQuery(".wpsc-setting-section-body").html(response);
2698 wpsc_reset_responsive_style();
2699 });
2700 }
2701
2702 /**
2703 * Get customer default filters
2704 */
2705 function wpsc_get_ctl_default_filters() {
2706 supportcandy.current_tab = "default-filters";
2707 jQuery(".wpsc-setting-tab-container button").removeClass("active");
2708 jQuery(
2709 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2710 ).addClass("active");
2711
2712 window.history.replaceState(
2713 {},
2714 null,
2715 "admin.php?page=wpsc-ticket-list&section=" +
2716 supportcandy.current_section +
2717 "&tab=" +
2718 supportcandy.current_tab
2719 );
2720 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2721
2722 wpsc_scroll_top();
2723
2724 var data = { action: "wpsc_get_ctl_default_filters" };
2725 jQuery.post(supportcandy.ajax_url, data, function (response) {
2726 jQuery(".wpsc-setting-section-body").html(response);
2727 wpsc_reset_responsive_style();
2728 });
2729 }
2730
2731 /**
2732 * Add customer default filter
2733 */
2734 function wpsc_get_add_ctl_default_filter() {
2735 wpsc_show_modal();
2736 var data = { action: "wpsc_get_add_ctl_default_filter" };
2737 jQuery.post(supportcandy.ajax_url, data, function (response) {
2738 jQuery(".wpsc-modal-header").text(response.title);
2739 jQuery(".wpsc-modal-body").html(response.body);
2740 jQuery(".wpsc-modal-footer").html(response.footer);
2741 jQuery(".wpsc-form-filter-container").append(
2742 jQuery(".wpsc-form-filter-snippet").html()
2743 );
2744 jQuery(".wpsc-form-filter-container select").selectWoo();
2745 wpsc_show_modal_inner_container();
2746 });
2747 }
2748
2749 /**
2750 * Set add customer default filters
2751 */
2752 function wpsc_set_add_ctl_default_filter(el) {
2753 var label = jQuery("#wpsc-ctl-df-label").val().trim();
2754 if (!label) {
2755 alert(supportcandy.translations.req_fields_missing);
2756 return;
2757 }
2758
2759 var filters = wpsc_get_condition_json("default_filters");
2760 if (
2761 filters.length === 0 ||
2762 (filters.length === 1 && filters[0].length === 0)
2763 ) {
2764 alert(supportcandy.translations.req_fields_missing);
2765 return;
2766 }
2767
2768 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2769 jQuery(el).text(supportcandy.translations.please_wait);
2770
2771 var form = jQuery(".wpsc-frm-add-ctl-default-filter")[0];
2772 var dataform = new FormData(form);
2773 dataform.append("filters", JSON.stringify(filters));
2774
2775 jQuery
2776 .ajax({
2777 url: supportcandy.ajax_url,
2778 type: "POST",
2779 data: dataform,
2780 processData: false,
2781 contentType: false,
2782 })
2783 .done(function (res) {
2784 wpsc_close_modal();
2785 wpsc_get_ctl_default_filters();
2786 });
2787 }
2788
2789 /**
2790 * Get edit customer defualt filter
2791 */
2792 function wpsc_get_edit_ctl_default_filter(slug, nonce) {
2793 wpsc_show_modal();
2794 var data = {
2795 action: "wpsc_get_edit_ctl_default_filter",
2796 slug,
2797 _ajax_nonce: nonce,
2798 };
2799 jQuery.post(supportcandy.ajax_url, data, function (response) {
2800 jQuery(".wpsc-modal-header").text(response.title);
2801 jQuery(".wpsc-modal-body").html(response.body);
2802 jQuery(".wpsc-modal-footer").html(response.footer);
2803 wpsc_show_modal_inner_container();
2804 });
2805 }
2806
2807 /**
2808 * Set edit customer default filter
2809 */
2810 function wpsc_set_edit_ctl_default_filter(el, flag) {
2811 var label = jQuery("#wpsc-ctl-df-label").val().trim();
2812 if (!label) {
2813 alert(supportcandy.translations.req_fields_missing);
2814 return;
2815 }
2816
2817 var form = jQuery(".wpsc-frm-edit-ctl-default-filter")[0];
2818 var dataform = new FormData(form);
2819
2820 if (flag) {
2821 var filters = wpsc_get_condition_json("default_filters");
2822 if (
2823 filters.length === 0 ||
2824 (filters.length === 1 && filters[0].length === 0)
2825 ) {
2826 alert(supportcandy.translations.req_fields_missing);
2827 return;
2828 }
2829 dataform.append("filters", JSON.stringify(filters));
2830 }
2831
2832 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2833 jQuery(el).text(supportcandy.translations.please_wait);
2834
2835 jQuery
2836 .ajax({
2837 url: supportcandy.ajax_url,
2838 type: "POST",
2839 data: dataform,
2840 processData: false,
2841 contentType: false,
2842 })
2843 .done(function (res) {
2844 wpsc_close_modal();
2845 wpsc_get_ctl_default_filters();
2846 });
2847 }
2848
2849 /**
2850 * Delete customer default filter
2851 */
2852 function wpsc_delete_ctl_default_filter(slug, nonce) {
2853 var flag = confirm(supportcandy.translations.confirm);
2854 if (!flag) {
2855 return;
2856 }
2857
2858 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2859
2860 var data = {
2861 action: "wpsc_delete_ctl_default_filter",
2862 slug,
2863 _ajax_nonce: nonce,
2864 };
2865 jQuery.post(supportcandy.ajax_url, data, function (response) {
2866 wpsc_get_ctl_default_filters();
2867 });
2868 }
2869
2870 /**
2871 * Toggle enable/disable status of a single default filter.
2872 * Note: the currently active default filter can't be disabled - if the
2873 * server refuses the disable, it sends back is_enable: 1 and we resync
2874 * the checkbox/row to reflect that.
2875 */
2876 function wpsc_toggle_ctl_default_filter_status(el, slug, nonce) {
2877 var checkbox = jQuery(el);
2878 var is_enable = checkbox.is(":checked") ? 1 : 0;
2879 var filter = checkbox.closest(".wpsc-setting-card");
2880
2881 var data = {
2882 action: "wpsc_toggle_ctl_default_filter_status",
2883 slug,
2884 is_enable,
2885 _ajax_nonce: nonce,
2886 };
2887 jQuery.post(supportcandy.ajax_url, data, function (response) {
2888 var saved_enable = response.data.is_enable;
2889 checkbox.prop("checked", !!saved_enable);
2890 filter.attr(
2891 "style",
2892 saved_enable ? "" : "background-color:#eec7ca;color:#dc2222"
2893 );
2894 }).fail(function () {
2895 // Revert checkbox on failure.
2896 checkbox.prop("checked", !is_enable);
2897 });
2898 }
2899
2900 /**
2901 * Set add new customer list items
2902 */
2903 function wpsc_set_add_customer_tl_item(el) {
2904 var form = jQuery(".frm-add-customer-tl-items")[0];
2905 var dataform = new FormData(form);
2906
2907 var cf_id = dataform.getAll("cf_id[]");
2908 if (!cf_id.length) {
2909 alert(supportcandy.translations.req_fields_missing);
2910 return;
2911 }
2912
2913 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2914 jQuery(el).text(supportcandy.translations.please_wait);
2915 jQuery
2916 .ajax({
2917 url: supportcandy.ajax_url,
2918 type: "POST",
2919 data: dataform,
2920 processData: false,
2921 contentType: false,
2922 })
2923 .done(function (res) {
2924 wpsc_close_modal();
2925 wpsc_get_customer_tl_items();
2926 });
2927 }
2928
2929 /**
2930 * Set delete customer ticket list item
2931 */
2932 function wpsc_delete_customer_tl_item(slug, nonce) {
2933 if (confirm(supportcandy.translations.confirm)) {
2934 var data = {
2935 action: "wpsc_delete_customer_tl_item",
2936 slug: slug,
2937 _ajax_nonce: nonce,
2938 };
2939
2940 jQuery(".wpsc-modal-footer button").attr("disabled", true);
2941 jQuery(slug).text(supportcandy.translations.please_wait);
2942 jQuery.post(supportcandy.ajax_url, data, function (res) {
2943 wpsc_get_customer_tl_items();
2944 });
2945 } else {
2946 return false;
2947 }
2948 }
2949
2950 /**
2951 * Get customer filter items
2952 */
2953 function wpsc_get_customer_filter_items() {
2954 supportcandy.current_tab = "filter-items";
2955 jQuery(".wpsc-setting-tab-container button").removeClass("active");
2956 jQuery(
2957 ".wpsc-setting-tab-container button." + supportcandy.current_tab
2958 ).addClass("active");
2959
2960 window.history.replaceState(
2961 {},
2962 null,
2963 "admin.php?page=wpsc-ticket-list&section=" +
2964 supportcandy.current_section +
2965 "&tab=" +
2966 supportcandy.current_tab
2967 );
2968 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
2969
2970 wpsc_scroll_top();
2971
2972 var data = { action: "wpsc_get_customer_filter_items" };
2973 jQuery.post(supportcandy.ajax_url, data, function (response) {
2974 jQuery(".wpsc-setting-section-body").html(response);
2975 wpsc_reset_responsive_style();
2976 });
2977 }
2978
2979 /**
2980 * Get add customer ticket list filter items modal UI
2981 */
2982 function wpsc_get_add_ctl_filter_item() {
2983 wpsc_show_modal();
2984 var data = { action: "wpsc_get_add_ctl_filter_item" };
2985 jQuery.post(supportcandy.ajax_url, data, function (response) {
2986 // Set to modal.
2987 jQuery(".wpsc-modal-header").text(response.title);
2988 jQuery(".wpsc-modal-body").html(response.body);
2989 jQuery(".wpsc-modal-footer").html(response.footer);
2990 // Display modal.
2991 wpsc_show_modal_inner_container();
2992 });
2993 }
2994
2995 /**
2996 * Set add new customer list items
2997 */
2998 function wpsc_set_add_ctl_filter_item(el) {
2999 var form = jQuery(".frm-add-customer-tl-filter-items")[0];
3000 var dataform = new FormData(form);
3001
3002 var cf_id = dataform.getAll("customer-tl-filter-id[]");
3003 if (!cf_id.length) {
3004 alert(supportcandy.translations.req_fields_missing);
3005 return;
3006 }
3007
3008 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3009 jQuery(el).text(supportcandy.translations.please_wait);
3010 jQuery
3011 .ajax({
3012 url: supportcandy.ajax_url,
3013 type: "POST",
3014 data: dataform,
3015 processData: false,
3016 contentType: false,
3017 })
3018 .done(function (res) {
3019 wpsc_close_modal();
3020 wpsc_get_customer_filter_items();
3021 });
3022 }
3023
3024 /**
3025 * Get delete customer ticket list item
3026 *
3027 * @param {*} slug
3028 */
3029 function wpsc_delete_ctl_filter_item(slug, nonce) {
3030 if (confirm(supportcandy.translations.confirm)) {
3031 var data = {
3032 action: "wpsc_delete_ctl_filter_item",
3033 slug: slug,
3034 _ajax_nonce: nonce,
3035 };
3036 jQuery.post(supportcandy.ajax_url, data, function (res) {
3037 wpsc_get_customer_filter_items();
3038 });
3039 }
3040 }
3041
3042 /**
3043 * Get Thank You Page Settings
3044 */
3045 function wpsc_get_gs_thankyou() {
3046 supportcandy.current_tab = "thank-you-page";
3047 jQuery(".wpsc-setting-tab-container button").removeClass("active");
3048 jQuery(
3049 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3050 ).addClass("active");
3051
3052 window.history.replaceState(
3053 {},
3054 null,
3055 "admin.php?page=wpsc-settings&section=" +
3056 supportcandy.current_section +
3057 "&tab=" +
3058 supportcandy.current_tab
3059 );
3060 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3061
3062 wpsc_scroll_top();
3063
3064 var data = { action: "wpsc_get_gs_thankyou" };
3065 jQuery.post(supportcandy.ajax_url, data, function (response) {
3066 jQuery(".wpsc-setting-section-body").html(response);
3067 wpsc_reset_responsive_style();
3068 });
3069 }
3070
3071 /**
3072 * Reset Thankyou page settings
3073 */
3074 function wpsc_reset_gs_thankyou(el, nonce) {
3075 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3076 jQuery(el).text(supportcandy.translations.please_wait);
3077 var data = { action: "wpsc_reset_gs_thankyou", _ajax_nonce: nonce };
3078 jQuery.post(supportcandy.ajax_url, data, function (response) {
3079 wpsc_get_gs_thankyou();
3080 });
3081 }
3082
3083 /**
3084 * Set Thankyou Page Settings
3085 */
3086 function wpsc_set_gs_thankyou(el) {
3087 var form = jQuery(".wpsc-frm-gs-thankyoupage")[0];
3088 var dataform = new FormData(form);
3089
3090 var is_tinymce =
3091 typeof tinyMCE !== "undefined" &&
3092 tinyMCE.get("wpsc-html-agent") &&
3093 !tinyMCE.get("wpsc-html-agent").isHidden();
3094 var description = is_tinymce
3095 ? tinyMCE.get("wpsc-html-agent").getContent().trim()
3096 : jQuery("#wpsc-html-agent").val();
3097 dataform.append("html-agent", description);
3098
3099 var is_tinymce =
3100 typeof tinyMCE !== "undefined" &&
3101 tinyMCE.get("wpsc-html-customer") &&
3102 !tinyMCE.get("wpsc-html-customer").isHidden();
3103 description = is_tinymce
3104 ? tinyMCE.get("wpsc-html-customer").getContent().trim()
3105 : jQuery("#wpsc-html-customer").val();
3106 dataform.append("html-customer", description);
3107
3108 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3109 jQuery(el).text(supportcandy.translations.please_wait);
3110 jQuery
3111 .ajax({
3112 url: supportcandy.ajax_url,
3113 type: "POST",
3114 data: dataform,
3115 processData: false,
3116 contentType: false,
3117 })
3118 .done(function (res) {
3119 wpsc_get_gs_thankyou();
3120 });
3121 }
3122
3123 /**
3124 * File attachment settings
3125 */
3126 function wpsc_get_gs_file_attachments() {
3127 supportcandy.current_tab = "file-attachments";
3128 jQuery(".wpsc-setting-tab-container button").removeClass("active");
3129 jQuery(
3130 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3131 ).addClass("active");
3132
3133 window.history.replaceState(
3134 {},
3135 null,
3136 "admin.php?page=wpsc-settings&section=" +
3137 supportcandy.current_section +
3138 "&tab=" +
3139 supportcandy.current_tab
3140 );
3141 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3142
3143 wpsc_scroll_top();
3144
3145 var data = { action: "wpsc_get_gs_file_attachments" };
3146 jQuery.post(supportcandy.ajax_url, data, function (response) {
3147 jQuery(".wpsc-setting-section-body").html(response);
3148 wpsc_reset_responsive_style();
3149 });
3150 }
3151
3152 /**
3153 * Save page settings
3154 */
3155 function wpsc_set_gs_file_attachments(el) {
3156 var form = jQuery(".wpsc-frm-gs-fa")[0];
3157 var dataform = new FormData(form);
3158 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3159 jQuery(el).text(supportcandy.translations.please_wait);
3160 jQuery
3161 .ajax({
3162 url: supportcandy.ajax_url,
3163 type: "POST",
3164 data: dataform,
3165 processData: false,
3166 contentType: false,
3167 })
3168 .done(function (res) {
3169 wpsc_get_gs_file_attachments();
3170 });
3171 }
3172
3173 /**
3174 * Reset file attachments
3175 */
3176 function wpsc_reset_gs_file_attachments(el, nonce) {
3177 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3178 jQuery(el).text(supportcandy.translations.please_wait);
3179 var data = { action: "wpsc_reset_gs_file_attachments", _ajax_nonce: nonce };
3180 jQuery.post(supportcandy.ajax_url, data, function (response) {
3181 wpsc_get_gs_file_attachments();
3182 });
3183 }
3184
3185 /**
3186 * Get email notifications general setting
3187 */
3188 function wpsc_get_en_general_setting(is_humbargar = false) {
3189 if (is_humbargar) {
3190 wpsc_toggle_humbargar();
3191 }
3192
3193 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
3194 jQuery(
3195 ".wpsc-setting-nav.general-settings, .wpsc-humbargar-menu-item.general-settings"
3196 ).addClass("active");
3197 jQuery(".wpsc-humbargar-title").html(
3198 supportcandy.humbargar_titles.general_settings
3199 );
3200
3201 window.history.replaceState(
3202 {},
3203 null,
3204 "admin.php?page=wpsc-email-notifications&section=general-settings"
3205 );
3206 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
3207
3208 wpsc_scroll_top();
3209
3210 var data = { action: "wpsc_get_en_general_setting" };
3211 jQuery.post(supportcandy.ajax_url, data, function (response) {
3212 jQuery(".wpsc-setting-body").html(response);
3213 wpsc_reset_responsive_style();
3214 });
3215 }
3216
3217 /**
3218 * Save email notification general settings
3219 */
3220 function wpsc_set_en_general(el) {
3221 var form = jQuery(".wpsc-frm-en-general")[0];
3222 var dataform = new FormData(form);
3223 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3224 jQuery(el).text(supportcandy.translations.please_wait);
3225 jQuery
3226 .ajax({
3227 url: supportcandy.ajax_url,
3228 type: "POST",
3229 data: dataform,
3230 processData: false,
3231 contentType: false,
3232 })
3233 .done(function (res) {
3234 wpsc_get_en_general_setting();
3235 });
3236 }
3237
3238 /**
3239 * Reset email notification general settings
3240 */
3241 function wpsc_reset_en_general(el, nonce) {
3242 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3243 jQuery(el).text(supportcandy.translations.please_wait);
3244 var data = { action: "wpsc_reset_en_general", _ajax_nonce: nonce };
3245 jQuery.post(supportcandy.ajax_url, data, function (response) {
3246 wpsc_get_en_general_setting();
3247 });
3248 }
3249
3250 /**
3251 * Get ticket notifications setting
3252 */
3253 function wpsc_get_ticket_notifications(is_humbargar = false) {
3254 if (is_humbargar) {
3255 wpsc_toggle_humbargar();
3256 }
3257
3258 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
3259 jQuery(
3260 ".wpsc-setting-nav.ticket-notifications, .wpsc-humbargar-menu-item.ticket-notifications"
3261 ).addClass("active");
3262 jQuery(".wpsc-humbargar-title").html(
3263 supportcandy.humbargar_titles.ticket_notifications
3264 );
3265
3266 window.history.replaceState(
3267 {},
3268 null,
3269 "admin.php?page=wpsc-email-notifications&section=ticket-notifications"
3270 );
3271 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
3272
3273 wpsc_scroll_top();
3274
3275 var data = { action: "wpsc_get_ticket_notifications" };
3276 jQuery.post(supportcandy.ajax_url, data, function (response) {
3277 jQuery(".wpsc-setting-body").html(response);
3278 wpsc_reset_responsive_style();
3279 });
3280 }
3281
3282 /**
3283 * Set add ticket notification
3284 */
3285 function wpsc_en_set_add_ticket_notification(el) {
3286 var title = jQuery(el)
3287 .closest(".modal")
3288 .find("input[name=title]")
3289 .val()
3290 .trim();
3291 if (!title) {
3292 alert(supportcandy.translations.req_fields_missing);
3293 return;
3294 }
3295
3296 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3297 jQuery(el).text(supportcandy.translations.please_wait);
3298
3299 var form = jQuery(".wpsc-frm-add-en")[0];
3300 var dataform = new FormData(form);
3301 jQuery
3302 .ajax({
3303 url: supportcandy.ajax_url,
3304 type: "POST",
3305 data: dataform,
3306 processData: false,
3307 contentType: false,
3308 })
3309 .done(function (response) {
3310 wpsc_close_modal();
3311 wpsc_en_get_edit_ticket_notification(response.index, response.nonce);
3312 });
3313 }
3314
3315 /**
3316 * Get edit email notification
3317 *
3318 * @param {int} id
3319 */
3320 function wpsc_en_get_edit_ticket_notification(template_id, nonce) {
3321 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3322 var data = {
3323 action: "wpsc_en_get_edit_ticket_notification",
3324 template_id,
3325 _ajax_nonce: nonce,
3326 };
3327 jQuery.post(supportcandy.ajax_url, data, function (res) {
3328 jQuery(".wpsc-setting-section-body").html(res);
3329 });
3330 }
3331
3332 /**
3333 * Set edit email notification
3334 */
3335 function wpsc_en_set_edit_ticket_notification() {
3336 var form = jQuery(".wpsc-frm-edit-en")[0];
3337 var dataform = new FormData(form);
3338
3339 var title = dataform.get("title").trim();
3340 if (!title) {
3341 alert(supportcandy.translations.req_fields_missing);
3342 return;
3343 }
3344
3345 var subject = dataform.get("subject").trim();
3346 if (!subject) {
3347 alert(supportcandy.translations.req_fields_missing);
3348 return;
3349 }
3350
3351 var is_tinymce =
3352 typeof tinyMCE != "undefined" &&
3353 tinyMCE.activeEditor &&
3354 !tinyMCE.activeEditor.isHidden();
3355 var body = is_tinymce
3356 ? tinyMCE.get("wpsc-en-body").getContent().trim()
3357 : dataform.get("body").trim();
3358 dataform.append("body", body);
3359
3360 if (!body) {
3361 alert(supportcandy.translations.req_fields_missing);
3362 return;
3363 }
3364
3365 // to.
3366 var toGeneral = dataform.getAll("to[general-recipients][]");
3367 var toRoles = dataform.getAll("to[agent-roles][]");
3368 var toCustom = dataform.get("to[custom]").trim();
3369 if (!(toGeneral.length || toRoles.length || toCustom)) {
3370 alert(supportcandy.translations.req_fields_missing);
3371 return;
3372 }
3373
3374 dataform.append(
3375 "conditions",
3376 JSON.stringify(wpsc_get_condition_json("conditions"))
3377 );
3378
3379 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3380 jQuery
3381 .ajax({
3382 url: supportcandy.ajax_url,
3383 type: "POST",
3384 data: dataform,
3385 processData: false,
3386 contentType: false,
3387 })
3388 .done(function (res) {
3389 wpsc_get_ticket_notifications();
3390 });
3391 }
3392
3393 /**
3394 * Get clone ticket notification
3395 *
3396 * @param {INT} template_id
3397 */
3398 function wpsc_en_get_clone_ticket_notification(template_id, nonce) {
3399 wpsc_show_modal();
3400 var data = {
3401 action: "wpsc_en_get_clone_ticket_notification",
3402 template_id,
3403 _ajax_nonce: nonce,
3404 };
3405
3406 jQuery.post(supportcandy.ajax_url, data, function (response) {
3407 jQuery(".wpsc-modal-header").text(response.title);
3408 jQuery(".wpsc-modal-body").html(response.body);
3409 jQuery(".wpsc-modal-footer").html(response.footer);
3410
3411 wpsc_show_modal_inner_container();
3412 });
3413 }
3414
3415 /**
3416 * Set clone ticket notification
3417 */
3418 function wpsc_en_set_clone_ticket_notification(el) {
3419 var form = jQuery(".wpsc-en-add-clone")[0];
3420 var dataform = new FormData(form);
3421
3422 if (dataform.get("title").trim() == "") {
3423 alert(supportcandy.translations.req_fields_missing);
3424 return;
3425 }
3426
3427 jQuery(el).text(supportcandy.translations.please_wait);
3428 jQuery
3429 .ajax({
3430 url: supportcandy.ajax_url,
3431 type: "POST",
3432 data: dataform,
3433 processData: false,
3434 contentType: false,
3435 })
3436 .done(function (response) {
3437 wpsc_close_modal();
3438 wpsc_en_get_edit_ticket_notification(response.index, response.nonce);
3439 });
3440 }
3441
3442 /**
3443 * Disable ticket notification
3444 */
3445 function wpsc_en_enable_disable_template(template_id, status, nonce) {
3446 var data = {
3447 action: "wpsc_en_enable_disable_template",
3448 template_id,
3449 status,
3450 _ajax_nonce: nonce,
3451 };
3452
3453 jQuery.post(supportcandy.ajax_url, data, function (response) {
3454 wpsc_get_ticket_notifications();
3455 });
3456 }
3457
3458 /**
3459 * Delete email notification
3460 *
3461 * @param {int} template_id
3462 */
3463 function wpsc_en_delete_ticket_notification(template_id, nonce) {
3464 var flag = confirm(supportcandy.translations.confirm);
3465 if (!flag) {
3466 return;
3467 }
3468
3469 var data = {
3470 action: "wpsc_en_delete_ticket_notification",
3471 template_id,
3472 _ajax_nonce: nonce,
3473 };
3474 jQuery.post(supportcandy.ajax_url, data, function (res) {
3475 wpsc_get_ticket_notifications();
3476 });
3477 }
3478
3479 /**
3480 * Get miscellaneous settings
3481 *
3482 * @param {*} is_humbargar
3483 */
3484 function wpsc_get_miscellaneous_settings(is_humbargar = false) {
3485 if (is_humbargar) {
3486 wpsc_toggle_humbargar();
3487 }
3488
3489 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
3490 jQuery(
3491 ".wpsc-setting-nav.miscellaneous-settings, .wpsc-humbargar-menu-item.miscellaneous-settings"
3492 ).addClass("active");
3493 jQuery(".wpsc-humbargar-title").html(
3494 supportcandy.humbargar_titles.miscellaneous_settings
3495 );
3496
3497 if (supportcandy.current_section !== "miscellaneous-settings") {
3498 supportcandy.current_section = "miscellaneous-settings";
3499 supportcandy.current_tab = "term-and-conditions";
3500 }
3501
3502 window.history.replaceState(
3503 {},
3504 null,
3505 "admin.php?page=wpsc-settings&section=miscellaneous-settings"
3506 );
3507 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
3508
3509 wpsc_scroll_top();
3510
3511 var data = { action: "wpsc_get_miscellaneous_settings" };
3512 jQuery.post(supportcandy.ajax_url, data, function (response) {
3513 jQuery(".wpsc-setting-body").html(response);
3514 wpsc_reset_responsive_style();
3515 jQuery(
3516 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3517 ).trigger("click");
3518 });
3519 }
3520
3521 /**
3522 * Get ticket widget
3523 */
3524 function wpsc_get_ticket_widget(is_humbargar) {
3525 if (is_humbargar) {
3526 wpsc_toggle_humbargar();
3527 }
3528
3529 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
3530 jQuery(
3531 ".wpsc-setting-nav.ticket-widgets, .wpsc-humbargar-menu-item.ticket-widgets"
3532 ).addClass("active");
3533 jQuery(".wpsc-humbargar-title").html(
3534 supportcandy.humbargar_titles.ticket_widget
3535 );
3536
3537 window.history.replaceState(
3538 {},
3539 null,
3540 "admin.php?page=wpsc-settings&section=ticket-widgets"
3541 );
3542 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
3543
3544 wpsc_scroll_top();
3545
3546 var data = { action: "wpsc_get_ticket_widget" };
3547 jQuery.post(supportcandy.ajax_url, data, function (response) {
3548 jQuery(".wpsc-setting-body").html(response);
3549 wpsc_reset_responsive_style();
3550 });
3551 }
3552
3553 /**
3554 * Get Terms and conditions settings
3555 */
3556 function wpsc_get_ms_term_and_conditions() {
3557 supportcandy.current_tab = "term-and-conditions";
3558 jQuery(".wpsc-setting-tab-container button").removeClass("active");
3559 jQuery(
3560 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3561 ).addClass("active");
3562
3563 window.history.replaceState(
3564 {},
3565 null,
3566 "admin.php?page=wpsc-settings&section=" +
3567 supportcandy.current_section +
3568 "&tab=" +
3569 supportcandy.current_tab
3570 );
3571 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3572
3573 wpsc_scroll_top();
3574 var data = { action: "wpsc_get_ms_term_and_conditions" };
3575 jQuery.post(supportcandy.ajax_url, data, function (response) {
3576 jQuery(".wpsc-setting-section-body").html(response);
3577 wpsc_reset_responsive_style();
3578 });
3579 }
3580
3581 /**
3582 * Get agent view settings
3583 */
3584 function wpsc_tl_ms_get_agent_view() {
3585 supportcandy.current_tab = "agent-view";
3586 jQuery(".wpsc-setting-tab-container button").removeClass("active");
3587 jQuery(
3588 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3589 ).addClass("active");
3590
3591 window.history.replaceState(
3592 {},
3593 null,
3594 "admin.php?page=wpsc-ticket-list&section=" +
3595 supportcandy.current_section +
3596 "&tab=" +
3597 supportcandy.current_tab
3598 );
3599 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3600
3601 wpsc_scroll_top();
3602
3603 var data = { action: "wpsc_tl_ms_get_agent_view" };
3604 jQuery.post(supportcandy.ajax_url, data, function (response) {
3605 jQuery(".wpsc-setting-section-body").html(response);
3606 wpsc_reset_responsive_style();
3607 });
3608 }
3609
3610 /**
3611 * Save terms and conditions
3612 *
3613 * @param {*} el
3614 */
3615 function wpsc_set_ms_term_and_conditions(el) {
3616 var form = jQuery(".wpsc-frm-ms-tandc")[0];
3617 var dataform = new FormData(form);
3618 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3619 var is_tinymce_ct =
3620 typeof tinyMCE != "undefined" &&
3621 tinyMCE.get("tandc-text") &&
3622 !tinyMCE.get("tandc-text").isHidden();
3623
3624 if (is_tinymce_ct) {
3625 var description = tinyMCE.get("tandc-text").getContent().trim();
3626 } else {
3627 var description = jQuery("#tandc-text").val();
3628 }
3629 dataform.append("tandc-text", description);
3630
3631 var is_tinymce_reg =
3632 typeof tinyMCE != "undefined" &&
3633 tinyMCE.get("tandc-text-reg-user") &&
3634 !tinyMCE.get("tandc-text-reg-user").isHidden();
3635
3636 if (is_tinymce_reg) {
3637 var description = tinyMCE.get("tandc-text-reg-user").getContent().trim();
3638 } else {
3639 var description = jQuery("#tandc-text-reg-user").val();
3640 }
3641 dataform.append("tandc-text-reg-user", description);
3642
3643 jQuery(el).text(supportcandy.translations.please_wait);
3644 jQuery
3645 .ajax({
3646 url: supportcandy.ajax_url,
3647 type: "POST",
3648 data: dataform,
3649 processData: false,
3650 contentType: false,
3651 })
3652 .done(function (res) {
3653 wpsc_get_ms_term_and_conditions();
3654 });
3655 }
3656
3657 /**
3658 * Sort ticket widget
3659 */
3660 function wpsc_set_tw_load_order(slugs, nonce) {
3661 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3662 var data = { action: "wpsc_set_tw_load_order", slugs, _ajax_nonce: nonce };
3663 jQuery.post(supportcandy.ajax_url, data, function (res) {
3664 wpsc_get_ticket_widget();
3665 });
3666 }
3667
3668 /**
3669 * Toggle enable/disable status of a single ticket widget
3670 */
3671 function wpsc_toggle_ticket_widget_status(el, slug, nonce) {
3672 var checkbox = jQuery(el);
3673 var is_enable = checkbox.is(":checked") ? 1 : 0;
3674 var widget = checkbox.closest(".wpsc-setting-card");
3675
3676 var data = {
3677 action: "wpsc_toggle_ticket_widget_status",
3678 slug,
3679 is_enable,
3680 _ajax_nonce: nonce,
3681 };
3682 jQuery.post(supportcandy.ajax_url, data, function () {
3683 widget.attr(
3684 "style",
3685 is_enable ? "" : "background-color:#eec7ca;color:#dc2222"
3686 );
3687 var total = jQuery(".wpsc-toggle-ticket-widget").length;
3688 var checked = jQuery(".wpsc-toggle-ticket-widget:checked").length;
3689 jQuery(".wpsc-toggle-all-ticket-widgets").prop(
3690 "checked",
3691 total > 0 && total === checked
3692 );
3693 }).fail(function () {
3694 // Revert checkbox on failure.
3695 checkbox.prop("checked", !is_enable);
3696 });
3697 }
3698
3699 /**
3700 * Enable or disable all ticket widgets at once
3701 */
3702 function wpsc_toggle_all_ticket_widgets(el, nonce) {
3703 var checkbox = jQuery(el);
3704 var is_enable = checkbox.is(":checked") ? 1 : 0;
3705
3706 var data = {
3707 action: "wpsc_toggle_all_ticket_widgets_status",
3708 is_enable,
3709 _ajax_nonce: nonce,
3710 };
3711 jQuery.post(supportcandy.ajax_url, data, function () {
3712 jQuery(".wpsc-toggle-ticket-widget").prop("checked", !!is_enable);
3713 jQuery(".wpsc-setting-card").attr(
3714 "style",
3715 is_enable ? "" : "background-color:#eec7ca;color:#dc2222"
3716 );
3717 }).fail(function () {
3718 // Revert checkbox on failure.
3719 checkbox.prop("checked", !is_enable);
3720 });
3721 }
3722
3723 /**
3724 * Get edit Agent Collision widget
3725 */
3726 function wpsc_get_tw_agent_collision() {
3727
3728 wpsc_show_modal();
3729 var data = { action: 'wpsc_get_tw_agent_collision' };
3730 jQuery.post(
3731 supportcandy.ajax_url,
3732 data,
3733 function (response) {
3734
3735 // Set to modal.
3736 jQuery( '.wpsc-modal-header' ).text( response.title );
3737 jQuery( '.wpsc-modal-body' ).html( response.body );
3738 jQuery( '.wpsc-modal-footer' ).html( response.footer );
3739 // Display modal.
3740 wpsc_show_modal_inner_container();
3741 }
3742 );
3743 }
3744
3745 /**
3746 * Set edit Agent Collision widget
3747 */
3748 function wpsc_set_tw_agent_collision(el) {
3749 var form = jQuery( '.wpsc-frm-edit-ac' )[0];
3750 var dataform = new FormData( form );
3751
3752 if (dataform.get( 'label' ).trim() == '') {
3753 alert( supportcandy.translations.req_fields_missing );
3754 return;
3755 }
3756
3757 jQuery( '.wpsc-modal-footer button' ).attr( 'disabled', true );
3758 jQuery( el ).text( supportcandy.translations.please_wait );
3759
3760 jQuery.ajax(
3761 {
3762 url: supportcandy.ajax_url,
3763 type: 'POST',
3764 data: dataform,
3765 processData: false,
3766 contentType: false
3767 }
3768 ).done(
3769 function (res) {
3770 wpsc_close_modal();
3771 wpsc_get_ticket_widget();
3772 }
3773 );
3774 }
3775
3776 /**
3777 * Ticket widget status
3778 */
3779 function wpsc_get_tw_ticket_status() {
3780 wpsc_show_modal();
3781 var data = { action: "wpsc_get_tw_ticket_status" };
3782 jQuery.post(supportcandy.ajax_url, data, function (response) {
3783 // Set to modal.
3784 jQuery(".wpsc-modal-header").text(response.title);
3785 jQuery(".wpsc-modal-body").html(response.body);
3786 jQuery(".wpsc-modal-footer").html(response.footer);
3787 // Display modal.
3788 wpsc_show_modal_inner_container();
3789 });
3790 }
3791
3792 /**
3793 * Set ticket widget status
3794 */
3795 function wpsc_set_tw_ticket_status(el) {
3796 var form = jQuery(".wpsc-frm-edit-ticket-status")[0];
3797 var dataform = new FormData(form);
3798
3799 if (dataform.get("label").trim() == "") {
3800 alert(supportcandy.translations.req_fields_missing);
3801 return;
3802 }
3803
3804 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3805 jQuery(el).text(supportcandy.translations.please_wait);
3806
3807 jQuery
3808 .ajax({
3809 url: supportcandy.ajax_url,
3810 type: "POST",
3811 data: dataform,
3812 processData: false,
3813 contentType: false,
3814 })
3815 .done(function (res) {
3816 wpsc_close_modal();
3817 wpsc_get_ticket_widget();
3818 });
3819 }
3820
3821 /**
3822 * Set agent view settings
3823 *
3824 * @param {*} el
3825 */
3826 function wpsc_tl_ms_set_agent_view(el) {
3827 var form = jQuery(".wpsc-frm-tl-ms-agent-view")[0];
3828 var dataform = new FormData(form);
3829 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3830 jQuery(el).text(supportcandy.translations.please_wait);
3831 jQuery
3832 .ajax({
3833 url: supportcandy.ajax_url,
3834 type: "POST",
3835 data: dataform,
3836 processData: false,
3837 contentType: false,
3838 })
3839 .done(function (res) {
3840 wpsc_tl_ms_get_agent_view();
3841 });
3842 }
3843
3844 /**
3845 * Reset terms and conditions
3846 *
3847 * @param {*} el
3848 */
3849 function wpsc_reset_ms_term_and_conditions(el, nonce) {
3850 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3851 jQuery(el).text(supportcandy.translations.please_wait);
3852 var data = {
3853 action: "wpsc_reset_ms_term_and_conditions",
3854 _ajax_nonce: nonce,
3855 };
3856 jQuery.post(supportcandy.ajax_url, data, function (response) {
3857 wpsc_get_ms_term_and_conditions();
3858 });
3859 }
3860
3861 /**
3862 * Get ticket widget raised by
3863 */
3864 function wpsc_get_tw_raised_by() {
3865 wpsc_show_modal();
3866 var data = { action: "wpsc_get_tw_raised_by" };
3867 jQuery.post(supportcandy.ajax_url, data, function (response) {
3868 // Set to modal.
3869 jQuery(".wpsc-modal-header").text(response.title);
3870 jQuery(".wpsc-modal-body").html(response.body);
3871 jQuery(".wpsc-modal-footer").html(response.footer);
3872 // Display modal.
3873 wpsc_show_modal_inner_container();
3874 });
3875 }
3876
3877 /**
3878 * Reset agent view settings
3879 *
3880 * @param {*} el
3881 */
3882 function wpsc_tl_ms_reset_agent_view(el, nonce) {
3883 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3884 jQuery(el).text(supportcandy.translations.please_wait);
3885 var data = { action: "wpsc_tl_ms_reset_agent_view", _ajax_nonce: nonce };
3886 jQuery.post(supportcandy.ajax_url, data, function (response) {
3887 wpsc_tl_ms_get_agent_view();
3888 });
3889 }
3890
3891 /**
3892 * Get reCaptcha settings
3893 */
3894 function wpsc_get_ms_recaptcha() {
3895 supportcandy.current_tab = "recaptcha";
3896 jQuery(".wpsc-setting-tab-container button").removeClass("active");
3897 jQuery(
3898 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3899 ).addClass("active");
3900
3901 window.history.replaceState(
3902 {},
3903 null,
3904 "admin.php?page=wpsc-settings&section=" +
3905 supportcandy.current_section +
3906 "&tab=" +
3907 supportcandy.current_tab
3908 );
3909 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3910
3911 wpsc_scroll_top();
3912
3913 var data = { action: "wpsc_get_ms_recaptcha" };
3914 jQuery.post(supportcandy.ajax_url, data, function (response) {
3915 jQuery(".wpsc-setting-section-body").html(response);
3916 wpsc_reset_responsive_style();
3917 });
3918 }
3919
3920 /**
3921 * Set ticket widget raised by
3922 */
3923 function wpsc_set_tw_raised_by(el) {
3924 var form = jQuery(".wpsc-frm-edit-ticket-raised-by")[0];
3925 var dataform = new FormData(form);
3926
3927 if (dataform.get("label").trim() == "") {
3928 alert(supportcandy.translations.req_fields_missing);
3929 return;
3930 }
3931
3932 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3933 jQuery(el).text(supportcandy.translations.please_wait);
3934
3935 jQuery
3936 .ajax({
3937 url: supportcandy.ajax_url,
3938 type: "POST",
3939 data: dataform,
3940 processData: false,
3941 contentType: false,
3942 })
3943 .done(function (res) {
3944 wpsc_close_modal();
3945 wpsc_get_ticket_widget();
3946 });
3947 }
3948
3949 /**
3950 * Get customer view settings
3951 */
3952 function wpsc_tl_ms_get_customer_view() {
3953 supportcandy.current_tab = "customer-view";
3954 jQuery(".wpsc-setting-tab-container button").removeClass("active");
3955 jQuery(
3956 ".wpsc-setting-tab-container button." + supportcandy.current_tab
3957 ).addClass("active");
3958
3959 window.history.replaceState(
3960 {},
3961 null,
3962 "admin.php?page=wpsc-ticket-list&section=" +
3963 supportcandy.current_section +
3964 "&tab=" +
3965 supportcandy.current_tab
3966 );
3967 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
3968
3969 wpsc_scroll_top();
3970
3971 var data = { action: "wpsc_tl_ms_get_customer_view" };
3972 jQuery.post(supportcandy.ajax_url, data, function (response) {
3973 jQuery(".wpsc-setting-section-body").html(response);
3974 wpsc_reset_responsive_style();
3975 });
3976 }
3977
3978 /**
3979 * Save reCaptcha
3980 *
3981 * @param {*} el
3982 */
3983 function wpsc_set_ms_recaptcha(el) {
3984 var form = jQuery(".wpsc-frm-ms-recaptcha")[0];
3985 var dataform = new FormData(form);
3986 jQuery(".wpsc-modal-footer button").attr("disabled", true);
3987 jQuery(el).text(supportcandy.translations.please_wait);
3988 jQuery
3989 .ajax({
3990 url: supportcandy.ajax_url,
3991 type: "POST",
3992 data: dataform,
3993 processData: false,
3994 contentType: false,
3995 })
3996 .done(function (res) {
3997 wpsc_get_ms_recaptcha();
3998 });
3999 }
4000
4001 /**
4002 * Get ticket widget ticket info
4003 */
4004 function wpsc_get_tw_ticket_info() {
4005 wpsc_show_modal();
4006 var data = { action: "wpsc_get_tw_ticket_info" };
4007 jQuery.post(supportcandy.ajax_url, data, function (response) {
4008 // Set to modal.
4009 jQuery(".wpsc-modal-header").text(response.title);
4010 jQuery(".wpsc-modal-body").html(response.body);
4011 jQuery(".wpsc-modal-footer").html(response.footer);
4012 // Display modal.
4013 wpsc_show_modal_inner_container();
4014 });
4015 }
4016
4017 /**
4018 * Add new option snippet
4019 */
4020 function wpsc_get_add_new_option() {
4021 jQuery(".wpsc-options-container").append(jQuery(".wpsc-add-option").html());
4022 jQuery(".wpsc-options-container")
4023 .children()
4024 .last()
4025 .find(".wpsc-add-option-container input:first")
4026 .focus();
4027 }
4028
4029 /**
4030 * Add new option for custom field
4031 */
4032 function wpsc_add_new_option(el, nonce) {
4033 var submitBtn = jQuery(el);
4034 var inputField = jQuery(el).parent().find("input").first();
4035
4036 var name = inputField.val().trim();
4037 if (!name) {
4038 return;
4039 }
4040
4041 submitBtn.attr("disabled", true);
4042 inputField.attr("disabled", true);
4043 submitBtn.html(supportcandy.inline_loader);
4044
4045 var data = { action: "wpsc_add_new_option", name, _ajax_nonce: nonce };
4046 jQuery.post(supportcandy.ajax_url, data, function (response) {
4047 submitBtn
4048 .closest(".wpsc-option-item")
4049 .find(".wpsc-option-listing-container .text")
4050 .text(response.name);
4051 submitBtn
4052 .closest(".wpsc-option-item")
4053 .append(
4054 '<input type="hidden" class="option_id" name="options[]" value="' +
4055 response.id +
4056 '">'
4057 );
4058 submitBtn.parent().hide();
4059 submitBtn.closest(".content").find(".wpsc-option-listing-container").show();
4060 wpsc_change_def_val_option_single();
4061 });
4062 }
4063
4064 /**
4065 * Set ticket widget ticket info
4066 */
4067 function wpsc_set_tw_ticket_info(el) {
4068 var form = jQuery(".wpsc-frm-edit-ticket-info")[0];
4069 var dataform = new FormData(form);
4070
4071 if (dataform.get("label").trim() == "") {
4072 alert(supportcandy.translations.req_fields_missing);
4073 return;
4074 }
4075
4076 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4077 jQuery(el).text(supportcandy.translations.please_wait);
4078
4079 jQuery
4080 .ajax({
4081 url: supportcandy.ajax_url,
4082 type: "POST",
4083 data: dataform,
4084 processData: false,
4085 contentType: false,
4086 })
4087 .done(function (res) {
4088 wpsc_close_modal();
4089 wpsc_get_ticket_widget();
4090 });
4091 }
4092
4093 /**
4094 * Reset reCaptcha
4095 *
4096 * @param {*} el
4097 */
4098 function wpsc_reset_ms_recaptcha(el, nonce) {
4099 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4100 jQuery(el).text(supportcandy.translations.please_wait);
4101 var data = { action: "wpsc_reset_ms_recaptcha", _ajax_nonce: nonce };
4102 jQuery.post(supportcandy.ajax_url, data, function (response) {
4103 wpsc_get_ms_recaptcha();
4104 });
4105 }
4106
4107 /**
4108 * Set customer view settings
4109 *
4110 * @param {*} el
4111 */
4112 function wpsc_tl_ms_set_customer_view(el) {
4113 var form = jQuery(".wpsc-frm-tl-ms-customer-view")[0];
4114 var dataform = new FormData(form);
4115 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4116 jQuery(el).text(supportcandy.translations.please_wait);
4117 jQuery
4118 .ajax({
4119 url: supportcandy.ajax_url,
4120 type: "POST",
4121 data: dataform,
4122 processData: false,
4123 contentType: false,
4124 })
4125 .done(function (res) {
4126 wpsc_tl_ms_get_customer_view();
4127 });
4128 }
4129
4130 /**
4131 * Get ticket widget agents
4132 */
4133 function wpsc_get_tw_agents() {
4134 wpsc_show_modal();
4135 var data = { action: "wpsc_get_tw_agents" };
4136 jQuery.post(supportcandy.ajax_url, data, function (response) {
4137 // Set to modal.
4138 jQuery(".wpsc-modal-header").text(response.title);
4139 jQuery(".wpsc-modal-body").html(response.body);
4140 jQuery(".wpsc-modal-footer").html(response.footer);
4141 // Display modal.
4142 wpsc_show_modal_inner_container();
4143 });
4144 }
4145
4146 /**
4147 * Reset customer view settings
4148 *
4149 * @param {*} el
4150 */
4151 function wpsc_tl_ms_reset_customer_view(el, nonce) {
4152 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4153 jQuery(el).text(supportcandy.translations.please_wait);
4154 var data = { action: "wpsc_tl_ms_reset_customer_view", _ajax_nonce: nonce };
4155 jQuery.post(supportcandy.ajax_url, data, function (response) {
4156 wpsc_tl_ms_get_customer_view();
4157 });
4158 }
4159
4160 /**
4161 * Set ticket widget agents
4162 */
4163 function wpsc_set_tw_agents(el) {
4164 var form = jQuery(".wpsc-frm-edit-agents")[0];
4165 var dataform = new FormData(form);
4166
4167 if (dataform.get("label").trim() == "") {
4168 alert(supportcandy.translations.req_fields_missing);
4169 return;
4170 }
4171
4172 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4173 jQuery(el).text(supportcandy.translations.please_wait);
4174
4175 jQuery
4176 .ajax({
4177 url: supportcandy.ajax_url,
4178 type: "POST",
4179 data: dataform,
4180 processData: false,
4181 contentType: false,
4182 })
4183 .done(function (res) {
4184 wpsc_close_modal();
4185 wpsc_get_ticket_widget();
4186 });
4187 }
4188
4189 /**
4190 * Get ticket widget ticket fields
4191 */
4192 function wpsc_get_tw_ticket_fields() {
4193 wpsc_show_modal();
4194 var data = { action: "wpsc_get_tw_ticket_fields" };
4195 jQuery.post(supportcandy.ajax_url, data, function (response) {
4196 // Set to modal.
4197 jQuery(".wpsc-modal-header").text(response.title);
4198 jQuery(".wpsc-modal-body").html(response.body);
4199 jQuery(".wpsc-modal-footer").html(response.footer);
4200 // Display modal.
4201 wpsc_show_modal_inner_container();
4202 });
4203 }
4204
4205 /**
4206 * Load edit option view
4207 */
4208 function wpsc_edit_option(el) {
4209 var editBtn = jQuery(el);
4210 var text = editBtn
4211 .closest(".wpsc-option-listing-container")
4212 .find(".text")
4213 .text();
4214 editBtn.closest(".content").find(".edit-option-text").val(text);
4215 editBtn.closest(".wpsc-option-listing-container").hide();
4216 editBtn.closest(".content").find(".wpsc-edit-option-container").show();
4217 }
4218
4219 /**
4220 * Update option
4221 */
4222 function wpsc_set_edit_option(el, nonce) {
4223 var submitBtn = jQuery(el);
4224 var inputField = jQuery(el).parent().find("input").first();
4225
4226 var option_id = submitBtn
4227 .closest(".wpsc-option-item")
4228 .find(".option_id")
4229 .val()
4230 .trim();
4231 if (!option_id) {
4232 return;
4233 }
4234
4235 var name = inputField.val().trim();
4236 if (!name) {
4237 return;
4238 }
4239
4240 submitBtn.attr("disabled", true);
4241 inputField.attr("disabled", true);
4242
4243 var submitHtml = submitBtn.html();
4244 submitBtn.html(supportcandy.inline_loader);
4245
4246 var data = {
4247 action: "wpsc_set_edit_option",
4248 id: option_id,
4249 name,
4250 _ajax_nonce: nonce,
4251 };
4252 jQuery.post(supportcandy.ajax_url, data, function (response) {
4253 submitBtn
4254 .closest(".wpsc-option-item")
4255 .find(".wpsc-option-listing-container .text")
4256 .text(response.name);
4257 submitBtn.attr("disabled", false);
4258 inputField.attr("disabled", false);
4259 submitBtn.html(submitHtml);
4260 submitBtn.parent().hide();
4261 submitBtn.closest(".content").find(".wpsc-option-listing-container").show();
4262 wpsc_change_def_val_option_single();
4263 });
4264 }
4265
4266 /**
4267 * Set ticket widget ticket fields
4268 */
4269 function wpsc_set_tw_ticket_fields(el) {
4270 var form = jQuery(".wpsc-frm-edit-ticket-fields")[0];
4271 var dataform = new FormData(form);
4272
4273 if (dataform.get("label").trim() == "") {
4274 alert(supportcandy.translations.req_fields_missing);
4275 return;
4276 }
4277
4278 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4279 jQuery(el).text(supportcandy.translations.please_wait);
4280
4281 jQuery
4282 .ajax({
4283 url: supportcandy.ajax_url,
4284 type: "POST",
4285 data: dataform,
4286 processData: false,
4287 contentType: false,
4288 })
4289 .done(function (res) {
4290 wpsc_close_modal();
4291 wpsc_get_ticket_widget();
4292 });
4293 }
4294
4295 /**
4296 * Get gdpr settings
4297 */
4298 function wpsc_get_ms_gdpr() {
4299 supportcandy.current_tab = "gdpr";
4300 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4301 jQuery(
4302 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4303 ).addClass("active");
4304
4305 window.history.replaceState(
4306 {},
4307 null,
4308 "admin.php?page=wpsc-settings&section=" +
4309 supportcandy.current_section +
4310 "&tab=" +
4311 supportcandy.current_tab
4312 );
4313 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4314
4315 wpsc_scroll_top();
4316
4317 var data = { action: "wpsc_get_ms_gdpr" };
4318 jQuery.post(supportcandy.ajax_url, data, function (response) {
4319 jQuery(".wpsc-setting-section-body").html(response);
4320 wpsc_reset_responsive_style();
4321 });
4322 }
4323
4324 /**
4325 * Get advanced settings of tl more settings
4326 */
4327 function wpsc_tl_ms_get_advanced() {
4328 supportcandy.current_tab = "advanced";
4329 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4330 jQuery(
4331 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4332 ).addClass("active");
4333
4334 window.history.replaceState(
4335 {},
4336 null,
4337 "admin.php?page=wpsc-ticket-list&section=" +
4338 supportcandy.current_section +
4339 "&tab=" +
4340 supportcandy.current_tab
4341 );
4342 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4343
4344 wpsc_scroll_top();
4345
4346 var data = { action: "wpsc_tl_ms_get_advanced" };
4347 jQuery.post(supportcandy.ajax_url, data, function (response) {
4348 jQuery(".wpsc-setting-section-body").html(response);
4349 wpsc_reset_responsive_style();
4350 });
4351 }
4352
4353 /**
4354 * Save gdpr
4355 *
4356 * @param {*} el
4357 */
4358 function wpsc_set_ms_gdpr(el) {
4359 var form = jQuery(".wpsc-frm-ms-gdpr")[0];
4360 var dataform = new FormData(form);
4361 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4362 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4363 var is_tinymce_ct =
4364 typeof tinyMCE != "undefined" &&
4365 tinyMCE.get("gdpr-text") &&
4366 !tinyMCE.get("gdpr-text").isHidden();
4367
4368 if (is_tinymce_ct) {
4369 var description = tinyMCE.get("gdpr-text").getContent().trim();
4370 } else {
4371 var description = jQuery("#gdpr-text").val();
4372 }
4373 dataform.append("gdpr-text", description);
4374
4375 var is_tinymce_reg =
4376 typeof tinyMCE != "undefined" &&
4377 tinyMCE.get("gdpr-text-reg-user") &&
4378 !tinyMCE.get("gdpr-text-reg-user").isHidden();
4379
4380 if (is_tinymce_reg) {
4381 var description = tinyMCE.get("gdpr-text-reg-user").getContent().trim();
4382 } else {
4383 var description = jQuery("#gdpr-text-reg-user").val();
4384 }
4385 dataform.append("gdpr-text-reg-user", description);
4386
4387 jQuery(el).text(supportcandy.translations.please_wait);
4388 jQuery
4389 .ajax({
4390 url: supportcandy.ajax_url,
4391 type: "POST",
4392 data: dataform,
4393 processData: false,
4394 contentType: false,
4395 })
4396 .done(function (res) {
4397 wpsc_get_ms_gdpr();
4398 });
4399 }
4400
4401 /**
4402 * Set advanced settings of tl more settings
4403 *
4404 * @param {*} el
4405 */
4406 function wpsc_tl_ms_set_advanced(el) {
4407 var form = jQuery(".wpsc-frm-advanced-settings")[0];
4408 var dataform = new FormData(form);
4409 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4410 jQuery(el).text(supportcandy.translations.please_wait);
4411 jQuery
4412 .ajax({
4413 url: supportcandy.ajax_url,
4414 type: "POST",
4415 data: dataform,
4416 processData: false,
4417 contentType: false,
4418 })
4419 .done(function (res) {
4420 wpsc_tl_ms_get_advanced();
4421 });
4422 }
4423
4424 /**
4425 * Get ticket widget agentOnly fields
4426 */
4427 function wpsc_get_tw_agentonly_fields() {
4428 wpsc_show_modal();
4429 var data = { action: "wpsc_get_tw_agentonly_fields" };
4430 jQuery.post(supportcandy.ajax_url, data, function (response) {
4431 // Set to modal.
4432 jQuery(".wpsc-modal-header").text(response.title);
4433 jQuery(".wpsc-modal-body").html(response.body);
4434 jQuery(".wpsc-modal-footer").html(response.footer);
4435 // Display modal.
4436 wpsc_show_modal_inner_container();
4437 });
4438 }
4439
4440 /**
4441 * Reset gdpr
4442 *
4443 * @param {*} el
4444 */
4445 function wpsc_reset_ms_gdpr(el, nonce) {
4446 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4447 jQuery(el).text(supportcandy.translations.please_wait);
4448 var data = { action: "wpsc_reset_ms_gdpr", _ajax_nonce: nonce };
4449 jQuery.post(supportcandy.ajax_url, data, function (response) {
4450 wpsc_get_ms_gdpr();
4451 });
4452 }
4453
4454 /**
4455 * Reset advanced settings of tl more settings
4456 *
4457 * @param {*} el
4458 */
4459 function wpsc_tl_ms_reset_advanced(el, nonce) {
4460 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4461 jQuery(el).text(supportcandy.translations.please_wait);
4462 var data = { action: "wpsc_tl_ms_reset_advanced", _ajax_nonce: nonce };
4463 jQuery.post(supportcandy.ajax_url, data, function (response) {
4464 wpsc_tl_ms_get_advanced();
4465 });
4466 }
4467
4468 /**
4469 * Get advanced miscellaneous settings
4470 */
4471 function wpsc_get_ms_advanced() {
4472 supportcandy.current_tab = "advanced";
4473 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4474 jQuery(
4475 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4476 ).addClass("active");
4477
4478 window.history.replaceState(
4479 {},
4480 null,
4481 "admin.php?page=wpsc-settings&section=" +
4482 supportcandy.current_section +
4483 "&tab=" +
4484 supportcandy.current_tab
4485 );
4486 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4487
4488 wpsc_scroll_top();
4489
4490 var data = { action: "wpsc_get_ms_advanced" };
4491 jQuery.post(supportcandy.ajax_url, data, function (response) {
4492 jQuery(".wpsc-setting-section-body").html(response);
4493 wpsc_reset_responsive_style();
4494 });
4495 }
4496
4497 /**
4498 * Set ticket widget agentOnly fields
4499 */
4500 function wpsc_set_tw_agentonly_fields(el) {
4501 var form = jQuery(".wpsc-frm-edit-agentonly-fields")[0];
4502 var dataform = new FormData(form);
4503
4504 if (dataform.get("label").trim() == "") {
4505 alert(supportcandy.translations.req_fields_missing);
4506 return;
4507 }
4508
4509 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4510 jQuery(el).text(supportcandy.translations.please_wait);
4511
4512 jQuery
4513 .ajax({
4514 url: supportcandy.ajax_url,
4515 type: "POST",
4516 data: dataform,
4517 processData: false,
4518 contentType: false,
4519 })
4520 .done(function (res) {
4521 wpsc_close_modal();
4522 wpsc_get_ticket_widget();
4523 });
4524 }
4525
4526 /**
4527 * Get ticket widget additional recipients
4528 */
4529 function wpsc_get_tw_additional_recipients() {
4530 wpsc_show_modal();
4531 var data = { action: "wpsc_get_tw_additional_recipients" };
4532 jQuery.post(supportcandy.ajax_url, data, function (response) {
4533 // Set to modal.
4534 jQuery(".wpsc-modal-header").text(response.title);
4535 jQuery(".wpsc-modal-body").html(response.body);
4536 jQuery(".wpsc-modal-footer").html(response.footer);
4537 // Display modal.
4538 wpsc_show_modal_inner_container();
4539 });
4540 }
4541
4542 /**
4543 * Save advanced miscellaneous settings
4544 *
4545 * @param {*} el
4546 */
4547 function wpsc_set_ms_advanced(el) {
4548 var form = jQuery(".wpsc-frm-ms-advanced")[0];
4549 var dataform = new FormData(form);
4550 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4551 jQuery(el).text(supportcandy.translations.please_wait);
4552 jQuery
4553 .ajax({
4554 url: supportcandy.ajax_url,
4555 type: "POST",
4556 data: dataform,
4557 processData: false,
4558 contentType: false,
4559 })
4560 .done(function (res) {
4561 wpsc_get_ms_advanced();
4562 });
4563 }
4564
4565 /**
4566 * Set ticket widget additional recipients
4567 */
4568 function wpsc_set_tw_additional_recipients(el) {
4569 var form = jQuery(".wpsc-frm-edit-additional-recipients")[0];
4570 var dataform = new FormData(form);
4571
4572 if (dataform.get("label").trim() == "") {
4573 alert(supportcandy.translations.req_fields_missing);
4574 return;
4575 }
4576
4577 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4578 jQuery(el).text(supportcandy.translations.please_wait);
4579
4580 jQuery
4581 .ajax({
4582 url: supportcandy.ajax_url,
4583 type: "POST",
4584 data: dataform,
4585 processData: false,
4586 contentType: false,
4587 })
4588 .done(function (res) {
4589 wpsc_close_modal();
4590 wpsc_get_ticket_widget();
4591 });
4592 }
4593
4594 /**
4595 * Reset advanced miscellaneous settings
4596 *
4597 * @param {*} el
4598 */
4599 function wpsc_reset_ms_advanced(el, nonce) {
4600 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4601 jQuery(el).text(supportcandy.translations.please_wait);
4602 var data = { action: "wpsc_reset_ms_advanced", _ajax_nonce: nonce };
4603 jQuery.post(supportcandy.ajax_url, data, function (response) {
4604 wpsc_get_ms_advanced();
4605 });
4606 }
4607
4608 /**
4609 * Cancel edit
4610 */
4611 function wpsc_edit_option_cancel(el) {
4612 var cancelBtn = jQuery(el);
4613 cancelBtn.closest(".wpsc-edit-option-container").hide();
4614 cancelBtn.closest(".content").find(".wpsc-option-listing-container").show();
4615 }
4616
4617 /**
4618 * Remove an item
4619 */
4620 function wpsc_remove_option_item(el) {
4621 jQuery(el).closest(".wpsc-option-item").remove();
4622 wpsc_change_def_val_option_single();
4623 }
4624
4625 /**
4626 * Change default value options
4627 */
4628 function wpsc_change_def_val_option_single() {
4629 var options = [];
4630 jQuery(".wpsc-options-container .option_id").each(function (index, el) {
4631 var key = jQuery(el).val().trim();
4632 var value = jQuery(el)
4633 .closest(".wpsc-option-item")
4634 .find(".wpsc-option-listing-container .text")
4635 .text();
4636 options.push({ key, value });
4637 });
4638 var optionStr = '<option value=""></option>';
4639 jQuery(options).each(function (index, el) {
4640 optionStr += '<option value="' + el.key + '">' + el.value + "</option>";
4641 });
4642
4643 var fieldType = jQuery("#wpsc-select-ticket-field").val();
4644
4645 var optionSingleTypes = ["cf_single_select", "cf_radio_button"];
4646 if (jQuery.inArray(fieldType, optionSingleTypes) != -1) {
4647 jQuery("#wpsc-default-val-option-single").html(optionStr);
4648 jQuery("#wpsc-default-val-option-single").selectWoo();
4649 }
4650
4651 var optionMultiTypes = ["cf_multi_select", "cf_checkbox"];
4652 if (jQuery.inArray(fieldType, optionMultiTypes) != -1) {
4653 var preValue = jQuery("#wpsc-default-val-option-multi").val();
4654
4655 jQuery("#wpsc-default-val-option-multi").html(optionStr);
4656 jQuery("#wpsc-default-val-option-multi").selectWoo();
4657
4658 if (preValue) {
4659 jQuery("#wpsc-default-val-option-multi").val(preValue);
4660 jQuery("#wpsc-default-val-option-multi").trigger("change");
4661 }
4662 }
4663 }
4664
4665 /**
4666 * Get rich text settings
4667 */
4668 function wpsc_get_rich_text_editor(is_humbargar = false) {
4669 if (is_humbargar) {
4670 wpsc_toggle_humbargar();
4671 }
4672
4673 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
4674 jQuery(
4675 ".wpsc-setting-nav.rich-text-editor, .wpsc-humbargar-menu-item.rich-text-editor"
4676 ).addClass("active");
4677 jQuery(".wpsc-humbargar-title").html(
4678 supportcandy.humbargar_titles.rich_text_editor
4679 );
4680
4681 if (supportcandy.current_section !== "rich-text-editor") {
4682 supportcandy.current_section = "rich-text-editor";
4683 supportcandy.current_tab = "agent";
4684 }
4685
4686 window.history.replaceState(
4687 {},
4688 null,
4689 "admin.php?page=wpsc-settings&section=" +
4690 supportcandy.current_section +
4691 "&tab=" +
4692 supportcandy.current_tab
4693 );
4694 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
4695
4696 wpsc_scroll_top();
4697
4698 var data = {
4699 action: "wpsc_get_rich_text_editor",
4700 tab: supportcandy.current_tab,
4701 };
4702 jQuery.post(supportcandy.ajax_url, data, function (response) {
4703 jQuery(".wpsc-setting-body").html(response);
4704 wpsc_reset_responsive_style();
4705 jQuery(
4706 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4707 ).trigger("click");
4708 });
4709 }
4710
4711 /**
4712 * Load agent tab ui
4713 */
4714 function wpsc_get_te_agent() {
4715 supportcandy.current_tab = "agent";
4716 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4717 jQuery(
4718 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4719 ).addClass("active");
4720
4721 window.history.replaceState(
4722 {},
4723 null,
4724 "admin.php?page=wpsc-settings&section=" +
4725 supportcandy.current_section +
4726 "&tab=" +
4727 supportcandy.current_tab
4728 );
4729 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4730
4731 wpsc_scroll_top();
4732
4733 const data = { action: "wpsc_get_te_agent" };
4734 jQuery.post(supportcandy.ajax_url, data, function (response) {
4735 jQuery(".wpsc-setting-section-body").html(response);
4736 wpsc_reset_responsive_style();
4737 });
4738 }
4739
4740 /**
4741 * Save agent settings
4742 */
4743 function wpsc_set_te_agent(el) {
4744 const form = jQuery(".wpsc-frm-te-agent")[0];
4745 const dataform = new FormData(form);
4746 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4747 jQuery(el).text(supportcandy.translations.please_wait);
4748 jQuery
4749 .ajax({
4750 url: supportcandy.ajax_url,
4751 type: "POST",
4752 data: dataform,
4753 processData: false,
4754 contentType: false,
4755 })
4756 .done(function (res) {
4757 wpsc_get_te_agent();
4758 });
4759 }
4760
4761 /**
4762 * Reset agent settings
4763 */
4764 function wpsc_reset_te_agent(el, nonce) {
4765 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4766 jQuery(el).text(supportcandy.translations.please_wait);
4767 const data = { action: "wpsc_reset_te_agent", _ajax_nonce: nonce };
4768 jQuery.post(supportcandy.ajax_url, data, function (response) {
4769 wpsc_get_te_agent();
4770 });
4771 }
4772
4773 /**
4774 * Load registered user tab ui
4775 */
4776 function wpsc_get_te_registered_user() {
4777 supportcandy.current_tab = "registered-user";
4778 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4779 jQuery(
4780 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4781 ).addClass("active");
4782
4783 window.history.replaceState(
4784 {},
4785 null,
4786 "admin.php?page=wpsc-settings&section=" +
4787 supportcandy.current_section +
4788 "&tab=" +
4789 supportcandy.current_tab
4790 );
4791 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4792
4793 wpsc_scroll_top();
4794
4795 const data = { action: "wpsc_get_te_registered_user" };
4796 jQuery.post(supportcandy.ajax_url, data, function (response) {
4797 jQuery(".wpsc-setting-section-body").html(response);
4798 wpsc_reset_responsive_style();
4799 });
4800 }
4801
4802 /**
4803 * Save registered user settings
4804 */
4805 function wpsc_set_te_registered_user(el) {
4806 const form = jQuery(".wpsc-frm-te-registered-user")[0];
4807 const dataform = new FormData(form);
4808 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4809 jQuery(el).text(supportcandy.translations.please_wait);
4810 jQuery
4811 .ajax({
4812 url: supportcandy.ajax_url,
4813 type: "POST",
4814 data: dataform,
4815 processData: false,
4816 contentType: false,
4817 })
4818 .done(function (res) {
4819 wpsc_get_te_registered_user();
4820 });
4821 }
4822
4823 /**
4824 * Reset registered user settings
4825 */
4826 function wpsc_reset_te_registered_user(el, nonce) {
4827 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4828 jQuery(el).text(supportcandy.translations.please_wait);
4829 const data = { action: "wpsc_reset_te_registered_user", _ajax_nonce: nonce };
4830 jQuery.post(supportcandy.ajax_url, data, function (response) {
4831 wpsc_get_te_registered_user();
4832 });
4833 }
4834
4835 /**
4836 * Load guest user tab ui
4837 */
4838 function wpsc_get_te_guest_user() {
4839 supportcandy.current_tab = "guest-user";
4840 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4841 jQuery(
4842 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4843 ).addClass("active");
4844
4845 window.history.replaceState(
4846 {},
4847 null,
4848 "admin.php?page=wpsc-settings&section=" +
4849 supportcandy.current_section +
4850 "&tab=" +
4851 supportcandy.current_tab
4852 );
4853 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4854
4855 wpsc_scroll_top();
4856
4857 const data = { action: "wpsc_get_te_guest_user" };
4858 jQuery.post(supportcandy.ajax_url, data, function (response) {
4859 jQuery(".wpsc-setting-section-body").html(response);
4860 wpsc_reset_responsive_style();
4861 });
4862 }
4863
4864 /**
4865 * Save guest user settings
4866 */
4867 function wpsc_set_te_guest_user(el) {
4868 const form = jQuery(".wpsc-frm-te-guest-user")[0];
4869 const dataform = new FormData(form);
4870 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4871 jQuery(el).text(supportcandy.translations.please_wait);
4872 jQuery
4873 .ajax({
4874 url: supportcandy.ajax_url,
4875 type: "POST",
4876 data: dataform,
4877 processData: false,
4878 contentType: false,
4879 })
4880 .done(function (res) {
4881 wpsc_get_te_guest_user();
4882 });
4883 }
4884
4885 /**
4886 * Reset guest user settings
4887 */
4888 function wpsc_reset_te_guest_user(el, nonce) {
4889 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4890 jQuery(el).text(supportcandy.translations.please_wait);
4891 const data = { action: "wpsc_reset_te_guest_user", _ajax_nonce: nonce };
4892 jQuery.post(supportcandy.ajax_url, data, function (response) {
4893 wpsc_get_te_guest_user();
4894 });
4895 }
4896
4897 /**
4898 * Load advanced tab ui
4899 */
4900 function wpsc_get_te_advanced() {
4901 supportcandy.current_tab = "advanced";
4902 jQuery(".wpsc-setting-tab-container button").removeClass("active");
4903 jQuery(
4904 ".wpsc-setting-tab-container button." + supportcandy.current_tab
4905 ).addClass("active");
4906
4907 window.history.replaceState(
4908 {},
4909 null,
4910 "admin.php?page=wpsc-settings&section=" +
4911 supportcandy.current_section +
4912 "&tab=" +
4913 supportcandy.current_tab
4914 );
4915 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4916
4917 wpsc_scroll_top();
4918
4919 const data = { action: "wpsc_get_te_advanced" };
4920 jQuery.post(supportcandy.ajax_url, data, function (response) {
4921 jQuery(".wpsc-setting-section-body").html(response);
4922 wpsc_reset_responsive_style();
4923 });
4924 }
4925
4926 /**
4927 * Save advanced settings
4928 */
4929 function wpsc_set_te_advanced(el) {
4930 const form = jQuery(".wpsc-frm-te-advanced")[0];
4931 const dataform = new FormData(form);
4932 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4933 jQuery(el).text(supportcandy.translations.please_wait);
4934 jQuery
4935 .ajax({
4936 url: supportcandy.ajax_url,
4937 type: "POST",
4938 data: dataform,
4939 processData: false,
4940 contentType: false,
4941 })
4942 .done(function (res) {
4943 wpsc_get_te_advanced();
4944 });
4945 }
4946
4947 /**
4948 * Reset advanced settings
4949 */
4950 function wpsc_reset_te_advanced(el, nonce) {
4951 jQuery(".wpsc-modal-footer button").attr("disabled", true);
4952 jQuery(el).text(supportcandy.translations.please_wait);
4953 const data = { action: "wpsc_reset_te_advanced", _ajax_nonce: nonce };
4954 jQuery.post(supportcandy.ajax_url, data, function (response) {
4955 wpsc_get_te_advanced();
4956 });
4957 }
4958
4959 /**
4960 * Get agent working hrs settings
4961 */
4962 function wpsc_get_agents_working_hrs(is_humbargar = false) {
4963 if (is_humbargar) {
4964 wpsc_toggle_humbargar();
4965 }
4966
4967 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
4968 jQuery(
4969 ".wpsc-setting-nav.working-hrs, .wpsc-humbargar-menu-item.working-hrs"
4970 ).addClass("active");
4971 jQuery(".wpsc-humbargar-title").html(
4972 supportcandy.humbargar_titles.working_hrs
4973 );
4974
4975 window.history.replaceState(
4976 {},
4977 null,
4978 "admin.php?page=wpsc-support-agents&section=working-hrs"
4979 );
4980 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
4981
4982 wpsc_scroll_top();
4983
4984 var data = { action: "wpsc_get_agents_working_hrs" };
4985 jQuery.post(supportcandy.ajax_url, data, function (response) {
4986 jQuery(".wpsc-setting-body").html(response);
4987 wpsc_reset_responsive_style();
4988 wpsc_get_agents_wh_hrs();
4989 });
4990 }
4991
4992 /**
4993 * Get working hrs of given agent id
4994 */
4995 function wpsc_get_agents_wh_hrs() {
4996 jQuery("button.tab.exceptions").removeClass("active");
4997 jQuery("button.tab.working-hrs").addClass("active");
4998 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
4999 var data = {
5000 action: "wpsc_get_agents_wh_hrs",
5001 agent_id: supportcandy.temp.agent_id,
5002 _ajax_nonce: supportcandy.nonce,
5003 };
5004 jQuery.post(supportcandy.ajax_url, data, function (response) {
5005 jQuery(".wpsc-setting-section-body").html(response);
5006 });
5007 }
5008
5009 /**
5010 * Get agent working hrs exceptions
5011 */
5012 function wpsc_get_agents_wh_exceptions() {
5013 jQuery("button.tab.working-hrs").removeClass("active");
5014 jQuery("button.tab.exceptions").addClass("active");
5015 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
5016 var data = {
5017 action: "wpsc_get_agents_wh_exceptions",
5018 agent_id: supportcandy.temp.agent_id,
5019 _ajax_nonce: supportcandy.nonce,
5020 };
5021 jQuery.post(supportcandy.ajax_url, data, function (response) {
5022 jQuery(".wpsc-setting-section-body").html(response);
5023 });
5024 }
5025
5026 /**
5027 * Get agent working hrs settings
5028 */
5029 function wpsc_get_agent_working_hrs(is_humbargar = false) {
5030 if (is_humbargar) {
5031 wpsc_toggle_humbargar();
5032 }
5033
5034 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
5035 jQuery(
5036 ".wpsc-setting-nav.working-hrs, .wpsc-humbargar-menu-item.working-hrs"
5037 ).addClass("active");
5038 jQuery(".wpsc-humbargar-title").html(
5039 supportcandy.humbargar_titles.working_hrs
5040 );
5041
5042 window.history.replaceState(
5043 {},
5044 null,
5045 "admin.php?page=wpsc-support-agents&section=working-hrs"
5046 );
5047 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
5048
5049 wpsc_scroll_top();
5050
5051 var data = { action: "wpsc_get_agent_working_hrs" };
5052 jQuery.post(supportcandy.ajax_url, data, function (response) {
5053 jQuery(".wpsc-setting-body").html(response);
5054 wpsc_reset_responsive_style();
5055 window.location.reload();
5056 });
5057 }
5058
5059 /**
5060 * Get all agent leaves
5061 */
5062 function wpsc_get_agent_leaves(is_humbargar = false) {
5063 if (is_humbargar) {
5064 wpsc_toggle_humbargar();
5065 }
5066
5067 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
5068 jQuery(".wpsc-setting-nav.leaves, .wpsc-humbargar-menu-item.leaves").addClass(
5069 "active"
5070 );
5071 jQuery(".wpsc-humbargar-title").html(supportcandy.humbargar_titles.leaves);
5072
5073 window.history.replaceState(
5074 {},
5075 null,
5076 "admin.php?page=wpsc-support-agents&section=leaves"
5077 );
5078 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
5079
5080 wpsc_scroll_top();
5081
5082 var data = { action: "wpsc_get_agent_leaves" };
5083 jQuery.post(supportcandy.ajax_url, data, function (response) {
5084 jQuery(".wpsc-setting-body").html(response);
5085 wpsc_reset_responsive_style();
5086 });
5087 }
5088
5089 /**
5090 * Get add agent leaves
5091 */
5092 function wpsc_get_add_agent_leaves(dateSelected, _ajax_nonce) {
5093 supportcandy.temp.dateSelected = dateSelected;
5094 wpsc_show_modal();
5095 var data = {
5096 action: "wpsc_get_add_agent_leaves",
5097 dateSelected,
5098 _ajax_nonce,
5099 };
5100 jQuery.post(supportcandy.ajax_url, data, function (response) {
5101 // Set to modal.
5102 jQuery(".wpsc-modal-header").text(response.title);
5103 jQuery(".wpsc-modal-body").html(response.body);
5104 jQuery(".wpsc-modal-footer").html(response.footer);
5105 // Display modal.
5106 wpsc_show_modal_inner_container();
5107 });
5108 }
5109
5110 /**
5111 * Set add agent leaves
5112 */
5113 function wpsc_set_add_agent_leaves(el) {
5114 const form = jQuery(".wpsc-frm-agent-holiday-actions")[0];
5115 const dataform = new FormData(form);
5116
5117 var agents = dataform.getAll("agents[]");
5118 if (!agents.length) {
5119 alert(supportcandy.translations.req_fields_missing);
5120 return;
5121 }
5122
5123 dataform.append("dateSelected", supportcandy.temp.dateSelected);
5124 jQuery(el).text(supportcandy.translations.please_wait);
5125 jQuery
5126 .ajax({
5127 url: supportcandy.ajax_url,
5128 type: "POST",
5129 data: dataform,
5130 processData: false,
5131 contentType: false,
5132 })
5133 .done(function (response) {
5134 calendar.refetchEvents();
5135 wpsc_close_modal();
5136 });
5137 }
5138
5139 /**
5140 * Delete agent leave
5141 */
5142 function wpsc_delete_agent_leave(id, nonce) {
5143 var flag = confirm(supportcandy.translations.deleteLeaveConfirmation);
5144 if (!flag) {
5145 return;
5146 }
5147
5148 var data = {
5149 action: "wpsc_delete_agent_leave",
5150 holidayId: id,
5151 _ajax_nonce: nonce,
5152 };
5153 jQuery.post(supportcandy.ajax_url, data, function (response) {
5154 calendar.refetchEvents();
5155 });
5156 }
5157
5158 /**
5159 * User registration otp email template
5160 */
5161 function wpsc_get_en_user_reg_otp(is_humbargar = false) {
5162 if (is_humbargar) {
5163 wpsc_toggle_humbargar();
5164 }
5165
5166 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
5167 jQuery(
5168 ".wpsc-setting-nav.registration-otp, .wpsc-humbargar-menu-item.registration-otp"
5169 ).addClass("active");
5170 jQuery(".wpsc-humbargar-title").html(
5171 supportcandy.humbargar_titles.registration_otp
5172 );
5173
5174 window.history.replaceState(
5175 {},
5176 null,
5177 "admin.php?page=wpsc-email-notifications&section=registration-otp"
5178 );
5179 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
5180
5181 wpsc_scroll_top();
5182
5183 var data = { action: "wpsc_get_en_user_reg_otp" };
5184 jQuery.post(supportcandy.ajax_url, data, function (response) {
5185 jQuery(".wpsc-setting-body").html(response);
5186 wpsc_reset_responsive_style();
5187 });
5188 }
5189
5190 /**
5191 * Set user registration otp email template
5192 */
5193 function wpsc_set_en_user_reg_otp(el) {
5194 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5195 jQuery(el).text(supportcandy.translations.please_wait);
5196 var form = jQuery(".wpsc-frm-en-user-reg-otp")[0];
5197 var dataform = new FormData(form);
5198 if (dataform.get("editor") == "html") {
5199 dataform.append("body", tinyMCE.get("wpsc-en-body").getContent());
5200 }
5201 jQuery
5202 .ajax({
5203 url: supportcandy.ajax_url,
5204 type: "POST",
5205 data: dataform,
5206 processData: false,
5207 contentType: false,
5208 })
5209 .done(function (res) {
5210 wpsc_get_en_user_reg_otp();
5211 });
5212 }
5213
5214 /**
5215 * Reset user registration otp email template
5216 */
5217 function wpsc_reset_en_user_reg_otp(el, nonce) {
5218 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5219 jQuery(el).text(supportcandy.translations.please_wait);
5220 const data = { action: "wpsc_reset_en_user_reg_otp", _ajax_nonce: nonce };
5221 jQuery.post(supportcandy.ajax_url, data, function (response) {
5222 wpsc_get_en_user_reg_otp();
5223 });
5224 }
5225
5226 /**
5227 * Get guest login otp email template
5228 *
5229 * @param {boolean} is_humbargar
5230 */
5231 function wpsc_get_en_guest_login_otp(is_humbargar = false) {
5232 if (is_humbargar) {
5233 wpsc_toggle_humbargar();
5234 }
5235
5236 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
5237 jQuery(
5238 ".wpsc-setting-nav.guest-login-otp, .wpsc-humbargar-menu-item.guest-login-otp"
5239 ).addClass("active");
5240 jQuery(".wpsc-humbargar-title").html(
5241 supportcandy.humbargar_titles.registration_otp
5242 );
5243
5244 window.history.replaceState(
5245 {},
5246 null,
5247 "admin.php?page=wpsc-email-notifications&section=guest-login-otp"
5248 );
5249 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
5250
5251 wpsc_scroll_top();
5252
5253 var data = { action: "wpsc_get_en_guest_login_otp" };
5254 jQuery.post(supportcandy.ajax_url, data, function (response) {
5255 jQuery(".wpsc-setting-body").html(response);
5256 wpsc_reset_responsive_style();
5257 });
5258 }
5259
5260 /**
5261 * Set guest login otp email template
5262 */
5263 function wpsc_set_en_guest_login_otp(el) {
5264 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5265 jQuery(el).text(supportcandy.translations.please_wait);
5266 var form = jQuery(".wpsc-frm-en-guest-login-otp")[0];
5267 var dataform = new FormData(form);
5268 if (dataform.get("editor") == "html") {
5269 dataform.append("body", tinyMCE.get("wpsc-en-body").getContent());
5270 }
5271 jQuery
5272 .ajax({
5273 url: supportcandy.ajax_url,
5274 type: "POST",
5275 data: dataform,
5276 processData: false,
5277 contentType: false,
5278 })
5279 .done(function (res) {
5280 wpsc_get_en_guest_login_otp();
5281 });
5282 }
5283
5284 /**
5285 * Reset guest login otp email template
5286 */
5287 function wpsc_reset_en_guest_login_otp(el, nonce) {
5288 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5289 jQuery(el).text(supportcandy.translations.please_wait);
5290 const data = { action: "wpsc_reset_en_guest_login_otp", _ajax_nonce: nonce };
5291 jQuery.post(supportcandy.ajax_url, data, function (response) {
5292 wpsc_get_en_guest_login_otp();
5293 });
5294 }
5295
5296 /**
5297 * Get ticket widget biographical info
5298 */
5299 function wpsc_get_tw_biographical_info() {
5300 wpsc_show_modal();
5301 var data = { action: "wpsc_get_tw_biographical_info" };
5302 jQuery.post(supportcandy.ajax_url, data, function (response) {
5303 // Set to modal.
5304 jQuery(".wpsc-modal-header").text(response.title);
5305 jQuery(".wpsc-modal-body").html(response.body);
5306 jQuery(".wpsc-modal-footer").html(response.footer);
5307 // Display modal.
5308 wpsc_show_modal_inner_container();
5309 });
5310 }
5311
5312 /**
5313 * Set ticket widget biographical info
5314 */
5315 function wpsc_set_tw_biographical_info(el) {
5316 var form = jQuery(".wpsc-frm-edit-biographical-info")[0];
5317 var dataform = new FormData(form);
5318
5319 if (dataform.get("label").trim() == "") {
5320 alert(supportcandy.translations.req_fields_missing);
5321 return;
5322 }
5323
5324 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5325 jQuery(el).text(supportcandy.translations.please_wait);
5326
5327 jQuery
5328 .ajax({
5329 url: supportcandy.ajax_url,
5330 type: "POST",
5331 data: dataform,
5332 processData: false,
5333 contentType: false,
5334 })
5335 .done(function (res) {
5336 wpsc_close_modal();
5337 wpsc_get_ticket_widget();
5338 });
5339 }
5340
5341 /**
5342 * Get edit agent ticket list items
5343 */
5344 function wpsc_get_edit_agent_tl_item(slug, _ajax_nonce) {
5345 wpsc_show_modal();
5346 var data = { action: "wpsc_get_edit_agent_tl_item", slug, _ajax_nonce };
5347 jQuery.post(supportcandy.ajax_url, data, function (response) {
5348 // Set to modal.
5349 jQuery(".wpsc-modal-header").text(response.title);
5350 jQuery(".wpsc-modal-body").html(response.body);
5351 jQuery(".wpsc-modal-footer").html(response.footer);
5352 // Display modal.
5353 wpsc_show_modal_inner_container();
5354 });
5355 }
5356
5357 /**
5358 * Set edit agent ticket list items
5359 */
5360 function wpsc_set_edit_agent_tl_item(el) {
5361 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5362 jQuery(el).text(supportcandy.translations.please_wait);
5363
5364 var form = jQuery(".frm-edit-agent-tl-items")[0];
5365 var dataform = new FormData(form);
5366 jQuery
5367 .ajax({
5368 url: supportcandy.ajax_url,
5369 type: "POST",
5370 data: dataform,
5371 processData: false,
5372 contentType: false,
5373 })
5374 .done(function (res) {
5375 wpsc_close_modal();
5376 wpsc_get_agent_tl_items();
5377 });
5378 }
5379
5380 /**
5381 * Get edit agent filter list items
5382 */
5383 function wpsc_get_edit_agent_filter_item(slug, _ajax_nonce) {
5384 wpsc_show_modal();
5385 var data = { action: "wpsc_get_edit_agent_filter_item", slug, _ajax_nonce };
5386 jQuery.post(supportcandy.ajax_url, data, function (response) {
5387 // Set to modal.
5388 jQuery(".wpsc-modal-header").text(response.title);
5389 jQuery(".wpsc-modal-body").html(response.body);
5390 jQuery(".wpsc-modal-footer").html(response.footer);
5391 // Display modal.
5392 wpsc_show_modal_inner_container();
5393 });
5394 }
5395
5396 /**
5397 * Set edit agent filter list items
5398 */
5399 function wpsc_set_edit_agent_filter_item(el) {
5400 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5401 jQuery(el).text(supportcandy.translations.please_wait);
5402
5403 var form = jQuery(".frm-edit-agent-fl-items")[0];
5404 var dataform = new FormData(form);
5405 jQuery
5406 .ajax({
5407 url: supportcandy.ajax_url,
5408 type: "POST",
5409 data: dataform,
5410 processData: false,
5411 contentType: false,
5412 })
5413 .done(function (res) {
5414 wpsc_close_modal();
5415 wpsc_get_agent_filter_items();
5416 });
5417 }
5418
5419 /**
5420 * Get edit company working hrs exception
5421 */
5422 function wpsc_get_edit_wh_exception(exception_id, _ajax_nonce) {
5423 wpsc_show_modal();
5424 var data = {
5425 action: "wpsc_get_edit_wh_exception",
5426 exception_id,
5427 _ajax_nonce,
5428 };
5429 jQuery.post(supportcandy.ajax_url, data, function (response) {
5430 // Set to modal.
5431 jQuery(".wpsc-modal-header").text(response.title);
5432 jQuery(".wpsc-modal-body").html(response.body);
5433 jQuery(".wpsc-modal-footer").html(response.footer);
5434 // Display modal.
5435 wpsc_show_modal_inner_container();
5436 });
5437 }
5438
5439 /**
5440 * Delete company working hrs exception
5441 */
5442 function wpsc_delete_wh_exception(exception_id, _ajax_nonce) {
5443 var flag = confirm(supportcandy.translations.confirm);
5444 if (!flag) {
5445 return;
5446 }
5447 var data = { action: "wpsc_delete_wh_exception", exception_id, _ajax_nonce };
5448 jQuery.post(supportcandy.ajax_url, data, function (res) {
5449 wpsc_get_wh_exceptions();
5450 });
5451 }
5452
5453 /**
5454 * Get edit customer ticket list items
5455 */
5456 function wpsc_get_edit_customer_tl_item(slug, _ajax_nonce) {
5457 wpsc_show_modal();
5458 var data = { action: "wpsc_get_edit_customer_tl_item", slug, _ajax_nonce };
5459 jQuery.post(supportcandy.ajax_url, data, function (response) {
5460 // Set to modal.
5461 jQuery(".wpsc-modal-header").text(response.title);
5462 jQuery(".wpsc-modal-body").html(response.body);
5463 jQuery(".wpsc-modal-footer").html(response.footer);
5464 // Display modal.
5465 wpsc_show_modal_inner_container();
5466 });
5467 }
5468
5469 /**
5470 * Set edit customer ticket list items
5471 */
5472 function wpsc_set_edit_customer_tl_item(el) {
5473 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5474 jQuery(el).text(supportcandy.translations.please_wait);
5475
5476 var form = jQuery(".frm-edit-customer-tl-items")[0];
5477 var dataform = new FormData(form);
5478 jQuery
5479 .ajax({
5480 url: supportcandy.ajax_url,
5481 type: "POST",
5482 data: dataform,
5483 processData: false,
5484 contentType: false,
5485 })
5486 .done(function (res) {
5487 wpsc_close_modal();
5488 wpsc_get_customer_tl_items();
5489 });
5490 }
5491
5492 /**
5493 * Get edit coustomer ticket filter items
5494 */
5495 function wpsc_get_edit_ctl_filter_item(slug, _ajax_nonce) {
5496 wpsc_show_modal();
5497 var data = { action: "wpsc_get_edit_ctl_filter_item", slug, _ajax_nonce };
5498 jQuery.post(supportcandy.ajax_url, data, function (response) {
5499 // Set to modal.
5500 jQuery(".wpsc-modal-header").text(response.title);
5501 jQuery(".wpsc-modal-body").html(response.body);
5502 jQuery(".wpsc-modal-footer").html(response.footer);
5503 // Display modal.
5504 wpsc_show_modal_inner_container();
5505 });
5506 }
5507
5508 /**
5509 * Set edit coustomer ticket filter items
5510 */
5511 function wpsc_set_edit_ctl_filter_item(el) {
5512 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5513 jQuery(el).text(supportcandy.translations.please_wait);
5514
5515 var form = jQuery(".frm-edit-customer-fl-items")[0];
5516 var dataform = new FormData(form);
5517 jQuery
5518 .ajax({
5519 url: supportcandy.ajax_url,
5520 type: "POST",
5521 data: dataform,
5522 processData: false,
5523 contentType: false,
5524 })
5525 .done(function (res) {
5526 wpsc_close_modal();
5527 wpsc_get_customer_filter_items();
5528 });
5529 }
5530
5531 /**
5532 * Get ticket tag settings
5533 */
5534 function wpsc_get_ticket_tags() {
5535 supportcandy.current_tab = "ticket-tags-list";
5536 jQuery(".wpsc-setting-tab-container button").removeClass("active");
5537 jQuery(
5538 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5539 ).addClass("active");
5540
5541 window.history.replaceState(
5542 {},
5543 null,
5544 "admin.php?page=wpsc-settings&section=" +
5545 supportcandy.current_section +
5546 "&tab=" +
5547 supportcandy.current_tab
5548 );
5549 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
5550
5551 wpsc_scroll_top();
5552
5553 var data = { action: "wpsc_get_ticket_tags" };
5554 jQuery.post(supportcandy.ajax_url, data, function (response) {
5555 jQuery(".wpsc-setting-section-body").html(response);
5556 wpsc_reset_responsive_style();
5557 });
5558 }
5559
5560 /**
5561 * Set add ticket tag
5562 */
5563 function wpsc_set_add_ticket_tags(el) {
5564 var form = jQuery(".wpsc-frm-add-ms-ticket-tags")[0];
5565 var dataform = new FormData(form);
5566
5567 if (!dataform.get("name")) {
5568 alert(supportcandy.translations.req_fields_missing);
5569 return;
5570 }
5571
5572 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5573 jQuery(el).text(supportcandy.translations.please_wait);
5574
5575 jQuery
5576 .ajax({
5577 url: supportcandy.ajax_url,
5578 type: "POST",
5579 data: dataform,
5580 processData: false,
5581 contentType: false,
5582 })
5583 .done(function (res) {
5584 wpsc_close_modal();
5585 wpsc_get_ticket_tags();
5586 });
5587 }
5588
5589 /**
5590 * Update tag
5591 */
5592 function wpsc_get_edit_ticket_tags(id, nonce) {
5593 wpsc_show_modal();
5594 var data = { action: "wpsc_get_edit_ticket_tags", id, _ajax_nonce: nonce };
5595 jQuery.post(supportcandy.ajax_url, data, function (res) {
5596 // Set to modal.
5597 jQuery(".wpsc-modal-header").text(res.title);
5598 jQuery(".wpsc-modal-body").html(res.body);
5599 jQuery(".wpsc-modal-footer").html(res.footer);
5600 // Display modal.
5601 wpsc_show_modal_inner_container();
5602 });
5603 }
5604
5605 function wpsc_set_edit_ticket_tags(el) {
5606 var form = jQuery(".wpsc-frm-edit-ticket-tag")[0];
5607 var dataform = new FormData(form);
5608
5609 if (!dataform.get("name")) {
5610 alert(supportcandy.translations.req_fields_missing);
5611 return;
5612 }
5613 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5614 jQuery(el).text(supportcandy.translations.please_wait);
5615
5616 jQuery
5617 .ajax({
5618 url: supportcandy.ajax_url,
5619 type: "POST",
5620 data: dataform,
5621 processData: false,
5622 contentType: false,
5623 })
5624 .done(function (res) {
5625 wpsc_close_modal();
5626 wpsc_get_ticket_tags();
5627 });
5628 }
5629
5630 /**
5631 * Delete ticket tag modal
5632 */
5633 function wpsc_set_delete_ticket_tags(id, nonce) {
5634 var flag = confirm(supportcandy.translations.confirm);
5635 if (!flag) {
5636 return;
5637 }
5638
5639 var data = { action: "wpsc_set_delete_ticket_tags", id, _ajax_nonce: nonce };
5640 jQuery.post(supportcandy.ajax_url, data, function (response) {
5641 wpsc_get_ticket_tags();
5642 });
5643 }
5644
5645 /**
5646 * Get ticket widget ticket tags
5647 */
5648 function wpsc_get_tw_ticket_tags() {
5649 wpsc_show_modal();
5650 var data = { action: "wpsc_get_tw_ticket_tags" };
5651 jQuery.post(supportcandy.ajax_url, data, function (response) {
5652 // Set to modal.
5653 jQuery(".wpsc-modal-header").text(response.title);
5654 jQuery(".wpsc-modal-body").html(response.body);
5655 jQuery(".wpsc-modal-footer").html(response.footer);
5656 // Display modal.
5657 wpsc_show_modal_inner_container();
5658 });
5659 }
5660
5661 /**
5662 * Set ticket widget ticket tags
5663 */
5664 function wpsc_set_tw_ticket_tags(el) {
5665 var form = jQuery(".wpsc-frm-edit-tags")[0];
5666 var dataform = new FormData(form);
5667
5668 if (dataform.get("label").trim() == "") {
5669 alert(supportcandy.translations.req_fields_missing);
5670 return;
5671 }
5672
5673 jQuery(".wpsc-modal-footer button").attr("disabled", true);
5674 jQuery(el).text(supportcandy.translations.please_wait);
5675
5676 jQuery
5677 .ajax({
5678 url: supportcandy.ajax_url,
5679 type: "POST",
5680 data: dataform,
5681 processData: false,
5682 contentType: false,
5683 })
5684 .done(function (res) {
5685 wpsc_close_modal();
5686 wpsc_get_ticket_widget();
5687 });
5688 }
5689
5690 /**
5691 * Get ticket tags modal UI
5692 */
5693 function wpsc_it_get_edit_ticket_tags(ticket_id, nonce) {
5694 wpsc_show_modal();
5695 var data = {
5696 action: "wpsc_it_get_edit_ticket_tags",
5697 ticket_id,
5698 _ajax_nonce: nonce,
5699 };
5700 jQuery.post(supportcandy.ajax_url, data, function (response) {
5701 jQuery(".wpsc-modal-header").text(response.title);
5702 jQuery(".wpsc-modal-body").html(response.body);
5703 jQuery(".wpsc-modal-footer").html(response.footer);
5704 wpsc_show_modal_inner_container();
5705 });
5706 }
5707
5708 /**
5709 * Get appearence settings
5710 */
5711 function wpsc_get_ticket_tags_settings(is_humbargar = false) {
5712 if (is_humbargar) {
5713 wpsc_toggle_humbargar();
5714 }
5715
5716 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
5717 jQuery(
5718 ".wpsc-setting-nav.ticket-tags, .wpsc-humbargar-menu-item.ticket-tags"
5719 ).addClass("active");
5720 jQuery(".wpsc-humbargar-title").html(
5721 supportcandy.humbargar_titles.tickettags
5722 );
5723
5724 if (supportcandy.current_section !== "ticket-tags") {
5725 supportcandy.current_section = "ticket-tags";
5726 supportcandy.current_tab = "general";
5727 }
5728
5729 window.history.replaceState(
5730 {},
5731 null,
5732 "admin.php?page=wpsc-settings&section=" +
5733 supportcandy.current_section +
5734 "&tab=" +
5735 supportcandy.current_tab
5736 );
5737 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
5738
5739 wpsc_scroll_top();
5740
5741 var data = {
5742 action: "wpsc_get_ticket_tags_settings",
5743 tab: supportcandy.current_tab,
5744 };
5745 jQuery.post(supportcandy.ajax_url, data, function (response) {
5746 jQuery(".wpsc-setting-body").html(response);
5747 wpsc_reset_responsive_style();
5748 jQuery(
5749 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5750 ).trigger("click");
5751 });
5752 }
5753
5754 /**
5755 * Get general appearence settings
5756 */
5757 function wpsc_ticket_tags_get_general_settings() {
5758 supportcandy.current_tab = "general";
5759 jQuery(".wpsc-setting-tab-container button").removeClass("active");
5760 jQuery(
5761 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5762 ).addClass("active");
5763
5764 window.history.replaceState(
5765 {},
5766 null,
5767 "admin.php?page=wpsc-settings&section=" +
5768 supportcandy.current_section +
5769 "&tab=" +
5770 supportcandy.current_tab
5771 );
5772 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
5773
5774 wpsc_scroll_top();
5775 var data = { action: "wpsc_ticket_tags_get_general_settings" };
5776 jQuery.post(supportcandy.ajax_url, data, function (response) {
5777 jQuery(".wpsc-setting-section-body").html(response);
5778 wpsc_reset_responsive_style();
5779 });
5780 }
5781
5782 /**
5783 * Set general settings
5784 */
5785 function wpsc_ticket_tags_set_general_settings(el) {
5786 var form = jQuery(".wpsc-ticket-tags-general-settings")[0];
5787 var dataform = new FormData(form);
5788 jQuery(el).text(supportcandy.translations.please_wait);
5789 jQuery
5790 .ajax({
5791 url: supportcandy.ajax_url,
5792 type: "POST",
5793 data: dataform,
5794 processData: false,
5795 contentType: false,
5796 })
5797 .done(function (res) {
5798 wpsc_ticket_tags_get_general_settings();
5799 });
5800 }
5801
5802 /**
5803 * Reset general settings
5804 */
5805 function wpsc_ticket_tags_reset_general_settings(el, nonce) {
5806 jQuery(el).text(supportcandy.translations.please_wait);
5807 var data = {
5808 action: "wpsc_ticket_tags_reset_general_settings",
5809 _ajax_nonce: nonce,
5810 };
5811 jQuery.post(supportcandy.ajax_url, data, function (response) {
5812 wpsc_ticket_tags_get_general_settings();
5813 });
5814 }
5815
5816 /**
5817 * Get dashboard settings
5818 */
5819 function wpsc_get_dashboard_settings(is_humbargar = false) {
5820 if (is_humbargar) {
5821 wpsc_toggle_humbargar();
5822 }
5823
5824 jQuery(".wpsc-setting-nav, .wpsc-humbargar-menu-item").removeClass("active");
5825 jQuery(
5826 ".wpsc-setting-nav.dashboard-settings, .wpsc-humbargar-menu-item.dashboard-settings"
5827 ).addClass("active");
5828 jQuery(".wpsc-humbargar-title").html(
5829 supportcandy.humbargar_titles.tickettags
5830 );
5831
5832 if (supportcandy.current_section !== "dashboard-settings") {
5833 supportcandy.current_section = "dashboard-settings";
5834 supportcandy.current_tab = "dashboard-general";
5835 }
5836
5837 window.history.replaceState(
5838 {},
5839 null,
5840 "admin.php?page=wpsc-settings&section=" +
5841 supportcandy.current_section +
5842 "&tab=" +
5843 supportcandy.current_tab
5844 );
5845 jQuery(".wpsc-setting-body").html(supportcandy.loader_html);
5846
5847 wpsc_scroll_top();
5848
5849 var data = {
5850 action: "wpsc_get_dashboard_settings",
5851 tab: supportcandy.current_tab,
5852 };
5853 jQuery.post(supportcandy.ajax_url, data, function (response) {
5854 jQuery(".wpsc-setting-body").html(response);
5855 wpsc_reset_responsive_style();
5856 jQuery(
5857 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5858 ).trigger("click");
5859 });
5860 }
5861
5862 /**
5863 * Get dashboard cards settings
5864 */
5865 function wpsc_get_dashboard_cards_settings() {
5866 supportcandy.current_tab = "dashboard-cards";
5867 jQuery(".wpsc-setting-tab-container button").removeClass("active");
5868 jQuery(
5869 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5870 ).addClass("active");
5871
5872 window.history.replaceState(
5873 {},
5874 null,
5875 "admin.php?page=wpsc-settings&section=" +
5876 supportcandy.current_section +
5877 "&tab=" +
5878 supportcandy.current_tab
5879 );
5880 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
5881
5882 wpsc_scroll_top();
5883 var data = { action: "wpsc_get_dashboard_cards_settings" };
5884 jQuery.post(supportcandy.ajax_url, data, function (response) {
5885 jQuery(".wpsc-setting-section-body").html(response);
5886 wpsc_reset_responsive_style();
5887 });
5888 }
5889
5890 /**
5891 * Sort dashboard cards
5892 */
5893 function wpsc_set_dashboard_card_load_order(slugs, nonce) {
5894 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
5895 var data = {
5896 action: "wpsc_set_dashboard_card_load_order",
5897 slugs,
5898 _ajax_nonce: nonce,
5899 };
5900 jQuery.post(supportcandy.ajax_url, data, function (res) {
5901 wpsc_get_dashboard_cards_settings();
5902 });
5903 }
5904
5905 /**
5906 * Toggle enable/disable status of a single dashboard card
5907 */
5908 function wpsc_toggle_dashboard_card_status(el, slug, nonce) {
5909 var checkbox = jQuery(el);
5910 var is_enable = checkbox.is(":checked") ? 1 : 0;
5911 var card = checkbox.closest(".wpsc-setting-card");
5912
5913 var data = {
5914 action: "wpsc_toggle_dashboard_card_status",
5915 slug,
5916 is_enable,
5917 _ajax_nonce: nonce,
5918 };
5919 jQuery.post(supportcandy.ajax_url, data, function () {
5920 card.attr(
5921 "style",
5922 is_enable ? "" : "background-color:#eec7ca;color:#dc2222"
5923 );
5924 var total = jQuery(".wpsc-toggle-dashboard-card").length;
5925 var checked = jQuery(".wpsc-toggle-dashboard-card:checked").length;
5926 jQuery(".wpsc-toggle-all-dashboard-cards").prop(
5927 "checked",
5928 total > 0 && total === checked
5929 );
5930 }).fail(function () {
5931 // Revert checkbox on failure.
5932 checkbox.prop("checked", !is_enable);
5933 });
5934 }
5935
5936 /**
5937 * Enable or disable all dashboard cards at once
5938 */
5939 function wpsc_toggle_all_dashboard_cards(el, nonce) {
5940 var checkbox = jQuery(el);
5941 var is_enable = checkbox.is(":checked") ? 1 : 0;
5942
5943 var data = {
5944 action: "wpsc_toggle_all_dashboard_cards_status",
5945 is_enable,
5946 _ajax_nonce: nonce,
5947 };
5948 jQuery.post(supportcandy.ajax_url, data, function () {
5949 jQuery(".wpsc-toggle-dashboard-card").prop("checked", !!is_enable);
5950 jQuery(".wpsc-setting-card").attr(
5951 "style",
5952 is_enable ? "" : "background-color:#eec7ca;color:#dc2222"
5953 );
5954 }).fail(function () {
5955 // Revert checkbox on failure.
5956 checkbox.prop("checked", !is_enable);
5957 });
5958 }
5959
5960 /**
5961 * Get dashboard widgets settings
5962 */
5963 function wpsc_get_dashboard_widgets_settings() {
5964 supportcandy.current_tab = "dashboard-widgets";
5965 jQuery(".wpsc-setting-tab-container button").removeClass("active");
5966 jQuery(
5967 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5968 ).addClass("active");
5969
5970 window.history.replaceState(
5971 {},
5972 null,
5973 "admin.php?page=wpsc-settings&section=" +
5974 supportcandy.current_section +
5975 "&tab=" +
5976 supportcandy.current_tab
5977 );
5978 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
5979
5980 wpsc_scroll_top();
5981 var data = { action: "wpsc_get_dashboard_widgets_settings" };
5982 jQuery.post(supportcandy.ajax_url, data, function (response) {
5983 jQuery(".wpsc-setting-section-body").html(response);
5984 wpsc_reset_responsive_style();
5985 });
5986 }
5987
5988 /**
5989 * Get dashboard widgets settings
5990 */
5991 function wpsc_get_dashboard_general_settings() {
5992 supportcandy.current_tab = "dashboard-general";
5993 jQuery(".wpsc-setting-tab-container button").removeClass("active");
5994 jQuery(
5995 ".wpsc-setting-tab-container button." + supportcandy.current_tab
5996 ).addClass("active");
5997
5998 window.history.replaceState(
5999 {},
6000 null,
6001 "admin.php?page=wpsc-settings&section=" +
6002 supportcandy.current_section +
6003 "&tab=" +
6004 supportcandy.current_tab
6005 );
6006 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
6007
6008 wpsc_scroll_top();
6009 var data = { action: "wpsc_get_dashboard_general_settings" };
6010 jQuery.post(supportcandy.ajax_url, data, function (response) {
6011 jQuery(".wpsc-setting-section-body").html(response);
6012 wpsc_reset_responsive_style();
6013 });
6014 }
6015
6016 /**
6017 * Save dashboard general settings
6018 *
6019 * @param {*} el
6020 */
6021 function wpsc_set_dashboard_general_settings(el) {
6022 var form = jQuery(".wpsc-frm-db-gs")[0];
6023 var dataform = new FormData(form);
6024 jQuery(".wpsc-modal-footer button").attr("disabled", true);
6025 jQuery(el).text(supportcandy.translations.please_wait);
6026 jQuery
6027 .ajax({
6028 url: supportcandy.ajax_url,
6029 type: "POST",
6030 data: dataform,
6031 processData: false,
6032 contentType: false,
6033 })
6034 .done(function (res) {
6035 wpsc_get_dashboard_general_settings();
6036 });
6037 }
6038
6039 /**
6040 * Reset dashboard general settings
6041 *
6042 * @param {*} el
6043 */
6044 function wpsc_reset_dashboard_general_settings(el, nonce) {
6045 jQuery(".wpsc-modal-footer button").attr("disabled", true);
6046 jQuery(el).text(supportcandy.translations.please_wait);
6047 var data = {
6048 action: "wpsc_reset_dashboard_general_settings",
6049 _ajax_nonce: nonce,
6050 };
6051 jQuery.post(supportcandy.ajax_url, data, function (response) {
6052 wpsc_get_dashboard_general_settings();
6053 });
6054 }
6055
6056 /**
6057 * Add new dashboard widget
6058 */
6059 function wpsc_get_new_dashboard_widget(nonce) {
6060 wpsc_show_modal();
6061 var data = { action: "wpsc_get_new_dashboard_widget", _ajax_nonce: nonce };
6062 jQuery.post(supportcandy.ajax_url, data, function (response) {
6063 // Set to modal.
6064 jQuery(".wpsc-modal-header").text(response.title);
6065 jQuery(".wpsc-modal-body").html(response.body);
6066 jQuery(".wpsc-modal-footer").html(response.footer);
6067 // Display modal.
6068 wpsc_show_modal_inner_container();
6069 });
6070 }
6071
6072 /**
6073 * Set new dashboard widget
6074 */
6075 function wpsc_set_new_dashboard_widget(el) {
6076 var form = jQuery(".wpsc-add-new-dashboard-widget")[0];
6077 var dataform = new FormData(form);
6078 jQuery(el).text(supportcandy.translations.please_wait);
6079 jQuery
6080 .ajax({
6081 url: supportcandy.ajax_url,
6082 type: "POST",
6083 data: dataform,
6084 processData: false,
6085 contentType: false,
6086 })
6087 .done(function (res) {
6088 wpsc_close_modal();
6089 wpsc_get_dashboard_settings();
6090 });
6091 }
6092
6093 /**
6094 * Delete dashboard widget
6095 */
6096 function wpsc_delete_dashboard_widget(slug, nonce) {
6097 var flag = confirm(supportcandy.translations.confirm);
6098 if (!flag) {
6099 return;
6100 }
6101
6102 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
6103 var data = {
6104 action: "wpsc_delete_dashboard_widget",
6105 slug,
6106 _ajax_nonce: nonce,
6107 };
6108 jQuery.post(supportcandy.ajax_url, data, function (response) {
6109 wpsc_get_dashboard_settings();
6110 });
6111 }
6112
6113 /**
6114 * Sort dashboard widgets
6115 */
6116 function wpsc_set_dashboard_widget_load_order(slugs, nonce) {
6117 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
6118 var data = {
6119 action: "wpsc_set_dashboard_widget_load_order",
6120 slugs,
6121 _ajax_nonce: nonce,
6122 };
6123 jQuery.post(supportcandy.ajax_url, data, function (res) {
6124 wpsc_get_dashboard_widgets_settings();
6125 });
6126 }
6127
6128 /**
6129 * Toggle enable/disable status of a single dashboard widget
6130 */
6131 function wpsc_toggle_dashboard_widget_status(el, slug, nonce) {
6132 var checkbox = jQuery(el);
6133 var is_enable = checkbox.is(":checked") ? 1 : 0;
6134 var widget = checkbox.closest(".wpsc-setting-card");
6135
6136 var data = {
6137 action: "wpsc_toggle_dashboard_widget_status",
6138 slug,
6139 is_enable,
6140 _ajax_nonce: nonce,
6141 };
6142 jQuery.post(supportcandy.ajax_url, data, function () {
6143 widget.attr(
6144 "style",
6145 is_enable ? "" : "background-color:#eec7ca;color:#dc2222"
6146 );
6147 var total = jQuery(".wpsc-toggle-dashboard-widget").length;
6148 var checked = jQuery(".wpsc-toggle-dashboard-widget:checked").length;
6149 jQuery(".wpsc-toggle-all-dashboard-widgets").prop(
6150 "checked",
6151 total > 0 && total === checked
6152 );
6153 }).fail(function () {
6154 // Revert checkbox on failure.
6155 checkbox.prop("checked", !is_enable);
6156 });
6157 }
6158
6159 /**
6160 * Enable or disable all dashboard widgets at once
6161 */
6162 function wpsc_toggle_all_dashboard_widgets(el, nonce) {
6163 var checkbox = jQuery(el);
6164 var is_enable = checkbox.is(":checked") ? 1 : 0;
6165
6166 var data = {
6167 action: "wpsc_toggle_all_dashboard_widgets_status",
6168 is_enable,
6169 _ajax_nonce: nonce,
6170 };
6171 jQuery.post(supportcandy.ajax_url, data, function () {
6172 jQuery(".wpsc-toggle-dashboard-widget").prop("checked", !!is_enable);
6173 jQuery(".wpsc-setting-card").attr(
6174 "style",
6175 is_enable ? "" : "background-color:#eec7ca;color:#dc2222"
6176 );
6177 }).fail(function () {
6178 // Revert checkbox on failure.
6179 checkbox.prop("checked", !is_enable);
6180 });
6181 }
6182
6183 /**
6184 * Edit bashboard widget
6185 */
6186 function wpsc_get_edit_dashboard_card_widget(type, slug, nonce) {
6187 wpsc_show_modal();
6188 var data = {
6189 action: "wpsc_get_edit_dashboard_card_widget",
6190 type,
6191 slug,
6192 _ajax_nonce: nonce,
6193 };
6194 jQuery.post(supportcandy.ajax_url, data, function (response) {
6195 // Set to modal.
6196 jQuery(".wpsc-modal-header").text(response.title);
6197 jQuery(".wpsc-modal-body").html(response.body);
6198 jQuery(".wpsc-modal-footer").html(response.footer);
6199 // Display modal.
6200 wpsc_show_modal_inner_container();
6201 });
6202 }
6203
6204 /**
6205 * Set edit bashboard widget
6206 */
6207 function wpsc_set_edit_dashboard_card_widget(el) {
6208 var form = jQuery(".wpsc-frm-edit-dashboard-cards-widgets")[0];
6209 var dataform = new FormData(form);
6210
6211 if (dataform.get("label").trim() == "") {
6212 alert(supportcandy.translations.req_fields_missing);
6213 return;
6214 }
6215
6216 jQuery(".wpsc-modal-footer button").attr("disabled", true);
6217 jQuery(el).text(supportcandy.translations.please_wait);
6218
6219 jQuery
6220 .ajax({
6221 url: supportcandy.ajax_url,
6222 type: "POST",
6223 data: dataform,
6224 processData: false,
6225 contentType: false,
6226 })
6227 .done(function (res) {
6228 wpsc_close_modal();
6229 wpsc_get_dashboard_settings();
6230 });
6231 }
6232
6233 /**
6234 * Get appearence dashboard
6235 */
6236 function wpsc_get_ap_dashboard() {
6237 supportcandy.current_tab = "dashboard";
6238 jQuery(".wpsc-setting-tab-container button").removeClass("active");
6239 jQuery(
6240 ".wpsc-setting-tab-container button." + supportcandy.current_tab
6241 ).addClass("active");
6242
6243 window.history.replaceState(
6244 {},
6245 null,
6246 "admin.php?page=wpsc-settings&section=" +
6247 supportcandy.current_section +
6248 "&tab=" +
6249 supportcandy.current_tab
6250 );
6251 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
6252
6253 wpsc_scroll_top();
6254 var data = { action: "wpsc_get_ap_dashboard" };
6255 jQuery.post(supportcandy.ajax_url, data, function (response) {
6256 jQuery(".wpsc-setting-section-body").html(response);
6257 wpsc_reset_responsive_style();
6258 });
6259 }
6260
6261 /**
6262 * Set appearence dashboard
6263 */
6264 function wpsc_set_ap_dashboard(el) {
6265 var form = jQuery(".wpsc-frm-ap-dash")[0];
6266 var dataform = new FormData(form);
6267 jQuery(el).text(supportcandy.translations.please_wait);
6268 jQuery
6269 .ajax({
6270 url: supportcandy.ajax_url,
6271 type: "POST",
6272 data: dataform,
6273 processData: false,
6274 contentType: false,
6275 })
6276 .done(function (res) {
6277 wpsc_get_ap_dashboard();
6278 });
6279 }
6280
6281 /**
6282 * Reset appearence dashboard
6283 */
6284 function wpsc_reset_ap_dashboard(el, nonce) {
6285 jQuery(el).text(supportcandy.translations.please_wait);
6286 var data = { action: "wpsc_reset_ap_dashboard", _ajax_nonce: nonce };
6287 jQuery.post(supportcandy.ajax_url, data, function (res) {
6288 wpsc_get_ap_dashboard();
6289 });
6290 }
6291
6292 /**
6293 * Get customer profile
6294 *
6295 * @param {int} id
6296 */
6297 function wpsc_view_customer_detailed_info(customer_id, nonce) {
6298 jQuery(".wpsc-setting-section-body").html(supportcandy.loader_html);
6299 var data = {
6300 action: "wpsc_view_customer_detailed_info",
6301 customer_id,
6302 _ajax_nonce: nonce,
6303 };
6304 jQuery.post(supportcandy.ajax_url, data, function (res) {
6305 jQuery(".wpsc-setting-section-body").html(res);
6306 });
6307 }
6308
6309 function wpsc_update_live_agents() {
6310
6311 if (!supportcandy.ticketListIsIndividual) {
6312 return;
6313 }
6314 agent_id = jQuery("#wpsc-current-agent").val();
6315 if (!agent_id) {
6316 return;
6317 }
6318 if (typeof supportcandy.agent_collision === "undefined" || !supportcandy.agent_collision) {
6319 return;
6320 }
6321
6322 ticket_id = jQuery("#wpsc-current-ticket").val();
6323 var data = { action: 'wpsc_check_live_agents', agent_id, ticket_id, operation: 'leave', _ajax_nonce: supportcandy.nonce };
6324 jQuery.post(
6325 supportcandy.ajax_url,
6326 data,
6327 function (response) {
6328 }
6329 );
6330 }
6331
6332 /**
6333 * Get ticket list
6334 */
6335 function wpsc_get_archive_ticket_list(is_humbargar = false) {
6336
6337 supportcandy.current_section = "archive-ticket-list";
6338 if (is_humbargar) {
6339 wpsc_toggle_humbargar();
6340 }
6341
6342 var id = supportcandy.current_archived_ticket_id;
6343 if (id) {
6344 delete supportcandy.current_archived_ticket_id;
6345 wpsc_get_individual_archive_ticket(id);
6346 return;
6347 }
6348
6349 // set flag to differenciate between ticket list and individual ticket.
6350 supportcandy.ticketListIsIndividual = false;
6351
6352 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
6353 jQuery(
6354 ".wpsc-tickets-nav.archive-ticket-list, .wpsc-humbargar-menu-item.archive-ticket-list"
6355 ).addClass("active");
6356 jQuery(".wpsc-humbargar-title").html(
6357 supportcandy.humbargar_titles.archived_ticket_list
6358 );
6359
6360 window.history.replaceState(
6361 {},
6362 null,
6363 "admin.php?page=wpsc-archive-tickets&section=archive-ticket-list"
6364 );
6365 jQuery(".wpsc-body").html(supportcandy.loader_html);
6366
6367 wpsc_scroll_top();
6368
6369 var data = {
6370 action: "wpsc_get_archive_ticket_list",
6371 _ajax_nonce: supportcandy.nonce,
6372 is_frontend: supportcandy.is_frontend,
6373 };
6374 jQuery.post(supportcandy.ajax_url, data, function (response) {
6375 jQuery(".wpsc-body").html(response);
6376 wpsc_reset_responsive_style();
6377 });
6378 wpsc_delete_auto_draft();
6379 }
6380
6381 /**
6382 * Get individual ticket
6383 */
6384 function wpsc_get_individual_archive_ticket(id) {
6385 jQuery(".wpsc-tickets-nav, .wpsc-humbargar-menu-item").removeClass("active");
6386 jQuery(
6387 ".wpsc-tickets-nav.archive-ticket-list, .wpsc-humbargar-menu-item.archive-ticket-list"
6388 ).addClass("active");
6389 jQuery(".wpsc-humbargar-title").html(
6390 supportcandy.humbargar_titles.archived_ticket_list
6391 );
6392
6393 window.history.replaceState(
6394 {},
6395 null,
6396 "admin.php?page=wpsc-archive-tickets&section=archive-ticket-list&id=" + id
6397 );
6398 jQuery(".wpsc-body").html(supportcandy.loader_html);
6399
6400 wpsc_scroll_top();
6401
6402 // set flag to differenciate between ticket list and individual ticket.
6403 supportcandy.ticketListIsIndividual = true;
6404
6405 var data = {
6406 action: "wpsc_get_individual_archive_ticket",
6407 ticket_id: id,
6408 };
6409 jQuery.post(supportcandy.ajax_url, data, function (response) {
6410 jQuery(".wpsc-body").html(response);
6411 wpsc_reset_responsive_style();
6412 });
6413 }