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