| 1 |
jQuery(document).ready(function(){ |
| 2 |
'use strict' |
| 3 |
//start new-update-for-codecanyon |
| 4 |
jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('focusout', function(){ |
| 5 |
qc_chatsessions_set_plugin_license_fields(); |
| 6 |
}); |
| 7 |
|
| 8 |
jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('keypress',function (e) { |
| 9 |
qc_chatsessions_set_plugin_license_fields(); |
| 10 |
}); |
| 11 |
|
| 12 |
jQuery('#qc-license-form input[type="submit"]').on('click', function(){ |
| 13 |
qc_chatsessions_set_plugin_license_fields(); |
| 14 |
jQuery('#qc-license-form').removeAttr('onsubmit').submit(); |
| 15 |
}); |
| 16 |
|
| 17 |
function qc_chatsessions_set_plugin_license_fields(){ |
| 18 |
var license_input = jQuery('#qcld_chatsessions_enter_license_or_purchase_key').val(); |
| 19 |
if( /^(\w{8})-((\w{4})-){3}(\w{12})$/.test(license_input) ){ |
| 20 |
jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('codecanyon'); |
| 21 |
jQuery('input[name="qcld_chatsessions_enter_envato_key"]').val(license_input); |
| 22 |
}else{ |
| 23 |
jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('quantumcloud'); |
| 24 |
jQuery('input[name="qcld_chatsessions_enter_license_key"]').val(license_input); |
| 25 |
} |
| 26 |
} |
| 27 |
function htmlspecialchars_decode(text) { |
| 28 |
const parser = new DOMParser(); |
| 29 |
const doc = parser.parseFromString(text, 'text/html'); |
| 30 |
return doc.documentElement.textContent; |
| 31 |
} |
| 32 |
var session_hover_state = ''; |
| 33 |
const modal = document.getElementById("session_details_modal"); |
| 34 |
jQuery('.session_detail_hover').hover(function(e) { |
| 35 |
var self = this; |
| 36 |
var hoverTimer = ''; |
| 37 |
const modal = document.getElementById("session_details_modal"); |
| 38 |
|
| 39 |
window.onclick = function(event) { |
| 40 |
if (event.target == modal) { |
| 41 |
modal.style.display = "none"; |
| 42 |
} |
| 43 |
} |
| 44 |
if(session_hover_state == ''){ |
| 45 |
session_hover_state = 1; |
| 46 |
modal.style.display = "none"; |
| 47 |
jQuery('.details_modal_body').html(''); |
| 48 |
modal.style.left = ''; |
| 49 |
modal.style.top = ''; |
| 50 |
setTimeout(function() { |
| 51 |
modal.style.display = "block"; |
| 52 |
jQuery('.loader-mask').show(); |
| 53 |
jQuery('.loader').show(); |
| 54 |
jQuery.ajax({ |
| 55 |
url: ajax_object.ajax_url, |
| 56 |
type: 'POST', |
| 57 |
dataType: "JSON", |
| 58 |
data: { |
| 59 |
action : 'wpbot_session_hover_details', |
| 60 |
security: ajax_object.ajax_nonce, |
| 61 |
session_id: jQuery(self).attr('data-id'), |
| 62 |
}, |
| 63 |
success: function (response) { |
| 64 |
jQuery('.loader').fadeOut(); |
| 65 |
jQuery('.loader-mask').delay(350).fadeOut('slow'); |
| 66 |
let htmlString = response.conversation; |
| 67 |
let doc = '<div class="session-details-sction-modal">' ; |
| 68 |
doc += htmlspecialchars_decode(htmlString); |
| 69 |
doc += '</div>'; |
| 70 |
if (response.email) { |
| 71 |
doc += '<div class="email-reply-container">' + |
| 72 |
'<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + response.email + ' <strong>From:</strong> <input type="email" id="reply_from_email" class="form-control" value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' + |
| 73 |
'<div class="form-group mb-2">' + |
| 74 |
'<input type="text" id="reply_subject" class="form-control" placeholder="Reply to your chat session">' + |
| 75 |
'</div>' + |
| 76 |
'<div class="form-group mb-2">' + |
| 77 |
'<textarea id="reply_message" class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' + |
| 78 |
'</div>' + |
| 79 |
'<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' + |
| 80 |
'</div>'; |
| 81 |
} else { |
| 82 |
doc += '<div class="email-reply-container">' + |
| 83 |
'<p class="email-reply-warning">Enable Asking for Email to get email reply option</p>' + |
| 84 |
'</div>'; |
| 85 |
} |
| 86 |
jQuery('.details_modal_body').html(doc); |
| 87 |
session_hover_state = ''; |
| 88 |
// location.reload(); |
| 89 |
}, |
| 90 |
}); |
| 91 |
}, 100); |
| 92 |
} |
| 93 |
}); |
| 94 |
jQuery('#chatsession-table').on('click', '.show_details_click', function(e) { |
| 95 |
var self = this; |
| 96 |
const modal = document.getElementById("session_details_modal"); |
| 97 |
|
| 98 |
window.onclick = function(event) { |
| 99 |
if (event.target == modal) { |
| 100 |
modal.style.display = "none"; |
| 101 |
} |
| 102 |
} |
| 103 |
if(session_hover_state == ''){ |
| 104 |
session_hover_state = 1; |
| 105 |
modal.style.display = "none"; |
| 106 |
jQuery('.details_modal_body').html(''); |
| 107 |
modal.style.left = ''; |
| 108 |
modal.style.top = ''; |
| 109 |
|
| 110 |
if (typeof Swal !== 'undefined') { |
| 111 |
Swal.fire({ |
| 112 |
html: '<div class="qcld-save-settings-spinner"></div>', |
| 113 |
allowOutsideClick: false, |
| 114 |
allowEscapeKey: false, |
| 115 |
showConfirmButton: false, |
| 116 |
background: 'transparent', |
| 117 |
customClass: { |
| 118 |
popup: 'qcld-swal-loading-only' |
| 119 |
} |
| 120 |
}); |
| 121 |
} |
| 122 |
|
| 123 |
jQuery.ajax({ |
| 124 |
url: ajax_object.ajax_url, |
| 125 |
type: 'POST', |
| 126 |
dataType: "JSON", |
| 127 |
data: { |
| 128 |
action : 'wpbot_session_hover_details', |
| 129 |
security: ajax_object.ajax_nonce, |
| 130 |
session_id: jQuery(self).attr('data-id'), |
| 131 |
}, |
| 132 |
success: function (response) { |
| 133 |
if (typeof Swal !== 'undefined') { |
| 134 |
Swal.close(); |
| 135 |
} |
| 136 |
let htmlString = response.conversation; |
| 137 |
let doc = '<div class="session-details-sction-modal">' ; |
| 138 |
doc += htmlspecialchars_decode(htmlString); |
| 139 |
doc += '</div>'; |
| 140 |
if (response.email) { |
| 141 |
var replyEmail = response.email || ''; |
| 142 |
var replyEmailText = jQuery('<div>').text(replyEmail).html(); |
| 143 |
var replyEmailLink = '<a href="mailto:' + encodeURIComponent(replyEmail) + '">' + replyEmailText + '</a>'; |
| 144 |
doc += '<div class="email-reply-container">' + |
| 145 |
'<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + replyEmailLink + ' <strong>From:</strong> <input type="email" id="reply_from_email" value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' + |
| 146 |
'<div class="form-group mb-2">' + |
| 147 |
'<input type="text" id="reply_subject" class="form-control" placeholder="Reply to your chat session">' + |
| 148 |
'</div>' + |
| 149 |
'<div class="form-group mb-2">' + |
| 150 |
'<textarea id="reply_message" class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' + |
| 151 |
'</div>' + |
| 152 |
'<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' + |
| 153 |
'</div>'; |
| 154 |
} else { |
| 155 |
doc += '<div class="email-reply-container">' + |
| 156 |
'<p class="email-reply-warning">To email this user and chat session, enable Asking for Email in General Settings</p>' + |
| 157 |
'<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + (response.email || '') + ' <strong>From:</strong> <input type="email" id="reply_from_email" disabled value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' + |
| 158 |
'<div class="form-group mb-2">' + |
| 159 |
'<input type="text" id="reply_subject" disabled class="form-control" placeholder="Reply to your chat session">' + |
| 160 |
'</div>' + |
| 161 |
'<div class="form-group mb-2">' + |
| 162 |
'<textarea id="reply_message" disabled class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' + |
| 163 |
'</div>' + |
| 164 |
'<button type="button" disabled class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' + |
| 165 |
'</div>'; |
| 166 |
} |
| 167 |
jQuery('.details_modal_body').html(doc); |
| 168 |
modal.style.display = "block"; |
| 169 |
session_hover_state = ''; |
| 170 |
}, |
| 171 |
error: function () { |
| 172 |
if (typeof Swal !== 'undefined') { |
| 173 |
Swal.close(); |
| 174 |
} |
| 175 |
session_hover_state = ''; |
| 176 |
} |
| 177 |
}); |
| 178 |
} |
| 179 |
}); |
| 180 |
jQuery('#session_details_modal').on('click','.details_session_close',function(){ |
| 181 |
const modal = document.getElementById("session_details_modal"); |
| 182 |
modal.style.display = "none"; |
| 183 |
}); |
| 184 |
|
| 185 |
jQuery(document).on('click', '#btn_send_reply_email', function () { |
| 186 |
var email = jQuery(this).attr('data-email'); |
| 187 |
var container = jQuery(this).closest('.email-reply-container'); |
| 188 |
var fromEmail = container.find('#reply_from_email').val(); |
| 189 |
var subject = container.find('#reply_subject').val(); |
| 190 |
var message = container.find('#reply_message').val(); |
| 191 |
var btn = jQuery(this); |
| 192 |
|
| 193 |
if (!message.trim()) { |
| 194 |
alert('Please enter a message.'); |
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
btn.prop('disabled', true).text('Sending...'); |
| 199 |
|
| 200 |
jQuery.ajax({ |
| 201 |
url: ajax_object.ajax_url, |
| 202 |
type: 'POST', |
| 203 |
dataType: "JSON", |
| 204 |
data: { |
| 205 |
action: 'wpbot_send_reply_email', |
| 206 |
security: ajax_object.ajax_nonce, |
| 207 |
email: email, |
| 208 |
from_email: fromEmail, |
| 209 |
subject: subject, |
| 210 |
message: message |
| 211 |
}, |
| 212 |
success: function (response) { |
| 213 |
btn.prop('disabled', false).text('Send Reply'); |
| 214 |
if (response.success) { |
| 215 |
if (typeof Swal !== 'undefined') { |
| 216 |
Swal.fire({ |
| 217 |
title: 'Success', |
| 218 |
text: response.msg, |
| 219 |
icon: 'success', |
| 220 |
confirmButtonText: 'OK' |
| 221 |
}); |
| 222 |
} else { |
| 223 |
alert(response.msg); |
| 224 |
} |
| 225 |
container.find('#reply_message').val(''); |
| 226 |
} else { |
| 227 |
if (typeof Swal !== 'undefined') { |
| 228 |
Swal.fire({ |
| 229 |
title: 'Error', |
| 230 |
text: response.msg, |
| 231 |
icon: 'error', |
| 232 |
confirmButtonText: 'OK' |
| 233 |
}); |
| 234 |
} else { |
| 235 |
alert(response.msg); |
| 236 |
} |
| 237 |
} |
| 238 |
}, |
| 239 |
error: function() { |
| 240 |
btn.prop('disabled', false).text('Send Reply'); |
| 241 |
alert('An error occurred. Please try again.'); |
| 242 |
} |
| 243 |
}); |
| 244 |
}); |
| 245 |
jQuery('#wpchatbot-sessioncorn-settings').on('click','#save_wpsseion_corn_setting',function(){ |
| 246 |
Swal.showLoading(); |
| 247 |
if (jQuery('#is_ai_enabled').is(":checked")){ |
| 248 |
var is_ai_enabled = 1; |
| 249 |
}else{ |
| 250 |
var is_ai_enabled = 0; |
| 251 |
} |
| 252 |
var corn_schedule_interval = jQuery("[id*='corn_schedule_interval'] :selected").val(); |
| 253 |
var qcld_wbsession_corn_starttime = jQuery('#qcld_wbsession_corn_starttime').val(); |
| 254 |
var qcld_wpsession_corn_promt = jQuery('#wpsession_corn_promt').val(); |
| 255 |
jQuery.ajax({ |
| 256 |
url: ajax_object.ajax_url, |
| 257 |
type: 'POST', |
| 258 |
dataType: "JSON", |
| 259 |
data: { |
| 260 |
action : 'wpbot_seesion_corn_save', |
| 261 |
security: ajax_object.ajax_nonce, |
| 262 |
ai_enabled: is_ai_enabled, |
| 263 |
corn_schedule_interval: corn_schedule_interval, |
| 264 |
qcld_wbsession_corn_starttime: qcld_wbsession_corn_starttime, |
| 265 |
qcld_wpsession_corn_promt: qcld_wpsession_corn_promt, |
| 266 |
}, |
| 267 |
success: function (response) { |
| 268 |
var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 269 |
var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 270 |
Swal.fire({ |
| 271 |
title: cleanMsg, |
| 272 |
text: cleanResponse, |
| 273 |
icon: response.icon, |
| 274 |
width: 450, |
| 275 |
confirmButtonText: 'Got it', |
| 276 |
confirmButtonWidth: 100, |
| 277 |
confirmButtonClass: 'btn btn-lg' |
| 278 |
}).then(() => { |
| 279 |
// location.reload(); |
| 280 |
}) |
| 281 |
|
| 282 |
}, |
| 283 |
}); |
| 284 |
}) |
| 285 |
jQuery('#wpchatbot-sessioncorn-mannual').on('click','#swpsseion_mannual_scraper_corn',function(){ |
| 286 |
Swal.showLoading(); |
| 287 |
var wpchatbot_sessioncorn_mannual_number = jQuery('#wpchatbot-sessioncorn-mannual-number').val(); |
| 288 |
jQuery.ajax({ |
| 289 |
url: ajax_object.ajax_url, |
| 290 |
type: 'POST', |
| 291 |
dataType: "JSON", |
| 292 |
data: { |
| 293 |
action : 'qcld_chatbot_session_mannual_scraper', |
| 294 |
security: ajax_object.ajax_nonce, |
| 295 |
wpchatbot_session_mannual_number : wpchatbot_sessioncorn_mannual_number, |
| 296 |
}, |
| 297 |
success: function (response) { |
| 298 |
var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 299 |
var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 300 |
Swal.fire({ |
| 301 |
title: cleanMsg, |
| 302 |
text: cleanResponse, |
| 303 |
icon: response.icon, |
| 304 |
width: 450, |
| 305 |
confirmButtonText: 'Got it', |
| 306 |
confirmButtonWidth: 100, |
| 307 |
confirmButtonClass: 'btn btn-lg' |
| 308 |
}).then(() => { |
| 309 |
// location.reload(); |
| 310 |
}) |
| 311 |
}, |
| 312 |
}); |
| 313 |
}) |
| 314 |
|
| 315 |
//end new-update-for-codecanyon |
| 316 |
jQuery('#wpcs_form_sessions').on('change', '#is_enabled_session_email_notice', function() { |
| 317 |
if(this.checked) { |
| 318 |
jQuery.ajax({ |
| 319 |
url: ajax_object.ajax_url, |
| 320 |
type: 'POST', |
| 321 |
dataType: "JSON", |
| 322 |
data: { |
| 323 |
action : 'session_email_notification_update', |
| 324 |
security: ajax_object.ajax_nonce, |
| 325 |
email_notification: 'checked', |
| 326 |
}, |
| 327 |
success: function (response) { |
| 328 |
location.reload(); |
| 329 |
}, |
| 330 |
}); |
| 331 |
}else{ |
| 332 |
jQuery.ajax({ |
| 333 |
url: ajax_object.ajax_url, |
| 334 |
type: 'POST', |
| 335 |
dataType: "JSON", |
| 336 |
data: { |
| 337 |
action : 'session_email_notification_update', |
| 338 |
security: ajax_object.ajax_nonce, |
| 339 |
email_notification: '', |
| 340 |
}, |
| 341 |
success: function (response) { |
| 342 |
location.reload(); |
| 343 |
}, |
| 344 |
}); |
| 345 |
} |
| 346 |
}); |
| 347 |
|
| 348 |
jQuery('#chatsession-table').on('click', '.forward_session', function () { |
| 349 |
jQuery('.details_modal_body').html(''); |
| 350 |
|
| 351 |
const forwardModal = document.getElementById("session_foward_modal"); |
| 352 |
if (forwardModal) { |
| 353 |
forwardModal.style.display = "block"; |
| 354 |
jQuery('#details_session_id').val(jQuery(this).attr('data-id')); |
| 355 |
} |
| 356 |
|
| 357 |
}); |
| 358 |
jQuery('#session_foward_modal').on('click', '.forward_session_close', function () { |
| 359 |
const forwardModal = document.getElementById("session_foward_modal"); |
| 360 |
if (forwardModal) { |
| 361 |
forwardModal.style.display = "none"; |
| 362 |
} |
| 363 |
}); |
| 364 |
|
| 365 |
jQuery('#session_foward_modal').on('click', '#qcld_details_forward_submit', function () { |
| 366 |
var session_id = jQuery('#details_session_id').val(); |
| 367 |
jQuery.ajax({ |
| 368 |
url: ajax_object.ajax_url, |
| 369 |
type: 'POST', |
| 370 |
dataType: "JSON", |
| 371 |
data: { |
| 372 |
action : 'forward_session_to_email', |
| 373 |
security: ajax_object.ajax_nonce, |
| 374 |
session_id: session_id, |
| 375 |
email: jQuery('#details_session_email').val(), |
| 376 |
subject: jQuery('#details_session_subject').val(), |
| 377 |
}, |
| 378 |
success: function (response) { |
| 379 |
jQuery('#session_foward_modal').hide() |
| 380 |
} |
| 381 |
}); |
| 382 |
}); |
| 383 |
jQuery('.wp-chatbot-messages-wrapper').on('click', '.forward_session', function () { |
| 384 |
|
| 385 |
var session_id = jQuery('#details_session_id').val(); |
| 386 |
jQuery.ajax({ |
| 387 |
url: ajax_object.ajax_url, |
| 388 |
type: 'POST', |
| 389 |
dataType: "JSON", |
| 390 |
data: { |
| 391 |
action : 'forward_session_to_email', |
| 392 |
security: ajax_object.ajax_nonce, |
| 393 |
session_id: session_id, |
| 394 |
email: jQuery('#details_session_email').val(), |
| 395 |
subject: jQuery('#details_session_subject').val(), |
| 396 |
}, |
| 397 |
success: function (response) { |
| 398 |
if(response.success){ |
| 399 |
Swal.fire({ |
| 400 |
title: 'Success', |
| 401 |
text: response.message, |
| 402 |
icon: 'success', |
| 403 |
confirmButtonText: 'OK' |
| 404 |
}); |
| 405 |
} else { |
| 406 |
Swal.fire({ |
| 407 |
title: 'Error', |
| 408 |
text: response.message, |
| 409 |
icon: 'error', |
| 410 |
confirmButtonText: 'OK' |
| 411 |
}); |
| 412 |
} |
| 413 |
} |
| 414 |
}); |
| 415 |
}); |
| 416 |
|
| 417 |
}); |
| 418 |
|