| @@ -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(); |
| @@ -3281,17 +3349,23 @@ | ||
| 3281 | 3349 | }; |
| 3282 | 3350 | jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3283 | 3351 | jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 3284 | 3352 | // add threads. |
| 3353 | + var $container = jQuery(".wpsc-it-thread-section-container"); | |
| 3354 | + var $before = $container.find(".thread-text"); | |
| 3285 | 3355 | if (supportcandy.reply_form_position === "top") { |
| 3286 | - jQuery(".wpsc-it-thread-section-container").append(response.threads); | |
| 3356 | + $container.append(response.threads); | |
| 3287 | 3357 | } else { |
| 3288 | 3358 | var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 3289 | 3359 | var windowScrollTop = jQuery(window).scrollTop(); |
| 3290 | - jQuery(".wpsc-it-thread-section-container").prepend(response.threads); | |
| 3360 | + $container.prepend(response.threads); | |
| 3291 | 3361 | var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 3292 | 3362 | jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 3293 | 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)); | |
| 3294 | 3368 | // show btn if there are more threads available. |
| 3295 | 3369 | if (response.has_next_page) { |
| 3296 | 3370 | supportcandy.threads.last_thread = response.last_thread; |
| 3297 | 3371 | oldBtnContainer.show(); |