From 16a3a4b7fe4ccad4f2e05c19ecc0ddb4694d4911 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 25 Jan 2016 10:56:25 +0100 Subject: [PATCH] [FIX] im_livechat,mail: various livechat fixes - prevent concurrent opening of the chat window - take into account the placeholder value of the livechat session record - don't send welcome message if empty --- .../im_livechat/static/src/js/im_livechat.js | 38 ++++++++++++------- addons/mail/static/src/js/chat_window.js | 2 +- addons/mail/static/src/xml/chat_window.xml | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index 9ccb50c10f8..84f626883c0 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -23,7 +23,7 @@ var LivechatButton = Widget.extend({ init: function (parent, server_url, options) { this._super(parent); this.options = _.defaults(options || {}, { - placeholder: _t('Ask something ...'), + input_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?"), @@ -91,10 +91,14 @@ var LivechatButton = Widget.extend({ return $.when.apply($, defs); }, - open_chat: function () { + open_chat: _.debounce(function () { + if (this.opening_chat) { + return; + } var self = this; var cookie = utils.get_cookie('im_livechat_session'); var def; + this.opening_chat = true; clearTimeout(this.auto_popup_timeout); if (cookie) { def = $.when(JSON.parse(cookie)); @@ -120,13 +124,16 @@ var LivechatButton = Widget.extend({ utils.set_cookie('im_livechat_session', JSON.stringify(channel), 60*60); utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60); } + }).always(function () { + self.opening_chat = false; }); - }, + }, 200, true), open_chat_window: function (channel) { var self = this; var options = { display_stars: false, + placeholder: this.options.input_placeholder || "", }; var is_folded = (channel.state === 'folded'); this.chat_window = new ChatWindow(this, channel.id, channel.name, is_folded, channel.message_unread_counter, options); @@ -136,7 +143,10 @@ var LivechatButton = Widget.extend({ }); this.chat_window.on("close_chat_session", this, function () { var input_disabled = this.chat_window.$(".o_chat_input input").prop('disabled'); - if (this.messages.length > 1 && !input_disabled) { + var ask_fb = !input_disabled && _.find(this.messages, function (msg) { + return msg.id !== '_welcome'; + }); + if (ask_fb) { this.chat_window.toggle_fold(false); this.ask_feedback(); } else { @@ -212,15 +222,17 @@ var LivechatButton = Widget.extend({ }, send_welcome_message: function () { - this.add_message({ - id: 1, - attachment_ids: [], - author_id: this.channel.operator_pid, - body: this.options.default_message, - channel_ids: [this.channel.id], - date: time.datetime_to_str(new Date()), - tracking_value_ids: [], - }, {prepend: true}); + if (this.options.default_message) { + this.add_message({ + id: '_welcome', + attachment_ids: [], + author_id: this.channel.operator_pid, + body: this.options.default_message, + channel_ids: [this.channel.id], + date: time.datetime_to_str(new Date()), + tracking_value_ids: [], + }, {prepend: true}); + } }, ask_feedback: function () { diff --git a/addons/mail/static/src/js/chat_window.js b/addons/mail/static/src/js/chat_window.js index 63074b403c9..95ac9dd8897 100644 --- a/addons/mail/static/src/js/chat_window.js +++ b/addons/mail/static/src/js/chat_window.js @@ -24,10 +24,10 @@ return Widget.extend({ this._super(parent); this.title = title; this.channel_id = channel_id; - this.placeholder = _t("Say something"); this.folded = is_folded; this.options = _.defaults(options || {}, { display_stars: true, + placeholder: _t("Say something"), }); this.unread_msgs = unread_msgs || 0; this.is_hidden = false; diff --git a/addons/mail/static/src/xml/chat_window.xml b/addons/mail/static/src/xml/chat_window.xml index f5c7273d832..eb003cd59cd 100644 --- a/addons/mail/static/src/xml/chat_window.xml +++ b/addons/mail/static/src/xml/chat_window.xml @@ -12,7 +12,7 @@
- +