| 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 |
session_id: jQuery(self).attr('data-id'), |
| 60 |
}, |
| 61 |
success: function (response) { |
| 62 |
jQuery('.loader').fadeOut(); |
| 63 |
jQuery('.loader-mask').delay(350).fadeOut('slow'); |
| 64 |
let htmlString = response.conversation; |
| 65 |
const doc = htmlspecialchars_decode(htmlString); |
| 66 |
jQuery('.details_modal_body').html(doc) |
| 67 |
session_hover_state = ''; |
| 68 |
// location.reload(); |
| 69 |
}, |
| 70 |
}); |
| 71 |
}, 100); |
| 72 |
} |
| 73 |
}); |
| 74 |
jQuery('#chatsession-table').on('click', '.show_details_click', function(e) { |
| 75 |
var self = this; |
| 76 |
const modal = document.getElementById("session_details_modal"); |
| 77 |
|
| 78 |
window.onclick = function(event) { |
| 79 |
if (event.target == modal) { |
| 80 |
modal.style.display = "none"; |
| 81 |
} |
| 82 |
} |
| 83 |
if(session_hover_state == ''){ |
| 84 |
session_hover_state = 1; |
| 85 |
modal.style.display = "none"; |
| 86 |
jQuery('.details_modal_body').html(''); |
| 87 |
modal.style.left = (jQuery('.session_detail_hover').width() * 2)+'px'; |
| 88 |
setTimeout(function() { |
| 89 |
modal.style.display = "block"; |
| 90 |
jQuery('.loader-mask').show(); |
| 91 |
jQuery('.loader').show(); |
| 92 |
jQuery.ajax({ |
| 93 |
url: ajax_object.ajax_url, |
| 94 |
type: 'POST', |
| 95 |
dataType: "JSON", |
| 96 |
data: { |
| 97 |
action : 'wpbot_session_hover_details', |
| 98 |
session_id: jQuery(self).attr('data-id'), |
| 99 |
}, |
| 100 |
success: function (response) { |
| 101 |
jQuery('.loader').fadeOut(); |
| 102 |
jQuery('.loader-mask').delay(350).fadeOut('slow'); |
| 103 |
let htmlString = response.conversation; |
| 104 |
const doc = htmlspecialchars_decode(htmlString); |
| 105 |
jQuery('.details_modal_body').html(doc) |
| 106 |
session_hover_state = ''; |
| 107 |
// location.reload(); |
| 108 |
}, |
| 109 |
}); |
| 110 |
}, 100); |
| 111 |
} |
| 112 |
}); |
| 113 |
jQuery('#session_details_modal').on('click','.details_session_close',function(){ |
| 114 |
const modal = document.getElementById("session_details_modal"); |
| 115 |
modal.style.display = "none"; |
| 116 |
}) |
| 117 |
jQuery('#wpchatbot-sessioncorn-settings').on('click','#save_wpsseion_corn_setting',function(){ |
| 118 |
Swal.showLoading(); |
| 119 |
if (jQuery('#is_ai_enabled').is(":checked")){ |
| 120 |
var is_ai_enabled = 1; |
| 121 |
}else{ |
| 122 |
var is_ai_enabled = 0; |
| 123 |
} |
| 124 |
var corn_schedule_interval = jQuery("[id*='corn_schedule_interval'] :selected").val(); |
| 125 |
var qcld_wbsession_corn_starttime = jQuery('#qcld_wbsession_corn_starttime').val(); |
| 126 |
var qcld_wpsession_corn_promt = jQuery('#wpsession_corn_promt').val(); |
| 127 |
jQuery.ajax({ |
| 128 |
url: ajax_object.ajax_url, |
| 129 |
type: 'POST', |
| 130 |
dataType: "JSON", |
| 131 |
data: { |
| 132 |
action : 'wpbot_seesion_corn_save', |
| 133 |
ai_enabled: is_ai_enabled, |
| 134 |
corn_schedule_interval: corn_schedule_interval, |
| 135 |
qcld_wbsession_corn_starttime: qcld_wbsession_corn_starttime, |
| 136 |
qcld_wpsession_corn_promt: qcld_wpsession_corn_promt, |
| 137 |
}, |
| 138 |
success: function (response) { |
| 139 |
var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 140 |
var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 141 |
Swal.fire({ |
| 142 |
title: cleanMsg, |
| 143 |
text: cleanResponse, |
| 144 |
icon: response.icon, |
| 145 |
width: 450, |
| 146 |
confirmButtonText: 'Got it', |
| 147 |
confirmButtonWidth: 100, |
| 148 |
confirmButtonClass: 'btn btn-lg' |
| 149 |
}).then(() => { |
| 150 |
// location.reload(); |
| 151 |
}) |
| 152 |
|
| 153 |
}, |
| 154 |
}); |
| 155 |
}) |
| 156 |
jQuery('#wpchatbot-sessioncorn-mannual').on('click','#swpsseion_mannual_scraper_corn',function(){ |
| 157 |
Swal.showLoading(); |
| 158 |
var wpchatbot_sessioncorn_mannual_number = jQuery('#wpchatbot-sessioncorn-mannual-number').val(); |
| 159 |
jQuery.ajax({ |
| 160 |
url: ajax_object.ajax_url, |
| 161 |
type: 'POST', |
| 162 |
dataType: "JSON", |
| 163 |
data: { |
| 164 |
action : 'qcld_chatbot_session_mannual_scraper', |
| 165 |
wpchatbot_session_mannual_number : wpchatbot_sessioncorn_mannual_number, |
| 166 |
}, |
| 167 |
success: function (response) { |
| 168 |
var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 169 |
var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; |
| 170 |
Swal.fire({ |
| 171 |
title: cleanMsg, |
| 172 |
text: cleanResponse, |
| 173 |
icon: response.icon, |
| 174 |
width: 450, |
| 175 |
confirmButtonText: 'Got it', |
| 176 |
confirmButtonWidth: 100, |
| 177 |
confirmButtonClass: 'btn btn-lg' |
| 178 |
}).then(() => { |
| 179 |
// location.reload(); |
| 180 |
}) |
| 181 |
}, |
| 182 |
}); |
| 183 |
}) |
| 184 |
|
| 185 |
//end new-update-for-codecanyon |
| 186 |
jQuery('#wpcs_form_sessions').on('change', '#is_enabled_session_email_notice', function() { |
| 187 |
if(this.checked) { |
| 188 |
jQuery.ajax({ |
| 189 |
url: ajax_object.ajax_url, |
| 190 |
type: 'POST', |
| 191 |
dataType: "JSON", |
| 192 |
data: { |
| 193 |
action : 'session_email_notification_update', |
| 194 |
email_notification: 'checked', |
| 195 |
}, |
| 196 |
success: function (response) { |
| 197 |
location.reload(); |
| 198 |
}, |
| 199 |
}); |
| 200 |
}else{ |
| 201 |
jQuery.ajax({ |
| 202 |
url: ajax_object.ajax_url, |
| 203 |
type: 'POST', |
| 204 |
dataType: "JSON", |
| 205 |
data: { |
| 206 |
action : 'session_email_notification_update', |
| 207 |
email_notification: '', |
| 208 |
}, |
| 209 |
success: function (response) { |
| 210 |
location.reload(); |
| 211 |
}, |
| 212 |
}); |
| 213 |
} |
| 214 |
}); |
| 215 |
|
| 216 |
jQuery('#chatsession-table').on('click', '.forward_session', function () { |
| 217 |
setTimeout(function() { |
| 218 |
var detailselement = document.getElementById("wp-chatbot-messages-container"); |
| 219 |
detailselement.remove(); |
| 220 |
}, 500); |
| 221 |
const forwardModal = document.getElementById("session_foward_modal"); |
| 222 |
if (forwardModal) { |
| 223 |
forwardModal.style.display = "block"; |
| 224 |
jQuery('#details_session_id').val(jQuery(this).attr('data-id')); |
| 225 |
} |
| 226 |
|
| 227 |
}); |
| 228 |
jQuery('#session_foward_modal').on('click', '.forward_session_close', function () { |
| 229 |
const forwardModal = document.getElementById("session_foward_modal"); |
| 230 |
if (forwardModal) { |
| 231 |
forwardModal.style.display = "none"; |
| 232 |
} |
| 233 |
}); |
| 234 |
|
| 235 |
jQuery('#session_foward_modal').on('click', '#qcld_details_forward_submit', function () { |
| 236 |
var session_id = jQuery('#details_session_id').val(); |
| 237 |
jQuery.ajax({ |
| 238 |
url: ajax_object.ajax_url, |
| 239 |
type: 'POST', |
| 240 |
dataType: "JSON", |
| 241 |
data: { |
| 242 |
action : 'forward_session_to_email', |
| 243 |
session_id: session_id, |
| 244 |
email: jQuery('#details_session_email').val(), |
| 245 |
subject: jQuery('#details_session_subject').val(), |
| 246 |
}, |
| 247 |
success: function (response) { |
| 248 |
jQuery('#session_foward_modal').hide() |
| 249 |
} |
| 250 |
}); |
| 251 |
}); |
| 252 |
jQuery('.wp-chatbot-messages-wrapper').on('click', '.forward_session', function () { |
| 253 |
|
| 254 |
var session_id = jQuery('#details_session_id').val(); |
| 255 |
jQuery.ajax({ |
| 256 |
url: ajax_object.ajax_url, |
| 257 |
type: 'POST', |
| 258 |
dataType: "JSON", |
| 259 |
data: { |
| 260 |
action : 'forward_session_to_email', |
| 261 |
session_id: session_id, |
| 262 |
email: jQuery('#details_session_email').val(), |
| 263 |
subject: jQuery('#details_session_subject').val(), |
| 264 |
}, |
| 265 |
success: function (response) { |
| 266 |
if(response.success){ |
| 267 |
Swal.fire({ |
| 268 |
title: 'Success', |
| 269 |
text: response.message, |
| 270 |
icon: 'success', |
| 271 |
confirmButtonText: 'OK' |
| 272 |
}); |
| 273 |
} else { |
| 274 |
Swal.fire({ |
| 275 |
title: 'Error', |
| 276 |
text: response.message, |
| 277 |
icon: 'error', |
| 278 |
confirmButtonText: 'OK' |
| 279 |
}); |
| 280 |
} |
| 281 |
} |
| 282 |
}); |
| 283 |
}); |
| 284 |
|
| 285 |
}); |