| @@ -428,8 +428,37 @@ | ||
| 428 | 428 | }); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 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 | +/** | |
| 432 | 461 | * Get edit ticket subject modal UI |
| 433 | 462 | */ |
| 434 | 463 | function wpsc_it_get_edit_subject(ticket_id) { |
| 435 | 464 | wpsc_show_modal(); |
| @@ -1455,8 +1484,25 @@ | ||
| 1455 | 1484 | type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1456 | 1485 | } |
| 1457 | 1486 | |
| 1458 | 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 | +/** | |
| 1459 | 1505 | * Get custom filter UI |
| 1460 | 1506 | */ |
| 1461 | 1507 | function wpsc_tl_get_custom_filter( type ) { |
| 1462 | 1508 | wpsc_show_modal(); |
| @@ -1941,17 +1987,33 @@ | ||
| 1941 | 1987 | }); |
| 1942 | 1988 | } |
| 1943 | 1989 | |
| 1944 | 1990 | /** |
| 1945 | - * Thread expander | |
| 1991 | + * Thread expander. | |
| 1946 | 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 | + | |
| 1947 | 2009 | function wpsc_ticket_thread_expander_toggle(el) { |
| 1948 | - var height = parseInt(jQuery(el).parent().find(".thread-text").height()); | |
| 1949 | - if (height === 100) { | |
| 1950 | - 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"); | |
| 1951 | 2013 | jQuery(el).text(supportcandy.translations.view_less); |
| 1952 | 2014 | } else { |
| 1953 | - jQuery(el).parent().find(".thread-text").height(100); | |
| 2015 | + $threadText.removeClass("wpsc-expanded").addClass("wpsc-collapsed"); | |
| 1954 | 2016 | jQuery(el).text(supportcandy.translations.view_more); |
| 1955 | 2017 | } |
| 1956 | 2018 | } |
| 1957 | 2019 | |
| @@ -2009,17 +2071,23 @@ | ||
| 2009 | 2071 | }; |
| 2010 | 2072 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2011 | 2073 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 2012 | 2074 | // add threads. |
| 2075 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 2076 | + var $before = $container.find(".thread-text"); | |
| 2013 | 2077 | if (supportcandy.reply_form_position === "top") { |
| 2014 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 2078 | + $container.append(response.threads); | |
| 2015 | 2079 | } else { |
| 2016 | 2080 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 2017 | 2081 | var windowScrollTop = jQuery(window).scrollTop(); |
| 2018 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 2082 | + $container.prepend(response.threads); | |
| 2019 | 2083 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 2020 | 2084 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 2021 | 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)); | |
| 2022 | 2090 | // show btn if there are more threads available. |
| 2023 | 2091 | if (response.has_next_page) { |
| 2024 | 2092 | supportcandy.threads.last_thread = response.last_thread; |
| 2025 | 2093 | oldBtnContainer.show(); |
| @@ -2474,8 +2542,15 @@ | ||
| 2474 | 2542 | /** |
| 2475 | 2543 | * Get tickets based on filter set |
| 2476 | 2544 | */ |
| 2477 | 2545 | function wpsc_get_tickets() { |
| 2546 | + | |
| 2547 | + if (supportcandy.ticket_list_loading) { | |
| 2548 | + return; | |
| 2549 | + } | |
| 2550 | + | |
| 2551 | + supportcandy.ticket_list_loading = true; | |
| 2552 | + | |
| 2478 | 2553 | jQuery(".wpsc-bulk-selector").prop("checked", false); |
| 2479 | 2554 | jQuery(".wpsc-ticket-list").html(supportcandy.loader_html); |
| 2480 | 2555 | |
| 2481 | 2556 | var data = { |
| @@ -2482,8 +2557,9 @@ | ||
| 2482 | 2557 | action: "wpsc_get_tickets", |
| 2483 | 2558 | _ajax_nonce: supportcandy.nonce, |
| 2484 | 2559 | is_frontend: supportcandy.is_frontend, |
| 2485 | 2560 | }; |
| 2561 | + | |
| 2486 | 2562 | if ( |
| 2487 | 2563 | typeof supportcandy.ticketList != "undefined" && |
| 2488 | 2564 | typeof supportcandy.ticketList.filters != "undefined" |
| 2489 | 2565 | ) { |
| @@ -2490,8 +2566,9 @@ | ||
| 2490 | 2566 | data.filters = supportcandy.ticketList.filters; |
| 2491 | 2567 | } |
| 2492 | 2568 | |
| 2493 | 2569 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2570 | + | |
| 2494 | 2571 | jQuery(".wpsc-filter-actions").html(response.filter_actions); |
| 2495 | 2572 | jQuery(".wpsc-ticket-bulk-actions").html(response.bulk_actions); |
| 2496 | 2573 | jQuery(".wpsc-ticket-list").html(response.tickets); |
| 2497 | 2574 | jQuery(".wpsc-pagination-txt").text(response.pagination_str); |
| @@ -2498,17 +2575,22 @@ | ||
| 2498 | 2575 | jQuery("select.wpsc-input-filter").val(response.filters.filterSlug); |
| 2499 | 2576 | jQuery("select.wpsc-input-sort-by").val(response.filters.orderby); |
| 2500 | 2577 | jQuery("select.wpsc-input-sort-order").val(response.filters.order); |
| 2501 | 2578 | jQuery("input.wpsc-search-input").val(response.filters.search); |
| 2579 | + | |
| 2502 | 2580 | if (response.pagination.total_pages > 1) { |
| 2503 | 2581 | jQuery(".wpsc-pagination-btn").show(); |
| 2504 | 2582 | } else { |
| 2505 | 2583 | jQuery(".wpsc-pagination-btn").hide(); |
| 2506 | 2584 | } |
| 2585 | + | |
| 2507 | 2586 | supportcandy.ticketList = { |
| 2508 | 2587 | filters: response.filters, |
| 2509 | 2588 | pagination: response.pagination, |
| 2510 | 2589 | }; |
| 2590 | + | |
| 2591 | + }).always(function(){ | |
| 2592 | + supportcandy.ticket_list_loading = false; | |
| 2511 | 2593 | }); |
| 2512 | 2594 | } |
| 2513 | 2595 | |
| 2514 | 2596 | /** |
| @@ -2576,30 +2658,33 @@ | ||
| 2576 | 2658 | /** |
| 2577 | 2659 | * Auto refresh |
| 2578 | 2660 | */ |
| 2579 | 2661 | function wpsc_tl_auto_refresh() { |
| 2580 | - if ( | |
| 2581 | - supportcandy.current_section === "ticket-list" && | |
| 2582 | - !supportcandy.ticketListIsIndividual && | |
| 2583 | - supportcandy.tl_auto_refresh === 1 && | |
| 2584 | - !( | |
| 2585 | - jQuery(".wpsc-bulk-select:checked").length || | |
| 2586 | - jQuery(".wpsc-search-input").is(":focus") | |
| 2587 | - ) | |
| 2588 | - ) { | |
| 2589 | - 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 | + | |
| 2590 | 2671 | if ( |
| 2591 | - typeof supportcandy.tl_auto_refresh_schedule !== "undefined" && | |
| 2592 | - 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 | + ) | |
| 2593 | 2679 | ) { |
| 2594 | - return; | |
| 2680 | + wpsc_get_tickets(); | |
| 2595 | 2681 | } |
| 2596 | - supportcandy.tl_auto_refresh_schedule = true; | |
| 2597 | - setTimeout(function () { | |
| 2598 | - supportcandy.tl_auto_refresh_schedule = false; | |
| 2599 | - wpsc_tl_auto_refresh(); | |
| 2600 | - }, 60000); | |
| 2682 | + | |
| 2683 | + setTimeout(run_refresh, 60000); | |
| 2601 | 2684 | } |
| 2685 | + | |
| 2686 | + run_refresh(); | |
| 2602 | 2687 | } |
| 2603 | 2688 | |
| 2604 | 2689 | /** |
| 2605 | 2690 | * User logout |
| @@ -3264,17 +3349,23 @@ | ||
| 3264 | 3349 | }; |
| 3265 | 3350 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3266 | 3351 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 3267 | 3352 | // add threads. |
| 3353 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 3354 | + var $before = $container.find(".thread-text"); | |
| 3268 | 3355 | if (supportcandy.reply_form_position === "top") { |
| 3269 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 3356 | + $container.append(response.threads); | |
| 3270 | 3357 | } else { |
| 3271 | 3358 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 3272 | 3359 | var windowScrollTop = jQuery(window).scrollTop(); |
| 3273 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 3360 | + $container.prepend(response.threads); | |
| 3274 | 3361 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 3275 | 3362 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 3276 | 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)); | |
| 3277 | 3368 | // show btn if there are more threads available. |
| 3278 | 3369 | if (response.has_next_page) { |
| 3279 | 3370 | supportcandy.threads.last_thread = response.last_thread; |
| 3280 | 3371 | oldBtnContainer.show(); |