PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
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
← All changes | framework/scripts.js +857 -406 3.3.8 → 3.5.4 View file →
@@ -336,11 +336,11 @@
336 336 typeof tinyMCE != "undefined" &&
337 337 tinyMCE.activeEditor &&
338 338 !tinyMCE.activeEditor.isHidden();
339 339 if (is_tinymce && tinymce.get("description")) {
340 - var description = tinyMCE.get("description").setContent("");
340 + tinyMCE.get("description").setContent("");
341 341 } else {
342 - var description = jQuery("#description").val("");
342 + jQuery("#description").val("");
343 343 }
344 344 wpsc_clear_saved_draft_reply(ticket_id);
345 345 }
346 346 }
@@ -376,12 +376,45 @@
376 376 });
377 377 }
378 378
379 379 /**
380 + * Get delete ticket
381 + */
382 +function wpsc_it_archive_ticket(ticket_id, nonce) {
383 + if (wpsc_is_description_text()) {
384 + if (!confirm(supportcandy.translations.warning_message)) {
385 + return;
386 + } else {
387 + var is_tinymce =
388 + typeof tinyMCE != "undefined" &&
389 + tinyMCE.activeEditor &&
390 + !tinyMCE.activeEditor.isHidden();
391 + if (is_tinymce && tinymce.get("description")) {
392 + var description = tinyMCE.get("description").setContent("");
393 + } else {
394 + var description = jQuery("#description").val("");
395 + }
396 + wpsc_clear_saved_draft_reply(ticket_id);
397 + }
398 + }
399 +
400 + var flag = confirm(supportcandy.translations.confirm);
401 + if (!flag) {
402 + return;
403 + }
404 +
405 + var data = { action: "wpsc_it_archive_ticket", ticket_id, _ajax_nonce: nonce };
406 + jQuery.post(supportcandy.ajax_url, data, function (response) {
407 + wpsc_get_ticket_list();
408 + wpsc_run_ajax_background_process();
409 + });
410 +}
411 +
412 +/**
380 413 * Delete permanently
381 414 */
382 415 function wpsc_it_delete_permanently(ticket_id, nonce) {
383 - var flag = confirm(supportcandy.translations.confirm);
416 + var flag = confirm(supportcandy.translations.delete_permanently);
384 417 if (!flag) {
385 418 return;
386 419 }
387 420
@@ -395,8 +428,37 @@
395 428 });
396 429 }
397 430
398 431 /**
432 + * Block/unblock notifications
433 + */
434 +function wpsc_it_block_unblock_notifications(ticketId, isBlock, nonce) {
435 +
436 + if (!ticketId || typeof isBlock !== 'boolean' || !nonce) {
437 + console.error('Invalid parameters passed to wpsc_it_block_unblock_notifications');
438 + return;
439 + }
440 +
441 + const message = isBlock
442 + ? supportcandy.translations.block_notifications
443 + : supportcandy.translations.unblock_notifications;
444 +
445 + if (!window.confirm(message)) {
446 + return;
447 + }
448 +
449 + var data = {
450 + action: 'wpsc_it_block_unblock_notifications',
451 + ticket_id: ticketId,
452 + is_block: isBlock ? 1 : 0,
453 + _ajax_nonce: nonce,
454 + };
455 + jQuery.post(supportcandy.ajax_url, data, function (response) {
456 + wpsc_get_individual_ticket(ticketId);
457 + });
458 +}
459 +
460 +/**
399 461 * Get edit ticket subject modal UI
400 462 */
401 463 function wpsc_it_get_edit_subject(ticket_id) {
402 464 wpsc_show_modal();
@@ -1239,12 +1301,16 @@
1239 1301 if (conditionalFields.length === 0) {
1240 1302 return;
1241 1303 }
1242 1304
1243 - jQuery('#wpsc-ct-submit').attr( 'disabled', true );
1244 - jQuery('.wpsc-ct-loader').html( supportcandy.inline_loader );
1245 - jQuery("select.create-as").attr( "disabled", true );
1305 + const callerId = Math.floor(Math.random() * 100000);
1306 + supportcandy.checkTffVisibityCallers =
1307 + supportcandy.checkTffVisibityCallers || [];
1308 + supportcandy.checkTffVisibityCallers.push(callerId);
1246 1309
1310 + jQuery(".wpsc-ct-loader").html(supportcandy.inline_loader);
1311 + jQuery("select.create-as").attr("disabled", true);
1312 +
1247 1313 var form = jQuery("form.wpsc-create-ticket")[0];
1248 1314 var dataform = new FormData(form);
1249 1315
1250 1316 var is_tinymce =
@@ -1276,16 +1342,22 @@
1276 1342 jQuery(".wpsc-tff." + key).removeClass("wpsc-hidden");
1277 1343 jQuery(".wpsc-tff." + key).addClass("wpsc-visible");
1278 1344 }
1279 1345 });
1280 - jQuery('#wpsc-ct-submit').removeAttr("disabled");
1281 - jQuery('.wpsc-ct-loader').html('');
1282 - jQuery("select.create-as").removeAttr( "disabled" );
1283 - }).fail(function(xhr, status, error) {
1284 - console.error('AJAX request failed:', status, error);
1285 - jQuery('#wpsc-ct-submit').removeAttr("disabled");
1286 - jQuery('.wpsc-ct-loader').html('');
1287 - jQuery("select.create-as").removeAttr( "disabled" );
1346 + jQuery(".wpsc-ct-loader").html("");
1347 + jQuery("select.create-as").removeAttr("disabled");
1348 + })
1349 + .fail(function (xhr, status, error) {
1350 + console.error("AJAX request failed:", status, error);
1351 + jQuery(".wpsc-ct-loader").html("");
1352 + jQuery("select.create-as").removeAttr("disabled");
1353 + })
1354 + .always(function () {
1355 + // remove callerId from supportcandy.checkTffVisibityCallers array
1356 + supportcandy.checkTffVisibityCallers =
1357 + supportcandy.checkTffVisibityCallers.filter(function (id) {
1358 + return id !== callerId;
1359 + });
1288 1360 });
1289 1361 }
1290 1362
1291 1363 /**
@@ -1316,24 +1388,26 @@
1316 1388
1317 1389 /**
1318 1390 * Change event for filter
1319 1391 */
1320 -function wpsc_tl_filter_change(el) {
1392 +function wpsc_tl_filter_change(el, type) {
1393 + const filterSlug = jQuery(el).val()?.trim();
1394 + const isTicketList = type === 'ticket_list';
1321 1395 supportcandy.prevFilter = supportcandy.ticketList.filters.filterSlug;
1322 - var filterSlug = jQuery(el).val().trim();
1323 - if (filterSlug != "custom") {
1324 - var filters = { filterSlug };
1325 - supportcandy.ticketList.filters = filters;
1326 - wpsc_get_tickets();
1327 - } else {
1328 - wpsc_tl_get_custom_filter();
1396 +
1397 + if (filterSlug === 'custom') {
1398 + wpsc_tl_get_custom_filter( type );
1399 + return;
1329 1400 }
1401 +
1402 + supportcandy.ticketList.filters = { filterSlug };
1403 + isTicketList ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1330 1404 }
1331 1405
1332 1406 /**
1333 1407 * Change ticket list page
1334 1408 */
1335 -function wpsc_tl_set_page(page) {
1409 +function wpsc_tl_set_page(page, type) {
1336 1410 switch (page) {
1337 1411 case "first":
1338 1412 if (supportcandy.ticketList.pagination.current_page == 1) {
1339 1413 return;
@@ -1367,24 +1441,24 @@
1367 1441 supportcandy.ticketList.filters.page_no =
1368 1442 supportcandy.ticketList.pagination.total_pages;
1369 1443 break;
1370 1444 }
1371 - wpsc_get_tickets();
1445 + type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1372 1446 }
1373 1447
1374 1448 /**
1375 1449 * Reset ticket list filters
1376 1450 */
1377 -function wpsc_tl_reset_filter() {
1451 +function wpsc_tl_reset_filter( type ) {
1378 1452 var filters = { filterSlug: "" };
1379 1453 supportcandy.ticketList.filters = filters;
1380 - wpsc_get_tickets();
1454 + type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1381 1455 }
1382 1456
1383 1457 /**
1384 1458 * Search input keyup
1385 1459 */
1386 -function wpsc_tl_search_keyup(e, el) {
1460 +function wpsc_tl_search_keyup(e, el, type) {
1387 1461 if (e.keyCode !== 13) {
1388 1462 return;
1389 1463 }
1390 1464 var search = jQuery(el).val().trim();
@@ -1389,15 +1463,15 @@
1389 1463 }
1390 1464 var search = jQuery(el).val().trim();
1391 1465 supportcandy.ticketList.filters.search = search;
1392 1466 supportcandy.ticketList.filters.page_no = 1;
1393 - wpsc_get_tickets();
1467 + type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1394 1468 }
1395 1469
1396 1470 /**
1397 1471 * Apply filters
1398 1472 */
1399 -function wpsc_tl_apply_filter_btn_click() {
1473 +function wpsc_tl_apply_filter_btn_click( type ) {
1400 1474 supportcandy.ticketList.filters.search = jQuery("input.wpsc-search-input")
1401 1475 .val()
1402 1476 .trim();
1403 1477 supportcandy.ticketList.filters.orderby = jQuery(
@@ -1406,29 +1480,48 @@
1406 1480 supportcandy.ticketList.filters.order = jQuery(
1407 1481 "select.wpsc-input-sort-order"
1408 1482 ).val();
1409 1483 supportcandy.ticketList.filters.page_no = 1;
1410 - wpsc_get_tickets();
1484 + type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1411 1485 }
1412 1486
1413 1487 /**
1488 + * Sort ticket list by clicking on a sortable column header.
1489 + * Toggles ASC/DESC when the same column is clicked again, otherwise
1490 + * defaults to ASC for the newly selected column.
1491 + */
1492 +function wpsc_tl_sort_column( slug, type ) {
1493 + var filters = supportcandy.ticketList.filters;
1494 + if ( filters.orderby === slug ) {
1495 + filters.order = filters.order === 'ASC' ? 'DESC' : 'ASC';
1496 + } else {
1497 + filters.orderby = slug;
1498 + filters.order = 'ASC';
1499 + }
1500 + filters.page_no = 1;
1501 + type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1502 +}
1503 +
1504 +/**
1414 1505 * Get custom filter UI
1415 1506 */
1416 -function wpsc_tl_get_custom_filter() {
1507 +function wpsc_tl_get_custom_filter( type ) {
1417 1508 wpsc_show_modal();
1418 - var data = {
1419 - action: "wpsc_get_tl_custom_filter",
1509 +
1510 + const isTicketList = type === 'ticket_list';
1511 + const action = isTicketList ? 'wpsc_get_tl_custom_filter' : 'wpsc_get_atl_custom_filter';
1512 +
1513 + const data = {
1514 + action,
1420 1515 _ajax_nonce: supportcandy.nonce,
1421 1516 };
1422 - if (supportcandy.ticketList.filters.filterSlug == "custom") {
1517 + if (supportcandy.ticketList.filters.filterSlug === 'custom') {
1423 1518 data.filters = supportcandy.ticketList.filters;
1424 1519 }
1425 1520 jQuery.post(supportcandy.ajax_url, data, function (response) {
1426 - // Set to modal.
1427 - jQuery(".wpsc-modal-header").text(response.title);
1428 - jQuery(".wpsc-modal-body").html(response.body);
1429 - jQuery(".wpsc-modal-footer").html(response.footer);
1430 - // Display modal.
1521 + jQuery('.wpsc-modal-header').text(response.title);
1522 + jQuery('.wpsc-modal-body').html(response.body);
1523 + jQuery('.wpsc-modal-footer').html(response.footer);
1431 1524 wpsc_show_modal_inner_container();
1432 1525 });
1433 1526 }
1434 1527
@@ -1434,9 +1527,10 @@
1434 1527
1435 1528 /**
1436 1529 * Apply custom filter
1437 1530 */
1438 -function wpsc_tl_apply_custom_filter(el) {
1531 +function wpsc_tl_apply_custom_filter(el, type) {
1532 +
1439 1533 var filters = wpsc_get_condition_json("custom_filters");
1440 1534 if (
1441 1535 filters.length === 0 ||
1442 1536 (filters.length === 1 && filters[0].length === 0)
@@ -1443,33 +1537,34 @@
1443 1537 ) {
1444 1538 alert(supportcandy.translations.req_fields_missing);
1445 1539 return;
1446 1540 }
1447 -
1541 +
1542 + const cust_filter = type === "ticket_list" ? "wpsc-tl-custom-filter" : "wpsc-atl-custom-filter";
1448 1543 filters = {
1449 1544 filterSlug: "custom",
1450 1545 "parent-filter": jQuery(
1451 - ".wpsc-tl-custom-filter select[name=parent-filter]"
1546 + "." + cust_filter + " select[name=parent-filter]"
1452 1547 ).val(),
1453 1548 filters: JSON.stringify(filters),
1454 - orderby: jQuery(".wpsc-tl-custom-filter select[name=sort-by]").val(),
1455 - order: jQuery(".wpsc-tl-custom-filter select[name=sort-order]").val(),
1549 + orderby: jQuery("." + cust_filter + " select[name=sort-by]").val(),
1550 + order: jQuery("." + cust_filter + " select[name=sort-order]").val(),
1456 1551 page_no: 1,
1457 1552 };
1553 + supportcandy.ticketList.filters = filters;
1458 1554
1459 - supportcandy.ticketList.filters = filters;
1460 1555 wpsc_close_modal();
1461 - wpsc_get_tickets();
1556 + type === "ticket_list" ? wpsc_get_tickets() : wpsc_get_archive_tickets();
1462 1557 }
1463 1558
1464 1559 /**
1465 1560 * Edit ticket list filter
1466 1561 */
1467 -function wpsc_tl_edit_filter() {
1562 +function wpsc_tl_edit_filter( type ) {
1468 1563 if (supportcandy.ticketList.filters.filterSlug == "custom") {
1469 - wpsc_tl_get_custom_filter();
1564 + wpsc_tl_get_custom_filter( type );
1470 1565 } else {
1471 - wpsc_tl_get_edit_saved_filter();
1566 + type === "ticket_list" ? wpsc_tl_get_edit_saved_filter() : wpsc_atl_get_edit_saved_filter();
1472 1567 }
1473 1568 }
1474 1569
1475 1570 /**
@@ -1606,9 +1701,9 @@
1606 1701
1607 1702 /**
1608 1703 * Delete saved filter
1609 1704 */
1610 -function wpsc_tl_delete_saved_filter() {
1705 +function wpsc_tl_delete_saved_filter( type ) {
1611 1706 var flag = confirm(supportcandy.translations.confirm);
1612 1707 if (!flag) {
1613 1708 return;
1614 1709 }
@@ -1821,12 +1916,12 @@
1821 1916 * Get thread info
1822 1917 *
1823 1918 * @param {*} thread_id
1824 1919 */
1825 -function wpsc_it_thread_info(el, ticket_id, thread_id, nonce) {
1920 +function wpsc_it_thread_info(el, ticket_id, thread_id, nonce, type = 'ticket_list') {
1826 1921 wpsc_show_modal();
1827 1922 var data = {
1828 - action: "wpsc_it_thread_info",
1923 + action: type === 'ticket_list' ? "wpsc_it_thread_info" : "wpsc_it_archive_thread_info",
1829 1924 thread_id,
1830 1925 ticket_id,
1831 1926 _ajax_nonce: nonce,
1832 1927 };
@@ -1892,17 +1987,33 @@
1892 1987 });
1893 1988 }
1894 1989
1895 1990 /**
1896 - * Thread expander
1991 + * Thread expander.
1897 1992 */
1993 +function wpsc_init_thread_expanders($threadTexts) {
1994 + $threadTexts.filter(".wpsc-collapsed").each(function () {
1995 + if (this.scrollHeight > this.clientHeight + 1) {
1996 + jQuery(this)
1997 + .parent()
1998 + .find(".wpsc-ticket-thread-expander")
1999 + .text(supportcandy.translations.view_more)
2000 + .show();
2001 + } else {
2002 + // Content already fits within the collapsed max-height; no need
2003 + // for an expander link.
2004 + jQuery(this).removeClass("wpsc-collapsed");
2005 + }
2006 + });
2007 +}
2008 +
1898 2009 function wpsc_ticket_thread_expander_toggle(el) {
1899 - var height = parseInt(jQuery(el).parent().find(".thread-text").height());
1900 - if (height === 100) {
1901 - jQuery(el).parent().find(".thread-text").height("auto");
2010 + var $threadText = jQuery(el).parent().find(".thread-text");
2011 + if ($threadText.hasClass("wpsc-collapsed")) {
2012 + $threadText.removeClass("wpsc-collapsed").addClass("wpsc-expanded");
1902 2013 jQuery(el).text(supportcandy.translations.view_less);
1903 2014 } else {
1904 - jQuery(el).parent().find(".thread-text").height(100);
2015 + $threadText.removeClass("wpsc-expanded").addClass("wpsc-collapsed");
1905 2016 jQuery(el).text(supportcandy.translations.view_more);
1906 2017 }
1907 2018 }
1908 2019
@@ -1960,17 +2071,23 @@
1960 2071 };
1961 2072 jQuery.post(supportcandy.ajax_url, data, function (response) {
1962 2073 jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove();
1963 2074 // add threads.
2075 + var $container = jQuery(".wpsc-it-thread-section-container");
2076 + var $before = $container.find(".thread-text");
1964 2077 if (supportcandy.reply_form_position === "top") {
1965 - jQuery(".wpsc-it-thread-section-container").append(response.threads);
2078 + $container.append(response.threads);
1966 2079 } else {
1967 2080 var scrollHeightBody = jQuery("body").prop("scrollHeight");
1968 2081 var windowScrollTop = jQuery(window).scrollTop();
1969 - jQuery(".wpsc-it-thread-section-container").prepend(response.threads);
2082 + $container.prepend(response.threads);
1970 2083 var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody;
1971 2084 jQuery(window).scrollTop(windowScrollTop + scrollDiff);
1972 2085 }
2086 + // Newly injected threads also need their "view more" state evaluated -
2087 + // the initial page-load script only runs once, so without this the
2088 + // lazily-loaded threads never get truncated/expandable.
2089 + wpsc_init_thread_expanders($container.find(".thread-text").not($before));
1973 2090 // show btn if there are more threads available.
1974 2091 if (response.has_next_page) {
1975 2092 supportcandy.threads.last_thread = response.last_thread;
1976 2093 oldBtnContainer.show();
@@ -2113,11 +2230,11 @@
2113 2230 });
2114 2231 }
2115 2232
2116 2233 /**
2117 - * Get bulk delete ticket
2234 + * Get bulk archive ticket
2118 2235 */
2119 -function wpsc_bulk_delete_tickets(nonce) {
2236 +function wpsc_bulk_archive_tickets(nonce) {
2120 2237 var items = jQuery(".wpsc-bulk-select:checked");
2121 2238 var checked = items.length === 0 ? false : true;
2122 2239 jQuery(".wpsc-bulk-selector").prop("checked", checked);
2123 2240 if (items.length != 0) {
@@ -2131,9 +2248,9 @@
2131 2248 return;
2132 2249 }
2133 2250
2134 2251 var data = {
2135 - action: "wpsc_bulk_delete_tickets",
2252 + action: "wpsc_bulk_archive_tickets",
2136 2253 ticket_ids,
2137 2254 _ajax_nonce: nonce,
2138 2255 };
2139 2256 jQuery.post(supportcandy.ajax_url, data, function (response) {
@@ -2143,8 +2260,38 @@
2143 2260 }
2144 2261 }
2145 2262
2146 2263 /**
2264 + * Get bulk permanently delete ticket
2265 + */
2266 +function wpsc_bulk_permanently_delete_tickets(nonce) {
2267 + var items = jQuery(".wpsc-bulk-select:checked");
2268 + var checked = items.length === 0 ? false : true;
2269 + jQuery(".wpsc-bulk-selector").prop("checked", checked);
2270 + if (items.length != 0) {
2271 + var ticket_ids = jQuery(".wpsc-bulk-select:checked")
2272 + .map(function () {
2273 + return this.value;
2274 + })
2275 + .get();
2276 + var flag = confirm(supportcandy.translations.delete_permanently);
2277 + if (!flag) {
2278 + return;
2279 + }
2280 +
2281 + var data = {
2282 + action: "wpsc_bulk_permanently_delete_tickets",
2283 + ticket_ids,
2284 + _ajax_nonce: nonce,
2285 + };
2286 + jQuery.post(supportcandy.ajax_url, data, function (response) {
2287 + wpsc_get_ticket_list();
2288 + wpsc_run_ajax_background_process();
2289 + });
2290 + }
2291 +}
2292 +
2293 +/**
2147 2294 * Set agent working hrs
2148 2295 */
2149 2296 function wpsc_set_agent_wh_hrs(el) {
2150 2297 const form = jQuery(".wpsc-frm-agent-wh")[0];
@@ -2159,9 +2306,9 @@
2159 2306 processData: false,
2160 2307 contentType: false,
2161 2308 })
2162 2309 .done(function (res) {
2163 - window.location.reload();
2310 + window.location.reload();
2164 2311 });
2165 2312 }
2166 2313
2167 2314 /**
@@ -2185,9 +2332,9 @@
2185 2332 processData: false,
2186 2333 contentType: false,
2187 2334 })
2188 2335 .done(function (res) {
2189 - window.location.reload();
2336 + window.location.reload();
2190 2337 });
2191 2338 }
2192 2339
2193 2340 /**
@@ -2212,9 +2359,9 @@
2212 2359 processData: false,
2213 2360 contentType: false,
2214 2361 })
2215 2362 .done(function (res) {
2216 - window.location.reload();
2363 + window.location.reload();
2217 2364 });
2218 2365 }
2219 2366
2220 2367 /**
@@ -2275,65 +2422,8 @@
2275 2422 });
2276 2423 }
2277 2424
2278 2425 /**
2279 - * Restore bulk tickets
2280 - */
2281 -function wpsc_bulk_restore_tickets(nonce) {
2282 - var items = jQuery(".wpsc-bulk-select:checked");
2283 - var checked = items.length === 0 ? false : true;
2284 - jQuery(".wpsc-bulk-selector").prop("checked", checked);
2285 - if (items.length != 0) {
2286 - var ticket_ids = jQuery(".wpsc-bulk-select:checked")
2287 - .map(function () {
2288 - return this.value;
2289 - })
2290 - .get();
2291 - var flag = confirm(supportcandy.translations.confirm);
2292 - if (!flag) {
2293 - return;
2294 - }
2295 - var data = {
2296 - action: "wpsc_bulk_restore_tickets",
2297 - ticket_ids,
2298 - _ajax_nonce: nonce,
2299 - };
2300 - jQuery.post(supportcandy.ajax_url, data, function (response) {
2301 - wpsc_get_ticket_list();
2302 - });
2303 - }
2304 -}
2305 -
2306 -/**
2307 - * Deletes bulk ticket permanentaly
2308 - */
2309 -function wpsc_bulk_delete_tickets_permanently(nonce) {
2310 - var items = jQuery(".wpsc-bulk-select:checked");
2311 - var checked = items.length === 0 ? false : true;
2312 - jQuery(".wpsc-bulk-selector").prop("checked", checked);
2313 - if (items.length != 0) {
2314 - var ticket_ids = jQuery(".wpsc-bulk-select:checked")
2315 - .map(function () {
2316 - return this.value;
2317 - })
2318 - .get();
2319 - var flag = confirm(supportcandy.translations.confirm);
2320 - if (!flag) {
2321 - return;
2322 - }
2323 -
2324 - var data = {
2325 - action: "wpsc_bulk_delete_tickets_permanently",
2326 - ticket_ids,
2327 - _ajax_nonce: nonce,
2328 - };
2329 - jQuery.post(supportcandy.ajax_url, data, function (response) {
2330 - wpsc_get_ticket_list();
2331 - });
2332 - }
2333 -}
2334 -
2335 -/**
2336 2426 * Clear dates
2337 2427 */
2338 2428 function wpsc_clear_date(el) {
2339 2429 jQuery(el).prev().val("");
@@ -2411,9 +2501,56 @@
2411 2501
2412 2502 /**
2413 2503 * Get tickets based on filter set
2414 2504 */
2505 +function wpsc_get_archive_tickets() {
2506 + jQuery(".wpsc-bulk-selector").prop("checked", false);
2507 + jQuery(".wpsc-ticket-list").html(supportcandy.loader_html);
2508 +
2509 + var data = {
2510 + action: "wpsc_get_archive_tickets",
2511 + _ajax_nonce: supportcandy.nonce,
2512 + is_frontend : supportcandy.is_frontend
2513 + };
2514 + if (
2515 + typeof supportcandy.ticketList != "undefined" &&
2516 + typeof supportcandy.ticketList.filters != "undefined"
2517 + ) {
2518 + data.filters = supportcandy.ticketList.filters;
2519 + }
2520 +
2521 + jQuery.post(supportcandy.ajax_url, data, function (response) {
2522 + jQuery(".wpsc-filter-actions").html(response.filter_actions);
2523 + jQuery(".wpsc-ticket-bulk-actions").html(response.bulk_actions);
2524 + jQuery(".wpsc-ticket-list").html(response.tickets);
2525 + jQuery(".wpsc-pagination-txt").text(response.pagination_str);
2526 + jQuery("select.wpsc-input-filter").val(response.filters.filterSlug);
2527 + jQuery("select.wpsc-input-sort-by").val(response.filters.orderby);
2528 + jQuery("select.wpsc-input-sort-order").val(response.filters.order);
2529 + jQuery("input.wpsc-search-input").val(response.filters.search);
2530 + if (response.pagination.total_pages > 1) {
2531 + jQuery(".wpsc-pagination-btn").show();
2532 + } else {
2533 + jQuery(".wpsc-pagination-btn").hide();
2534 + }
2535 + supportcandy.ticketList = {
2536 + filters: response.filters,
2537 + pagination: response.pagination,
2538 + };
2539 + });
2540 +}
2541 +
2542 +/**
2543 + * Get tickets based on filter set
2544 + */
2415 2545 function wpsc_get_tickets() {
2546 +
2547 + if (supportcandy.ticket_list_loading) {
2548 + return;
2549 + }
2550 +
2551 + supportcandy.ticket_list_loading = true;
2552 +
2416 2553 jQuery(".wpsc-bulk-selector").prop("checked", false);
2417 2554 jQuery(".wpsc-ticket-list").html(supportcandy.loader_html);
2418 2555
2419 2556 var data = {
@@ -2418,10 +2555,11 @@
2418 2555
2419 2556 var data = {
2420 2557 action: "wpsc_get_tickets",
2421 2558 _ajax_nonce: supportcandy.nonce,
2422 - is_frontend : supportcandy.is_frontend
2559 + is_frontend: supportcandy.is_frontend,
2423 2560 };
2561 +
2424 2562 if (
2425 2563 typeof supportcandy.ticketList != "undefined" &&
2426 2564 typeof supportcandy.ticketList.filters != "undefined"
2427 2565 ) {
@@ -2428,8 +2566,9 @@
2428 2566 data.filters = supportcandy.ticketList.filters;
2429 2567 }
2430 2568
2431 2569 jQuery.post(supportcandy.ajax_url, data, function (response) {
2570 +
2432 2571 jQuery(".wpsc-filter-actions").html(response.filter_actions);
2433 2572 jQuery(".wpsc-ticket-bulk-actions").html(response.bulk_actions);
2434 2573 jQuery(".wpsc-ticket-list").html(response.tickets);
2435 2574 jQuery(".wpsc-pagination-txt").text(response.pagination_str);
@@ -2436,17 +2575,22 @@
2436 2575 jQuery("select.wpsc-input-filter").val(response.filters.filterSlug);
2437 2576 jQuery("select.wpsc-input-sort-by").val(response.filters.orderby);
2438 2577 jQuery("select.wpsc-input-sort-order").val(response.filters.order);
2439 2578 jQuery("input.wpsc-search-input").val(response.filters.search);
2579 +
2440 2580 if (response.pagination.total_pages > 1) {
2441 2581 jQuery(".wpsc-pagination-btn").show();
2442 2582 } else {
2443 2583 jQuery(".wpsc-pagination-btn").hide();
2444 2584 }
2585 +
2445 2586 supportcandy.ticketList = {
2446 2587 filters: response.filters,
2447 2588 pagination: response.pagination,
2448 2589 };
2590 +
2591 + }).always(function(){
2592 + supportcandy.ticket_list_loading = false;
2449 2593 });
2450 2594 }
2451 2595
2452 2596 /**
@@ -2514,30 +2658,33 @@
2514 2658 /**
2515 2659 * Auto refresh
2516 2660 */
2517 2661 function wpsc_tl_auto_refresh() {
2518 - if (
2519 - supportcandy.current_section === "ticket-list" &&
2520 - !supportcandy.ticketListIsIndividual &&
2521 - supportcandy.tl_auto_refresh === 1 &&
2522 - !(
2523 - jQuery(".wpsc-bulk-select:checked").length ||
2524 - jQuery(".wpsc-search-input").is(":focus")
2525 - )
2526 - ) {
2527 - wpsc_get_tickets();
2662 +
2663 + if (supportcandy.tl_auto_refresh_started) {
2664 + return;
2665 + }
2666 +
2667 + supportcandy.tl_auto_refresh_started = true;
2668 +
2669 + function run_refresh() {
2670 +
2528 2671 if (
2529 - typeof supportcandy.tl_auto_refresh_schedule !== "undefined" &&
2530 - supportcandy.tl_auto_refresh_schedule == true
2672 + supportcandy.current_section === "ticket-list" &&
2673 + !supportcandy.ticketListIsIndividual &&
2674 + supportcandy.tl_auto_refresh === 1 &&
2675 + !(
2676 + jQuery(".wpsc-bulk-select:checked").length ||
2677 + jQuery(".wpsc-search-input").is(":focus")
2678 + )
2531 2679 ) {
2532 - return;
2680 + wpsc_get_tickets();
2533 2681 }
2534 - supportcandy.tl_auto_refresh_schedule = true;
2535 - setTimeout(function () {
2536 - supportcandy.tl_auto_refresh_schedule = false;
2537 - wpsc_tl_auto_refresh();
2538 - }, 60000);
2682 +
2683 + setTimeout(run_refresh, 60000);
2539 2684 }
2685 +
2686 + run_refresh();
2540 2687 }
2541 2688
2542 2689 /**
2543 2690 * User logout
@@ -2594,25 +2741,25 @@
2594 2741 /**
2595 2742 * Set edit customer info
2596 2743 */
2597 2744 function wpsc_set_edit_customer_info(el, id, nonce) {
2598 - var form = jQuery("form.frm-edit-customer-info")[0];
2599 - var dataform = new FormData(form);
2600 - jQuery(".wpsc-modal-footer button").attr("disabled", true);
2601 - jQuery(el).text(supportcandy.translations.please_wait);
2745 + var form = jQuery("form.frm-edit-customer-info")[0];
2746 + var dataform = new FormData(form);
2747 + jQuery(".wpsc-modal-footer button").attr("disabled", true);
2748 + jQuery(el).text(supportcandy.translations.please_wait);
2602 2749
2603 - jQuery.ajax(
2604 - {
2605 - url: supportcandy.ajax_url,
2606 - type: "POST",
2607 - data: dataform,
2608 - processData: false,
2609 - contentType: false,
2610 - }
2611 - ).done(function (res) {
2612 - wpsc_close_modal();
2613 - wpsc_scroll_top();
2614 - wpsc_view_customer_detailed_info( res.customer_id, res.nonce );
2750 + jQuery
2751 + .ajax({
2752 + url: supportcandy.ajax_url,
2753 + type: "POST",
2754 + data: dataform,
2755 + processData: false,
2756 + contentType: false,
2757 + })
2758 + .done(function (res) {
2759 + wpsc_close_modal();
2760 + wpsc_scroll_top();
2761 + wpsc_view_customer_detailed_info(res.customer_id, res.nonce);
2615 2762 });
2616 2763 }
2617 2764
2618 2765 /**
@@ -2716,108 +2863,156 @@
2716 2863 /**
2717 2864 * Dashboard - Get filter from and to dates based on duration slug
2718 2865 */
2719 2866 function wpsc_db_set_filter_duration_dates(duration) {
2867 + let dateStr = "";
2868 + let date = new Date();
2869 + let from_date, to_date;
2720 2870
2721 - let dateStr = '';
2722 - let date = new Date();
2723 - let from_date, to_date;
2724 -
2725 - switch (duration) {
2726 -
2727 - case 'today':
2728 - dateStr = date.toISOString().split('T')[0];
2871 + switch (duration) {
2872 + case "today":
2873 + dateStr = date.toISOString().split("T")[0];
2729 2874 date_from_to = {
2730 - 'from': dateStr,
2731 - 'to': dateStr
2875 + from: dateStr,
2876 + to: dateStr,
2732 2877 };
2733 2878 break;
2734 -
2735 - case 'yesterday':
2879 +
2880 + case "yesterday":
2736 2881 date.setDate(date.getDate() - 1);
2737 - dateStr = date.toISOString().split('T')[0];
2882 + dateStr = date.toISOString().split("T")[0];
2738 2883 date_from_to = {
2739 - 'from': dateStr,
2740 - 'to': dateStr
2884 + from: dateStr,
2885 + to: dateStr,
2741 2886 };
2742 2887 break;
2743 -
2744 - case 'this-week':
2888 +
2889 + case "this-week":
2745 2890 let firstDayOfWeek = date.getDay() === 0 ? 6 : date.getDay() - 1;
2746 2891 date.setDate(date.getDate() - firstDayOfWeek);
2747 - from_date = date.toISOString().split('T')[0];
2892 + from_date = date.toISOString().split("T")[0];
2748 2893 date.setDate(date.getDate() + 6);
2749 - to_date = date.toISOString().split('T')[0];
2894 + to_date = date.toISOString().split("T")[0];
2750 2895 date_from_to = {
2751 - 'from': from_date,
2752 - 'to': to_date
2896 + from: from_date,
2897 + to: to_date,
2753 2898 };
2754 2899 break;
2755 -
2756 - case 'last-week':
2900 +
2901 + case "last-week":
2757 2902 let firstDayOfLastWeek = date.getDay() === 0 ? 7 : date.getDay();
2758 2903 date.setDate(date.getDate() - firstDayOfLastWeek - 6);
2759 - from_date = date.toISOString().split('T')[0];
2904 + from_date = date.toISOString().split("T")[0];
2760 2905 date.setDate(date.getDate() + 6);
2761 - to_date = date.toISOString().split('T')[0];
2906 + to_date = date.toISOString().split("T")[0];
2762 2907 date_from_to = {
2763 - 'from': from_date,
2764 - 'to': to_date
2908 + from: from_date,
2909 + to: to_date,
2765 2910 };
2766 2911 break;
2767 -
2768 - case 'last-7':
2912 +
2913 + case "last-7":
2769 2914 date.setDate(date.getDate() - 1); // Exclude today
2770 - to_date = date.toISOString().split('T')[0];
2915 + to_date = date.toISOString().split("T")[0];
2771 2916 date.setDate(date.getDate() - 6); // Last 7 days from yesterday
2772 - from_date = date.toISOString().split('T')[0];
2917 + from_date = date.toISOString().split("T")[0];
2773 2918 date_from_to = {
2774 - 'from': from_date,
2775 - 'to': to_date
2919 + from: from_date,
2920 + to: to_date,
2776 2921 };
2777 2922 break;
2778 -
2779 - case 'last-30-days':
2923 +
2924 + case "last-30-days":
2780 2925 date.setDate(date.getDate() - 1); // Exclude today
2781 - to_date = date.toISOString().split('T')[0];
2926 + to_date = date.toISOString().split("T")[0];
2782 2927 date.setDate(date.getDate() - 29); // Last 30 days from yesterday
2783 - from_date = date.toISOString().split('T')[0];
2928 + from_date = date.toISOString().split("T")[0];
2784 2929 date_from_to = {
2785 - 'from': from_date,
2786 - 'to': to_date
2930 + from: from_date,
2931 + to: to_date,
2787 2932 };
2788 2933 break;
2789 -
2790 - case 'this-month':
2934 +
2935 + case "this-month":
2791 2936 let this_month_starts = new Date(date.getFullYear(), date.getMonth(), 1);
2792 - let this_month_ends = new Date(date.getFullYear(), date.getMonth() + 1, 0);
2937 + let this_month_ends = new Date(
2938 + date.getFullYear(),
2939 + date.getMonth() + 1,
2940 + 0
2941 + );
2793 2942 date_from_to = {
2794 - 'from': `${this_month_starts.getFullYear()}-${(this_month_starts.getMonth() + 1).toString().padStart(2, '0')}-${this_month_starts.getDate().toString().padStart(2, '0')}`,
2795 - 'to': `${this_month_ends.getFullYear()}-${(this_month_ends.getMonth() + 1).toString().padStart(2, '0')}-${this_month_ends.getDate().toString().padStart(2, '0')}`
2943 + from: `${this_month_starts.getFullYear()}-${(
2944 + this_month_starts.getMonth() + 1
2945 + )
2946 + .toString()
2947 + .padStart(2, "0")}-${this_month_starts
2948 + .getDate()
2949 + .toString()
2950 + .padStart(2, "0")}`,
2951 + to: `${this_month_ends.getFullYear()}-${(this_month_ends.getMonth() + 1)
2952 + .toString()
2953 + .padStart(2, "0")}-${this_month_ends
2954 + .getDate()
2955 + .toString()
2956 + .padStart(2, "0")}`,
2796 2957 };
2797 2958 break;
2798 2959
2799 - case 'last-month':
2960 + case "last-month":
2800 2961 date.setMonth(date.getMonth() - 1);
2801 2962 let last_month_starts = new Date(date.getFullYear(), date.getMonth(), 1);
2802 - let last_month_ends = new Date(date.getFullYear(), date.getMonth() + 1, 0);
2963 + let last_month_ends = new Date(
2964 + date.getFullYear(),
2965 + date.getMonth() + 1,
2966 + 0
2967 + );
2803 2968 date_from_to = {
2804 - 'from': `${last_month_starts.getFullYear()}-${(last_month_starts.getMonth() + 1).toString().padStart(2, '0')}-${last_month_starts.getDate().toString().padStart(2, '0')}`,
2805 - 'to': `${last_month_ends.getFullYear()}-${(last_month_ends.getMonth() + 1).toString().padStart(2, '0')}-${last_month_ends.getDate().toString().padStart(2, '0')}`
2969 + from: `${last_month_starts.getFullYear()}-${(
2970 + last_month_starts.getMonth() + 1
2971 + )
2972 + .toString()
2973 + .padStart(2, "0")}-${last_month_starts
2974 + .getDate()
2975 + .toString()
2976 + .padStart(2, "0")}`,
2977 + to: `${last_month_ends.getFullYear()}-${(last_month_ends.getMonth() + 1)
2978 + .toString()
2979 + .padStart(2, "0")}-${last_month_ends
2980 + .getDate()
2981 + .toString()
2982 + .padStart(2, "0")}`,
2806 2983 };
2807 2984 break;
2808 2985
2809 - case 'this-quarter':
2986 + case "this-quarter":
2810 2987 let this_quarter_month_starts = Math.floor(date.getMonth() / 3) * 3;
2811 - let quarter_start = new Date(date.getFullYear(), this_quarter_month_starts, 1);
2812 - let quarter_end = new Date(date.getFullYear(), this_quarter_month_starts + 3, 0);
2988 + let quarter_start = new Date(
2989 + date.getFullYear(),
2990 + this_quarter_month_starts,
2991 + 1
2992 + );
2993 + let quarter_end = new Date(
2994 + date.getFullYear(),
2995 + this_quarter_month_starts + 3,
2996 + 0
2997 + );
2813 2998 date_from_to = {
2814 - 'from': `${quarter_start.getFullYear()}-${(quarter_start.getMonth() + 1).toString().padStart(2, '0')}-${quarter_start.getDate().toString().padStart(2, '0')}`,
2815 - 'to': `${quarter_end.getFullYear()}-${(quarter_end.getMonth() + 1).toString().padStart(2, '0')}-${quarter_end.getDate().toString().padStart(2, '0')}`
2999 + from: `${quarter_start.getFullYear()}-${(quarter_start.getMonth() + 1)
3000 + .toString()
3001 + .padStart(2, "0")}-${quarter_start
3002 + .getDate()
3003 + .toString()
3004 + .padStart(2, "0")}`,
3005 + to: `${quarter_end.getFullYear()}-${(quarter_end.getMonth() + 1)
3006 + .toString()
3007 + .padStart(2, "0")}-${quarter_end
3008 + .getDate()
3009 + .toString()
3010 + .padStart(2, "0")}`,
2816 3011 };
2817 3012 break;
2818 -
2819 - case 'last-quarter':
3013 +
3014 + case "last-quarter":
2820 3015 let last_quarter_month_ends = Math.floor(date.getMonth() / 3) * 3 - 1; // End month of last quarter
2821 3016 let last_quarter_month_starts = last_quarter_month_ends - 2; // Start month of last quarter
2822 3017 if (last_quarter_month_ends < 0) {
2823 3018 last_quarter_month_ends += 12;
@@ -2822,31 +3017,53 @@
2822 3017 if (last_quarter_month_ends < 0) {
2823 3018 last_quarter_month_ends += 12;
2824 3019 last_quarter_month_starts += 12;
2825 3020 }
2826 - let last_quarter_start = new Date(date.getFullYear(), last_quarter_month_starts, 1);
2827 - let last_quarter_end = new Date(date.getFullYear(), last_quarter_month_ends + 1, 0);
3021 + let last_quarter_start = new Date(
3022 + date.getFullYear(),
3023 + last_quarter_month_starts,
3024 + 1
3025 + );
3026 + let last_quarter_end = new Date(
3027 + date.getFullYear(),
3028 + last_quarter_month_ends + 1,
3029 + 0
3030 + );
2828 3031 date_from_to = {
2829 - 'from': `${last_quarter_start.getFullYear()}-${(last_quarter_start.getMonth() + 1).toString().padStart(2, '0')}-${last_quarter_start.getDate().toString().padStart(2, '0')}`,
2830 - 'to': `${last_quarter_end.getFullYear()}-${(last_quarter_end.getMonth() + 1).toString().padStart(2, '0')}-${last_quarter_end.getDate().toString().padStart(2, '0')}`
3032 + from: `${last_quarter_start.getFullYear()}-${(
3033 + last_quarter_start.getMonth() + 1
3034 + )
3035 + .toString()
3036 + .padStart(2, "0")}-${last_quarter_start
3037 + .getDate()
3038 + .toString()
3039 + .padStart(2, "0")}`,
3040 + to: `${last_quarter_end.getFullYear()}-${(
3041 + last_quarter_end.getMonth() + 1
3042 + )
3043 + .toString()
3044 + .padStart(2, "0")}-${last_quarter_end
3045 + .getDate()
3046 + .toString()
3047 + .padStart(2, "0")}`,
2831 3048 };
2832 3049 break;
2833 -
2834 - case 'this-year':
3050 +
3051 + case "this-year":
2835 3052 date_from_to = {
2836 - 'from': `${date.getFullYear()}-01-01`,
2837 - 'to': `${date.getFullYear()}-12-31`
3053 + from: `${date.getFullYear()}-01-01`,
3054 + to: `${date.getFullYear()}-12-31`,
2838 3055 };
2839 3056 break;
2840 -
2841 - case 'last-year':
3057 +
3058 + case "last-year":
2842 3059 date_from_to = {
2843 - 'from': `${date.getFullYear() - 1}-01-01`,
2844 - 'to': `${date.getFullYear() - 1}-12-31`
3060 + from: `${date.getFullYear() - 1}-01-01`,
3061 + to: `${date.getFullYear() - 1}-12-31`,
2845 3062 };
2846 3063 break;
2847 3064 }
2848 - return date_from_to;
3065 + return date_from_to;
2849 3066 }
2850 3067
2851 3068 /**
2852 3069 * Get batches for async report loading
@@ -2851,153 +3068,144 @@
2851 3068 /**
2852 3069 * Get batches for async report loading
2853 3070 */
2854 3071 function wpsc_rp_get_baches(fromDate, toDate) {
3072 + let diffTime = Math.abs(toDate - fromDate);
3073 + let diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1;
2855 3074
2856 - let diffTime = Math.abs( toDate - fromDate );
2857 - let diffDays = Math.ceil( diffTime / (1000 * 60 * 60 * 24) ) + 1;
3075 + let batches = [];
3076 + let batchData = [];
2858 3077
2859 - let batches = [];
2860 - let batchData = [];
3078 + if (diffDays == 1) {
3079 + // one day.
2861 3080
2862 - if (diffDays == 1) { // one day.
3081 + for (var i = 0; i <= 23; i++) {
3082 + var hr = String(i);
3083 + hr = hr.length == 1 ? "0" + hr : hr;
3084 + batchData.push({
3085 + fromDate: fromDate.toISOString().split("T")[0] + " " + hr + ":00:00",
3086 + toDate: fromDate.toISOString().split("T")[0] + " " + hr + ":59:59",
3087 + durationType: "day",
3088 + });
3089 + }
3090 + } else if (diffDays <= 31) {
3091 + // days.
2863 3092
2864 - for (var i = 0; i <= 23; i++) {
3093 + do {
3094 + batchData.push({
3095 + fromDate: fromDate.toISOString().split("T")[0] + " 00:00:00",
3096 + toDate: fromDate.toISOString().split("T")[0] + " 23:59:59",
3097 + durationType: "days",
3098 + });
3099 + fromDate.setDate(fromDate.getDate() + 1);
3100 + } while (fromDate <= toDate);
3101 + } else if (diffDays <= 180) {
3102 + // weeks.
2865 3103
2866 - var hr = String( i );
2867 - hr = hr.length == 1 ? '0' + hr : hr;
2868 - batchData.push(
2869 - {
2870 - fromDate: fromDate.toISOString().split('T')[0] + ' ' + hr + ':00:00',
2871 - toDate: fromDate.toISOString().split('T')[0] + ' ' + hr + ':59:59',
2872 - durationType: 'day'
2873 - }
2874 - );
2875 - }
3104 + var from = fromDate.toISOString().split("T")[0];
3105 + fromDate.setDate(fromDate.getDate() + (7 - fromDate.getDay()));
3106 + batchData.push({
3107 + fromDate: from + " 00:00:00",
3108 + toDate: fromDate.toISOString().split("T")[0] + " 23:59:59",
3109 + durationType: "weeks",
3110 + });
3111 + do {
3112 + fromDate.setDate(fromDate.getDate() + 1);
3113 + var from = new Date(fromDate.toLocaleDateString("en-CA"));
3114 + fromDate.setDate(fromDate.getDate() + 6);
3115 + var to = new Date(fromDate.toLocaleDateString("en-CA"));
3116 + to = toDate < to ? new Date(toDate.toLocaleDateString("en-CA")) : to;
3117 + batchData.push({
3118 + fromDate: from.toISOString().split("T")[0] + " 00:00:00",
3119 + toDate: to.toISOString().split("T")[0] + " 23:59:59",
3120 + durationType: "weeks",
3121 + });
3122 + } while (fromDate < toDate);
3123 + } else if (diffDays <= 720) {
3124 + // months.
2876 3125
2877 - } else if (diffDays <= 31) { // days.
3126 + // convert toDate from local to UTC.
3127 + toDate = new Date(
3128 + toDate.getFullYear(),
3129 + toDate.getMonth(),
3130 + toDate.getDate()
3131 + );
2878 3132
2879 - do {
2880 - batchData.push(
2881 - {
2882 - fromDate: fromDate.toISOString().split('T')[0] + ' 00:00:00',
2883 - toDate: fromDate.toISOString().split('T')[0] + ' 23:59:59',
2884 - durationType: 'days'
2885 - }
2886 - );
2887 - fromDate.setDate( fromDate.getDate() + 1 );
2888 - } while (fromDate <= toDate);
3133 + var from = fromDate.toISOString().split("T")[0];
3134 + if (fromDate.getMonth() == 11) {
3135 + fromDate = new Date(fromDate.getFullYear(), 11, 31);
3136 + } else {
3137 + fromDate = new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0);
3138 + }
3139 + batchData.push({
3140 + fromDate: from + " 00:00:00",
3141 + toDate: fromDate.toISOString().split("T")[0] + " 23:59:59",
3142 + durationType: "months",
3143 + });
3144 + do {
3145 + fromDate.setDate(fromDate.getDate() + 1);
3146 + var from = new Date(fromDate.toLocaleDateString("en-CA"));
3147 + if (fromDate.getMonth() == 11) {
3148 + fromDate = new Date(fromDate.getFullYear(), 11, 31);
3149 + } else {
3150 + fromDate = new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0);
3151 + }
3152 + var to = new Date(fromDate.toLocaleDateString("en-CA"));
3153 + to = toDate < to ? new Date(toDate.toLocaleDateString("en-CA")) : to;
3154 + batchData.push({
3155 + fromDate: from.toISOString().split("T")[0] + " 00:00:00",
3156 + toDate: to.toISOString().split("T")[0] + " 23:59:59",
3157 + durationType: "months",
3158 + });
3159 + } while (fromDate < toDate);
3160 + } else {
3161 + // years.
2889 3162
2890 - } else if (diffDays <= 180) { // weeks.
3163 + // convert toDate from local to UTC.
3164 + toDate = new Date(
3165 + toDate.getFullYear(),
3166 + toDate.getMonth(),
3167 + toDate.getDate()
3168 + );
2891 3169
2892 - var from = fromDate.toISOString().split('T')[0];
2893 - fromDate.setDate( fromDate.getDate() + (7 - fromDate.getDay()) );
2894 - batchData.push(
2895 - {
2896 - fromDate: from + ' 00:00:00',
2897 - toDate: fromDate.toISOString().split('T')[0] + ' 23:59:59',
2898 - durationType: 'weeks'
2899 - }
2900 - );
2901 - do {
2902 - fromDate.setDate( fromDate.getDate() + 1 );
2903 - var from = new Date( fromDate.toLocaleDateString( 'en-CA' ) );
2904 - fromDate.setDate( fromDate.getDate() + 6 );
2905 - var to = new Date( fromDate.toLocaleDateString( 'en-CA' ) );
2906 - to = toDate < to ? new Date( toDate.toLocaleDateString( 'en-CA' ) ) : to;
2907 - batchData.push(
2908 - {
2909 - fromDate: from.toISOString().split('T')[0] + ' 00:00:00',
2910 - toDate: to.toISOString().split('T')[0] + ' 23:59:59',
2911 - durationType: 'weeks'
2912 - }
2913 - );
2914 - } while (fromDate < toDate);
3170 + var from = fromDate.toISOString().split("T")[0];
3171 + fromDate = new Date(fromDate.getFullYear(), 11, 31);
3172 + batchData.push({
3173 + fromDate: from + " 00:00:00",
3174 + toDate: fromDate.toISOString().split("T")[0] + " 23:59:59",
3175 + durationType: "years",
3176 + });
3177 + do {
3178 + fromDate.setDate(fromDate.getDate() + 1);
3179 + var from = new Date(fromDate.toLocaleDateString("en-CA"));
3180 + fromDate = new Date(fromDate.getFullYear(), 11, 31);
3181 + var to = new Date(fromDate.toLocaleDateString("en-CA"));
3182 + to = toDate < to ? new Date(toDate.toLocaleDateString("en-CA")) : to;
3183 + batchData.push({
3184 + fromDate: from.toISOString().split("T")[0] + " 00:00:00",
3185 + toDate: to.toISOString().split("T")[0] + " 23:59:59",
3186 + durationType: "years",
3187 + });
3188 + } while (fromDate < toDate);
3189 + }
2915 3190
2916 - } else if (diffDays <= 720) { // months.
3191 + // devide into batches of 5.
3192 + var batchLength = batchData.length;
3193 + for (var i = 0; i < batchLength; i = i + 5) {
3194 + var batch = [];
3195 + var counter = 0;
3196 + do {
3197 + var index = i + counter;
3198 + if (index == batchLength) {
3199 + break;
3200 + }
3201 + batch.push(batchData[index]);
3202 + counter++;
3203 + } while (counter < 5);
3204 + batches.push(batch);
3205 + }
2917 3206
2918 - // convert toDate from local to UTC.
2919 - toDate = new Date( toDate.getFullYear(), toDate.getMonth(), toDate.getDate() );
2920 -
2921 - var from = fromDate.toISOString().split('T')[0];
2922 - if (fromDate.getMonth() == 11) {
2923 - fromDate = new Date( fromDate.getFullYear(), 11, 31 );
2924 - } else {
2925 - fromDate = new Date( fromDate.getFullYear(), fromDate.getMonth() + 1, 0 );
2926 - }
2927 - batchData.push(
2928 - {
2929 - fromDate: from + ' 00:00:00',
2930 - toDate: fromDate.toISOString().split('T')[0] + ' 23:59:59',
2931 - durationType: 'months'
2932 - }
2933 - );
2934 - do {
2935 - fromDate.setDate( fromDate.getDate() + 1 );
2936 - var from = new Date( fromDate.toLocaleDateString( 'en-CA' ) );
2937 - if (fromDate.getMonth() == 11) {
2938 - fromDate = new Date( fromDate.getFullYear(), 11, 31 );
2939 - } else {
2940 - fromDate = new Date( fromDate.getFullYear(), fromDate.getMonth() + 1, 0 );
2941 - }
2942 - var to = new Date( fromDate.toLocaleDateString( 'en-CA' ) );
2943 - to = toDate < to ? new Date( toDate.toLocaleDateString( 'en-CA' ) ) : to;
2944 - batchData.push(
2945 - {
2946 - fromDate: from.toISOString().split('T')[0] + ' 00:00:00',
2947 - toDate: to.toISOString().split('T')[0] + ' 23:59:59',
2948 - durationType: 'months'
2949 - }
2950 - );
2951 - } while (fromDate < toDate);
2952 -
2953 - } else { // years.
2954 -
2955 - // convert toDate from local to UTC.
2956 - toDate = new Date( toDate.getFullYear(), toDate.getMonth(), toDate.getDate() );
2957 -
2958 - var from = fromDate.toISOString().split('T')[0];
2959 - fromDate = new Date( fromDate.getFullYear(), 11, 31 );
2960 - batchData.push(
2961 - {
2962 - fromDate: from + ' 00:00:00',
2963 - toDate: fromDate.toISOString().split('T')[0] + ' 23:59:59',
2964 - durationType: 'years'
2965 - }
2966 - );
2967 - do {
2968 - fromDate.setDate( fromDate.getDate() + 1 );
2969 - var from = new Date( fromDate.toLocaleDateString( 'en-CA' ) );
2970 - fromDate = new Date( fromDate.getFullYear(), 11, 31 );
2971 - var to = new Date( fromDate.toLocaleDateString( 'en-CA' ) );
2972 - to = toDate < to ? new Date( toDate.toLocaleDateString( 'en-CA' ) ) : to;
2973 - batchData.push(
2974 - {
2975 - fromDate: from.toISOString().split('T')[0] + ' 00:00:00',
2976 - toDate: to.toISOString().split('T')[0] + ' 23:59:59',
2977 - durationType: 'years'
2978 - }
2979 - );
2980 - } while (fromDate < toDate);
2981 - }
2982 -
2983 - // devide into batches of 5.
2984 - var batchLength = batchData.length;
2985 - for (var i = 0; i < batchLength; i = i + 5) {
2986 - var batch = [];
2987 - var counter = 0;
2988 - do {
2989 - var index = i + counter;
2990 - if (index == batchLength) {
2991 - break;
2992 - }
2993 - batch.push( batchData[index] );
2994 - counter++;
2995 - } while (counter < 5);
2996 - batches.push( batch );
2997 - }
2998 -
2999 - return batches;
3207 + return batches;
3000 3208 }
3001 3209
3002 3210 function wpsc_generate_random_color() {
3003 3211 var minLuminance = 0.7;
@@ -3002,53 +3210,53 @@
3002 3210 function wpsc_generate_random_color() {
3003 3211 var minLuminance = 0.7;
3004 3212
3005 3213 do {
3006 - var color = Math.floor(Math.random() * 16777216); // 0x000000 to 0xFFFFFF
3007 - var red = (color >> 16) & 0xFF;
3008 - var green = (color >> 8) & 0xFF;
3009 - var blue = color & 0xFF;
3214 + var color = Math.floor(Math.random() * 16777216); // 0x000000 to 0xFFFFFF
3215 + var red = (color >> 16) & 0xff;
3216 + var green = (color >> 8) & 0xff;
3217 + var blue = color & 0xff;
3010 3218
3011 - // Calculate luminance (brightness).
3012 - var luminance = (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
3013 -
3219 + // Calculate luminance (brightness).
3220 + var luminance = (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
3014 3221 } while (luminance < minLuminance);
3015 3222
3016 - return '#' + color.toString(16).toUpperCase();
3223 + return "#" + color.toString(16).toUpperCase();
3017 3224 }
3018 3225
3019 3226 // onclick load respective card ticket list
3020 3227 function wpsc_get_dbc_ticket_list(element, card) {
3021 -
3022 - var count = parseInt( jQuery( element ).find('.wpsc-dbc-count').text(), 10);
3023 - if ( count === 0 ) {
3024 - return;
3025 - }
3026 - var data = { action: 'wpsc_dash_card_count_filter', card : card, view: supportcandy.is_frontend, _ajax_nonce: supportcandy.nonce };
3027 - jQuery.post(
3028 - supportcandy.ajax_url,
3029 - data,
3030 - function (response) {
3031 - if( response.url ) {
3032 - window.location = response.url;
3033 - }
3034 - }
3035 - );
3228 + var count = parseInt(jQuery(element).find(".wpsc-dbc-count").text(), 10);
3229 + if (count === 0) {
3230 + return;
3231 + }
3232 + var data = {
3233 + action: "wpsc_dash_card_count_filter",
3234 + card: card,
3235 + view: supportcandy.is_frontend,
3236 + _ajax_nonce: supportcandy.nonce,
3237 + };
3238 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3239 + if (response.url) {
3240 + window.location = response.url;
3241 + }
3242 + });
3036 3243 }
3037 3244
3038 3245 // onclick load respective card ticket list
3039 3246 function wpsc_get_agent_status_ticket_list(agent_id, status_id, nonce) {
3040 -
3041 - var data = { action: 'wpsc_get_agent_status_ticket_list', agent_id : agent_id, status_id : status_id, view: supportcandy.is_frontend, _ajax_nonce: nonce };
3042 - jQuery.post(
3043 - supportcandy.ajax_url,
3044 - data,
3045 - function (response) {
3046 - if( response.url ) {
3047 - window.location = response.url;
3048 - }
3049 - }
3050 - );
3247 + var data = {
3248 + action: "wpsc_get_agent_status_ticket_list",
3249 + agent_id: agent_id,
3250 + status_id: status_id,
3251 + view: supportcandy.is_frontend,
3252 + _ajax_nonce: nonce,
3253 + };
3254 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3255 + if (response.url) {
3256 + window.location = response.url;
3257 + }
3258 + });
3051 3259 }
3052 3260
3053 3261 /**
3054 3262 * Refresh tags list
@@ -3053,19 +3261,14 @@
3053 3261 /**
3054 3262 * Refresh tags list
3055 3263 */
3056 3264 function wpsc_it_refresh_tags(ticket_id) {
3265 + jQuery(".wpsc-it-tag-body").html(supportcandy.loader_html);
3057 3266
3058 - jQuery( '.wpsc-it-tag-body' ).html( supportcandy.loader_html );
3059 -
3060 - var data = { action: 'wpsc_it_refresh_tags', ticket_id };
3061 - jQuery.post(
3062 - supportcandy.ajax_url,
3063 - data,
3064 - function (res) {
3065 - jQuery( '.wpsc-it-tag-body' ).html( res );
3066 - }
3067 - );
3267 + var data = { action: "wpsc_it_refresh_tags", ticket_id };
3268 + jQuery.post(supportcandy.ajax_url, data, function (res) {
3269 + jQuery(".wpsc-it-tag-body").html(res);
3270 + });
3068 3271 }
3069 3272
3070 3273 /**
3071 3274 * View user wordpress profile
@@ -3073,16 +3276,264 @@
3073 3276 function wpsc_wp_user_profile(el, ticket_id, nonce) {
3074 3277 var data = {
3075 3278 action: "wpsc_wp_user_profile",
3076 3279 ticket_id,
3280 + _ajax_nonce: nonce,
3281 + };
3282 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3283 + if (response.url) {
3284 + window.open(response.url, "_blank");
3285 + }
3286 + });
3287 +}
3288 +
3289 +/**
3290 + * Restore archived ticket
3291 + */
3292 +function wpsc_it_restore_archived(ticket_id, nonce) {
3293 +
3294 + if (!confirm(supportcandy.translations.confirm)){
3295 + return;
3296 + }
3297 +
3298 + var data = {
3299 + action: "wpsc_it_restore_archived",
3300 + ticket_id,
3077 3301 _ajax_nonce: nonce
3078 3302 };
3303 +
3079 3304 jQuery.post(
3080 3305 supportcandy.ajax_url,
3081 3306 data,
3082 3307 function (response) {
3083 - if (response.url) {
3084 - window.open(response.url, "_blank");
3085 - }
3308 + wpsc_get_archive_ticket_list();
3086 3309 }
3087 3310 );
3088 3311 }
3312 +
3313 +/**
3314 + * Get refresh current ticket
3315 + */
3316 +function wpsc_it_archive_ab_refresh(ticket_id) {
3317 + if (wpsc_is_description_text()) {
3318 + if (confirm(supportcandy.translations.confirm)) {
3319 + wpsc_clear_saved_draft_reply(ticket_id);
3320 + } else {
3321 + return;
3322 + }
3323 + }
3324 +
3325 + wpsc_get_individual_archive_ticket(ticket_id);
3326 +}
3327 +
3328 +/**
3329 + * Load older threads
3330 + */
3331 +function wpsc_load_older_archive_threads(el, ticket_id) {
3332 + if (supportcandy.reply_form_position === "top") {
3333 + jQuery(".wpsc-it-thread-section-container").append(
3334 + supportcandy.loader_html
3335 + );
3336 + } else {
3337 + jQuery(".wpsc-it-thread-section-container").prepend(
3338 + supportcandy.loader_html
3339 + );
3340 + }
3341 +
3342 + var oldBtnContainer = jQuery(el).parent();
3343 + oldBtnContainer.hide();
3344 +
3345 + var data = {
3346 + action: "wpsc_load_older_archive_threads",
3347 + ticket_id,
3348 + last_thread: supportcandy.threads.last_thread,
3349 + };
3350 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3351 + jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove();
3352 + // add threads.
3353 + var $container = jQuery(".wpsc-it-thread-section-container");
3354 + var $before = $container.find(".thread-text");
3355 + if (supportcandy.reply_form_position === "top") {
3356 + $container.append(response.threads);
3357 + } else {
3358 + var scrollHeightBody = jQuery("body").prop("scrollHeight");
3359 + var windowScrollTop = jQuery(window).scrollTop();
3360 + $container.prepend(response.threads);
3361 + var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody;
3362 + jQuery(window).scrollTop(windowScrollTop + scrollDiff);
3363 + }
3364 + // Newly injected threads also need their "view more" state evaluated -
3365 + // the initial page-load script only runs once, so without this the
3366 + // lazily-loaded threads never get truncated/expandable.
3367 + wpsc_init_thread_expanders($container.find(".thread-text").not($before));
3368 + // show btn if there are more threads available.
3369 + if (response.has_next_page) {
3370 + supportcandy.threads.last_thread = response.last_thread;
3371 + oldBtnContainer.show();
3372 + }
3373 + });
3374 +}
3375 +
3376 +
3377 +/**
3378 + * Delete permanently
3379 + */
3380 +function wpsc_iat_delete_permanently(ticket_id, nonce) {
3381 + var flag = confirm(supportcandy.translations.delete_permanently);
3382 + if (!flag) {
3383 + return;
3384 + }
3385 +
3386 + var data = {
3387 + action: "wpsc_iat_delete_permanently",
3388 + ticket_id,
3389 + _ajax_nonce: nonce,
3390 + };
3391 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3392 + wpsc_get_archive_ticket_list();
3393 + });
3394 +}
3395 +
3396 +/**
3397 + * Get bulk delete archive ticket
3398 + */
3399 +function wpsc_bulk_delete_archive_tickets(nonce) {
3400 + var items = jQuery(".wpsc-bulk-select:checked");
3401 + var checked = items.length === 0 ? false : true;
3402 + jQuery(".wpsc-bulk-selector").prop("checked", checked);
3403 + if (items.length != 0) {
3404 + var ticket_ids = jQuery(".wpsc-bulk-select:checked")
3405 + .map(function () {
3406 + return this.value;
3407 + })
3408 + .get();
3409 + var flag = confirm(supportcandy.translations.delete_permanently);
3410 + if (!flag) {
3411 + return;
3412 + }
3413 +
3414 + var data = {
3415 + action: "wpsc_bulk_delete_archive_tickets",
3416 + ticket_ids,
3417 + _ajax_nonce: nonce,
3418 + };
3419 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3420 + wpsc_get_archive_ticket_list();
3421 + wpsc_run_ajax_background_process();
3422 + });
3423 + }
3424 +}
3425 +
3426 +/**
3427 + * Restore bulk archive tickets
3428 + */
3429 +function wpsc_bulk_restore_archive_tickets(nonce) {
3430 + var items = jQuery(".wpsc-bulk-select:checked");
3431 + var checked = items.length === 0 ? false : true;
3432 + jQuery(".wpsc-bulk-selector").prop("checked", checked);
3433 + if (items.length != 0) {
3434 + var ticket_ids = jQuery(".wpsc-bulk-select:checked")
3435 + .map(function () {
3436 + return this.value;
3437 + })
3438 + .get();
3439 + var flag = confirm(supportcandy.translations.confirm);
3440 + if (!flag) {
3441 + return;
3442 + }
3443 + var data = {
3444 + action: "wpsc_bulk_restore_archive_tickets",
3445 + ticket_ids,
3446 + _ajax_nonce: nonce,
3447 + };
3448 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3449 + wpsc_get_archive_ticket_list();
3450 + });
3451 + }
3452 +}
3453 +
3454 +/**
3455 + * Get bulk archive ticket
3456 + */
3457 +function wpsc_bulk_delete_tickets(nonce) {
3458 + var items = jQuery(".wpsc-bulk-select:checked");
3459 + var checked = items.length === 0 ? false : true;
3460 + jQuery(".wpsc-bulk-selector").prop("checked", checked);
3461 + if (items.length != 0) {
3462 + var ticket_ids = jQuery(".wpsc-bulk-select:checked")
3463 + .map(function () {
3464 + return this.value;
3465 + })
3466 + .get();
3467 + var flag = confirm(supportcandy.translations.confirm);
3468 + if (!flag) {
3469 + return;
3470 + }
3471 +
3472 + var data = {
3473 + action: "wpsc_bulk_delete_tickets",
3474 + ticket_ids,
3475 + _ajax_nonce: nonce,
3476 + };
3477 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3478 + wpsc_get_ticket_list();
3479 + wpsc_run_ajax_background_process();
3480 + });
3481 + }
3482 +}
3483 +
3484 +/**
3485 + * Restore bulk tickets
3486 + */
3487 +function wpsc_bulk_restore_tickets(nonce) {
3488 + var items = jQuery(".wpsc-bulk-select:checked");
3489 + var checked = items.length === 0 ? false : true;
3490 + jQuery(".wpsc-bulk-selector").prop("checked", checked);
3491 + if (items.length != 0) {
3492 + var ticket_ids = jQuery(".wpsc-bulk-select:checked")
3493 + .map(function () {
3494 + return this.value;
3495 + })
3496 + .get();
3497 + var flag = confirm(supportcandy.translations.confirm);
3498 + if (!flag) {
3499 + return;
3500 + }
3501 + var data = {
3502 + action: "wpsc_bulk_restore_tickets",
3503 + ticket_ids,
3504 + _ajax_nonce: nonce,
3505 + };
3506 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3507 + wpsc_get_ticket_list();
3508 + });
3509 + }
3510 +}
3511 +
3512 +/**
3513 + * Deletes bulk ticket permanentaly
3514 + */
3515 +function wpsc_bulk_delete_tickets_permanently(nonce) {
3516 + var items = jQuery(".wpsc-bulk-select:checked");
3517 + var checked = items.length === 0 ? false : true;
3518 + jQuery(".wpsc-bulk-selector").prop("checked", checked);
3519 + if (items.length != 0) {
3520 + var ticket_ids = jQuery(".wpsc-bulk-select:checked")
3521 + .map(function () {
3522 + return this.value;
3523 + })
3524 + .get();
3525 + var flag = confirm(supportcandy.translations.confirm);
3526 + if (!flag) {
3527 + return;
3528 + }
3529 +
3530 + var data = {
3531 + action: "wpsc_bulk_delete_tickets_permanently",
3532 + ticket_ids,
3533 + _ajax_nonce: nonce,
3534 + };
3535 + jQuery.post(supportcandy.ajax_url, data, function (response) {
3536 + wpsc_get_ticket_list();
3537 + });
3538 + }
3539 +}