| 1 |
jQuery(document).ready(function () { |
| 2 |
wpsc_reset_responsive_style(); |
| 3 |
jQuery(window).resize(function () { |
| 4 |
wpsc_reset_responsive_style(true); |
| 5 |
}); |
| 6 |
wpsc_document_ready(); |
| 7 |
|
| 8 |
// for check there is value in reply box. |
| 9 |
jQuery(window).on("popstate", function () { |
| 10 |
if (wpsc_is_description_text()) { |
| 11 |
if (!confirm(supportcandy.translations.warning_message)) { |
| 12 |
return; |
| 13 |
} |
| 14 |
} |
| 15 |
}); |
| 16 |
|
| 17 |
// Change the element from h1 to h2 |
| 18 |
if (jQuery('#link-modal-title').length > 0) { |
| 19 |
jQuery('#link-modal-title').replaceWith('<h2 id="link-modal-title">' + jQuery('#link-modal-title').html() + '</h2>'); |
| 20 |
} |
| 21 |
}); |
| 22 |
|
| 23 |
/** |
| 24 |
* Apply responsive styles based on container size |
| 25 |
*/ |
| 26 |
function wpsc_reset_responsive_style(isWindowResize = false) { |
| 27 |
var lastContainerWidth = supportcandy.lastContainerWidth |
| 28 |
? supportcandy.lastContainerWidth |
| 29 |
: 0; |
| 30 |
var containerWidth = jQuery("#wpsc-container").outerWidth(); |
| 31 |
|
| 32 |
if (isWindowResize && lastContainerWidth === containerWidth) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
supportcandy.lastContainerWidth = containerWidth; |
| 37 |
|
| 38 |
jQuery("#wpsc-container").hide(); |
| 39 |
var style = "xs"; |
| 40 |
if (containerWidth <= 768) { |
| 41 |
style = "xs"; |
| 42 |
} else if (containerWidth > 768 && containerWidth <= 992) { |
| 43 |
style = "sm"; |
| 44 |
} else if (containerWidth > 992 && containerWidth <= 1200) { |
| 45 |
style = "md"; |
| 46 |
} else { |
| 47 |
style = "lg"; |
| 48 |
} |
| 49 |
supportcandy.responsiveStyle = style; |
| 50 |
var styleURL = |
| 51 |
supportcandy.plugin_url + |
| 52 |
"framework/responsive/" + |
| 53 |
style + |
| 54 |
".css?version=" + |
| 55 |
supportcandy.version; |
| 56 |
var styleEl = |
| 57 |
'<link id="wpsc-responsive-css" rel="stylesheet" type="text/css" href="' + |
| 58 |
styleURL + |
| 59 |
'" />'; |
| 60 |
jQuery("#wpsc-responsive-css").remove(); |
| 61 |
jQuery("head").append(styleEl); |
| 62 |
wpsc_apply_responsive_styles(); |
| 63 |
jQuery("#wpsc-container").show(); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Apply visible elements on screen resize |
| 68 |
*/ |
| 69 |
function wpsc_el_reset_visible() { |
| 70 |
jQuery( |
| 71 |
".wpsc-visible-xs,.wpsc-visible-sm,.wpsc-visible-md,.wpsc-visible-lg" |
| 72 |
).hide(); |
| 73 |
jQuery(".wpsc-visible-" + supportcandy.responsiveStyle).show(); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Apply hidden elements on screen resize |
| 78 |
*/ |
| 79 |
function wpsc_el_reset_hidden() { |
| 80 |
jQuery( |
| 81 |
".wpsc-hidden-xs,.wpsc-hidden-sm,.wpsc-hidden-md,.wpsc-hidden-lg" |
| 82 |
).show(); |
| 83 |
jQuery(".wpsc-hidden-" + supportcandy.responsiveStyle).hide(); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Toggle humbargar menu |
| 88 |
*/ |
| 89 |
function wpsc_toggle_humbargar() { |
| 90 |
var flag = supportcandy.humbargar ? true : false; |
| 91 |
if (flag) { |
| 92 |
jQuery(".wpsc-humbargar-menu").hide( |
| 93 |
"slide", |
| 94 |
{ direction: "right" }, |
| 95 |
200, |
| 96 |
function () { |
| 97 |
jQuery(".wpsc-humbargar-overlay").hide(); |
| 98 |
} |
| 99 |
); |
| 100 |
supportcandy.humbargar = false; |
| 101 |
} else { |
| 102 |
jQuery(".wpsc-humbargar-overlay").show(); |
| 103 |
jQuery(".wpsc-humbargar-menu").show("slide", { direction: "right" }, 200); |
| 104 |
supportcandy.humbargar = true; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Close humbargar menu if open |
| 110 |
*/ |
| 111 |
function wpsc_close_humbargar() { |
| 112 |
var flag = supportcandy.humbargar ? true : false; |
| 113 |
if (flag) { |
| 114 |
jQuery(".wpsc-humbargar-menu").hide(); |
| 115 |
jQuery(".wpsc-humbargar-overlay").hide(); |
| 116 |
supportcandy.humbargar = false; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Bulk selector change |
| 122 |
*/ |
| 123 |
function wpsc_bulk_select_change() { |
| 124 |
var checked = jQuery(".wpsc-bulk-selector").is(":checked"); |
| 125 |
jQuery(".wpsc-bulk-select").prop("checked", checked); |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Bulk item selector change |
| 130 |
*/ |
| 131 |
function wpsc_bulk_item_select_change() { |
| 132 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 133 |
var checked = items.length === 0 ? false : true; |
| 134 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Show modal with loading screen |
| 139 |
*/ |
| 140 |
function wpsc_show_modal() { |
| 141 |
jQuery(".wpsc-modal .inner-container").hide(); |
| 142 |
jQuery(".wpsc-modal .loader").show(); |
| 143 |
jQuery(".wpsc-modal").show(); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Close modal |
| 148 |
*/ |
| 149 |
function wpsc_show_modal_inner_container() { |
| 150 |
jQuery(".wpsc-modal .loader").hide(); |
| 151 |
jQuery(".wpsc-modal .inner-container").show( |
| 152 |
"slide", |
| 153 |
{ direction: "up" }, |
| 154 |
200 |
| 155 |
); |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Close modal |
| 160 |
*/ |
| 161 |
function wpsc_close_modal() { |
| 162 |
jQuery(".wpsc-modal .inner-container").hide( |
| 163 |
"slide", |
| 164 |
{ direction: "up" }, |
| 165 |
200, |
| 166 |
function () { |
| 167 |
jQuery(".wpsc-modal").hide(); |
| 168 |
} |
| 169 |
); |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* OFF toggle button click |
| 174 |
*/ |
| 175 |
function wpsc_toggle_off(el) { |
| 176 |
var off = jQuery(el); |
| 177 |
var on = jQuery(el).next(); |
| 178 |
var input = on.next(); |
| 179 |
|
| 180 |
if (input.val() === 0) { |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
input.val(0); |
| 185 |
on.removeClass("active"); |
| 186 |
off.addClass("active"); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* ON toggle button click |
| 191 |
*/ |
| 192 |
function wpsc_toggle_on(el) { |
| 193 |
var on = jQuery(el); |
| 194 |
var off = jQuery(el).prev(); |
| 195 |
var input = on.next(); |
| 196 |
|
| 197 |
if (input.val() === 1) { |
| 198 |
return; |
| 199 |
} |
| 200 |
|
| 201 |
input.val(1); |
| 202 |
off.removeClass("active"); |
| 203 |
on.addClass("active"); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Scroll to top of WPSC component |
| 208 |
*/ |
| 209 |
function wpsc_scroll_top() { |
| 210 |
jQuery("html, body").animate( |
| 211 |
{ |
| 212 |
scrollTop: jQuery("#wpsc-container").offset().top - 42, |
| 213 |
}, |
| 214 |
500 |
| 215 |
); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Toggle individual widgets |
| 220 |
*/ |
| 221 |
function wpsc_toggle_mob_it_widgets() { |
| 222 |
var status = parseInt( |
| 223 |
jQuery(".wpsc-it-mob-widgets-inner-container").data("status") |
| 224 |
); |
| 225 |
|
| 226 |
if (!status) { |
| 227 |
jQuery(".wpsc-it-mob-widgets-inner-container").slideDown(); |
| 228 |
jQuery(".wpsc-it-mob-widget-trigger-btn .down").hide(); |
| 229 |
jQuery(".wpsc-it-mob-widget-trigger-btn .up").show(); |
| 230 |
jQuery(".wpsc-it-mob-widgets-inner-container").data("status", 1); |
| 231 |
} else { |
| 232 |
jQuery(".wpsc-it-mob-widgets-inner-container").slideUp(); |
| 233 |
jQuery(".wpsc-it-mob-widget-trigger-btn .up").hide(); |
| 234 |
jQuery(".wpsc-it-mob-widget-trigger-btn .down").show(); |
| 235 |
jQuery(".wpsc-it-mob-widgets-inner-container").data("status", 0); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* Get refresh current ticket |
| 241 |
*/ |
| 242 |
function wpsc_it_ab_refresh(ticket_id) { |
| 243 |
if (wpsc_is_description_text()) { |
| 244 |
if (confirm(supportcandy.translations.warning_message)) { |
| 245 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 246 |
} else { |
| 247 |
return; |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
wpsc_get_individual_ticket(ticket_id); |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* Get close current ticket modal UI |
| 256 |
*/ |
| 257 |
function wpsc_it_close_ticket(ticket_id, nonce) { |
| 258 |
if (wpsc_is_description_text()) { |
| 259 |
if (!confirm(supportcandy.translations.warning_message)) return; |
| 260 |
} |
| 261 |
|
| 262 |
var flag = confirm(supportcandy.translations.confirm); |
| 263 |
if (flag) { |
| 264 |
if (wpsc_is_description_text()) { |
| 265 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 266 |
} |
| 267 |
} else { |
| 268 |
return; |
| 269 |
} |
| 270 |
|
| 271 |
var data = { action: "wpsc_it_close_ticket", ticket_id, _ajax_nonce: nonce }; |
| 272 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 273 |
wpsc_run_ajax_background_process(); |
| 274 |
wpsc_after_close_ticket(ticket_id); |
| 275 |
}); |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Get duplicate ticket |
| 280 |
*/ |
| 281 |
function wpsc_it_get_duplicate_ticket(ticket_id, nonce) { |
| 282 |
wpsc_show_modal(); |
| 283 |
var data = { |
| 284 |
action: "wpsc_it_get_duplicate_ticket", |
| 285 |
ticket_id, |
| 286 |
_ajax_nonce: nonce, |
| 287 |
}; |
| 288 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 289 |
jQuery(".wpsc-modal-header").text(response.title); |
| 290 |
jQuery(".wpsc-modal-body").html(response.body); |
| 291 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 292 |
wpsc_show_modal_inner_container(); |
| 293 |
}); |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* Set duplicate ticket |
| 298 |
*/ |
| 299 |
function wpsc_it_set_duplicate_ticket(el, ticket_id) { |
| 300 |
if (wpsc_is_description_text()) { |
| 301 |
if (confirm(supportcandy.translations.warning_message)) { |
| 302 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 303 |
} else { |
| 304 |
return; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
var form = jQuery("form.duplicate")[0]; |
| 309 |
var dataform = new FormData(form); |
| 310 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 311 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 312 |
|
| 313 |
jQuery |
| 314 |
.ajax({ |
| 315 |
url: supportcandy.ajax_url, |
| 316 |
type: "POST", |
| 317 |
data: dataform, |
| 318 |
processData: false, |
| 319 |
contentType: false, |
| 320 |
}) |
| 321 |
.done(function (response) { |
| 322 |
wpsc_close_modal(); |
| 323 |
wpsc_get_individual_ticket(response.ticket_id); |
| 324 |
}); |
| 325 |
} |
| 326 |
|
| 327 |
/** |
| 328 |
* Get delete ticket |
| 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 |
*/ |
| 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 |
/** |
| 413 |
* Delete permanently |
| 414 |
*/ |
| 415 |
function wpsc_it_delete_permanently(ticket_id, nonce) { |
| 416 |
var flag = confirm(supportcandy.translations.delete_permanently); |
| 417 |
if (!flag) { |
| 418 |
return; |
| 419 |
} |
| 420 |
|
| 421 |
var data = { |
| 422 |
action: "wpsc_it_delete_permanently", |
| 423 |
ticket_id, |
| 424 |
_ajax_nonce: nonce, |
| 425 |
}; |
| 426 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 427 |
wpsc_get_ticket_list(); |
| 428 |
}); |
| 429 |
} |
| 430 |
|
| 431 |
/** |
| 432 |
* Get edit ticket subject modal UI |
| 433 |
*/ |
| 434 |
function wpsc_it_get_edit_subject(ticket_id) { |
| 435 |
wpsc_show_modal(); |
| 436 |
var data = { |
| 437 |
action: "wpsc_it_get_edit_subject", |
| 438 |
ticket_id, |
| 439 |
}; |
| 440 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 441 |
jQuery(".wpsc-modal-header").text(response.title); |
| 442 |
jQuery(".wpsc-modal-body").html(response.body); |
| 443 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 444 |
wpsc_show_modal_inner_container(); |
| 445 |
}); |
| 446 |
} |
| 447 |
|
| 448 |
/** |
| 449 |
* Set edit ticket subject |
| 450 |
*/ |
| 451 |
function wpsc_it_set_edit_subject(el, ticket_id) { |
| 452 |
if (wpsc_is_description_text()) { |
| 453 |
if (!confirm(supportcandy.translations.warning_message)) { |
| 454 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 455 |
} else { |
| 456 |
return; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
var form = jQuery("form.edit-subject")[0]; |
| 461 |
var dataform = new FormData(form); |
| 462 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 463 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 464 |
jQuery |
| 465 |
.ajax({ |
| 466 |
url: supportcandy.ajax_url, |
| 467 |
type: "POST", |
| 468 |
data: dataform, |
| 469 |
processData: false, |
| 470 |
contentType: false, |
| 471 |
}) |
| 472 |
.done(function (res) { |
| 473 |
wpsc_close_modal(); |
| 474 |
wpsc_get_individual_ticket(ticket_id); |
| 475 |
}); |
| 476 |
} |
| 477 |
|
| 478 |
/** |
| 479 |
* Get change status modal UI |
| 480 |
*/ |
| 481 |
function wpsc_it_get_edit_ticket_status(ticket_id, nonce) { |
| 482 |
wpsc_show_modal(); |
| 483 |
var data = { |
| 484 |
action: "wpsc_it_get_edit_ticket_status", |
| 485 |
ticket_id, |
| 486 |
_ajax_nonce: nonce, |
| 487 |
}; |
| 488 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 489 |
// Set to modal. |
| 490 |
jQuery(".wpsc-modal-header").text(response.title); |
| 491 |
jQuery(".wpsc-modal-body").html(response.body); |
| 492 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 493 |
// Display modal. |
| 494 |
wpsc_show_modal_inner_container(); |
| 495 |
}); |
| 496 |
} |
| 497 |
|
| 498 |
/** |
| 499 |
* Update ticket status |
| 500 |
* |
| 501 |
* @param {*} el |
| 502 |
*/ |
| 503 |
function wpsc_it_set_edit_ticket_status(el, ticket_id) { |
| 504 |
if (wpsc_is_description_text()) { |
| 505 |
if (confirm(supportcandy.translations.warning_message)) { |
| 506 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 507 |
} else { |
| 508 |
return; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
var form = jQuery("form.frm-edit-ticket-status")[0]; |
| 513 |
var dataform = new FormData(form); |
| 514 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 515 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 516 |
jQuery |
| 517 |
.ajax({ |
| 518 |
url: supportcandy.ajax_url, |
| 519 |
type: "POST", |
| 520 |
data: dataform, |
| 521 |
processData: false, |
| 522 |
contentType: false, |
| 523 |
}) |
| 524 |
.done(function (res) { |
| 525 |
wpsc_close_modal(); |
| 526 |
wpsc_get_individual_ticket(ticket_id); |
| 527 |
wpsc_run_ajax_background_process(); |
| 528 |
}); |
| 529 |
} |
| 530 |
|
| 531 |
/** |
| 532 |
* Get additional recipients modal UI |
| 533 |
*/ |
| 534 |
function wpsc_it_get_add_ar(ticket_id, nonce) { |
| 535 |
wpsc_show_modal(); |
| 536 |
var data = { |
| 537 |
action: "wpsc_it_get_add_ar", |
| 538 |
ticket_id, |
| 539 |
_ajax_nonce: nonce, |
| 540 |
}; |
| 541 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 542 |
jQuery(".wpsc-modal-header").text(response.title); |
| 543 |
jQuery(".wpsc-modal-body").html(response.body); |
| 544 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 545 |
wpsc_show_modal_inner_container(); |
| 546 |
}); |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Update additional recipients |
| 551 |
* |
| 552 |
* @param {*} el |
| 553 |
*/ |
| 554 |
function wpsc_it_set_add_ar(el, ticket_id) { |
| 555 |
if (wpsc_is_description_text()) { |
| 556 |
if (confirm(supportcandy.translations.warning_message)) { |
| 557 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 558 |
} else { |
| 559 |
return; |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
var form = jQuery("form.additional-recipients")[0]; |
| 564 |
var dataform = new FormData(form); |
| 565 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 566 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 567 |
jQuery |
| 568 |
.ajax({ |
| 569 |
url: supportcandy.ajax_url, |
| 570 |
type: "POST", |
| 571 |
data: dataform, |
| 572 |
processData: false, |
| 573 |
contentType: false, |
| 574 |
}) |
| 575 |
.done(function (res) { |
| 576 |
wpsc_close_modal(); |
| 577 |
wpsc_get_individual_ticket(ticket_id); |
| 578 |
}); |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Get assigned agents modal UI |
| 583 |
*/ |
| 584 |
function wpsc_it_get_edit_assigned_agents(ticket_id, nonce) { |
| 585 |
wpsc_show_modal(); |
| 586 |
var data = { |
| 587 |
action: "wpsc_it_get_edit_assigned_agents", |
| 588 |
ticket_id, |
| 589 |
_ajax_nonce: nonce, |
| 590 |
}; |
| 591 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 592 |
jQuery(".wpsc-modal-header").text(response.title); |
| 593 |
jQuery(".wpsc-modal-body").html(response.body); |
| 594 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 595 |
wpsc_show_modal_inner_container(); |
| 596 |
}); |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Update assigned agents |
| 601 |
* |
| 602 |
* @param {*} el |
| 603 |
*/ |
| 604 |
function wpsc_it_set_edit_assigned_agents(el, ticket_id, uniqueId) { |
| 605 |
if (wpsc_is_description_text()) { |
| 606 |
if (confirm(supportcandy.translations.warning_message)) { |
| 607 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 608 |
} else { |
| 609 |
return; |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
var form = jQuery("form.change-assignee." + uniqueId)[0]; |
| 614 |
var dataform = new FormData(form); |
| 615 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 616 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 617 |
jQuery |
| 618 |
.ajax({ |
| 619 |
url: supportcandy.ajax_url, |
| 620 |
type: "POST", |
| 621 |
data: dataform, |
| 622 |
processData: false, |
| 623 |
contentType: false, |
| 624 |
}) |
| 625 |
.done(function (res) { |
| 626 |
wpsc_close_modal(); |
| 627 |
if (res.viewPermission) { |
| 628 |
wpsc_get_individual_ticket(ticket_id); |
| 629 |
} else { |
| 630 |
wpsc_get_ticket_list(); |
| 631 |
} |
| 632 |
wpsc_run_ajax_background_process(); |
| 633 |
}); |
| 634 |
} |
| 635 |
|
| 636 |
/** |
| 637 |
* Get raised by modal UI |
| 638 |
*/ |
| 639 |
function wpsc_it_get_edit_raised_by(ticket_id, nonce) { |
| 640 |
wpsc_show_modal(); |
| 641 |
var data = { |
| 642 |
action: "wpsc_it_get_edit_raised_by", |
| 643 |
ticket_id, |
| 644 |
_ajax_nonce: nonce, |
| 645 |
}; |
| 646 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 647 |
// Set to modal. |
| 648 |
jQuery(".wpsc-modal-header").text(response.title); |
| 649 |
jQuery(".wpsc-modal-body").html(response.body); |
| 650 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 651 |
// Display modal. |
| 652 |
wpsc_show_modal_inner_container(); |
| 653 |
}); |
| 654 |
} |
| 655 |
|
| 656 |
/** |
| 657 |
* Update raised by |
| 658 |
* |
| 659 |
* @param {*} el |
| 660 |
*/ |
| 661 |
function wpsc_it_set_edit_raised_by(el, ticket_id, uniqueId) { |
| 662 |
if (wpsc_is_description_text()) { |
| 663 |
if (confirm(supportcandy.translations.warning_message)) { |
| 664 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 665 |
} else { |
| 666 |
return; |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
var type = jQuery(".type." + uniqueId).val(); |
| 671 |
if (type == "new") { |
| 672 |
var name = jQuery(".name." + uniqueId) |
| 673 |
.val() |
| 674 |
.trim(); |
| 675 |
var email = jQuery(".email." + uniqueId) |
| 676 |
.val() |
| 677 |
.trim(); |
| 678 |
if (!name || !email) { |
| 679 |
return; |
| 680 |
} |
| 681 |
|
| 682 |
if (!validateEmail(email)) { |
| 683 |
alert(supportcandy.translations.raisedByEditWidget.invalidEmail); |
| 684 |
return; |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
var form = jQuery("form.change-raised-by." + uniqueId)[0]; |
| 689 |
var dataform = new FormData(form); |
| 690 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 691 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 692 |
jQuery |
| 693 |
.ajax({ |
| 694 |
url: supportcandy.ajax_url, |
| 695 |
type: "POST", |
| 696 |
data: dataform, |
| 697 |
processData: false, |
| 698 |
contentType: false, |
| 699 |
}) |
| 700 |
.done(function (res) { |
| 701 |
wpsc_close_modal(); |
| 702 |
wpsc_get_individual_ticket(ticket_id); |
| 703 |
}); |
| 704 |
} |
| 705 |
|
| 706 |
/** |
| 707 |
* Get ticket fields modal UI |
| 708 |
*/ |
| 709 |
function wpsc_it_get_edit_ticket_fields(ticket_id, nonce) { |
| 710 |
wpsc_show_modal(); |
| 711 |
var data = { |
| 712 |
action: "wpsc_it_get_edit_ticket_fields", |
| 713 |
ticket_id, |
| 714 |
_ajax_nonce: nonce, |
| 715 |
}; |
| 716 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 717 |
jQuery(".wpsc-modal-header").text(response.title); |
| 718 |
jQuery(".wpsc-modal-body").html(response.body); |
| 719 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 720 |
wpsc_show_modal_inner_container(); |
| 721 |
}); |
| 722 |
} |
| 723 |
|
| 724 |
/** |
| 725 |
* Update ticket fields |
| 726 |
* |
| 727 |
* @param {*} el |
| 728 |
*/ |
| 729 |
function wpsc_it_set_edit_ticket_fields(el, ticket_id) { |
| 730 |
if (wpsc_is_description_text()) { |
| 731 |
if (confirm(supportcandy.translations.warning_message)) { |
| 732 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 733 |
} else { |
| 734 |
return; |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
var form = jQuery("form.change-ticket-fields")[0]; |
| 739 |
var dataform = new FormData(form); |
| 740 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 741 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 742 |
jQuery |
| 743 |
.ajax({ |
| 744 |
url: supportcandy.ajax_url, |
| 745 |
type: "POST", |
| 746 |
data: dataform, |
| 747 |
processData: false, |
| 748 |
contentType: false, |
| 749 |
}) |
| 750 |
.done(function (res) { |
| 751 |
wpsc_close_modal(); |
| 752 |
wpsc_get_individual_ticket(ticket_id); |
| 753 |
}); |
| 754 |
} |
| 755 |
|
| 756 |
/** |
| 757 |
* Get agent only filds modal UI |
| 758 |
*/ |
| 759 |
function wpsc_it_get_edit_agentonly_fields(ticket_id, nonce) { |
| 760 |
wpsc_show_modal(); |
| 761 |
var data = { |
| 762 |
action: "wpsc_it_get_edit_agentonly_fields", |
| 763 |
ticket_id, |
| 764 |
_ajax_nonce: nonce, |
| 765 |
}; |
| 766 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 767 |
jQuery(".wpsc-modal-header").text(response.title); |
| 768 |
jQuery(".wpsc-modal-body").html(response.body); |
| 769 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 770 |
wpsc_show_modal_inner_container(); |
| 771 |
}); |
| 772 |
} |
| 773 |
|
| 774 |
/** |
| 775 |
* Update agent only fields |
| 776 |
* |
| 777 |
* @param {*} el |
| 778 |
*/ |
| 779 |
function wpsc_it_set_edit_agentonly_fields(el, ticket_id) { |
| 780 |
if (wpsc_is_description_text()) { |
| 781 |
if (confirm(supportcandy.translations.warning_message)) { |
| 782 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 783 |
} else { |
| 784 |
return; |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
var form = jQuery("form.change-agentonly-fields")[0]; |
| 789 |
var dataform = new FormData(form); |
| 790 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 791 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 792 |
jQuery |
| 793 |
.ajax({ |
| 794 |
url: supportcandy.ajax_url, |
| 795 |
type: "POST", |
| 796 |
data: dataform, |
| 797 |
processData: false, |
| 798 |
contentType: false, |
| 799 |
}) |
| 800 |
.done(function (res) { |
| 801 |
wpsc_close_modal(); |
| 802 |
wpsc_get_individual_ticket(ticket_id); |
| 803 |
}); |
| 804 |
} |
| 805 |
|
| 806 |
/** |
| 807 |
* Get edit thread |
| 808 |
*/ |
| 809 |
function wpsc_it_get_edit_thread(el, ticket_id, thread_id, nonce) { |
| 810 |
var thread = jQuery(el).closest(".wpsc-thread"); |
| 811 |
thread.html(supportcandy.loader_html); |
| 812 |
|
| 813 |
var data = { |
| 814 |
action: "wpsc_it_get_edit_thread", |
| 815 |
ticket_id, |
| 816 |
thread_id, |
| 817 |
_ajax_nonce: nonce, |
| 818 |
}; |
| 819 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 820 |
thread.html(res); |
| 821 |
}); |
| 822 |
} |
| 823 |
|
| 824 |
/** |
| 825 |
* Set edit thread |
| 826 |
*/ |
| 827 |
function wpsc_it_set_edit_thread(el, uniqueId) { |
| 828 |
var form = jQuery("form.edit-thread")[0]; |
| 829 |
var dataform = new FormData(form); |
| 830 |
|
| 831 |
var is_tinymce = |
| 832 |
typeof tinyMCE != "undefined" && |
| 833 |
tinyMCE.activeEditor && |
| 834 |
!tinyMCE.activeEditor.isHidden(); |
| 835 |
var description = |
| 836 |
is_tinymce && tinymce.get(uniqueId) |
| 837 |
? tinyMCE.get(uniqueId).getContent() |
| 838 |
: jQuery("#" + uniqueId) |
| 839 |
.val() |
| 840 |
.trim(); |
| 841 |
if (!description) { |
| 842 |
return; |
| 843 |
} |
| 844 |
|
| 845 |
dataform.append("thread_content", description); |
| 846 |
|
| 847 |
var thread = jQuery(el).closest(".wpsc-thread"); |
| 848 |
thread.html(supportcandy.loader_html); |
| 849 |
|
| 850 |
jQuery |
| 851 |
.ajax({ |
| 852 |
url: supportcandy.ajax_url, |
| 853 |
type: "POST", |
| 854 |
data: dataform, |
| 855 |
processData: false, |
| 856 |
contentType: false, |
| 857 |
}) |
| 858 |
.done(function (res) { |
| 859 |
if (thread.next().length > 0) { |
| 860 |
thread.next().before(res); |
| 861 |
} else { |
| 862 |
thread.parent().append(res); |
| 863 |
} |
| 864 |
thread.remove(); |
| 865 |
}); |
| 866 |
} |
| 867 |
|
| 868 |
/** |
| 869 |
* Delete thread |
| 870 |
*/ |
| 871 |
function wpsc_it_thread_delete(el, ticket_id, thread_id, nonce) { |
| 872 |
var flag = confirm(supportcandy.translations.confirm); |
| 873 |
if (!flag) { |
| 874 |
return; |
| 875 |
} |
| 876 |
|
| 877 |
var thread = jQuery(el).closest(".wpsc-thread"); |
| 878 |
thread.html(supportcandy.loader_html); |
| 879 |
|
| 880 |
var data = { |
| 881 |
action: "wpsc_it_thread_delete", |
| 882 |
ticket_id, |
| 883 |
thread_id, |
| 884 |
_ajax_nonce: nonce, |
| 885 |
}; |
| 886 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 887 |
if (res.trim()) { |
| 888 |
if (thread.next().length > 0) { |
| 889 |
thread.next().before(res); |
| 890 |
} else { |
| 891 |
thread.parent().append(res); |
| 892 |
} |
| 893 |
} |
| 894 |
thread.remove(); |
| 895 |
}); |
| 896 |
} |
| 897 |
|
| 898 |
/** |
| 899 |
* Get thread html |
| 900 |
*/ |
| 901 |
function wpsc_it_get_thread(el, ticket_id, thread_id, _ajax_nonce) { |
| 902 |
var thread = jQuery(el).closest(".wpsc-thread"); |
| 903 |
thread.html(supportcandy.loader_html); |
| 904 |
|
| 905 |
var data = { |
| 906 |
action: "wpsc_it_get_thread", |
| 907 |
ticket_id, |
| 908 |
thread_id, |
| 909 |
_ajax_nonce, |
| 910 |
}; |
| 911 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 912 |
if (thread.next().length > 0) { |
| 913 |
thread.next().before(res); |
| 914 |
} else { |
| 915 |
thread.parent().append(res); |
| 916 |
} |
| 917 |
thread.remove(); |
| 918 |
}); |
| 919 |
} |
| 920 |
|
| 921 |
/** |
| 922 |
* View thread log |
| 923 |
*/ |
| 924 |
function wpsc_it_view_thread_log(ticket_id, thread_id, log_id, _ajax_nonce) { |
| 925 |
wpsc_show_modal(); |
| 926 |
var data = { |
| 927 |
action: "wpsc_it_view_thread_log", |
| 928 |
ticket_id, |
| 929 |
thread_id, |
| 930 |
log_id, |
| 931 |
_ajax_nonce, |
| 932 |
}; |
| 933 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 934 |
jQuery(".wpsc-modal-header").text(response.title); |
| 935 |
jQuery(".wpsc-modal-body").html(response.body); |
| 936 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 937 |
wpsc_show_modal_inner_container(); |
| 938 |
}); |
| 939 |
} |
| 940 |
|
| 941 |
/** |
| 942 |
* View thread |
| 943 |
*/ |
| 944 |
function wpsc_it_view_deleted_thread(ticket_id, thread_id, _ajax_nonce) { |
| 945 |
wpsc_show_modal(); |
| 946 |
var data = { |
| 947 |
action: "wpsc_it_view_deleted_thread", |
| 948 |
ticket_id, |
| 949 |
thread_id, |
| 950 |
_ajax_nonce, |
| 951 |
}; |
| 952 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 953 |
jQuery(".wpsc-modal-header").text(response.title); |
| 954 |
jQuery(".wpsc-modal-body").html(response.body); |
| 955 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 956 |
wpsc_show_modal_inner_container(); |
| 957 |
}); |
| 958 |
} |
| 959 |
|
| 960 |
/** |
| 961 |
* Restore thread |
| 962 |
*/ |
| 963 |
function wpsc_it_restore_thread(ticket_id, thread_id, _ajax_nonce) { |
| 964 |
var flag = confirm(supportcandy.translations.confirm); |
| 965 |
if (!flag) { |
| 966 |
return; |
| 967 |
} |
| 968 |
|
| 969 |
wpsc_close_modal(); |
| 970 |
var thread = jQuery(".wpsc-thread." + thread_id); |
| 971 |
thread.html(supportcandy.loader_html); |
| 972 |
|
| 973 |
var data = { |
| 974 |
action: "wpsc_it_restore_thread", |
| 975 |
ticket_id, |
| 976 |
thread_id, |
| 977 |
_ajax_nonce, |
| 978 |
}; |
| 979 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 980 |
if (thread.next().length > 0) { |
| 981 |
thread.next().before(res); |
| 982 |
} else { |
| 983 |
thread.parent().append(res); |
| 984 |
} |
| 985 |
thread.remove(); |
| 986 |
}); |
| 987 |
} |
| 988 |
|
| 989 |
/** |
| 990 |
* Restore thread |
| 991 |
*/ |
| 992 |
function wpsc_it_thread_delete_permanently(ticket_id, thread_id, _ajax_nonce) { |
| 993 |
var flag = confirm(supportcandy.translations.confirm); |
| 994 |
if (!flag) { |
| 995 |
return; |
| 996 |
} |
| 997 |
|
| 998 |
wpsc_close_modal(); |
| 999 |
var thread = jQuery(".wpsc-thread." + thread_id); |
| 1000 |
thread.html(supportcandy.loader_html); |
| 1001 |
|
| 1002 |
var data = { |
| 1003 |
action: "wpsc_it_thread_delete_permanently", |
| 1004 |
ticket_id, |
| 1005 |
thread_id, |
| 1006 |
_ajax_nonce, |
| 1007 |
}; |
| 1008 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 1009 |
thread.remove(); |
| 1010 |
}); |
| 1011 |
} |
| 1012 |
|
| 1013 |
/** |
| 1014 |
* Get macros modal UI |
| 1015 |
*/ |
| 1016 |
function wpsc_get_macros() { |
| 1017 |
wpsc_show_modal(); |
| 1018 |
var data = { |
| 1019 |
action: "wpsc_get_macros", |
| 1020 |
}; |
| 1021 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1022 |
// Set to modal. |
| 1023 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1024 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1025 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1026 |
// Display modal. |
| 1027 |
wpsc_show_modal_inner_container(); |
| 1028 |
jQuery("input[type=text]").focus(); |
| 1029 |
}); |
| 1030 |
} |
| 1031 |
|
| 1032 |
/** |
| 1033 |
* Add and condition item |
| 1034 |
* @param {*} el |
| 1035 |
* @param {*} uniqueId |
| 1036 |
*/ |
| 1037 |
function wpsc_add_and_condition(el, uniqueId) { |
| 1038 |
var container = jQuery(el) |
| 1039 |
.closest(".wpsc-form-filter-container") |
| 1040 |
.find(".and-container"); |
| 1041 |
container.append(jQuery(".and-template." + uniqueId).html()); |
| 1042 |
container = container.find(".and-item:last-child .or-container"); |
| 1043 |
container.append(jQuery(".or-template." + uniqueId).html()); |
| 1044 |
container.find("select").selectWoo(); |
| 1045 |
} |
| 1046 |
|
| 1047 |
/** |
| 1048 |
* Add and condition item |
| 1049 |
* @param {*} el |
| 1050 |
* @param {*} uniqueId |
| 1051 |
*/ |
| 1052 |
function wpsc_add_or_condition(el, uniqueId) { |
| 1053 |
var container = jQuery(el).closest(".and-item").find(".or-container"); |
| 1054 |
container.append(jQuery(".or-template." + uniqueId).html()); |
| 1055 |
container.find(":last-child").find("select").selectWoo(); |
| 1056 |
} |
| 1057 |
|
| 1058 |
/** |
| 1059 |
* Remove condition item |
| 1060 |
* @param {*} el |
| 1061 |
*/ |
| 1062 |
function wpsc_remove_condition_item(el) { |
| 1063 |
var andItem = jQuery(el).closest(".and-item"); |
| 1064 |
jQuery(el).closest(".wpsc-form-filter-item").remove(); |
| 1065 |
if (andItem.find(".or-container").children().length === 0) { |
| 1066 |
jQuery(andItem).remove(); |
| 1067 |
} |
| 1068 |
} |
| 1069 |
|
| 1070 |
/** |
| 1071 |
* Get JSON string for the condition input of given name |
| 1072 |
* @param {*} name |
| 1073 |
*/ |
| 1074 |
function wpsc_get_condition_json(name) { |
| 1075 |
var conditions = []; |
| 1076 |
jQuery(".wpsc-form-filter-container." + name + " .and-item").each( |
| 1077 |
function () { |
| 1078 |
var andCondition = []; |
| 1079 |
jQuery(this) |
| 1080 |
.find(".wpsc-form-filter-item") |
| 1081 |
.each(function () { |
| 1082 |
var slug = jQuery(this).find("select.filter").first().val(); |
| 1083 |
if (!slug) { |
| 1084 |
return; |
| 1085 |
} |
| 1086 |
var operator = jQuery(this).find("select.operator").first().val(); |
| 1087 |
if (!operator) { |
| 1088 |
return; |
| 1089 |
} |
| 1090 |
var operand_val_1 = jQuery(this).find(".operand_val_1").first().val(); |
| 1091 |
if (!operand_val_1) { |
| 1092 |
return; |
| 1093 |
} |
| 1094 |
var filter = { slug, operator, operand_val_1 }; |
| 1095 |
if (operator === "BETWEEN") { |
| 1096 |
var operand_val_2 = jQuery(this) |
| 1097 |
.find(".operand_val_2") |
| 1098 |
.first() |
| 1099 |
.val(); |
| 1100 |
if (!operand_val_2) { |
| 1101 |
return; |
| 1102 |
} |
| 1103 |
filter.operand_val_2 = operand_val_2; |
| 1104 |
} |
| 1105 |
andCondition.push(filter); |
| 1106 |
}); |
| 1107 |
conditions.push(andCondition); |
| 1108 |
} |
| 1109 |
); |
| 1110 |
return conditions; |
| 1111 |
} |
| 1112 |
|
| 1113 |
/** |
| 1114 |
* Get form filter oprators |
| 1115 |
*/ |
| 1116 |
function wpsc_get_ticket_filter_operators(el, nonce) { |
| 1117 |
var content = jQuery(el).closest(".content"); |
| 1118 |
var slug = jQuery(el).val().trim(); |
| 1119 |
|
| 1120 |
content.find(".conditional, .wpsc-inline-loader").remove(); |
| 1121 |
if (!slug) { |
| 1122 |
return; |
| 1123 |
} |
| 1124 |
|
| 1125 |
content.append(supportcandy.inline_loader); |
| 1126 |
var data = { |
| 1127 |
action: "wpsc_get_ticket_filter_operators", |
| 1128 |
slug: slug, |
| 1129 |
_ajax_nonce: nonce, |
| 1130 |
}; |
| 1131 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1132 |
content.find(".wpsc-inline-loader").remove(); |
| 1133 |
content.append(response); |
| 1134 |
}); |
| 1135 |
} |
| 1136 |
|
| 1137 |
/** |
| 1138 |
* Get ticket filter value input(s) |
| 1139 |
*/ |
| 1140 |
function wpsc_get_ticket_filter_operands(el, id, nonce) { |
| 1141 |
var content = jQuery(el).closest(".content"); |
| 1142 |
var operator = jQuery(el).val().trim(); |
| 1143 |
|
| 1144 |
content.find(".conditional.operand, .wpsc-inline-loader").remove(); |
| 1145 |
if (!operator) { |
| 1146 |
return; |
| 1147 |
} |
| 1148 |
|
| 1149 |
content.append(supportcandy.inline_loader); |
| 1150 |
var data = { |
| 1151 |
action: "wpsc_get_ticket_filter_operands", |
| 1152 |
operator, |
| 1153 |
id, |
| 1154 |
_ajax_nonce: nonce, |
| 1155 |
}; |
| 1156 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1157 |
content.find(".wpsc-inline-loader").remove(); |
| 1158 |
content.append(response); |
| 1159 |
}); |
| 1160 |
} |
| 1161 |
|
| 1162 |
/** |
| 1163 |
* Single file attachment upload handler |
| 1164 |
*/ |
| 1165 |
function wpsc_set_attach_single(el, uniqueId, slug) { |
| 1166 |
var fileAttachment = el.files[0]; |
| 1167 |
wpsc_file_upload(fileAttachment, uniqueId, slug, true); |
| 1168 |
jQuery(el).val(""); |
| 1169 |
} |
| 1170 |
|
| 1171 |
/** |
| 1172 |
* Myltiple file attachment upload handler |
| 1173 |
*/ |
| 1174 |
function wpsc_set_attach_multiple(el, uniqueId, slug) { |
| 1175 |
jQuery.each(el.files, function (index, fileAttachment) { |
| 1176 |
wpsc_file_upload(fileAttachment, uniqueId, slug); |
| 1177 |
}); |
| 1178 |
jQuery(el).val(""); |
| 1179 |
} |
| 1180 |
|
| 1181 |
/** |
| 1182 |
* Trigger description attachments |
| 1183 |
*/ |
| 1184 |
function wpsc_trigger_desc_attachments(uniqueId) { |
| 1185 |
jQuery("input." + uniqueId).trigger("click"); |
| 1186 |
} |
| 1187 |
|
| 1188 |
/** |
| 1189 |
* Remove an attachment |
| 1190 |
*/ |
| 1191 |
function wpsc_remove_attachment(el) { |
| 1192 |
var single = jQuery(el).data("single"); |
| 1193 |
var uniqueId = jQuery(el).data("uniqueid"); |
| 1194 |
jQuery(el).closest(".wpsc-editor-attachment").remove(); |
| 1195 |
if (single) { |
| 1196 |
jQuery("input." + uniqueId).show(); |
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
/** |
| 1201 |
* Attachment upload progess update |
| 1202 |
*/ |
| 1203 |
function wpscAttachmentUploadProgress(e) { |
| 1204 |
if (e.lengthComputable) { |
| 1205 |
var max = e.total; |
| 1206 |
var current = e.loaded; |
| 1207 |
var progrss = current / max; |
| 1208 |
e.currentTarget.attachment |
| 1209 |
.find(".attachment-waiting") |
| 1210 |
.circleProgress("value", progrss); |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
/** |
| 1215 |
* Change raised by or create ticket as |
| 1216 |
*/ |
| 1217 |
function wpsc_get_change_create_as(nonce) { |
| 1218 |
wpsc_show_modal(); |
| 1219 |
var data = { action: "wpsc_get_change_create_as", _ajax_nonce: nonce }; |
| 1220 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1221 |
// Set to modal. |
| 1222 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1223 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1224 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1225 |
// Display modal. |
| 1226 |
wpsc_show_modal_inner_container(); |
| 1227 |
}); |
| 1228 |
} |
| 1229 |
|
| 1230 |
/** |
| 1231 |
* Change create as |
| 1232 |
*/ |
| 1233 |
function wpsc_set_change_create_as(uniqueId, _ajax_nonce) { |
| 1234 |
var name = jQuery("input.name." + uniqueId) |
| 1235 |
.val() |
| 1236 |
.trim(); |
| 1237 |
var email = jQuery("input.email." + uniqueId) |
| 1238 |
.val() |
| 1239 |
.trim(); |
| 1240 |
if (!name || !email) { |
| 1241 |
alert(supportcandy.translations.req_fields_missing); |
| 1242 |
return; |
| 1243 |
} |
| 1244 |
|
| 1245 |
if (!validateEmail(email)) { |
| 1246 |
alert(supportcandy.translations.invalidEmail); |
| 1247 |
return; |
| 1248 |
} |
| 1249 |
|
| 1250 |
var data = { action: "wpsc_add_new_create_as", name, email, _ajax_nonce }; |
| 1251 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1252 |
jQuery("input.name").val(response.name); |
| 1253 |
jQuery("input.email").val(response.email); |
| 1254 |
|
| 1255 |
// add option and select. |
| 1256 |
if (jQuery("select.create-as").val() != response.id) { |
| 1257 |
var newOption = new Option(response.label, response.id, false, false); |
| 1258 |
jQuery("select.create-as").append(newOption); |
| 1259 |
jQuery("select.create-as").val(response.id).trigger("change"); |
| 1260 |
} |
| 1261 |
|
| 1262 |
wpsc_close_modal(); |
| 1263 |
wpsc_after_change_create_as(); |
| 1264 |
}); |
| 1265 |
} |
| 1266 |
|
| 1267 |
/** |
| 1268 |
* Check visibility conditions |
| 1269 |
*/ |
| 1270 |
function wpsc_check_tff_visibility() { |
| 1271 |
var conditionalFields = jQuery(".wpsc-tff.conditional"); |
| 1272 |
if (conditionalFields.length === 0) { |
| 1273 |
return; |
| 1274 |
} |
| 1275 |
|
| 1276 |
const callerId = Math.floor(Math.random() * 100000); |
| 1277 |
supportcandy.checkTffVisibityCallers = |
| 1278 |
supportcandy.checkTffVisibityCallers || []; |
| 1279 |
supportcandy.checkTffVisibityCallers.push(callerId); |
| 1280 |
|
| 1281 |
jQuery(".wpsc-ct-loader").html(supportcandy.inline_loader); |
| 1282 |
jQuery("select.create-as").attr("disabled", true); |
| 1283 |
|
| 1284 |
var form = jQuery("form.wpsc-create-ticket")[0]; |
| 1285 |
var dataform = new FormData(form); |
| 1286 |
|
| 1287 |
var is_tinymce = |
| 1288 |
typeof tinyMCE != "undefined" && |
| 1289 |
tinyMCE.activeEditor && |
| 1290 |
!tinyMCE.activeEditor.isHidden(); |
| 1291 |
if (is_tinymce && tinymce.get("description")) { |
| 1292 |
var description = tinyMCE.get("description").getContent(); |
| 1293 |
} else { |
| 1294 |
var description = jQuery("#description").val(); |
| 1295 |
} |
| 1296 |
|
| 1297 |
dataform.append("description", description); |
| 1298 |
dataform.append("action", "wpsc_check_tff_visibility"); |
| 1299 |
jQuery |
| 1300 |
.ajax({ |
| 1301 |
url: supportcandy.ajax_url, |
| 1302 |
type: "POST", |
| 1303 |
data: dataform, |
| 1304 |
processData: false, |
| 1305 |
contentType: false, |
| 1306 |
}) |
| 1307 |
.done(function (results) { |
| 1308 |
jQuery.each(results, function (key, val) { |
| 1309 |
if (parseInt(val) === 0) { |
| 1310 |
jQuery(".wpsc-tff." + key).addClass("wpsc-hidden"); |
| 1311 |
jQuery(".wpsc-tff." + key).removeClass("wpsc-visible"); |
| 1312 |
} else { |
| 1313 |
jQuery(".wpsc-tff." + key).removeClass("wpsc-hidden"); |
| 1314 |
jQuery(".wpsc-tff." + key).addClass("wpsc-visible"); |
| 1315 |
} |
| 1316 |
}); |
| 1317 |
jQuery(".wpsc-ct-loader").html(""); |
| 1318 |
jQuery("select.create-as").removeAttr("disabled"); |
| 1319 |
}) |
| 1320 |
.fail(function (xhr, status, error) { |
| 1321 |
console.error("AJAX request failed:", status, error); |
| 1322 |
jQuery(".wpsc-ct-loader").html(""); |
| 1323 |
jQuery("select.create-as").removeAttr("disabled"); |
| 1324 |
}) |
| 1325 |
.always(function () { |
| 1326 |
// remove callerId from supportcandy.checkTffVisibityCallers array |
| 1327 |
supportcandy.checkTffVisibityCallers = |
| 1328 |
supportcandy.checkTffVisibityCallers.filter(function (id) { |
| 1329 |
return id !== callerId; |
| 1330 |
}); |
| 1331 |
}); |
| 1332 |
} |
| 1333 |
|
| 1334 |
/** |
| 1335 |
* Validate input for email address |
| 1336 |
*/ |
| 1337 |
function validateEmail(email) { |
| 1338 |
var re = |
| 1339 |
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| 1340 |
return re.test(email); |
| 1341 |
} |
| 1342 |
|
| 1343 |
/** |
| 1344 |
* Validate input for URL |
| 1345 |
*/ |
| 1346 |
function validateURL(url) { |
| 1347 |
var re = |
| 1348 |
/^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/; |
| 1349 |
return re.test(url); |
| 1350 |
} |
| 1351 |
|
| 1352 |
/** |
| 1353 |
* Validate input for number |
| 1354 |
*/ |
| 1355 |
function validateNumber(number) { |
| 1356 |
var re = /^[0-9]+$/; |
| 1357 |
return re.test(number); |
| 1358 |
} |
| 1359 |
|
| 1360 |
/** |
| 1361 |
* Change event for filter |
| 1362 |
*/ |
| 1363 |
function wpsc_tl_filter_change(el, type) { |
| 1364 |
const filterSlug = jQuery(el).val()?.trim(); |
| 1365 |
const isTicketList = type === 'ticket_list'; |
| 1366 |
supportcandy.prevFilter = supportcandy.ticketList.filters.filterSlug; |
| 1367 |
|
| 1368 |
if (filterSlug === 'custom') { |
| 1369 |
wpsc_tl_get_custom_filter( type ); |
| 1370 |
return; |
| 1371 |
} |
| 1372 |
|
| 1373 |
supportcandy.ticketList.filters = { filterSlug }; |
| 1374 |
isTicketList ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1375 |
} |
| 1376 |
|
| 1377 |
/** |
| 1378 |
* Change ticket list page |
| 1379 |
*/ |
| 1380 |
function wpsc_tl_set_page(page, type) { |
| 1381 |
switch (page) { |
| 1382 |
case "first": |
| 1383 |
if (supportcandy.ticketList.pagination.current_page == 1) { |
| 1384 |
return; |
| 1385 |
} |
| 1386 |
supportcandy.ticketList.filters.page_no = 1; |
| 1387 |
break; |
| 1388 |
|
| 1389 |
case "prev": |
| 1390 |
if (supportcandy.ticketList.pagination.current_page < 2) { |
| 1391 |
return; |
| 1392 |
} |
| 1393 |
supportcandy.ticketList.filters.page_no = |
| 1394 |
supportcandy.ticketList.pagination.current_page - 1; |
| 1395 |
break; |
| 1396 |
|
| 1397 |
case "next": |
| 1398 |
if (!supportcandy.ticketList.pagination.has_next_page) { |
| 1399 |
return; |
| 1400 |
} |
| 1401 |
supportcandy.ticketList.filters.page_no = |
| 1402 |
supportcandy.ticketList.pagination.current_page + 1; |
| 1403 |
break; |
| 1404 |
|
| 1405 |
case "last": |
| 1406 |
if ( |
| 1407 |
supportcandy.ticketList.pagination.current_page == |
| 1408 |
supportcandy.ticketList.pagination.total_pages |
| 1409 |
) { |
| 1410 |
return; |
| 1411 |
} |
| 1412 |
supportcandy.ticketList.filters.page_no = |
| 1413 |
supportcandy.ticketList.pagination.total_pages; |
| 1414 |
break; |
| 1415 |
} |
| 1416 |
type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1417 |
} |
| 1418 |
|
| 1419 |
/** |
| 1420 |
* Reset ticket list filters |
| 1421 |
*/ |
| 1422 |
function wpsc_tl_reset_filter( type ) { |
| 1423 |
var filters = { filterSlug: "" }; |
| 1424 |
supportcandy.ticketList.filters = filters; |
| 1425 |
type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1426 |
} |
| 1427 |
|
| 1428 |
/** |
| 1429 |
* Search input keyup |
| 1430 |
*/ |
| 1431 |
function wpsc_tl_search_keyup(e, el, type) { |
| 1432 |
if (e.keyCode !== 13) { |
| 1433 |
return; |
| 1434 |
} |
| 1435 |
var search = jQuery(el).val().trim(); |
| 1436 |
supportcandy.ticketList.filters.search = search; |
| 1437 |
supportcandy.ticketList.filters.page_no = 1; |
| 1438 |
type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1439 |
} |
| 1440 |
|
| 1441 |
/** |
| 1442 |
* Apply filters |
| 1443 |
*/ |
| 1444 |
function wpsc_tl_apply_filter_btn_click( type ) { |
| 1445 |
supportcandy.ticketList.filters.search = jQuery("input.wpsc-search-input") |
| 1446 |
.val() |
| 1447 |
.trim(); |
| 1448 |
supportcandy.ticketList.filters.orderby = jQuery( |
| 1449 |
"select.wpsc-input-sort-by" |
| 1450 |
).val(); |
| 1451 |
supportcandy.ticketList.filters.order = jQuery( |
| 1452 |
"select.wpsc-input-sort-order" |
| 1453 |
).val(); |
| 1454 |
supportcandy.ticketList.filters.page_no = 1; |
| 1455 |
type === 'ticket_list' ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1456 |
} |
| 1457 |
|
| 1458 |
/** |
| 1459 |
* Get custom filter UI |
| 1460 |
*/ |
| 1461 |
function wpsc_tl_get_custom_filter( type ) { |
| 1462 |
wpsc_show_modal(); |
| 1463 |
|
| 1464 |
const isTicketList = type === 'ticket_list'; |
| 1465 |
const action = isTicketList ? 'wpsc_get_tl_custom_filter' : 'wpsc_get_atl_custom_filter'; |
| 1466 |
|
| 1467 |
const data = { |
| 1468 |
action, |
| 1469 |
_ajax_nonce: supportcandy.nonce, |
| 1470 |
}; |
| 1471 |
if (supportcandy.ticketList.filters.filterSlug === 'custom') { |
| 1472 |
data.filters = supportcandy.ticketList.filters; |
| 1473 |
} |
| 1474 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1475 |
jQuery('.wpsc-modal-header').text(response.title); |
| 1476 |
jQuery('.wpsc-modal-body').html(response.body); |
| 1477 |
jQuery('.wpsc-modal-footer').html(response.footer); |
| 1478 |
wpsc_show_modal_inner_container(); |
| 1479 |
}); |
| 1480 |
} |
| 1481 |
|
| 1482 |
/** |
| 1483 |
* Apply custom filter |
| 1484 |
*/ |
| 1485 |
function wpsc_tl_apply_custom_filter(el, type) { |
| 1486 |
|
| 1487 |
var filters = wpsc_get_condition_json("custom_filters"); |
| 1488 |
if ( |
| 1489 |
filters.length === 0 || |
| 1490 |
(filters.length === 1 && filters[0].length === 0) |
| 1491 |
) { |
| 1492 |
alert(supportcandy.translations.req_fields_missing); |
| 1493 |
return; |
| 1494 |
} |
| 1495 |
|
| 1496 |
const cust_filter = type === "ticket_list" ? "wpsc-tl-custom-filter" : "wpsc-atl-custom-filter"; |
| 1497 |
filters = { |
| 1498 |
filterSlug: "custom", |
| 1499 |
"parent-filter": jQuery( |
| 1500 |
"." + cust_filter + " select[name=parent-filter]" |
| 1501 |
).val(), |
| 1502 |
filters: JSON.stringify(filters), |
| 1503 |
orderby: jQuery("." + cust_filter + " select[name=sort-by]").val(), |
| 1504 |
order: jQuery("." + cust_filter + " select[name=sort-order]").val(), |
| 1505 |
page_no: 1, |
| 1506 |
}; |
| 1507 |
supportcandy.ticketList.filters = filters; |
| 1508 |
|
| 1509 |
wpsc_close_modal(); |
| 1510 |
type === "ticket_list" ? wpsc_get_tickets() : wpsc_get_archive_tickets(); |
| 1511 |
} |
| 1512 |
|
| 1513 |
/** |
| 1514 |
* Edit ticket list filter |
| 1515 |
*/ |
| 1516 |
function wpsc_tl_edit_filter( type ) { |
| 1517 |
if (supportcandy.ticketList.filters.filterSlug == "custom") { |
| 1518 |
wpsc_tl_get_custom_filter( type ); |
| 1519 |
} else { |
| 1520 |
type === "ticket_list" ? wpsc_tl_get_edit_saved_filter() : wpsc_atl_get_edit_saved_filter(); |
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
/** |
| 1525 |
* Add saved filter |
| 1526 |
*/ |
| 1527 |
function wpsc_tl_add_saved_filter() { |
| 1528 |
var filters = wpsc_get_condition_json("custom_filters"); |
| 1529 |
if ( |
| 1530 |
filters.length === 0 || |
| 1531 |
(filters.length === 1 && filters[0].length === 0) |
| 1532 |
) { |
| 1533 |
alert(supportcandy.translations.req_fields_missing); |
| 1534 |
return; |
| 1535 |
} |
| 1536 |
|
| 1537 |
filters = { |
| 1538 |
"parent-filter": jQuery( |
| 1539 |
".wpsc-tl-custom-filter select[name=parent-filter]" |
| 1540 |
).val(), |
| 1541 |
filters: JSON.stringify(filters), |
| 1542 |
orderby: jQuery(".wpsc-tl-custom-filter select[name=sort-by]").val(), |
| 1543 |
order: jQuery(".wpsc-tl-custom-filter select[name=sort-order]").val(), |
| 1544 |
}; |
| 1545 |
|
| 1546 |
supportcandy.tempFilters = filters; |
| 1547 |
wpsc_close_modal(); |
| 1548 |
setTimeout(function () { |
| 1549 |
wpsc_tl_get_add_saved_filter(); |
| 1550 |
}, 500); |
| 1551 |
} |
| 1552 |
|
| 1553 |
/** |
| 1554 |
* Get add saved filter ui |
| 1555 |
*/ |
| 1556 |
function wpsc_tl_get_add_saved_filter() { |
| 1557 |
wpsc_show_modal(); |
| 1558 |
var data = { action: "wpsc_tl_get_add_saved_filter" }; |
| 1559 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1560 |
// Set to modal. |
| 1561 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1562 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1563 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1564 |
// Display modal. |
| 1565 |
wpsc_show_modal_inner_container(); |
| 1566 |
}); |
| 1567 |
} |
| 1568 |
|
| 1569 |
/** |
| 1570 |
* Save and apply custom filter |
| 1571 |
*/ |
| 1572 |
function wpsc_tl_set_add_saved_filter(el, nonce) { |
| 1573 |
var label = jQuery("input.wpsc-cf-label").val().trim(); |
| 1574 |
if (!label) { |
| 1575 |
alert(supportcandy.translations.req_fields_missing); |
| 1576 |
return; |
| 1577 |
} |
| 1578 |
|
| 1579 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 1580 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 1581 |
|
| 1582 |
var data = { |
| 1583 |
action: "wpsc_tl_set_add_saved_filter", |
| 1584 |
filters: supportcandy.tempFilters, |
| 1585 |
_ajax_nonce: nonce, |
| 1586 |
}; |
| 1587 |
data.filters.label = label; |
| 1588 |
|
| 1589 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1590 |
supportcandy.ticketList.filters = { filterSlug: response.slug }; |
| 1591 |
wpsc_close_modal(); |
| 1592 |
wpsc_get_ticket_list(); |
| 1593 |
}); |
| 1594 |
} |
| 1595 |
|
| 1596 |
/** |
| 1597 |
* Get edit saved filter modal |
| 1598 |
*/ |
| 1599 |
function wpsc_tl_get_edit_saved_filter() { |
| 1600 |
wpsc_show_modal(); |
| 1601 |
var data = { |
| 1602 |
action: "wpsc_tl_get_edit_saved_filter", |
| 1603 |
filterSlug: supportcandy.ticketList.filters.filterSlug, |
| 1604 |
_ajax_nonce: supportcandy.nonce, |
| 1605 |
}; |
| 1606 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1607 |
// Set to modal. |
| 1608 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1609 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1610 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1611 |
// Display modal. |
| 1612 |
wpsc_show_modal_inner_container(); |
| 1613 |
}); |
| 1614 |
} |
| 1615 |
|
| 1616 |
/** |
| 1617 |
* Set edit saved filter |
| 1618 |
*/ |
| 1619 |
function wpsc_tl_set_edit_saved_filter(el) { |
| 1620 |
var label = jQuery("input.wpsc-cf-label").val().trim(); |
| 1621 |
if (!label) { |
| 1622 |
alert(supportcandy.translations.req_fields_missing); |
| 1623 |
return; |
| 1624 |
} |
| 1625 |
|
| 1626 |
var filters = wpsc_get_condition_json("custom_filters"); |
| 1627 |
if ( |
| 1628 |
filters.length === 0 || |
| 1629 |
(filters.length === 1 && filters[0].length === 0) |
| 1630 |
) { |
| 1631 |
alert(supportcandy.translations.req_fields_missing); |
| 1632 |
return; |
| 1633 |
} |
| 1634 |
|
| 1635 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 1636 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 1637 |
|
| 1638 |
var form = jQuery(".wpsc-tl-custom-filter")[0]; |
| 1639 |
var dataform = new FormData(form); |
| 1640 |
dataform.append("filters", JSON.stringify(filters)); |
| 1641 |
|
| 1642 |
jQuery |
| 1643 |
.ajax({ |
| 1644 |
url: supportcandy.ajax_url, |
| 1645 |
type: "POST", |
| 1646 |
data: dataform, |
| 1647 |
processData: false, |
| 1648 |
contentType: false, |
| 1649 |
}) |
| 1650 |
.done(function (res) { |
| 1651 |
wpsc_close_modal(); |
| 1652 |
wpsc_get_ticket_list(); |
| 1653 |
}); |
| 1654 |
} |
| 1655 |
|
| 1656 |
/** |
| 1657 |
* Delete saved filter |
| 1658 |
*/ |
| 1659 |
function wpsc_tl_delete_saved_filter( type ) { |
| 1660 |
var flag = confirm(supportcandy.translations.confirm); |
| 1661 |
if (!flag) { |
| 1662 |
return; |
| 1663 |
} |
| 1664 |
|
| 1665 |
var data = { |
| 1666 |
action: "wpsc_tl_delete_saved_filter", |
| 1667 |
slug: supportcandy.ticketList.filters.filterSlug, |
| 1668 |
_ajax_nonce: supportcandy.nonce, |
| 1669 |
}; |
| 1670 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 1671 |
supportcandy.ticketList.filters = { filterSlug: "" }; |
| 1672 |
wpsc_get_ticket_list(); |
| 1673 |
}); |
| 1674 |
} |
| 1675 |
|
| 1676 |
/** |
| 1677 |
* Close custom filter modal |
| 1678 |
*/ |
| 1679 |
function wpsc_tl_close_custom_filter_modal() { |
| 1680 |
jQuery("select.wpsc-input-filter").val(supportcandy.prevFilter); |
| 1681 |
wpsc_close_modal(); |
| 1682 |
} |
| 1683 |
|
| 1684 |
/** |
| 1685 |
* Get form filter oprators |
| 1686 |
*/ |
| 1687 |
function wpsc_tc_get_operators(el, nonce) { |
| 1688 |
var content = jQuery(el).closest(".content"); |
| 1689 |
var slug = jQuery(el).val().trim(); |
| 1690 |
|
| 1691 |
content.find(".conditional, .wpsc-inline-loader").remove(); |
| 1692 |
if (!slug) { |
| 1693 |
return; |
| 1694 |
} |
| 1695 |
|
| 1696 |
content.append(supportcandy.inline_loader); |
| 1697 |
var data = { |
| 1698 |
action: "wpsc_tc_get_operators", |
| 1699 |
slug: slug, |
| 1700 |
_ajax_nonce: nonce, |
| 1701 |
}; |
| 1702 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1703 |
content.find(".wpsc-inline-loader").remove(); |
| 1704 |
content.append(response); |
| 1705 |
}); |
| 1706 |
} |
| 1707 |
|
| 1708 |
/** |
| 1709 |
* Get email notification condition operands |
| 1710 |
*/ |
| 1711 |
function wpsc_tc_get_operand(el, slug, nonce) { |
| 1712 |
var content = jQuery(el).closest(".content"); |
| 1713 |
var operator = jQuery(el).val().trim(); |
| 1714 |
|
| 1715 |
content.find(".conditional.operand, .wpsc-inline-loader").remove(); |
| 1716 |
if (!operator) { |
| 1717 |
return; |
| 1718 |
} |
| 1719 |
|
| 1720 |
content.append(supportcandy.inline_loader); |
| 1721 |
var data = { |
| 1722 |
action: "wpsc_tc_get_operand", |
| 1723 |
operator, |
| 1724 |
slug, |
| 1725 |
_ajax_nonce: nonce, |
| 1726 |
}; |
| 1727 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1728 |
content.find(".wpsc-inline-loader").remove(); |
| 1729 |
content.append(response); |
| 1730 |
}); |
| 1731 |
} |
| 1732 |
|
| 1733 |
/** |
| 1734 |
* Add image to editor |
| 1735 |
* |
| 1736 |
* @param {*} editor |
| 1737 |
*/ |
| 1738 |
function wpsc_add_custom_image_tinymce(editor, nonce) { |
| 1739 |
wpsc_show_modal(); |
| 1740 |
var data = { |
| 1741 |
action: "wpsc_add_custom_image_tinymce", |
| 1742 |
editor_id: editor.id, |
| 1743 |
_ajax_nonce: nonce, |
| 1744 |
}; |
| 1745 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1746 |
// Set to modal. |
| 1747 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1748 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1749 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1750 |
// Display modal. |
| 1751 |
wpsc_show_modal_inner_container(); |
| 1752 |
}); |
| 1753 |
} |
| 1754 |
|
| 1755 |
/** |
| 1756 |
* Check whether given url has image or not |
| 1757 |
* |
| 1758 |
* @param {*} url |
| 1759 |
*/ |
| 1760 |
function isValidImageURL(url) { |
| 1761 |
if (typeof url !== "string") { |
| 1762 |
return false; |
| 1763 |
} |
| 1764 |
return !!url.match(/\w+\.(jpg|jpeg|gif|png|tiff|bmp)$/gi); |
| 1765 |
} |
| 1766 |
|
| 1767 |
/** |
| 1768 |
* Upload image to tinymce editor |
| 1769 |
* |
| 1770 |
* @param {*} el |
| 1771 |
*/ |
| 1772 |
function wpsc_insert_editor_img(ed) { |
| 1773 |
if ( |
| 1774 |
jQuery("#wpsc-tinymce-image-url").val().trim() === "" && |
| 1775 |
validateURL(jQuery("#wpsc-tinymce-image-url").val().trim()) && |
| 1776 |
isValidImageURL(jQuery("#wpsc-tinymce-image-url").val().trim()) |
| 1777 |
) { |
| 1778 |
alert(supportcandy.translations.req_fields_error); |
| 1779 |
return; |
| 1780 |
} |
| 1781 |
|
| 1782 |
if (jQuery("#wpsc-tinymce-image-width").val().trim() === "") { |
| 1783 |
alert(supportcandy.translations.req_fields_error); |
| 1784 |
return; |
| 1785 |
} |
| 1786 |
|
| 1787 |
if (jQuery("#wpsc-tinymce-image-height").val().trim() === "") { |
| 1788 |
alert(supportcandy.translations.req_fields_error); |
| 1789 |
return; |
| 1790 |
} |
| 1791 |
|
| 1792 |
var is_tinymce = |
| 1793 |
typeof tinyMCE != "undefined" && |
| 1794 |
tinyMCE.activeEditor && |
| 1795 |
!tinyMCE.activeEditor.isHidden(); |
| 1796 |
if (!is_tinymce) { |
| 1797 |
return; |
| 1798 |
} |
| 1799 |
|
| 1800 |
wpsc_close_modal(); |
| 1801 |
|
| 1802 |
var source = jQuery("#wpsc-tinymce-image-url").val().trim(); |
| 1803 |
var height = jQuery("#wpsc-tinymce-image-height").val().trim(); |
| 1804 |
var width = jQuery("#wpsc-tinymce-image-width").val().trim(); |
| 1805 |
tinymce |
| 1806 |
.get(ed) |
| 1807 |
.execCommand( |
| 1808 |
"mceInsertContent", |
| 1809 |
false, |
| 1810 |
'<img height="' + |
| 1811 |
height + |
| 1812 |
'" width="' + |
| 1813 |
width + |
| 1814 |
'" src="' + |
| 1815 |
source + |
| 1816 |
'"/>' |
| 1817 |
); |
| 1818 |
} |
| 1819 |
|
| 1820 |
/** |
| 1821 |
* Add image to editor |
| 1822 |
* |
| 1823 |
* @param {*} editor |
| 1824 |
*/ |
| 1825 |
function wpsc_edit_custom_image_tinymce(editor, image_obj, nonce) { |
| 1826 |
if (!(editor && image_obj)) { |
| 1827 |
alert(supportcandy.translations.req_fields_error); |
| 1828 |
return; |
| 1829 |
} |
| 1830 |
|
| 1831 |
wpsc_show_modal(); |
| 1832 |
var data = { |
| 1833 |
action: "wpsc_edit_custom_image_tinymce", |
| 1834 |
editor_id: editor.id, |
| 1835 |
height: image_obj.height, |
| 1836 |
width: image_obj.width, |
| 1837 |
src: image_obj.src, |
| 1838 |
_ajax_nonce: nonce, |
| 1839 |
}; |
| 1840 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1841 |
// Set to modal. |
| 1842 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1843 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1844 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1845 |
// Display modal. |
| 1846 |
wpsc_show_modal_inner_container(); |
| 1847 |
}); |
| 1848 |
} |
| 1849 |
|
| 1850 |
/** |
| 1851 |
* Get create ticket from thread |
| 1852 |
*/ |
| 1853 |
function wpsc_it_thread_new_ticket(el, ticket_id, thread_id, nonce) { |
| 1854 |
wpsc_show_modal(); |
| 1855 |
var data = { |
| 1856 |
action: "wpsc_it_thread_new_ticket", |
| 1857 |
ticket_id, |
| 1858 |
thread_id, |
| 1859 |
_ajax_nonce: nonce, |
| 1860 |
}; |
| 1861 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1862 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1863 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1864 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1865 |
wpsc_show_modal_inner_container(); |
| 1866 |
}); |
| 1867 |
} |
| 1868 |
|
| 1869 |
/** |
| 1870 |
* Get thread info |
| 1871 |
* |
| 1872 |
* @param {*} thread_id |
| 1873 |
*/ |
| 1874 |
function wpsc_it_thread_info(el, ticket_id, thread_id, nonce, type = 'ticket_list') { |
| 1875 |
wpsc_show_modal(); |
| 1876 |
var data = { |
| 1877 |
action: type === 'ticket_list' ? "wpsc_it_thread_info" : "wpsc_it_archive_thread_info", |
| 1878 |
thread_id, |
| 1879 |
ticket_id, |
| 1880 |
_ajax_nonce: nonce, |
| 1881 |
}; |
| 1882 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1883 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1884 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1885 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1886 |
wpsc_show_modal_inner_container(); |
| 1887 |
}); |
| 1888 |
} |
| 1889 |
|
| 1890 |
/** |
| 1891 |
* Set thread new ticket |
| 1892 |
*/ |
| 1893 |
function wpsc_it_set_thread_new_ticket(el, thread_id, nonce) { |
| 1894 |
var form = jQuery("form.new_ticket_from_thread")[0]; |
| 1895 |
var dataform = new FormData(form); |
| 1896 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 1897 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 1898 |
jQuery |
| 1899 |
.ajax({ |
| 1900 |
url: supportcandy.ajax_url, |
| 1901 |
type: "POST", |
| 1902 |
data: dataform, |
| 1903 |
processData: false, |
| 1904 |
contentType: false, |
| 1905 |
}) |
| 1906 |
.done(function (response) { |
| 1907 |
wpsc_close_modal(); |
| 1908 |
wpsc_get_individual_ticket(response.ticket_id); |
| 1909 |
}); |
| 1910 |
} |
| 1911 |
|
| 1912 |
/** |
| 1913 |
* Get customer other tickets |
| 1914 |
*/ |
| 1915 |
function wpsc_get_rb_other_tickets(el, ticket_id, nonce) { |
| 1916 |
wpsc_show_modal(); |
| 1917 |
var data = { |
| 1918 |
action: "wpsc_get_rb_other_tickets", |
| 1919 |
ticket_id, |
| 1920 |
_ajax_nonce: nonce, |
| 1921 |
}; |
| 1922 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1923 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1924 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1925 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1926 |
wpsc_show_modal_inner_container(); |
| 1927 |
}); |
| 1928 |
} |
| 1929 |
|
| 1930 |
/** |
| 1931 |
* Get raised by info |
| 1932 |
*/ |
| 1933 |
function wpsc_get_rb_info(el, ticket_id, nonce) { |
| 1934 |
wpsc_show_modal(); |
| 1935 |
var data = { action: "wpsc_get_rb_info", ticket_id, _ajax_nonce: nonce }; |
| 1936 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1937 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1938 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1939 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1940 |
wpsc_show_modal_inner_container(); |
| 1941 |
}); |
| 1942 |
} |
| 1943 |
|
| 1944 |
/** |
| 1945 |
* Thread expander |
| 1946 |
*/ |
| 1947 |
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"); |
| 1951 |
jQuery(el).text(supportcandy.translations.view_less); |
| 1952 |
} else { |
| 1953 |
jQuery(el).parent().find(".thread-text").height(100); |
| 1954 |
jQuery(el).text(supportcandy.translations.view_more); |
| 1955 |
} |
| 1956 |
} |
| 1957 |
|
| 1958 |
/** |
| 1959 |
* Get change bulk status |
| 1960 |
*/ |
| 1961 |
function wpsc_bulk_change_status(nonce) { |
| 1962 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 1963 |
var checked = items.length === 0 ? false : true; |
| 1964 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 1965 |
if (items.length != 0) { |
| 1966 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 1967 |
.map(function () { |
| 1968 |
return this.value; |
| 1969 |
}) |
| 1970 |
.get(); |
| 1971 |
wpsc_show_modal(); |
| 1972 |
var data = { |
| 1973 |
action: "wpsc_bulk_change_status", |
| 1974 |
ticket_ids, |
| 1975 |
_ajax_nonce: nonce, |
| 1976 |
}; |
| 1977 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 1978 |
// Set to modal. |
| 1979 |
jQuery(".wpsc-modal-header").text(response.title); |
| 1980 |
jQuery(".wpsc-modal-body").html(response.body); |
| 1981 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 1982 |
// Display modal. |
| 1983 |
wpsc_show_modal_inner_container(); |
| 1984 |
}); |
| 1985 |
} |
| 1986 |
} |
| 1987 |
|
| 1988 |
/** |
| 1989 |
* Load older threads |
| 1990 |
*/ |
| 1991 |
function wpsc_load_older_threads(el, ticket_id) { |
| 1992 |
if (supportcandy.reply_form_position === "top") { |
| 1993 |
jQuery(".wpsc-it-thread-section-container").append( |
| 1994 |
supportcandy.loader_html |
| 1995 |
); |
| 1996 |
} else { |
| 1997 |
jQuery(".wpsc-it-thread-section-container").prepend( |
| 1998 |
supportcandy.loader_html |
| 1999 |
); |
| 2000 |
} |
| 2001 |
|
| 2002 |
var oldBtnContainer = jQuery(el).parent(); |
| 2003 |
oldBtnContainer.hide(); |
| 2004 |
|
| 2005 |
var data = { |
| 2006 |
action: "wpsc_load_older_threads", |
| 2007 |
ticket_id, |
| 2008 |
last_thread: supportcandy.threads.last_thread, |
| 2009 |
}; |
| 2010 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2011 |
jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 2012 |
// add threads. |
| 2013 |
if (supportcandy.reply_form_position === "top") { |
| 2014 |
jQuery(".wpsc-it-thread-section-container").append(response.threads); |
| 2015 |
} else { |
| 2016 |
var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 2017 |
var windowScrollTop = jQuery(window).scrollTop(); |
| 2018 |
jQuery(".wpsc-it-thread-section-container").prepend(response.threads); |
| 2019 |
var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 2020 |
jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 2021 |
} |
| 2022 |
// show btn if there are more threads available. |
| 2023 |
if (response.has_next_page) { |
| 2024 |
supportcandy.threads.last_thread = response.last_thread; |
| 2025 |
oldBtnContainer.show(); |
| 2026 |
} |
| 2027 |
}); |
| 2028 |
} |
| 2029 |
|
| 2030 |
/** |
| 2031 |
* Set change bulk status |
| 2032 |
*/ |
| 2033 |
function wpsc_set_bulk_change_status(el) { |
| 2034 |
var form = jQuery("form.frm-edit-bulk-status")[0]; |
| 2035 |
var dataform = new FormData(form); |
| 2036 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 2037 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2038 |
jQuery |
| 2039 |
.ajax({ |
| 2040 |
url: supportcandy.ajax_url, |
| 2041 |
type: "POST", |
| 2042 |
data: dataform, |
| 2043 |
processData: false, |
| 2044 |
contentType: false, |
| 2045 |
}) |
| 2046 |
.done(function (res) { |
| 2047 |
wpsc_close_modal(); |
| 2048 |
wpsc_get_ticket_list(); |
| 2049 |
wpsc_run_ajax_background_process(); |
| 2050 |
}); |
| 2051 |
} |
| 2052 |
|
| 2053 |
/** |
| 2054 |
* Get bulk assign agent |
| 2055 |
*/ |
| 2056 |
function wpsc_bulk_assign_agents(nonce) { |
| 2057 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 2058 |
var checked = items.length === 0 ? false : true; |
| 2059 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 2060 |
if (items.length != 0) { |
| 2061 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 2062 |
.map(function () { |
| 2063 |
return this.value; |
| 2064 |
}) |
| 2065 |
.get(); |
| 2066 |
wpsc_show_modal(); |
| 2067 |
var data = { |
| 2068 |
action: "wpsc_bulk_assign_agents", |
| 2069 |
ticket_ids, |
| 2070 |
_ajax_nonce: nonce, |
| 2071 |
}; |
| 2072 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2073 |
// Set to modal. |
| 2074 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2075 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2076 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2077 |
// Display modal. |
| 2078 |
wpsc_show_modal_inner_container(); |
| 2079 |
}); |
| 2080 |
} |
| 2081 |
} |
| 2082 |
|
| 2083 |
/** |
| 2084 |
* Set change assign agent |
| 2085 |
*/ |
| 2086 |
function wpsc_set_bulk_assign_agent(el) { |
| 2087 |
var form = jQuery("form.frm-bulk-assign-agent")[0]; |
| 2088 |
var dataform = new FormData(form); |
| 2089 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 2090 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2091 |
jQuery |
| 2092 |
.ajax({ |
| 2093 |
url: supportcandy.ajax_url, |
| 2094 |
type: "POST", |
| 2095 |
data: dataform, |
| 2096 |
processData: false, |
| 2097 |
contentType: false, |
| 2098 |
}) |
| 2099 |
.done(function (res) { |
| 2100 |
wpsc_close_modal(); |
| 2101 |
wpsc_get_ticket_list(); |
| 2102 |
wpsc_run_ajax_background_process(); |
| 2103 |
}); |
| 2104 |
} |
| 2105 |
|
| 2106 |
/** |
| 2107 |
* Get bulk assign tags |
| 2108 |
*/ |
| 2109 |
function wpsc_bulk_assign_tags(nonce) { |
| 2110 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 2111 |
var checked = items.length === 0 ? false : true; |
| 2112 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 2113 |
if (items.length != 0) { |
| 2114 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 2115 |
.map(function () { |
| 2116 |
return this.value; |
| 2117 |
}) |
| 2118 |
.get(); |
| 2119 |
wpsc_show_modal(); |
| 2120 |
var data = { |
| 2121 |
action: "wpsc_bulk_assign_tags", |
| 2122 |
ticket_ids, |
| 2123 |
_ajax_nonce: nonce, |
| 2124 |
}; |
| 2125 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2126 |
// Set to modal. |
| 2127 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2128 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2129 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2130 |
// Display modal. |
| 2131 |
wpsc_show_modal_inner_container(); |
| 2132 |
}); |
| 2133 |
} |
| 2134 |
} |
| 2135 |
|
| 2136 |
/** |
| 2137 |
* Set change assign tags |
| 2138 |
*/ |
| 2139 |
function wpsc_set_bulk_assign_tag(el) { |
| 2140 |
var form = jQuery("form.frm-bulk-assign-tags")[0]; |
| 2141 |
var dataform = new FormData(form); |
| 2142 |
|
| 2143 |
var tags = dataform.getAll("tags[]"); |
| 2144 |
if (!tags.length) { |
| 2145 |
return; |
| 2146 |
} |
| 2147 |
|
| 2148 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 2149 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2150 |
jQuery |
| 2151 |
.ajax({ |
| 2152 |
url: supportcandy.ajax_url, |
| 2153 |
type: "POST", |
| 2154 |
data: dataform, |
| 2155 |
processData: false, |
| 2156 |
contentType: false, |
| 2157 |
}) |
| 2158 |
.done(function (res) { |
| 2159 |
wpsc_close_modal(); |
| 2160 |
wpsc_get_ticket_list(); |
| 2161 |
wpsc_run_ajax_background_process(); |
| 2162 |
}); |
| 2163 |
} |
| 2164 |
|
| 2165 |
/** |
| 2166 |
* Get bulk archive ticket |
| 2167 |
*/ |
| 2168 |
function wpsc_bulk_archive_tickets(nonce) { |
| 2169 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 2170 |
var checked = items.length === 0 ? false : true; |
| 2171 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 2172 |
if (items.length != 0) { |
| 2173 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 2174 |
.map(function () { |
| 2175 |
return this.value; |
| 2176 |
}) |
| 2177 |
.get(); |
| 2178 |
var flag = confirm(supportcandy.translations.confirm); |
| 2179 |
if (!flag) { |
| 2180 |
return; |
| 2181 |
} |
| 2182 |
|
| 2183 |
var data = { |
| 2184 |
action: "wpsc_bulk_archive_tickets", |
| 2185 |
ticket_ids, |
| 2186 |
_ajax_nonce: nonce, |
| 2187 |
}; |
| 2188 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2189 |
wpsc_get_ticket_list(); |
| 2190 |
wpsc_run_ajax_background_process(); |
| 2191 |
}); |
| 2192 |
} |
| 2193 |
} |
| 2194 |
|
| 2195 |
/** |
| 2196 |
* Get bulk permanently delete ticket |
| 2197 |
*/ |
| 2198 |
function wpsc_bulk_permanently_delete_tickets(nonce) { |
| 2199 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 2200 |
var checked = items.length === 0 ? false : true; |
| 2201 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 2202 |
if (items.length != 0) { |
| 2203 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 2204 |
.map(function () { |
| 2205 |
return this.value; |
| 2206 |
}) |
| 2207 |
.get(); |
| 2208 |
var flag = confirm(supportcandy.translations.delete_permanently); |
| 2209 |
if (!flag) { |
| 2210 |
return; |
| 2211 |
} |
| 2212 |
|
| 2213 |
var data = { |
| 2214 |
action: "wpsc_bulk_permanently_delete_tickets", |
| 2215 |
ticket_ids, |
| 2216 |
_ajax_nonce: nonce, |
| 2217 |
}; |
| 2218 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2219 |
wpsc_get_ticket_list(); |
| 2220 |
wpsc_run_ajax_background_process(); |
| 2221 |
}); |
| 2222 |
} |
| 2223 |
} |
| 2224 |
|
| 2225 |
/** |
| 2226 |
* Set agent working hrs |
| 2227 |
*/ |
| 2228 |
function wpsc_set_agent_wh_hrs(el) { |
| 2229 |
const form = jQuery(".wpsc-frm-agent-wh")[0]; |
| 2230 |
const dataform = new FormData(form); |
| 2231 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2232 |
jQuery(".wpsc-section-container").html(supportcandy.loader_html); |
| 2233 |
jQuery |
| 2234 |
.ajax({ |
| 2235 |
url: supportcandy.ajax_url, |
| 2236 |
type: "POST", |
| 2237 |
data: dataform, |
| 2238 |
processData: false, |
| 2239 |
contentType: false, |
| 2240 |
}) |
| 2241 |
.done(function (res) { |
| 2242 |
window.location.reload(); |
| 2243 |
}); |
| 2244 |
} |
| 2245 |
|
| 2246 |
/** |
| 2247 |
* Set add agent exception |
| 2248 |
*/ |
| 2249 |
function wpsc_set_add_agent_wh_exception(el) { |
| 2250 |
var title = jQuery("input[name=title]").val(); |
| 2251 |
var from_date = jQuery("input[name=exception_date]").val(); |
| 2252 |
if (!title || !from_date) { |
| 2253 |
alert(supportcandy.translations.req_fields_missing); |
| 2254 |
return; |
| 2255 |
} |
| 2256 |
const form = jQuery(".wpsc-frm-add-agent-exception")[0]; |
| 2257 |
const dataform = new FormData(form); |
| 2258 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2259 |
jQuery |
| 2260 |
.ajax({ |
| 2261 |
url: supportcandy.ajax_url, |
| 2262 |
type: "POST", |
| 2263 |
data: dataform, |
| 2264 |
processData: false, |
| 2265 |
contentType: false, |
| 2266 |
}) |
| 2267 |
.done(function (res) { |
| 2268 |
window.location.reload(); |
| 2269 |
}); |
| 2270 |
} |
| 2271 |
|
| 2272 |
/** |
| 2273 |
* Update agent working hour exception |
| 2274 |
*/ |
| 2275 |
function wpsc_set_edit_agent_wh_exception(el) { |
| 2276 |
var title = jQuery("input[name=title]").val(); |
| 2277 |
var from_date = jQuery("input[name=exception_date]").val(); |
| 2278 |
if (!title || !from_date) { |
| 2279 |
alert(supportcandy.translations.req_fields_missing); |
| 2280 |
return; |
| 2281 |
} |
| 2282 |
|
| 2283 |
const form = jQuery(".wpsc-frm-edit-agent-exception")[0]; |
| 2284 |
const dataform = new FormData(form); |
| 2285 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2286 |
jQuery |
| 2287 |
.ajax({ |
| 2288 |
url: supportcandy.ajax_url, |
| 2289 |
type: "POST", |
| 2290 |
data: dataform, |
| 2291 |
processData: false, |
| 2292 |
contentType: false, |
| 2293 |
}) |
| 2294 |
.done(function (res) { |
| 2295 |
window.location.reload(); |
| 2296 |
}); |
| 2297 |
} |
| 2298 |
|
| 2299 |
/** |
| 2300 |
* Get agent profile holiday actions |
| 2301 |
*/ |
| 2302 |
function wpsc_get_ap_leaves_actions(dateSelected, nonce) { |
| 2303 |
supportcandy.temp.dateSelected = dateSelected; |
| 2304 |
wpsc_show_modal(); |
| 2305 |
var data = { |
| 2306 |
action: "wpsc_get_ap_leaves_actions", |
| 2307 |
dateSelected, |
| 2308 |
_ajax_nonce: nonce, |
| 2309 |
}; |
| 2310 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2311 |
// Set to modal. |
| 2312 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2313 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2314 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2315 |
// Display modal. |
| 2316 |
wpsc_show_modal_inner_container(); |
| 2317 |
}); |
| 2318 |
} |
| 2319 |
|
| 2320 |
/** |
| 2321 |
* Set agent profile holiday actions |
| 2322 |
*/ |
| 2323 |
function wpsc_set_ap_leaves_actions(el) { |
| 2324 |
const form = jQuery(".wpsc-frm-ap-holiday-actions")[0]; |
| 2325 |
const dataform = new FormData(form); |
| 2326 |
dataform.append("dateSelected", supportcandy.temp.dateSelected); |
| 2327 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2328 |
jQuery |
| 2329 |
.ajax({ |
| 2330 |
url: supportcandy.ajax_url, |
| 2331 |
type: "POST", |
| 2332 |
data: dataform, |
| 2333 |
processData: false, |
| 2334 |
contentType: false, |
| 2335 |
}) |
| 2336 |
.done(function (response) { |
| 2337 |
jQuery.each(supportcandy.temp.dateSelected, function (index, value) { |
| 2338 |
if (response.action == "add" && response.is_recurring == 1) { |
| 2339 |
jQuery("td") |
| 2340 |
.find("[data-date=" + value + "]") |
| 2341 |
.css({ "background-color": "#eb4d4b" }); |
| 2342 |
} else if (response.action == "add" && response.is_recurring == 0) { |
| 2343 |
jQuery("td") |
| 2344 |
.find("[data-date=" + value + "]") |
| 2345 |
.css({ "background-color": "#f0932b" }); |
| 2346 |
} else { |
| 2347 |
jQuery("td") |
| 2348 |
.find("[data-date=" + value + "]") |
| 2349 |
.css("background-color", "unset"); |
| 2350 |
} |
| 2351 |
}); |
| 2352 |
supportcandy.temp.holidayList = response.holidayList; |
| 2353 |
wpsc_close_modal(); |
| 2354 |
}); |
| 2355 |
} |
| 2356 |
|
| 2357 |
/** |
| 2358 |
* Clear dates |
| 2359 |
*/ |
| 2360 |
function wpsc_clear_date(el) { |
| 2361 |
jQuery(el).prev().val(""); |
| 2362 |
|
| 2363 |
var conditionalFields = jQuery(".wpsc-tff.conditional"); |
| 2364 |
if (conditionalFields.length !== 0) { |
| 2365 |
wpsc_check_tff_visibility(); |
| 2366 |
} |
| 2367 |
} |
| 2368 |
|
| 2369 |
/** |
| 2370 |
* Check whether there is text in reply box |
| 2371 |
*/ |
| 2372 |
function wpsc_is_description_text() { |
| 2373 |
var is_tinymce = |
| 2374 |
typeof tinyMCE != "undefined" && |
| 2375 |
tinyMCE.activeEditor && |
| 2376 |
!tinyMCE.activeEditor.isHidden(); |
| 2377 |
if (is_tinymce && tinymce.get("description")) { |
| 2378 |
var description = tinyMCE.get("description").getContent(); |
| 2379 |
} else { |
| 2380 |
var description = jQuery("#description").val(); |
| 2381 |
} |
| 2382 |
|
| 2383 |
var flag = false; |
| 2384 |
if (description && description.length != 0) { |
| 2385 |
flag = true; |
| 2386 |
} |
| 2387 |
|
| 2388 |
return flag; |
| 2389 |
} |
| 2390 |
|
| 2391 |
/** |
| 2392 |
* Get Edit customer info |
| 2393 |
* |
| 2394 |
* @param {Int} ticket_id |
| 2395 |
*/ |
| 2396 |
function wpsc_get_edit_rb_info(el, ticket_id, nonce) { |
| 2397 |
wpsc_show_modal(); |
| 2398 |
var data = { action: "wpsc_get_edit_rb_info", ticket_id, _ajax_nonce: nonce }; |
| 2399 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2400 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2401 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2402 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2403 |
wpsc_show_modal_inner_container(); |
| 2404 |
}); |
| 2405 |
} |
| 2406 |
|
| 2407 |
/** |
| 2408 |
* Set edit customer info |
| 2409 |
* |
| 2410 |
* @param {object} el |
| 2411 |
* @param {Int} ticket_id |
| 2412 |
*/ |
| 2413 |
function wpsc_set_edit_rb_info(el, ticket_id, nonce) { |
| 2414 |
var form = jQuery("form.frm-edit-rb-info")[0]; |
| 2415 |
var dataform = new FormData(form); |
| 2416 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 2417 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2418 |
jQuery |
| 2419 |
.ajax({ |
| 2420 |
url: supportcandy.ajax_url, |
| 2421 |
type: "POST", |
| 2422 |
data: dataform, |
| 2423 |
processData: false, |
| 2424 |
contentType: false, |
| 2425 |
}) |
| 2426 |
.done(function (res) { |
| 2427 |
wpsc_close_modal(); |
| 2428 |
setTimeout(function () { |
| 2429 |
wpsc_get_rb_info(el, ticket_id, nonce); |
| 2430 |
}, 500); |
| 2431 |
}); |
| 2432 |
} |
| 2433 |
|
| 2434 |
/** |
| 2435 |
* Get tickets based on filter set |
| 2436 |
*/ |
| 2437 |
function wpsc_get_archive_tickets() { |
| 2438 |
jQuery(".wpsc-bulk-selector").prop("checked", false); |
| 2439 |
jQuery(".wpsc-ticket-list").html(supportcandy.loader_html); |
| 2440 |
|
| 2441 |
var data = { |
| 2442 |
action: "wpsc_get_archive_tickets", |
| 2443 |
_ajax_nonce: supportcandy.nonce, |
| 2444 |
is_frontend : supportcandy.is_frontend |
| 2445 |
}; |
| 2446 |
if ( |
| 2447 |
typeof supportcandy.ticketList != "undefined" && |
| 2448 |
typeof supportcandy.ticketList.filters != "undefined" |
| 2449 |
) { |
| 2450 |
data.filters = supportcandy.ticketList.filters; |
| 2451 |
} |
| 2452 |
|
| 2453 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2454 |
jQuery(".wpsc-filter-actions").html(response.filter_actions); |
| 2455 |
jQuery(".wpsc-ticket-bulk-actions").html(response.bulk_actions); |
| 2456 |
jQuery(".wpsc-ticket-list").html(response.tickets); |
| 2457 |
jQuery(".wpsc-pagination-txt").text(response.pagination_str); |
| 2458 |
jQuery("select.wpsc-input-filter").val(response.filters.filterSlug); |
| 2459 |
jQuery("select.wpsc-input-sort-by").val(response.filters.orderby); |
| 2460 |
jQuery("select.wpsc-input-sort-order").val(response.filters.order); |
| 2461 |
jQuery("input.wpsc-search-input").val(response.filters.search); |
| 2462 |
if (response.pagination.total_pages > 1) { |
| 2463 |
jQuery(".wpsc-pagination-btn").show(); |
| 2464 |
} else { |
| 2465 |
jQuery(".wpsc-pagination-btn").hide(); |
| 2466 |
} |
| 2467 |
supportcandy.ticketList = { |
| 2468 |
filters: response.filters, |
| 2469 |
pagination: response.pagination, |
| 2470 |
}; |
| 2471 |
}); |
| 2472 |
} |
| 2473 |
|
| 2474 |
/** |
| 2475 |
* Get tickets based on filter set |
| 2476 |
*/ |
| 2477 |
function wpsc_get_tickets() { |
| 2478 |
|
| 2479 |
if (supportcandy.ticket_list_loading) { |
| 2480 |
return; |
| 2481 |
} |
| 2482 |
|
| 2483 |
supportcandy.ticket_list_loading = true; |
| 2484 |
|
| 2485 |
jQuery(".wpsc-bulk-selector").prop("checked", false); |
| 2486 |
jQuery(".wpsc-ticket-list").html(supportcandy.loader_html); |
| 2487 |
|
| 2488 |
var data = { |
| 2489 |
action: "wpsc_get_tickets", |
| 2490 |
_ajax_nonce: supportcandy.nonce, |
| 2491 |
is_frontend: supportcandy.is_frontend, |
| 2492 |
}; |
| 2493 |
|
| 2494 |
if ( |
| 2495 |
typeof supportcandy.ticketList != "undefined" && |
| 2496 |
typeof supportcandy.ticketList.filters != "undefined" |
| 2497 |
) { |
| 2498 |
data.filters = supportcandy.ticketList.filters; |
| 2499 |
} |
| 2500 |
|
| 2501 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2502 |
|
| 2503 |
jQuery(".wpsc-filter-actions").html(response.filter_actions); |
| 2504 |
jQuery(".wpsc-ticket-bulk-actions").html(response.bulk_actions); |
| 2505 |
jQuery(".wpsc-ticket-list").html(response.tickets); |
| 2506 |
jQuery(".wpsc-pagination-txt").text(response.pagination_str); |
| 2507 |
jQuery("select.wpsc-input-filter").val(response.filters.filterSlug); |
| 2508 |
jQuery("select.wpsc-input-sort-by").val(response.filters.orderby); |
| 2509 |
jQuery("select.wpsc-input-sort-order").val(response.filters.order); |
| 2510 |
jQuery("input.wpsc-search-input").val(response.filters.search); |
| 2511 |
|
| 2512 |
if (response.pagination.total_pages > 1) { |
| 2513 |
jQuery(".wpsc-pagination-btn").show(); |
| 2514 |
} else { |
| 2515 |
jQuery(".wpsc-pagination-btn").hide(); |
| 2516 |
} |
| 2517 |
|
| 2518 |
supportcandy.ticketList = { |
| 2519 |
filters: response.filters, |
| 2520 |
pagination: response.pagination, |
| 2521 |
}; |
| 2522 |
|
| 2523 |
}).always(function(){ |
| 2524 |
supportcandy.ticket_list_loading = false; |
| 2525 |
}); |
| 2526 |
} |
| 2527 |
|
| 2528 |
/** |
| 2529 |
* Copy ticket url |
| 2530 |
* |
| 2531 |
* @param {int} ticket_id |
| 2532 |
*/ |
| 2533 |
function wpsc_it_copy_url(ticket_id) { |
| 2534 |
var temp = jQuery("<input>"); |
| 2535 |
jQuery("body").append(temp); |
| 2536 |
temp.val(jQuery("#wpsc-ticket-url").text()).select(); |
| 2537 |
document.execCommand("copy"); |
| 2538 |
temp.remove(); |
| 2539 |
alert(supportcandy.translations.copy_url); |
| 2540 |
} |
| 2541 |
|
| 2542 |
/** |
| 2543 |
* Open auto-refresh toggle |
| 2544 |
*/ |
| 2545 |
function wpsc_get_tl_auto_refresh() { |
| 2546 |
wpsc_show_modal(); |
| 2547 |
|
| 2548 |
// Get modal parts from static modals. |
| 2549 |
var headerText = jQuery( |
| 2550 |
".wpsc-tl_snippets .auto-refresh .modal-header" |
| 2551 |
).text(); |
| 2552 |
var bodyHTML = jQuery(".wpsc-tl_snippets .auto-refresh .modal-body").html(); |
| 2553 |
var footerHTML = jQuery( |
| 2554 |
".wpsc-tl_snippets .auto-refresh .modal-footer" |
| 2555 |
).html(); |
| 2556 |
|
| 2557 |
// Set them to modal. |
| 2558 |
jQuery(".wpsc-modal-header").text(headerText); |
| 2559 |
jQuery(".wpsc-modal-body").html(bodyHTML); |
| 2560 |
jQuery(".wpsc-modal-footer").html(footerHTML); |
| 2561 |
|
| 2562 |
// Set current status. |
| 2563 |
var status = supportcandy.tl_auto_refresh ? supportcandy.tl_auto_refresh : 0; |
| 2564 |
var el = status |
| 2565 |
? jQuery(".wpsc-modal .toggle-on") |
| 2566 |
: jQuery(".wpsc-modal .toggle-off"); |
| 2567 |
jQuery(".wpsc-modal-body input").val(status); |
| 2568 |
status ? wpsc_toggle_on(el) : wpsc_toggle_off(el); |
| 2569 |
|
| 2570 |
// Display modal. |
| 2571 |
wpsc_show_modal_inner_container(); |
| 2572 |
} |
| 2573 |
|
| 2574 |
/** |
| 2575 |
* Set auto-refresh settings |
| 2576 |
*/ |
| 2577 |
function wpsc_set_tl_auto_refresh(el) { |
| 2578 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 2579 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2580 |
var status = parseInt(jQuery(".wpsc-modal-body input").val()); |
| 2581 |
wpsc_close_modal(); |
| 2582 |
if (supportcandy.tl_auto_refresh !== status) { |
| 2583 |
supportcandy.tl_auto_refresh = status; |
| 2584 |
if (status === 1) { |
| 2585 |
wpsc_tl_auto_refresh(); |
| 2586 |
} |
| 2587 |
} |
| 2588 |
} |
| 2589 |
|
| 2590 |
/** |
| 2591 |
* Auto refresh |
| 2592 |
*/ |
| 2593 |
function wpsc_tl_auto_refresh() { |
| 2594 |
|
| 2595 |
if (supportcandy.tl_auto_refresh_started) { |
| 2596 |
return; |
| 2597 |
} |
| 2598 |
|
| 2599 |
supportcandy.tl_auto_refresh_started = true; |
| 2600 |
|
| 2601 |
function run_refresh() { |
| 2602 |
|
| 2603 |
if ( |
| 2604 |
supportcandy.current_section === "ticket-list" && |
| 2605 |
!supportcandy.ticketListIsIndividual && |
| 2606 |
supportcandy.tl_auto_refresh === 1 && |
| 2607 |
!( |
| 2608 |
jQuery(".wpsc-bulk-select:checked").length || |
| 2609 |
jQuery(".wpsc-search-input").is(":focus") |
| 2610 |
) |
| 2611 |
) { |
| 2612 |
wpsc_get_tickets(); |
| 2613 |
} |
| 2614 |
|
| 2615 |
setTimeout(run_refresh, 60000); |
| 2616 |
} |
| 2617 |
|
| 2618 |
run_refresh(); |
| 2619 |
} |
| 2620 |
|
| 2621 |
/** |
| 2622 |
* User logout |
| 2623 |
*/ |
| 2624 |
function wpsc_user_logout(el, nonce) { |
| 2625 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2626 |
var data = { action: "wpsc_user_logout", _ajax_nonce: nonce }; |
| 2627 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 2628 |
window.location.reload(); |
| 2629 |
}); |
| 2630 |
} |
| 2631 |
|
| 2632 |
/** |
| 2633 |
* Close model popup on escape key. |
| 2634 |
*/ |
| 2635 |
jQuery(document).keydown(function (e) { |
| 2636 |
if (e.keyCode == 27) { |
| 2637 |
wpsc_close_modal(); |
| 2638 |
} |
| 2639 |
}); |
| 2640 |
|
| 2641 |
/** |
| 2642 |
* Get customer info |
| 2643 |
*/ |
| 2644 |
function wpsc_view_customer_info(customer_id, _ajax_nonce) { |
| 2645 |
wpsc_show_modal(); |
| 2646 |
var data = { action: "wpsc_view_customer_info", customer_id, _ajax_nonce }; |
| 2647 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2648 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2649 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2650 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2651 |
wpsc_show_modal_inner_container(); |
| 2652 |
}); |
| 2653 |
} |
| 2654 |
|
| 2655 |
/** |
| 2656 |
* Get edit customer info |
| 2657 |
*/ |
| 2658 |
function wpsc_get_edit_customer_info(customer_id, _ajax_nonce) { |
| 2659 |
wpsc_show_modal(); |
| 2660 |
var data = { |
| 2661 |
action: "wpsc_get_edit_customer_info", |
| 2662 |
customer_id, |
| 2663 |
_ajax_nonce, |
| 2664 |
}; |
| 2665 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2666 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2667 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2668 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2669 |
wpsc_show_modal_inner_container(); |
| 2670 |
}); |
| 2671 |
} |
| 2672 |
|
| 2673 |
/** |
| 2674 |
* Set edit customer info |
| 2675 |
*/ |
| 2676 |
function wpsc_set_edit_customer_info(el, id, nonce) { |
| 2677 |
var form = jQuery("form.frm-edit-customer-info")[0]; |
| 2678 |
var dataform = new FormData(form); |
| 2679 |
jQuery(".wpsc-modal-footer button").attr("disabled", true); |
| 2680 |
jQuery(el).text(supportcandy.translations.please_wait); |
| 2681 |
|
| 2682 |
jQuery |
| 2683 |
.ajax({ |
| 2684 |
url: supportcandy.ajax_url, |
| 2685 |
type: "POST", |
| 2686 |
data: dataform, |
| 2687 |
processData: false, |
| 2688 |
contentType: false, |
| 2689 |
}) |
| 2690 |
.done(function (res) { |
| 2691 |
wpsc_close_modal(); |
| 2692 |
wpsc_scroll_top(); |
| 2693 |
wpsc_view_customer_detailed_info(res.customer_id, res.nonce); |
| 2694 |
}); |
| 2695 |
} |
| 2696 |
|
| 2697 |
/** |
| 2698 |
* Get customer logs |
| 2699 |
*/ |
| 2700 |
function wpsc_view_customer_logs(customer_id, _ajax_nonce) { |
| 2701 |
wpsc_show_modal(); |
| 2702 |
var data = { action: "wpsc_view_customer_logs", customer_id, _ajax_nonce }; |
| 2703 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2704 |
jQuery(".wpsc-modal-header").text(response.title); |
| 2705 |
jQuery(".wpsc-modal-body").html(response.body); |
| 2706 |
jQuery(".wpsc-modal-footer").html(response.footer); |
| 2707 |
wpsc_show_modal_inner_container(); |
| 2708 |
}); |
| 2709 |
} |
| 2710 |
|
| 2711 |
/** |
| 2712 |
* |
| 2713 |
* @param {*} ticket |
| 2714 |
*/ |
| 2715 |
function wpsc_clear_saved_draft_reply(ticket_id) { |
| 2716 |
var draft_replies = JSON.parse(localStorage.getItem("wpsc_auto_draft")) || {}; |
| 2717 |
var is_tinymce = |
| 2718 |
typeof tinyMCE != "undefined" && |
| 2719 |
tinyMCE.activeEditor && |
| 2720 |
!tinyMCE.activeEditor.isHidden(); |
| 2721 |
if (is_tinymce && tinymce.get("description")) { |
| 2722 |
tinyMCE.get("description").setContent(""); |
| 2723 |
} |
| 2724 |
jQuery("#description").val(""); |
| 2725 |
if (!ticket_id) return; |
| 2726 |
delete draft_replies[ticket_id]; |
| 2727 |
localStorage.setItem("wpsc_auto_draft", JSON.stringify(draft_replies)); |
| 2728 |
} |
| 2729 |
|
| 2730 |
/** |
| 2731 |
* Run background processes. |
| 2732 |
*/ |
| 2733 |
function wpsc_run_ajax_background_process() { |
| 2734 |
var data = { action: "wpsc_run_ajax_background_process" }; |
| 2735 |
jQuery.post(supportcandy.ajax_url, data, function (response) {}); |
| 2736 |
} |
| 2737 |
|
| 2738 |
/** |
| 2739 |
* Assign ticket to self |
| 2740 |
*/ |
| 2741 |
function wpsc_self_assign_ticket(ticket_id, nonce) { |
| 2742 |
var data = { |
| 2743 |
action: "wpsc_self_assign_ticket", |
| 2744 |
ticket_id, |
| 2745 |
_ajax_nonce: nonce, |
| 2746 |
}; |
| 2747 |
|
| 2748 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2749 |
wpsc_get_individual_ticket(ticket_id); |
| 2750 |
}); |
| 2751 |
} |
| 2752 |
|
| 2753 |
/** |
| 2754 |
* Delete wpsc_auto_draft localStorage after 24 hr |
| 2755 |
*/ |
| 2756 |
function wpsc_delete_auto_draft() { |
| 2757 |
var draft_cron_time = localStorage.getItem("wpsc_draft_cron_time"); |
| 2758 |
if (!draft_cron_time) { |
| 2759 |
localStorage.setItem("wpsc_draft_cron_time", new Date().getTime()); |
| 2760 |
} |
| 2761 |
var diff = new Date().getTime() - draft_cron_time; |
| 2762 |
if (diff < 3600000) { |
| 2763 |
return; |
| 2764 |
} |
| 2765 |
var draft_replies = JSON.parse(localStorage.getItem("wpsc_auto_draft")) || {}; |
| 2766 |
Object.keys(draft_replies).forEach((ticket_id) => { |
| 2767 |
var timeDifference = |
| 2768 |
new Date() - new Date(draft_replies[ticket_id].date_updated); |
| 2769 |
if (timeDifference > 86400000) { |
| 2770 |
delete draft_replies[ticket_id]; |
| 2771 |
} |
| 2772 |
}); |
| 2773 |
localStorage.setItem("wpsc_auto_draft", JSON.stringify(draft_replies)); |
| 2774 |
localStorage.setItem("wpsc_draft_cron_time", new Date().getTime()); |
| 2775 |
} |
| 2776 |
|
| 2777 |
/** |
| 2778 |
* Delete customer |
| 2779 |
*/ |
| 2780 |
function wpsc_delete_customer(customer_id, nonce) { |
| 2781 |
if (!confirm(supportcandy.translations.customer_delete_warn)) { |
| 2782 |
return; |
| 2783 |
} |
| 2784 |
|
| 2785 |
var data = { |
| 2786 |
action: "wpsc_delete_customer", |
| 2787 |
customer_id, |
| 2788 |
_ajax_nonce: nonce, |
| 2789 |
}; |
| 2790 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 2791 |
window.location.reload(); |
| 2792 |
}); |
| 2793 |
} |
| 2794 |
|
| 2795 |
/** |
| 2796 |
* Dashboard - Get filter from and to dates based on duration slug |
| 2797 |
*/ |
| 2798 |
function wpsc_db_set_filter_duration_dates(duration) { |
| 2799 |
let dateStr = ""; |
| 2800 |
let date = new Date(); |
| 2801 |
let from_date, to_date; |
| 2802 |
|
| 2803 |
switch (duration) { |
| 2804 |
case "today": |
| 2805 |
dateStr = date.toISOString().split("T")[0]; |
| 2806 |
date_from_to = { |
| 2807 |
from: dateStr, |
| 2808 |
to: dateStr, |
| 2809 |
}; |
| 2810 |
break; |
| 2811 |
|
| 2812 |
case "yesterday": |
| 2813 |
date.setDate(date.getDate() - 1); |
| 2814 |
dateStr = date.toISOString().split("T")[0]; |
| 2815 |
date_from_to = { |
| 2816 |
from: dateStr, |
| 2817 |
to: dateStr, |
| 2818 |
}; |
| 2819 |
break; |
| 2820 |
|
| 2821 |
case "this-week": |
| 2822 |
let firstDayOfWeek = date.getDay() === 0 ? 6 : date.getDay() - 1; |
| 2823 |
date.setDate(date.getDate() - firstDayOfWeek); |
| 2824 |
from_date = date.toISOString().split("T")[0]; |
| 2825 |
date.setDate(date.getDate() + 6); |
| 2826 |
to_date = date.toISOString().split("T")[0]; |
| 2827 |
date_from_to = { |
| 2828 |
from: from_date, |
| 2829 |
to: to_date, |
| 2830 |
}; |
| 2831 |
break; |
| 2832 |
|
| 2833 |
case "last-week": |
| 2834 |
let firstDayOfLastWeek = date.getDay() === 0 ? 7 : date.getDay(); |
| 2835 |
date.setDate(date.getDate() - firstDayOfLastWeek - 6); |
| 2836 |
from_date = date.toISOString().split("T")[0]; |
| 2837 |
date.setDate(date.getDate() + 6); |
| 2838 |
to_date = date.toISOString().split("T")[0]; |
| 2839 |
date_from_to = { |
| 2840 |
from: from_date, |
| 2841 |
to: to_date, |
| 2842 |
}; |
| 2843 |
break; |
| 2844 |
|
| 2845 |
case "last-7": |
| 2846 |
date.setDate(date.getDate() - 1); // Exclude today |
| 2847 |
to_date = date.toISOString().split("T")[0]; |
| 2848 |
date.setDate(date.getDate() - 6); // Last 7 days from yesterday |
| 2849 |
from_date = date.toISOString().split("T")[0]; |
| 2850 |
date_from_to = { |
| 2851 |
from: from_date, |
| 2852 |
to: to_date, |
| 2853 |
}; |
| 2854 |
break; |
| 2855 |
|
| 2856 |
case "last-30-days": |
| 2857 |
date.setDate(date.getDate() - 1); // Exclude today |
| 2858 |
to_date = date.toISOString().split("T")[0]; |
| 2859 |
date.setDate(date.getDate() - 29); // Last 30 days from yesterday |
| 2860 |
from_date = date.toISOString().split("T")[0]; |
| 2861 |
date_from_to = { |
| 2862 |
from: from_date, |
| 2863 |
to: to_date, |
| 2864 |
}; |
| 2865 |
break; |
| 2866 |
|
| 2867 |
case "this-month": |
| 2868 |
let this_month_starts = new Date(date.getFullYear(), date.getMonth(), 1); |
| 2869 |
let this_month_ends = new Date( |
| 2870 |
date.getFullYear(), |
| 2871 |
date.getMonth() + 1, |
| 2872 |
0 |
| 2873 |
); |
| 2874 |
date_from_to = { |
| 2875 |
from: `${this_month_starts.getFullYear()}-${( |
| 2876 |
this_month_starts.getMonth() + 1 |
| 2877 |
) |
| 2878 |
.toString() |
| 2879 |
.padStart(2, "0")}-${this_month_starts |
| 2880 |
.getDate() |
| 2881 |
.toString() |
| 2882 |
.padStart(2, "0")}`, |
| 2883 |
to: `${this_month_ends.getFullYear()}-${(this_month_ends.getMonth() + 1) |
| 2884 |
.toString() |
| 2885 |
.padStart(2, "0")}-${this_month_ends |
| 2886 |
.getDate() |
| 2887 |
.toString() |
| 2888 |
.padStart(2, "0")}`, |
| 2889 |
}; |
| 2890 |
break; |
| 2891 |
|
| 2892 |
case "last-month": |
| 2893 |
date.setMonth(date.getMonth() - 1); |
| 2894 |
let last_month_starts = new Date(date.getFullYear(), date.getMonth(), 1); |
| 2895 |
let last_month_ends = new Date( |
| 2896 |
date.getFullYear(), |
| 2897 |
date.getMonth() + 1, |
| 2898 |
0 |
| 2899 |
); |
| 2900 |
date_from_to = { |
| 2901 |
from: `${last_month_starts.getFullYear()}-${( |
| 2902 |
last_month_starts.getMonth() + 1 |
| 2903 |
) |
| 2904 |
.toString() |
| 2905 |
.padStart(2, "0")}-${last_month_starts |
| 2906 |
.getDate() |
| 2907 |
.toString() |
| 2908 |
.padStart(2, "0")}`, |
| 2909 |
to: `${last_month_ends.getFullYear()}-${(last_month_ends.getMonth() + 1) |
| 2910 |
.toString() |
| 2911 |
.padStart(2, "0")}-${last_month_ends |
| 2912 |
.getDate() |
| 2913 |
.toString() |
| 2914 |
.padStart(2, "0")}`, |
| 2915 |
}; |
| 2916 |
break; |
| 2917 |
|
| 2918 |
case "this-quarter": |
| 2919 |
let this_quarter_month_starts = Math.floor(date.getMonth() / 3) * 3; |
| 2920 |
let quarter_start = new Date( |
| 2921 |
date.getFullYear(), |
| 2922 |
this_quarter_month_starts, |
| 2923 |
1 |
| 2924 |
); |
| 2925 |
let quarter_end = new Date( |
| 2926 |
date.getFullYear(), |
| 2927 |
this_quarter_month_starts + 3, |
| 2928 |
0 |
| 2929 |
); |
| 2930 |
date_from_to = { |
| 2931 |
from: `${quarter_start.getFullYear()}-${(quarter_start.getMonth() + 1) |
| 2932 |
.toString() |
| 2933 |
.padStart(2, "0")}-${quarter_start |
| 2934 |
.getDate() |
| 2935 |
.toString() |
| 2936 |
.padStart(2, "0")}`, |
| 2937 |
to: `${quarter_end.getFullYear()}-${(quarter_end.getMonth() + 1) |
| 2938 |
.toString() |
| 2939 |
.padStart(2, "0")}-${quarter_end |
| 2940 |
.getDate() |
| 2941 |
.toString() |
| 2942 |
.padStart(2, "0")}`, |
| 2943 |
}; |
| 2944 |
break; |
| 2945 |
|
| 2946 |
case "last-quarter": |
| 2947 |
let last_quarter_month_ends = Math.floor(date.getMonth() / 3) * 3 - 1; // End month of last quarter |
| 2948 |
let last_quarter_month_starts = last_quarter_month_ends - 2; // Start month of last quarter |
| 2949 |
if (last_quarter_month_ends < 0) { |
| 2950 |
last_quarter_month_ends += 12; |
| 2951 |
last_quarter_month_starts += 12; |
| 2952 |
} |
| 2953 |
let last_quarter_start = new Date( |
| 2954 |
date.getFullYear(), |
| 2955 |
last_quarter_month_starts, |
| 2956 |
1 |
| 2957 |
); |
| 2958 |
let last_quarter_end = new Date( |
| 2959 |
date.getFullYear(), |
| 2960 |
last_quarter_month_ends + 1, |
| 2961 |
0 |
| 2962 |
); |
| 2963 |
date_from_to = { |
| 2964 |
from: `${last_quarter_start.getFullYear()}-${( |
| 2965 |
last_quarter_start.getMonth() + 1 |
| 2966 |
) |
| 2967 |
.toString() |
| 2968 |
.padStart(2, "0")}-${last_quarter_start |
| 2969 |
.getDate() |
| 2970 |
.toString() |
| 2971 |
.padStart(2, "0")}`, |
| 2972 |
to: `${last_quarter_end.getFullYear()}-${( |
| 2973 |
last_quarter_end.getMonth() + 1 |
| 2974 |
) |
| 2975 |
.toString() |
| 2976 |
.padStart(2, "0")}-${last_quarter_end |
| 2977 |
.getDate() |
| 2978 |
.toString() |
| 2979 |
.padStart(2, "0")}`, |
| 2980 |
}; |
| 2981 |
break; |
| 2982 |
|
| 2983 |
case "this-year": |
| 2984 |
date_from_to = { |
| 2985 |
from: `${date.getFullYear()}-01-01`, |
| 2986 |
to: `${date.getFullYear()}-12-31`, |
| 2987 |
}; |
| 2988 |
break; |
| 2989 |
|
| 2990 |
case "last-year": |
| 2991 |
date_from_to = { |
| 2992 |
from: `${date.getFullYear() - 1}-01-01`, |
| 2993 |
to: `${date.getFullYear() - 1}-12-31`, |
| 2994 |
}; |
| 2995 |
break; |
| 2996 |
} |
| 2997 |
return date_from_to; |
| 2998 |
} |
| 2999 |
|
| 3000 |
/** |
| 3001 |
* Get batches for async report loading |
| 3002 |
*/ |
| 3003 |
function wpsc_rp_get_baches(fromDate, toDate) { |
| 3004 |
let diffTime = Math.abs(toDate - fromDate); |
| 3005 |
let diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1; |
| 3006 |
|
| 3007 |
let batches = []; |
| 3008 |
let batchData = []; |
| 3009 |
|
| 3010 |
if (diffDays == 1) { |
| 3011 |
// one day. |
| 3012 |
|
| 3013 |
for (var i = 0; i <= 23; i++) { |
| 3014 |
var hr = String(i); |
| 3015 |
hr = hr.length == 1 ? "0" + hr : hr; |
| 3016 |
batchData.push({ |
| 3017 |
fromDate: fromDate.toISOString().split("T")[0] + " " + hr + ":00:00", |
| 3018 |
toDate: fromDate.toISOString().split("T")[0] + " " + hr + ":59:59", |
| 3019 |
durationType: "day", |
| 3020 |
}); |
| 3021 |
} |
| 3022 |
} else if (diffDays <= 31) { |
| 3023 |
// days. |
| 3024 |
|
| 3025 |
do { |
| 3026 |
batchData.push({ |
| 3027 |
fromDate: fromDate.toISOString().split("T")[0] + " 00:00:00", |
| 3028 |
toDate: fromDate.toISOString().split("T")[0] + " 23:59:59", |
| 3029 |
durationType: "days", |
| 3030 |
}); |
| 3031 |
fromDate.setDate(fromDate.getDate() + 1); |
| 3032 |
} while (fromDate <= toDate); |
| 3033 |
} else if (diffDays <= 180) { |
| 3034 |
// weeks. |
| 3035 |
|
| 3036 |
var from = fromDate.toISOString().split("T")[0]; |
| 3037 |
fromDate.setDate(fromDate.getDate() + (7 - fromDate.getDay())); |
| 3038 |
batchData.push({ |
| 3039 |
fromDate: from + " 00:00:00", |
| 3040 |
toDate: fromDate.toISOString().split("T")[0] + " 23:59:59", |
| 3041 |
durationType: "weeks", |
| 3042 |
}); |
| 3043 |
do { |
| 3044 |
fromDate.setDate(fromDate.getDate() + 1); |
| 3045 |
var from = new Date(fromDate.toLocaleDateString("en-CA")); |
| 3046 |
fromDate.setDate(fromDate.getDate() + 6); |
| 3047 |
var to = new Date(fromDate.toLocaleDateString("en-CA")); |
| 3048 |
to = toDate < to ? new Date(toDate.toLocaleDateString("en-CA")) : to; |
| 3049 |
batchData.push({ |
| 3050 |
fromDate: from.toISOString().split("T")[0] + " 00:00:00", |
| 3051 |
toDate: to.toISOString().split("T")[0] + " 23:59:59", |
| 3052 |
durationType: "weeks", |
| 3053 |
}); |
| 3054 |
} while (fromDate < toDate); |
| 3055 |
} else if (diffDays <= 720) { |
| 3056 |
// months. |
| 3057 |
|
| 3058 |
// convert toDate from local to UTC. |
| 3059 |
toDate = new Date( |
| 3060 |
toDate.getFullYear(), |
| 3061 |
toDate.getMonth(), |
| 3062 |
toDate.getDate() |
| 3063 |
); |
| 3064 |
|
| 3065 |
var from = fromDate.toISOString().split("T")[0]; |
| 3066 |
if (fromDate.getMonth() == 11) { |
| 3067 |
fromDate = new Date(fromDate.getFullYear(), 11, 31); |
| 3068 |
} else { |
| 3069 |
fromDate = new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0); |
| 3070 |
} |
| 3071 |
batchData.push({ |
| 3072 |
fromDate: from + " 00:00:00", |
| 3073 |
toDate: fromDate.toISOString().split("T")[0] + " 23:59:59", |
| 3074 |
durationType: "months", |
| 3075 |
}); |
| 3076 |
do { |
| 3077 |
fromDate.setDate(fromDate.getDate() + 1); |
| 3078 |
var from = new Date(fromDate.toLocaleDateString("en-CA")); |
| 3079 |
if (fromDate.getMonth() == 11) { |
| 3080 |
fromDate = new Date(fromDate.getFullYear(), 11, 31); |
| 3081 |
} else { |
| 3082 |
fromDate = new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0); |
| 3083 |
} |
| 3084 |
var to = new Date(fromDate.toLocaleDateString("en-CA")); |
| 3085 |
to = toDate < to ? new Date(toDate.toLocaleDateString("en-CA")) : to; |
| 3086 |
batchData.push({ |
| 3087 |
fromDate: from.toISOString().split("T")[0] + " 00:00:00", |
| 3088 |
toDate: to.toISOString().split("T")[0] + " 23:59:59", |
| 3089 |
durationType: "months", |
| 3090 |
}); |
| 3091 |
} while (fromDate < toDate); |
| 3092 |
} else { |
| 3093 |
// years. |
| 3094 |
|
| 3095 |
// convert toDate from local to UTC. |
| 3096 |
toDate = new Date( |
| 3097 |
toDate.getFullYear(), |
| 3098 |
toDate.getMonth(), |
| 3099 |
toDate.getDate() |
| 3100 |
); |
| 3101 |
|
| 3102 |
var from = fromDate.toISOString().split("T")[0]; |
| 3103 |
fromDate = new Date(fromDate.getFullYear(), 11, 31); |
| 3104 |
batchData.push({ |
| 3105 |
fromDate: from + " 00:00:00", |
| 3106 |
toDate: fromDate.toISOString().split("T")[0] + " 23:59:59", |
| 3107 |
durationType: "years", |
| 3108 |
}); |
| 3109 |
do { |
| 3110 |
fromDate.setDate(fromDate.getDate() + 1); |
| 3111 |
var from = new Date(fromDate.toLocaleDateString("en-CA")); |
| 3112 |
fromDate = new Date(fromDate.getFullYear(), 11, 31); |
| 3113 |
var to = new Date(fromDate.toLocaleDateString("en-CA")); |
| 3114 |
to = toDate < to ? new Date(toDate.toLocaleDateString("en-CA")) : to; |
| 3115 |
batchData.push({ |
| 3116 |
fromDate: from.toISOString().split("T")[0] + " 00:00:00", |
| 3117 |
toDate: to.toISOString().split("T")[0] + " 23:59:59", |
| 3118 |
durationType: "years", |
| 3119 |
}); |
| 3120 |
} while (fromDate < toDate); |
| 3121 |
} |
| 3122 |
|
| 3123 |
// devide into batches of 5. |
| 3124 |
var batchLength = batchData.length; |
| 3125 |
for (var i = 0; i < batchLength; i = i + 5) { |
| 3126 |
var batch = []; |
| 3127 |
var counter = 0; |
| 3128 |
do { |
| 3129 |
var index = i + counter; |
| 3130 |
if (index == batchLength) { |
| 3131 |
break; |
| 3132 |
} |
| 3133 |
batch.push(batchData[index]); |
| 3134 |
counter++; |
| 3135 |
} while (counter < 5); |
| 3136 |
batches.push(batch); |
| 3137 |
} |
| 3138 |
|
| 3139 |
return batches; |
| 3140 |
} |
| 3141 |
|
| 3142 |
function wpsc_generate_random_color() { |
| 3143 |
var minLuminance = 0.7; |
| 3144 |
|
| 3145 |
do { |
| 3146 |
var color = Math.floor(Math.random() * 16777216); // 0x000000 to 0xFFFFFF |
| 3147 |
var red = (color >> 16) & 0xff; |
| 3148 |
var green = (color >> 8) & 0xff; |
| 3149 |
var blue = color & 0xff; |
| 3150 |
|
| 3151 |
// Calculate luminance (brightness). |
| 3152 |
var luminance = (0.299 * red + 0.587 * green + 0.114 * blue) / 255; |
| 3153 |
} while (luminance < minLuminance); |
| 3154 |
|
| 3155 |
return "#" + color.toString(16).toUpperCase(); |
| 3156 |
} |
| 3157 |
|
| 3158 |
// onclick load respective card ticket list |
| 3159 |
function wpsc_get_dbc_ticket_list(element, card) { |
| 3160 |
var count = parseInt(jQuery(element).find(".wpsc-dbc-count").text(), 10); |
| 3161 |
if (count === 0) { |
| 3162 |
return; |
| 3163 |
} |
| 3164 |
var data = { |
| 3165 |
action: "wpsc_dash_card_count_filter", |
| 3166 |
card: card, |
| 3167 |
view: supportcandy.is_frontend, |
| 3168 |
_ajax_nonce: supportcandy.nonce, |
| 3169 |
}; |
| 3170 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3171 |
if (response.url) { |
| 3172 |
window.location = response.url; |
| 3173 |
} |
| 3174 |
}); |
| 3175 |
} |
| 3176 |
|
| 3177 |
// onclick load respective card ticket list |
| 3178 |
function wpsc_get_agent_status_ticket_list(agent_id, status_id, nonce) { |
| 3179 |
var data = { |
| 3180 |
action: "wpsc_get_agent_status_ticket_list", |
| 3181 |
agent_id: agent_id, |
| 3182 |
status_id: status_id, |
| 3183 |
view: supportcandy.is_frontend, |
| 3184 |
_ajax_nonce: nonce, |
| 3185 |
}; |
| 3186 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3187 |
if (response.url) { |
| 3188 |
window.location = response.url; |
| 3189 |
} |
| 3190 |
}); |
| 3191 |
} |
| 3192 |
|
| 3193 |
/** |
| 3194 |
* Refresh tags list |
| 3195 |
*/ |
| 3196 |
function wpsc_it_refresh_tags(ticket_id) { |
| 3197 |
jQuery(".wpsc-it-tag-body").html(supportcandy.loader_html); |
| 3198 |
|
| 3199 |
var data = { action: "wpsc_it_refresh_tags", ticket_id }; |
| 3200 |
jQuery.post(supportcandy.ajax_url, data, function (res) { |
| 3201 |
jQuery(".wpsc-it-tag-body").html(res); |
| 3202 |
}); |
| 3203 |
} |
| 3204 |
|
| 3205 |
/** |
| 3206 |
* View user wordpress profile |
| 3207 |
*/ |
| 3208 |
function wpsc_wp_user_profile(el, ticket_id, nonce) { |
| 3209 |
var data = { |
| 3210 |
action: "wpsc_wp_user_profile", |
| 3211 |
ticket_id, |
| 3212 |
_ajax_nonce: nonce, |
| 3213 |
}; |
| 3214 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3215 |
if (response.url) { |
| 3216 |
window.open(response.url, "_blank"); |
| 3217 |
} |
| 3218 |
}); |
| 3219 |
} |
| 3220 |
|
| 3221 |
/** |
| 3222 |
* Restore archived ticket |
| 3223 |
*/ |
| 3224 |
function wpsc_it_restore_archived(ticket_id, nonce) { |
| 3225 |
|
| 3226 |
if (!confirm(supportcandy.translations.confirm)){ |
| 3227 |
return; |
| 3228 |
} |
| 3229 |
|
| 3230 |
var data = { |
| 3231 |
action: "wpsc_it_restore_archived", |
| 3232 |
ticket_id, |
| 3233 |
_ajax_nonce: nonce |
| 3234 |
}; |
| 3235 |
|
| 3236 |
jQuery.post( |
| 3237 |
supportcandy.ajax_url, |
| 3238 |
data, |
| 3239 |
function (response) { |
| 3240 |
wpsc_get_archive_ticket_list(); |
| 3241 |
} |
| 3242 |
); |
| 3243 |
} |
| 3244 |
|
| 3245 |
/** |
| 3246 |
* Get refresh current ticket |
| 3247 |
*/ |
| 3248 |
function wpsc_it_archive_ab_refresh(ticket_id) { |
| 3249 |
if (wpsc_is_description_text()) { |
| 3250 |
if (confirm(supportcandy.translations.confirm)) { |
| 3251 |
wpsc_clear_saved_draft_reply(ticket_id); |
| 3252 |
} else { |
| 3253 |
return; |
| 3254 |
} |
| 3255 |
} |
| 3256 |
|
| 3257 |
wpsc_get_individual_archive_ticket(ticket_id); |
| 3258 |
} |
| 3259 |
|
| 3260 |
/** |
| 3261 |
* Load older threads |
| 3262 |
*/ |
| 3263 |
function wpsc_load_older_archive_threads(el, ticket_id) { |
| 3264 |
if (supportcandy.reply_form_position === "top") { |
| 3265 |
jQuery(".wpsc-it-thread-section-container").append( |
| 3266 |
supportcandy.loader_html |
| 3267 |
); |
| 3268 |
} else { |
| 3269 |
jQuery(".wpsc-it-thread-section-container").prepend( |
| 3270 |
supportcandy.loader_html |
| 3271 |
); |
| 3272 |
} |
| 3273 |
|
| 3274 |
var oldBtnContainer = jQuery(el).parent(); |
| 3275 |
oldBtnContainer.hide(); |
| 3276 |
|
| 3277 |
var data = { |
| 3278 |
action: "wpsc_load_older_archive_threads", |
| 3279 |
ticket_id, |
| 3280 |
last_thread: supportcandy.threads.last_thread, |
| 3281 |
}; |
| 3282 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3283 |
jQuery(".wpsc-it-thread-section-container").find(".wpsc-loader").remove(); |
| 3284 |
// add threads. |
| 3285 |
if (supportcandy.reply_form_position === "top") { |
| 3286 |
jQuery(".wpsc-it-thread-section-container").append(response.threads); |
| 3287 |
} else { |
| 3288 |
var scrollHeightBody = jQuery("body").prop("scrollHeight"); |
| 3289 |
var windowScrollTop = jQuery(window).scrollTop(); |
| 3290 |
jQuery(".wpsc-it-thread-section-container").prepend(response.threads); |
| 3291 |
var scrollDiff = jQuery("body").prop("scrollHeight") - scrollHeightBody; |
| 3292 |
jQuery(window).scrollTop(windowScrollTop + scrollDiff); |
| 3293 |
} |
| 3294 |
// show btn if there are more threads available. |
| 3295 |
if (response.has_next_page) { |
| 3296 |
supportcandy.threads.last_thread = response.last_thread; |
| 3297 |
oldBtnContainer.show(); |
| 3298 |
} |
| 3299 |
}); |
| 3300 |
} |
| 3301 |
|
| 3302 |
|
| 3303 |
/** |
| 3304 |
* Delete permanently |
| 3305 |
*/ |
| 3306 |
function wpsc_iat_delete_permanently(ticket_id, nonce) { |
| 3307 |
var flag = confirm(supportcandy.translations.delete_permanently); |
| 3308 |
if (!flag) { |
| 3309 |
return; |
| 3310 |
} |
| 3311 |
|
| 3312 |
var data = { |
| 3313 |
action: "wpsc_iat_delete_permanently", |
| 3314 |
ticket_id, |
| 3315 |
_ajax_nonce: nonce, |
| 3316 |
}; |
| 3317 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3318 |
wpsc_get_archive_ticket_list(); |
| 3319 |
}); |
| 3320 |
} |
| 3321 |
|
| 3322 |
/** |
| 3323 |
* Get bulk delete archive ticket |
| 3324 |
*/ |
| 3325 |
function wpsc_bulk_delete_archive_tickets(nonce) { |
| 3326 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 3327 |
var checked = items.length === 0 ? false : true; |
| 3328 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 3329 |
if (items.length != 0) { |
| 3330 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 3331 |
.map(function () { |
| 3332 |
return this.value; |
| 3333 |
}) |
| 3334 |
.get(); |
| 3335 |
var flag = confirm(supportcandy.translations.delete_permanently); |
| 3336 |
if (!flag) { |
| 3337 |
return; |
| 3338 |
} |
| 3339 |
|
| 3340 |
var data = { |
| 3341 |
action: "wpsc_bulk_delete_archive_tickets", |
| 3342 |
ticket_ids, |
| 3343 |
_ajax_nonce: nonce, |
| 3344 |
}; |
| 3345 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3346 |
wpsc_get_archive_ticket_list(); |
| 3347 |
wpsc_run_ajax_background_process(); |
| 3348 |
}); |
| 3349 |
} |
| 3350 |
} |
| 3351 |
|
| 3352 |
/** |
| 3353 |
* Restore bulk archive tickets |
| 3354 |
*/ |
| 3355 |
function wpsc_bulk_restore_archive_tickets(nonce) { |
| 3356 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 3357 |
var checked = items.length === 0 ? false : true; |
| 3358 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 3359 |
if (items.length != 0) { |
| 3360 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 3361 |
.map(function () { |
| 3362 |
return this.value; |
| 3363 |
}) |
| 3364 |
.get(); |
| 3365 |
var flag = confirm(supportcandy.translations.confirm); |
| 3366 |
if (!flag) { |
| 3367 |
return; |
| 3368 |
} |
| 3369 |
var data = { |
| 3370 |
action: "wpsc_bulk_restore_archive_tickets", |
| 3371 |
ticket_ids, |
| 3372 |
_ajax_nonce: nonce, |
| 3373 |
}; |
| 3374 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3375 |
wpsc_get_archive_ticket_list(); |
| 3376 |
}); |
| 3377 |
} |
| 3378 |
} |
| 3379 |
|
| 3380 |
/** |
| 3381 |
* Get bulk archive ticket |
| 3382 |
*/ |
| 3383 |
function wpsc_bulk_delete_tickets(nonce) { |
| 3384 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 3385 |
var checked = items.length === 0 ? false : true; |
| 3386 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 3387 |
if (items.length != 0) { |
| 3388 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 3389 |
.map(function () { |
| 3390 |
return this.value; |
| 3391 |
}) |
| 3392 |
.get(); |
| 3393 |
var flag = confirm(supportcandy.translations.confirm); |
| 3394 |
if (!flag) { |
| 3395 |
return; |
| 3396 |
} |
| 3397 |
|
| 3398 |
var data = { |
| 3399 |
action: "wpsc_bulk_delete_tickets", |
| 3400 |
ticket_ids, |
| 3401 |
_ajax_nonce: nonce, |
| 3402 |
}; |
| 3403 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3404 |
wpsc_get_ticket_list(); |
| 3405 |
wpsc_run_ajax_background_process(); |
| 3406 |
}); |
| 3407 |
} |
| 3408 |
} |
| 3409 |
|
| 3410 |
/** |
| 3411 |
* Restore bulk tickets |
| 3412 |
*/ |
| 3413 |
function wpsc_bulk_restore_tickets(nonce) { |
| 3414 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 3415 |
var checked = items.length === 0 ? false : true; |
| 3416 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 3417 |
if (items.length != 0) { |
| 3418 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 3419 |
.map(function () { |
| 3420 |
return this.value; |
| 3421 |
}) |
| 3422 |
.get(); |
| 3423 |
var flag = confirm(supportcandy.translations.confirm); |
| 3424 |
if (!flag) { |
| 3425 |
return; |
| 3426 |
} |
| 3427 |
var data = { |
| 3428 |
action: "wpsc_bulk_restore_tickets", |
| 3429 |
ticket_ids, |
| 3430 |
_ajax_nonce: nonce, |
| 3431 |
}; |
| 3432 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3433 |
wpsc_get_ticket_list(); |
| 3434 |
}); |
| 3435 |
} |
| 3436 |
} |
| 3437 |
|
| 3438 |
/** |
| 3439 |
* Deletes bulk ticket permanentaly |
| 3440 |
*/ |
| 3441 |
function wpsc_bulk_delete_tickets_permanently(nonce) { |
| 3442 |
var items = jQuery(".wpsc-bulk-select:checked"); |
| 3443 |
var checked = items.length === 0 ? false : true; |
| 3444 |
jQuery(".wpsc-bulk-selector").prop("checked", checked); |
| 3445 |
if (items.length != 0) { |
| 3446 |
var ticket_ids = jQuery(".wpsc-bulk-select:checked") |
| 3447 |
.map(function () { |
| 3448 |
return this.value; |
| 3449 |
}) |
| 3450 |
.get(); |
| 3451 |
var flag = confirm(supportcandy.translations.confirm); |
| 3452 |
if (!flag) { |
| 3453 |
return; |
| 3454 |
} |
| 3455 |
|
| 3456 |
var data = { |
| 3457 |
action: "wpsc_bulk_delete_tickets_permanently", |
| 3458 |
ticket_ids, |
| 3459 |
_ajax_nonce: nonce, |
| 3460 |
}; |
| 3461 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 3462 |
wpsc_get_ticket_list(); |
| 3463 |
}); |
| 3464 |
} |
| 3465 |
} |