| @@ -326,8 +326,60 @@ | ||
| 326 | 326 | |
| 327 | 327 | /** |
| 328 | 328 | * Get delete ticket |
| 329 | 329 | */ |
| 330 | +function wpsc_it_delete_ticket(ticket_id, nonce) { | |
| 331 | + if (wpsc_is_description_text()) { | |
| 332 | + if (!confirm(supportcandy.translations.warning_message)) { | |
| 333 | + return; | |
| 334 | + } else { | |
| 335 | + var is_tinymce = | |
| 336 | + typeof tinyMCE != "undefined" && | |
| 337 | + tinyMCE.activeEditor && | |
| 338 | + !tinyMCE.activeEditor.isHidden(); | |
| 339 | + if (is_tinymce && tinymce.get("description")) { | |
| 340 | + tinyMCE.get("description").setContent(""); | |
| 341 | + } else { | |
| 342 | + jQuery("#description").val(""); | |
| 343 | + } | |
| 344 | + wpsc_clear_saved_draft_reply(ticket_id); | |
| 345 | + } | |
| 346 | + } | |
| 347 | + | |
| 348 | + var flag = confirm(supportcandy.translations.confirm); | |
| 349 | + if (!flag) { | |
| 350 | + return; | |
| 351 | + } | |
| 352 | + | |
| 353 | + var data = { action: "wpsc_it_delete_ticket", ticket_id, _ajax_nonce: nonce }; | |
| 354 | + jQuery.post(supportcandy.ajax_url, data, function (response) { | |
| 355 | + wpsc_get_ticket_list(); | |
| 356 | + wpsc_run_ajax_background_process(); | |
| 357 | + }); | |
| 358 | +} | |
| 359 | + | |
| 360 | +/** | |
| 361 | + * Restore ticket | |
| 362 | + */ | |
| 363 | +function wpsc_it_ticket_restore(ticket_id, nonce) { | |
| 364 | + var flag = confirm(supportcandy.translations.confirm); | |
| 365 | + if (!flag) { | |
| 366 | + return; | |
| 367 | + } | |
| 368 | + | |
| 369 | + var data = { | |
| 370 | + action: "wpsc_it_ticket_restore", | |
| 371 | + ticket_id, | |
| 372 | + _ajax_nonce: nonce, | |
| 373 | + }; | |
| 374 | + jQuery.post(supportcandy.ajax_url, data, function (response) { | |
| 375 | + wpsc_get_individual_ticket(ticket_id); | |
| 376 | + }); | |
| 377 | +} | |
| 378 | + | |
| 379 | +/** | |
| 380 | + * Get delete ticket | |
| 381 | + */ | |
| 330 | 382 | function wpsc_it_archive_ticket(ticket_id, nonce) { |
| 331 | 383 | if (wpsc_is_description_text()) { |
| 332 | 384 | if (!confirm(supportcandy.translations.warning_message)) { |
| 333 | 385 | return; |
| @@ -376,8 +428,37 @@ | ||
| 376 | 428 | }); |
| 377 | 429 | } |
| 378 | 430 | |
| 379 | 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 | +/** | |
| 380 | 461 | * Get edit ticket subject modal UI |
| 381 | 462 | */ |
| 382 | 463 | function wpsc_it_get_edit_subject(ticket_id) { |
| 383 | 464 | wpsc_show_modal(); |
| @@ -1403,8 +1484,25 @@ | ||
| 1403 | 1484 | type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1404 | 1485 | } |
| 1405 | 1486 | |
| 1406 | 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 | +/** | |
| 1407 | 1505 | * Get custom filter UI |
| 1408 | 1506 | */ |
| 1409 | 1507 | function wpsc_tl_get_custom_filter( type ) { |
| 1410 | 1508 | wpsc_show_modal(); |
| @@ -1889,17 +1987,33 @@ | ||
| 1889 | 1987 | }); |
| 1890 | 1988 | } |
| 1891 | 1989 | |
| 1892 | 1990 | /** |
| 1893 | - * Thread expander | |
| 1991 | + * Thread expander. | |
| 1894 | 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 | + | |
| 1895 | 2009 | function wpsc_ticket_thread_expander_toggle(el) { |
| 1896 | - var height = parseInt(jQuery(el).parent().find(".thread-text").height()); | |
| 1897 | - if (height === 100) { | |
| 1898 | - 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"); | |
| 1899 | 2013 | jQuery(el).text(supportcandy.translations.view_less); |
| 1900 | 2014 | } else { |
| 1901 | - jQuery(el).parent().find(".thread-text").height(100); | |
| 2015 | + $threadText.removeClass("wpsc-expanded").addClass("wpsc-collapsed"); | |
| 1902 | 2016 | jQuery(el).text(supportcandy.translations.view_more); |
| 1903 | 2017 | } |
| 1904 | 2018 | } |
| 1905 | 2019 | |
| @@ -1957,17 +2071,23 @@ | ||
| 1957 | 2071 | }; |
| 1958 | 2072 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1959 | 2073 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 1960 | 2074 | // add threads. |
| 2075 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 2076 | + var $before = $container.find(".thread-text"); | |
| 1961 | 2077 | if (supportcandy.reply_form_position === "top") { |
| 1962 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 2078 | + $container.append(response.threads); | |
| 1963 | 2079 | } else { |
| 1964 | 2080 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 1965 | 2081 | var windowScrollTop = jQuery(window).scrollTop(); |
| 1966 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 2082 | + $container.prepend(response.threads); | |
| 1967 | 2083 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 1968 | 2084 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 1969 | 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)); | |
| 1970 | 2090 | // show btn if there are more threads available. |
| 1971 | 2091 | if (response.has_next_page) { |
| 1972 | 2092 | supportcandy.threads.last_thread = response.last_thread; |
| 1973 | 2093 | oldBtnContainer.show(); |
| @@ -2140,8 +2260,38 @@ | ||
| 2140 | 2260 | } |
| 2141 | 2261 | } |
| 2142 | 2262 | |
| 2143 | 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 | +/** | |
| 2144 | 2294 | * Set agent working hrs |
| 2145 | 2295 | */ |
| 2146 | 2296 | function wpsc_set_agent_wh_hrs(el) { |
| 2147 | 2297 | const form = jQuery(".wpsc-frm-agent-wh")[0]; |
| @@ -2392,8 +2542,15 @@ | ||
| 2392 | 2542 | /** |
| 2393 | 2543 | * Get tickets based on filter set |
| 2394 | 2544 | */ |
| 2395 | 2545 | function wpsc_get_tickets() { |
| 2546 | + | |
| 2547 | + if (supportcandy.ticket_list_loading) { | |
| 2548 | + return; | |
| 2549 | + } | |
| 2550 | + | |
| 2551 | + supportcandy.ticket_list_loading = true; | |
| 2552 | + | |
| 2396 | 2553 | jQuery(".wpsc-bulk-selector").prop("checked", false); |
| 2397 | 2554 | jQuery(".wpsc-ticket-list").html(supportcandy.loader_html); |
| 2398 | 2555 | |
| 2399 | 2556 | var data = { |
| @@ -2400,8 +2557,9 @@ | ||
| 2400 | 2557 | action: "wpsc_get_tickets", |
| 2401 | 2558 | _ajax_nonce: supportcandy.nonce, |
| 2402 | 2559 | is_frontend: supportcandy.is_frontend, |
| 2403 | 2560 | }; |
| 2561 | + | |
| 2404 | 2562 | if ( |
| 2405 | 2563 | typeof supportcandy.ticketList != "undefined" && |
| 2406 | 2564 | typeof supportcandy.ticketList.filters != "undefined" |
| 2407 | 2565 | ) { |
| @@ -2408,8 +2566,9 @@ | ||
| 2408 | 2566 | data.filters = supportcandy.ticketList.filters; |
| 2409 | 2567 | } |
| 2410 | 2568 | |
| 2411 | 2569 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2570 | + | |
| 2412 | 2571 | jQuery(".wpsc-filter-actions").html(response.filter_actions); |
| 2413 | 2572 | jQuery(".wpsc-ticket-bulk-actions").html(response.bulk_actions); |
| 2414 | 2573 | jQuery(".wpsc-ticket-list").html(response.tickets); |
| 2415 | 2574 | jQuery(".wpsc-pagination-txt").text(response.pagination_str); |
| @@ -2416,17 +2575,22 @@ | ||
| 2416 | 2575 | jQuery("select.wpsc-input-filter").val(response.filters.filterSlug); |
| 2417 | 2576 | jQuery("select.wpsc-input-sort-by").val(response.filters.orderby); |
| 2418 | 2577 | jQuery("select.wpsc-input-sort-order").val(response.filters.order); |
| 2419 | 2578 | jQuery("input.wpsc-search-input").val(response.filters.search); |
| 2579 | + | |
| 2420 | 2580 | if (response.pagination.total_pages > 1) { |
| 2421 | 2581 | jQuery(".wpsc-pagination-btn").show(); |
| 2422 | 2582 | } else { |
| 2423 | 2583 | jQuery(".wpsc-pagination-btn").hide(); |
| 2424 | 2584 | } |
| 2585 | + | |
| 2425 | 2586 | supportcandy.ticketList = { |
| 2426 | 2587 | filters: response.filters, |
| 2427 | 2588 | pagination: response.pagination, |
| 2428 | 2589 | }; |
| 2590 | + | |
| 2591 | + }).always(function(){ | |
| 2592 | + supportcandy.ticket_list_loading = false; | |
| 2429 | 2593 | }); |
| 2430 | 2594 | } |
| 2431 | 2595 | |
| 2432 | 2596 | /** |
| @@ -2494,30 +2658,33 @@ | ||
| 2494 | 2658 | /** |
| 2495 | 2659 | * Auto refresh |
| 2496 | 2660 | */ |
| 2497 | 2661 | function wpsc_tl_auto_refresh() { |
| 2498 | - if ( | |
| 2499 | - supportcandy.current_section === "ticket-list" && | |
| 2500 | - !supportcandy.ticketListIsIndividual && | |
| 2501 | - supportcandy.tl_auto_refresh === 1 && | |
| 2502 | - !( | |
| 2503 | - jQuery(".wpsc-bulk-select:checked").length || | |
| 2504 | - jQuery(".wpsc-search-input").is(":focus") | |
| 2505 | - ) | |
| 2506 | - ) { | |
| 2507 | - 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 | + | |
| 2508 | 2671 | if ( |
| 2509 | - typeof supportcandy.tl_auto_refresh_schedule !== "undefined" && | |
| 2510 | - 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 | + ) | |
| 2511 | 2679 | ) { |
| 2512 | - return; | |
| 2680 | + wpsc_get_tickets(); | |
| 2513 | 2681 | } |
| 2514 | - supportcandy.tl_auto_refresh_schedule = true; | |
| 2515 | - setTimeout(function () { | |
| 2516 | - supportcandy.tl_auto_refresh_schedule = false; | |
| 2517 | - wpsc_tl_auto_refresh(); | |
| 2518 | - }, 60000); | |
| 2682 | + | |
| 2683 | + setTimeout(run_refresh, 60000); | |
| 2519 | 2684 | } |
| 2685 | + | |
| 2686 | + run_refresh(); | |
| 2520 | 2687 | } |
| 2521 | 2688 | |
| 2522 | 2689 | /** |
| 2523 | 2690 | * User logout |
| @@ -3182,17 +3349,23 @@ | ||
| 3182 | 3349 | }; |
| 3183 | 3350 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3184 | 3351 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 3185 | 3352 | // add threads. |
| 3353 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 3354 | + var $before = $container.find(".thread-text"); | |
| 3186 | 3355 | if (supportcandy.reply_form_position === "top") { |
| 3187 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 3356 | + $container.append(response.threads); | |
| 3188 | 3357 | } else { |
| 3189 | 3358 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 3190 | 3359 | var windowScrollTop = jQuery(window).scrollTop(); |
| 3191 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 3360 | + $container.prepend(response.threads); | |
| 3192 | 3361 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 3193 | 3362 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 3194 | 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)); | |
| 3195 | 3368 | // show btn if there are more threads available. |
| 3196 | 3369 | if (response.has_next_page) { |
| 3197 | 3370 | supportcandy.threads.last_thread = response.last_thread; |
| 3198 | 3371 | oldBtnContainer.show(); |
| @@ -3273,7 +3446,94 @@ | ||
| 3273 | 3446 | _ajax_nonce: nonce, |
| 3274 | 3447 | }; |
| 3275 | 3448 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3276 | 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(); | |
| 3277 | 3537 | }); |
| 3278 | 3538 | } |
| 3279 | 3539 | } |