summaryrefslogtreecommitdiff
path: root/addons/website_livechat/static/src/legacy
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website_livechat/static/src/legacy
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_livechat/static/src/legacy')
-rw-r--r--addons/website_livechat/static/src/legacy/public_livechat.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/addons/website_livechat/static/src/legacy/public_livechat.js b/addons/website_livechat/static/src/legacy/public_livechat.js
new file mode 100644
index 00000000..6bb15735
--- /dev/null
+++ b/addons/website_livechat/static/src/legacy/public_livechat.js
@@ -0,0 +1,47 @@
+odoo.define('website_livechat.legacy.website_livechat.livechat_request', function (require) {
+"use strict";
+
+var utils = require('web.utils');
+var session = require('web.session');
+var LivechatButton = require('im_livechat.legacy.im_livechat.im_livechat').LivechatButton;
+
+
+LivechatButton.include({
+
+ /**
+ * @override
+ * Check if a chat request is opened for this visitor
+ * if yes, replace the session cookie and start the conversation immediately.
+ * Do this before calling super to have everything ready before executing existing start logic.
+ * This is used for chat request mechanism, when an operator send a chat request
+ * from backend to a website visitor.
+ */
+ willStart: function () {
+ if (this.options.chat_request_session) {
+ utils.set_cookie('im_livechat_session', JSON.stringify(this.options.chat_request_session), 60*60);
+ }
+ return this._super();
+ },
+
+ /**
+ * @override
+ * Called when the visitor closes the livechat chatter the first time (first click on X button)
+ * this will deactivate the mail_channel, clean the chat request if any
+ * and allow the operators to send the visitor a new chat request
+ */
+ _onCloseChatWindow: function (ev) {
+ this._super(ev);
+ var cookie = utils.get_cookie('im_livechat_session');
+ if (cookie) {
+ var channel = JSON.parse(cookie);
+ session.rpc('/im_livechat/visitor_leave_session', {uuid: channel.uuid});
+ utils.set_cookie('im_livechat_session', "", -1); // remove cookie
+ }
+ },
+});
+
+return {
+ LivechatButton: LivechatButton,
+};
+
+});