From 0c92788d88b85107ede2457256d906a72a7dd041 Mon Sep 17 00:00:00 2001 From: Aaron Bohy <aab@odoo.com> Date: Wed, 16 Dec 2015 09:16:51 +0100 Subject: [PATCH] [FIX] im_livechat: various fixes - use channel configuration for the auto_popup - clear auto_popup timeout when chat open to prevent opening the chat twice if the user opens it himself before the end of the timeout - don't send message when no feedback given --- addons/im_livechat/static/src/js/im_livechat.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index 4179149d68bb..b47ee3726c4b 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -20,16 +20,15 @@ var LivechatButton = Widget.extend({ "click": "open_chat" }, - init: function (parent, server_url, options) { + init: function (parent, server_url, options, rule) { this._super(parent); this.options = _.defaults(options || {}, { placeholder: _t('Ask something ...'), default_username: _t("Visitor"), button_text: _t("Chat with one of our collaborators"), default_message: _t("How may I help you?"), - auto_popup: true, - auto_popup_timer: 10, // auto popup after 10 seconds }); + this.rule = rule || {}; this.channel = null; this.chat_window = null; this.messages = []; @@ -62,10 +61,10 @@ var LivechatButton = Widget.extend({ if (this.history) { _.each(this.history.reverse(), this.add_message.bind(this)); this.open_chat(); - } else if (this.options.auto_popup) { + } else if (this.rule.action === 'auto_popup') { var auto_popup_cookie = utils.get_cookie('im_livechat_auto_popup'); - if (!auto_popup_cookie || JSON.parse(auto_popup_cookie)){ - setTimeout(this.open_chat.bind(this), this.options.auto_popup_timer*1000); + if (!auto_popup_cookie || JSON.parse(auto_popup_cookie)) { + this.auto_popup_timeout = setTimeout(this.open_chat.bind(this), this.rule.auto_popup_timer*1000); } } bus.on('notification', this, function (notification) { @@ -97,6 +96,7 @@ var LivechatButton = Widget.extend({ var self = this; var cookie = utils.get_cookie('im_livechat_session'); var def; + clearTimeout(this.auto_popup_timeout); if (cookie) { def = $.when(JSON.parse(cookie)); } else { @@ -261,9 +261,7 @@ var Feedback = Widget.extend({ this._send_feedback({close: close_chat}); }, - on_click_no_feedback: function (ev) { - var content = _t("I did not rate this conversation. Bye."); - this.trigger("send_message", {content: content}); + on_click_no_feedback: function () { this.trigger("feedback_sent"); // will close the chat }, -- GitLab