diff --git a/mail_archives/__openerp__.py b/mail_archives/__openerp__.py index 132b4c7..8dd83b3 100644 --- a/mail_archives/__openerp__.py +++ b/mail_archives/__openerp__.py @@ -23,5 +23,5 @@ "qweb": [ "static/src/xml/menu.xml", ], - 'installable': False, + 'installable': True, } diff --git a/mail_archives/static/src/js/archives.js b/mail_archives/static/src/js/archives.js index 8134ac2..bc7f7ad 100644 --- a/mail_archives/static/src/js/archives.js +++ b/mail_archives/static/src/js/archives.js @@ -1,14 +1,13 @@ odoo.define('mail_archives.archives', function (require) { "use strict"; -var base_obj = require('mail_base.base'); +var chat_manager = require('mail_base.base').chat_manager; //------------------------------------------------------------------------------- var bus = require('bus.bus').bus; var config = require('web.config'); var core = require('web.core'); var data = require('web.data'); -var Model = require('web.Model'); var session = require('web.session'); var time = require('web.time'); var web_client = require('web.web_client'); @@ -33,53 +32,50 @@ ChatAction.include({ }); // Inherit class and override methods -base_obj.MailTools.include({ - get_properties: function(msg){ - var properties = this._super.apply(this, arguments); - properties.is_archive = this.property_descr("channel_archive", msg, this); - return properties; - }, - set_channel_flags: function(data, msg){ - this._super.apply(this, arguments); - // Get recipients ids - var recipients_ids = []; - for (var i = 0; i < (data.partner_ids || []).length; i++){ - recipients_ids.push(data.partner_ids[i][0]); - } - - // If author or recipient - if (data.author_id[0] === session.partner_id || recipients_ids.indexOf(session.partner_id) != -1) { - msg.is_archive = true; - } - - return msg; - }, +var chat_manager_super = _.clone(chat_manager); - get_channel_array: function(msg){ - var arr = this._super.apply(this, arguments); - return arr.concat('channel_archive'); - }, +chat_manager.get_properties = function (msg) { + var properties = chat_manager_super.get_properties.apply(this, arguments); + properties.is_archive = this.property_descr("channel_archive", msg, this); + return properties; +}; - get_domain: function(channel){ - return (channel.id === "channel_archive") ? [ - '|', ['partner_ids', 'in', [openerp.session.partner_id]], - ['author_id.user_ids', 'in', [openerp.session.uid]] - ] : this._super.apply(this, arguments); +chat_manager.set_channel_flags = function (data, msg) { + chat_manager_super.set_channel_flags.apply(this, arguments); + // Get recipients ids + var recipients_ids = []; + for (var i = 0; i < (data.partner_ids || []).length; i++){ + recipients_ids.push(data.partner_ids[i][0]); } -}); -base_obj.chat_manager.is_ready.then(function(){ - // Add archive channel - base_obj.chat_manager.mail_tools.add_channel({ - id: "channel_archive", - name: _lt("Archive"), - type: "static" - }); + // If author or recipient + if (data.author_id[0] === session.partner_id || recipients_ids.indexOf(session.partner_id) != -1) { + msg.is_archive = true; + } - return $.when(); - }); + return msg; +}; + +chat_manager.get_channel_array = function (msg) { + var arr = chat_manager_super.get_channel_array.apply(this, arguments); + return arr.concat('channel_archive'); +}; + +chat_manager.get_domain = function(channel){ + return (channel.id === "channel_archive") ? [ + '|', ['partner_ids', 'in', [openerp.session.partner_id]], + ['author_id.user_ids', 'in', [openerp.session.uid]] + ] : chat_manager_super.get_domain.apply(this, arguments); +} + + +chat_manager.add_channel({ + id: "channel_archive", + name: _lt("Archive"), + type: "static" +}); -return base_obj.chat_manager; +return chat_manager; }); diff --git a/mail_archives/static/src/xml/menu.xml b/mail_archives/static/src/xml/menu.xml index 30e39e2..f446be3 100644 --- a/mail_archives/static/src/xml/menu.xml +++ b/mail_archives/static/src/xml/menu.xml @@ -3,7 +3,7 @@ -
+
Archive
diff --git a/mail_base/static/lib/base.js b/mail_base/static/lib/base.js index a32d63e..f5a7ba4 100644 --- a/mail_base/static/lib/base.js +++ b/mail_base/static/lib/base.js @@ -47,6 +47,79 @@ bus.on("window_focus", null, function() { web_client.set_title_part("_chat"); }); +var ChatAction = core.action_registry.get('mail.chat.instant_messaging'); +ChatAction.include({ + init: function(parent, action, options) { + this._super.apply(this, arguments); + this.channels_show_send_button = ['channel_inbox']; + this.channels_display_subject = []; + }, + start: function() { + var result = this._super.apply(this, arguments); + + var search_defaults = {}; + var context = this.action ? this.action.context : []; + _.each(context, function (value, key) { + var match = /^search_default_(.*)$/.exec(key); + if (match) { + search_defaults[match[1]] = value; + } + }); + this.searchview.defaults = search_defaults; + + var self = this; + return $.when(result).done(function() { + $('.oe_leftbar').toggle(false); + self.searchview.do_search(); + }); + }, + destroy: function() { + var result = this._super.apply(this, arguments); + $('.oe_leftbar .oe_secondary_menu').each(function(){ + if ($(this).css('display') == 'block'){ + if ($(this).children().length > 0) { + $('.oe_leftbar').toggle(true); + } + return false; + } + }); + return result; + }, + set_channel: function(channel){ + var result = this._super.apply(this, arguments); + var self = this; + return $.when(result).done(function() { + self.$buttons + .find('.o_mail_chat_button_new_message') + .toggle(self.channels_show_send_button.indexOf(channel.id) != -1); + }); + }, + get_thread_rendering_options: function (messages) { + var options = this._super.apply(this, arguments); + options.display_subject = options.display_subject || this.channels_display_subject.indexOf(this.channel.id) != -1; + return options; + }, + update_message_on_current_channel: function(current_channel_id, message){ + var starred = current_channel_id === "channel_starred" && !message.is_starred; + var inbox = current_channel_id === "channel_inbox" && !message.is_needaction; + return starred || inbox; + }, + on_update_message: function (message) { + var self = this; + var current_channel_id = this.channel.id; + if (this.update_message_on_current_channel(current_channel_id, message)) { + chat_manager.get_messages({channel_id: this.channel.id, domain: this.domain}).then(function (messages) { + var options = self.get_thread_rendering_options(messages); + self.thread.remove_message_and_render(message.id, messages, options).then(function () { + self.update_button_status(messages.length === 0); + }); + }); + } else if (_.contains(message.channel_ids, current_channel_id)) { + this.fetch_and_render_thread(); + } + } +}); + chat_manager.notify_incoming_message = function (msg, options) { if (bus.is_odoo_focused() && options.is_displayed) { // no need to notify diff --git a/mailgun/__openerp__.py b/mailgun/__openerp__.py index 442fb4a..b1e1efb 100644 --- a/mailgun/__openerp__.py +++ b/mailgun/__openerp__.py @@ -11,4 +11,5 @@ 'data': [ 'data/cron.xml', ], + 'installable': False }