[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
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<div class="o_chat_content">
|
||||
</div>
|
||||
<div class="o_chat_input">
|
||||
<input t-att-placeholder="widget.placeholder"/>
|
||||
<input t-att-placeholder="widget.options.placeholder"/>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user