Skip to content
Snippets Groups Projects
Commit 0c92788d authored by Aaron Bohy's avatar Aaron Bohy
Browse files

[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
parent 2b99a369
No related branches found
No related tags found
No related merge requests found
...@@ -20,16 +20,15 @@ var LivechatButton = Widget.extend({ ...@@ -20,16 +20,15 @@ var LivechatButton = Widget.extend({
"click": "open_chat" "click": "open_chat"
}, },
init: function (parent, server_url, options) { init: function (parent, server_url, options, rule) {
this._super(parent); this._super(parent);
this.options = _.defaults(options || {}, { this.options = _.defaults(options || {}, {
placeholder: _t('Ask something ...'), placeholder: _t('Ask something ...'),
default_username: _t("Visitor"), default_username: _t("Visitor"),
button_text: _t("Chat with one of our collaborators"), button_text: _t("Chat with one of our collaborators"),
default_message: _t("How may I help you?"), 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.channel = null;
this.chat_window = null; this.chat_window = null;
this.messages = []; this.messages = [];
...@@ -62,10 +61,10 @@ var LivechatButton = Widget.extend({ ...@@ -62,10 +61,10 @@ var LivechatButton = Widget.extend({
if (this.history) { if (this.history) {
_.each(this.history.reverse(), this.add_message.bind(this)); _.each(this.history.reverse(), this.add_message.bind(this));
this.open_chat(); 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'); var auto_popup_cookie = utils.get_cookie('im_livechat_auto_popup');
if (!auto_popup_cookie || JSON.parse(auto_popup_cookie)){ if (!auto_popup_cookie || JSON.parse(auto_popup_cookie)) {
setTimeout(this.open_chat.bind(this), this.options.auto_popup_timer*1000); this.auto_popup_timeout = setTimeout(this.open_chat.bind(this), this.rule.auto_popup_timer*1000);
} }
} }
bus.on('notification', this, function (notification) { bus.on('notification', this, function (notification) {
...@@ -97,6 +96,7 @@ var LivechatButton = Widget.extend({ ...@@ -97,6 +96,7 @@ var LivechatButton = Widget.extend({
var self = this; var self = this;
var cookie = utils.get_cookie('im_livechat_session'); var cookie = utils.get_cookie('im_livechat_session');
var def; var def;
clearTimeout(this.auto_popup_timeout);
if (cookie) { if (cookie) {
def = $.when(JSON.parse(cookie)); def = $.when(JSON.parse(cookie));
} else { } else {
...@@ -261,9 +261,7 @@ var Feedback = Widget.extend({ ...@@ -261,9 +261,7 @@ var Feedback = Widget.extend({
this._send_feedback({close: close_chat}); this._send_feedback({close: close_chat});
}, },
on_click_no_feedback: function (ev) { on_click_no_feedback: function () {
var content = _t("I did not rate this conversation. Bye.");
this.trigger("send_message", {content: content});
this.trigger("feedback_sent"); // will close the chat this.trigger("feedback_sent"); // will close the chat
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment