diff options
| author | Jérome Maes <jem@openerp.com> | 2015-08-10 16:23:44 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2015-09-01 20:16:09 +0200 |
| commit | 95b97d1010e2596c8dbe719382c77c6009819afa (patch) | |
| tree | 2a5d3b0400785eab023ec1c7768829482682cf24 /addons/im_livechat/static/src | |
| parent | 1d54858cbdd10dd6fbfbb3edc1e032317e2ba3f6 (diff) | |
[REF] im_livechat : refactoring, make it compatbile with the nw mail module, change reporting sql view (split them in 2), adapt view, ...
Diffstat (limited to 'addons/im_livechat/static/src')
5 files changed, 156 insertions, 47 deletions
diff --git a/addons/im_livechat/static/src/css/im_livechat.css b/addons/im_livechat/static/src/css/im_livechat.css index becceb34f7f..07040610e99 100644 --- a/addons/im_livechat/static/src/css/im_livechat.css +++ b/addons/im_livechat/static/src/css/im_livechat.css @@ -1,42 +1,75 @@ + +.openerp { /* base style of openerp */ + font-family: "Lucida Grande", Helvetica, Verdana, Arial, sans-serif; + color: #4c4c4c; + font-size: 13px; +} + +.o_mail_chat_im_window * { + box-sizing: border-box; +} + + +.oe_chat_button { + width: 230px; + position: fixed; + bottom: 0px; + right: 6px; + display: inline-block; + min-width: 100px; + background-color: rgba(60, 60, 60, 0.6); + font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; + font-size: 14px; + font-weight: bold; + padding: 10px; + color: white; + text-shadow: rgb(59, 76, 88) 1px 1px 0px; + border: 1px solid rgb(80, 80, 80); + border-bottom: 0px; + border-top-left-radius: 5px; + border-top-right-radius: 5px; + cursor: pointer; + z-index:500; +} + /* Livechat Rating : feedback smiley */ -.oe_im_chatview .oe_livechat_rating{ +.o_mail_chat_im_window_content .o_livechat_rating{ padding: 15px; vertical-align: middle; } -.oe_im_chatview .oe_livechat_rating .oe_im_feedback_text { - color: white; +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_feedback_text { vertical-align: middle; font-size: 14px; } -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_choices{ +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_choices{ height:40px; text-align: center; margin: 10px 0 30px 0; } -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_choices img{ +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_choices img{ width: 50px; opacity: 0.60; cursor: pointer; margin: 5px; } -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_choices img:hover{ +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_choices img:hover{ opacity:1; } -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_choices img.selected{ +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_choices img.selected{ opacity: 1; } /* feedback reason */ -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_reason { +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_reason { margin: 10px 0; display: none; /* hidden by default */ } -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_reason textarea { +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_reason textarea { width: 100%; height: 70px; resize: none; } -.oe_im_chatview .oe_livechat_rating .oe_livechat_rating_reason_button input{ +.o_mail_chat_im_window_content .o_livechat_rating .o_livechat_rating_reason_button input{ float: right; margin-left : 10px; } diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index d59f7b4a5cf..faabae44909 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -7,7 +7,7 @@ var user_session = require('web.session'); var time = require('web.time'); var utils = require('web.utils'); var Widget = require('web.Widget'); -var im_chat_common = require('mail.chat_common'); +var mail_chat_common = require('mail.chat_common'); var _t = core._t; var QWeb = core.qweb; @@ -19,11 +19,12 @@ var COOKIE_NAME = 'livechat_conversation'; The state of anonymous session is hold by the client and not the server. Override the method managing the state of normal conversation. */ -im_chat_common.Conversation.include({ - init: function(){ +mail_chat_common.Conversation.include({ + init: function(parent, session, options){ this._super.apply(this, arguments); this.shown = true; this.feedback = false; + this.options.default_username = session.anonymous_name || this.options.default_username; }, show: function(){ this._super.apply(this, arguments); @@ -33,7 +34,7 @@ im_chat_common.Conversation.include({ this._super.apply(this, arguments); this.shown = false; }, - session_update_state: function(state){ + session_fold: function(state){ // set manually the new state if(state === 'closed'){ this.destroy(); @@ -54,14 +55,14 @@ im_chat_common.Conversation.include({ this._super(state); utils.set_cookie(COOKIE_NAME, JSON.stringify(this.get('session')), 60*60); }, - click_close: function(event) { + on_click_close: function(event) { if(!this.feedback && (this.get('messages').length > 1)){ this.feedback = new Feedback(this); - this.$(".oe_im_chatview_content").empty(); - this.$(".oe_im_chatview_input").prop('disabled', true); - this.feedback.appendTo( this.$(".oe_im_chatview_content")); + this.$(".o_mail_chat_im_window_content").empty(); + this.$(".o_mail_chat_im_window_input").prop('disabled', true); + this.feedback.appendTo(this.$(".o_mail_chat_im_window_content")); // bind event to close conversation - this.feedback.on("feedback_sent", this, this.click_close); + this.feedback.on("feedback_sent", this, this.on_click_close); }else{ this._super.apply(this, arguments); utils.set_cookie(COOKIE_NAME, "", -1); @@ -72,7 +73,7 @@ im_chat_common.Conversation.include({ // To avoid exeption when the anonymous has close his // conversation and when operator send him a message. -im_chat_common.ConversationManager.include({ +var LivechatConversationManager = mail_chat_common.ConversationManager.extend({ message_receive: function(message) { try{ this._super(message); @@ -95,7 +96,7 @@ var LiveSupport = Widget.extend({ this.load_template(db, channel, options, rule); }, _get_template_list: function(){ - return ['/im_livechat/static/src/xml/im_livechat.xml', '/im_chat/static/src/xml/im_chat.xml']; + return ['/im_livechat/static/src/xml/im_livechat.xml', '/mail/static/src/xml/mail_chat_common.xml']; }, load_template: function(db, channel, options, rule){ var self = this; @@ -153,7 +154,7 @@ var ChatButton = Widget.extend({ start: function() { this.$().append(QWeb.render("im_livechat.chatButton", {widget: this})); // set up the manager - this.manager = new im_chat_common.ConversationManager(this, this.options); + this.manager = new LivechatConversationManager(this, this.options); this.manager.set("bottom_offset", $('.oe_chat_button').outerHeight()); if(this.session){ this.set_conversation(this.session); @@ -200,20 +201,20 @@ var ChatButton = Widget.extend({ }, send_welcome_message: function(){ var self = this; - if(this.session.users.length > 0){ - if (self.options.defaultMessage) { - setTimeout(function(){ - var operator = _.last(_.filter(self.session.users, function(user){return user.is_operator})); - self.conv.message_receive({ - id : 1, - type: "message", - message: self.options.defaultMessage, - create_date: time.datetime_to_str(new Date()), - from_id: [operator.id, operator.name], - to_id: [0, self.session.uuid] - }); - }, 1000); - } + if(this.session.operator_pid && self.options.defaultMessage) { + setTimeout(function(){ + self.conv.message_receive({ + id : 1, + message_type: "comment", + model: 'mail.channel', + body: self.options.defaultMessage, + date: time.datetime_to_str(new Date()), + author_id: self.session.operator_pid, + channel_ids: [self.session.id], + tracking_value_ids: [], + attachment_ids: [], + }); + }, 1000); } } }); @@ -231,20 +232,20 @@ var Feedback = Widget.extend({ start: function(){ this._super.apply(this.arguments); // bind events - this.$('.oe_livechat_rating_choices img').on('click', _.bind(this.click_smiley, this)); + this.$('.o_livechat_rating_choices img').on('click', _.bind(this.click_smiley, this)); this.$('#rating_submit').on('click', _.bind(this.click_send, this)); }, click_smiley: function(ev){ var self = this; this.rating = parseInt($(ev.currentTarget).data('value')); - this.$('.oe_livechat_rating_choices img').removeClass('selected'); - this.$('.oe_livechat_rating_choices img[data-value="'+this.rating+'"]').addClass('selected'); + this.$('.o_livechat_rating_choices img').removeClass('selected'); + this.$('.o_livechat_rating_choices img[data-value="'+this.rating+'"]').addClass('selected'); // only display textearea if bad smiley selected var close_conv = false; if(this.rating === 0){ - this.$('.oe_livechat_rating_reason').show(); + this.$('.o_livechat_rating_reason').show(); }else{ - this.$('.oe_livechat_rating_reason').hide(); + this.$('.o_livechat_rating_reason').hide(); close_conv = true; } this._send_feedback(close_conv).then(function(){ @@ -260,7 +261,7 @@ var Feedback = Widget.extend({ _send_feedback: function(close){ var self = this; var uuid = this.conversation.get('session').uuid; - return user_session.rpc('/rating/livechat/feedback', {uuid: uuid, rate: this.rating, reason : this.reason}).then(function(res) { + return user_session.rpc('/im_livechat/feedback', {uuid: uuid, rate: this.rating, reason : this.reason}).then(function(res) { if(close){ self.trigger("feedback_sent"); // will close the conversation self.conversation.message_send(_.str.sprintf(_t("I rated you with :rating_%d"), self.rating), "message"); diff --git a/addons/im_livechat/static/src/js/im_livechat_backend.js b/addons/im_livechat/static/src/js/im_livechat_backend.js new file mode 100644 index 00000000000..e3a03db1248 --- /dev/null +++ b/addons/im_livechat/static/src/js/im_livechat_backend.js @@ -0,0 +1,53 @@ +odoo.define('im_livechat.chat_backend', function (require) { +"use strict"; + +var mail_chat_backend = require('mail.chat_backend'); + + +/** + * Patch for the client action to integrate Livechat Mail Channel in a particular slot + */ +mail_chat_backend.ChatMailThread.include({ + init: function(parent, action){ + this._super.apply(this, arguments); + this.set('channel_livechat', []); + }, + start: function(){ + var self = this; + this.on("change:channel_livechat", this, function(){ + self.channel_render('channel_livechat'); + }); + return this._super.apply(this, arguments).then(function(){ + self.$el.on('click', '.o_mail_chat_channel_unpin', _.bind(self.on_click_channel_unpin, self)); + }); + }, + on_click_channel_unpin: function(event){ + var self = this; + var channel_id = this.$(event.currentTarget).data('channel-id'); + var channel = this.channels[channel_id]; + return this.channel_pin(channel.uuid, false).then(function(){ + self.channel_remove(channel_id); + // if unpin current channel, switch to inbox + if(self.get('current_channel_id') === channel_id){ + self.set('current_channel_id', 'channel_inbox'); + } + }); + }, + channel_change: function(){ + // update the default username + var current_channel = this.channels[this.get('current_channel_id')]; + if(current_channel){ + this.options.default_username = current_channel.anonymous_name || this.options.default_username + } + return this._super.apply(this, arguments); + }, + // utils function + get_channel_slot: function(channel){ + if(channel.channel_type === 'livechat'){ + return 'channel_livechat'; + } + return this._super.apply(this, arguments); + }, +}); + +}); diff --git a/addons/im_livechat/static/src/xml/im_livechat.xml b/addons/im_livechat/static/src/xml/im_livechat.xml index fb0b9ca3072..fc004cb4dcf 100644 --- a/addons/im_livechat/static/src/xml/im_livechat.xml +++ b/addons/im_livechat/static/src/xml/im_livechat.xml @@ -7,18 +7,18 @@ </t> <t t-name="im_livechat.feedback"> - <div class="oe_livechat_rating"> - <div class="oe_im_feedback_text"> + <div class="o_livechat_rating"> + <div class="o_livechat_rating_feedback_text"> Did we correctly answer your question ? </div> - <div class="oe_livechat_rating_choices"> + <div class="o_livechat_rating_choices"> <img t-att-src="widget.server_origin + '/rating/static/src/img/rating_10.png'" alt="Good" data-value="10"/> <img t-att-src="widget.server_origin + '/rating/static/src/img/rating_5.png'" alt="OK" data-value="5"/> <img t-att-src="widget.server_origin + '/rating/static/src/img/rating_0.png'" alt="Bad" data-value="0" /> </div> - <div class="oe_livechat_rating_reason"> + <div class="o_livechat_rating_reason"> <textarea id="reason" placeholder="Explain your note"></textarea> - <div class="oe_livechat_rating_reason_button"> + <div class="o_livechat_rating_reason_button"> <input type="button" id="rating_submit" value="Send" /> </div> </div> diff --git a/addons/im_livechat/static/src/xml/im_livechat_backend.xml b/addons/im_livechat/static/src/xml/im_livechat_backend.xml new file mode 100644 index 00000000000..a48027b6047 --- /dev/null +++ b/addons/im_livechat/static/src/xml/im_livechat_backend.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<template> + + <t t-extend="mail.chat.ChatMailThread.channels"> + <t t-jquery="li > a" t-operation="append"> + <t t-if="channel.channel_type === 'livechat'"> + <span class="fa fa-times pull-right o_mail_chat_channel_unpin" t-att-title="_t('Untoggle')" t-att-data-channel-id="channel.id"/> + </t> + </t> + </t> + + <t t-extend="mail.chat.ChatMailThread"> + <t t-jquery=".o_mail_chat_sidebar" t-operation="append"> + <!-- Livechat list --> + <h4 class="o_mail_chat_sidebar_title"><t t-esc="_t('Livechat')"/></h4> + <t t-call="mail.chat.ChatMailThread.channels"> + <t t-set="channel_slot" t-value="'channel_livechat'"/> + </t> + </t> + </t> + +</template> |
