Browse Source

⬆️1️⃣2️⃣ mail_archives

pull/188/head
KolushovAlexandr 6 years ago
parent
commit
c8ef80cd8c
No known key found for this signature in database GPG Key ID: C3E04B793421FD2
  1. 8
      mail_archives/README.rst
  2. 6
      mail_archives/__manifest__.py
  3. 4
      mail_archives/static/description/index.html
  4. 98
      mail_archives/static/src/js/archives.js
  5. 15
      mail_archives/static/src/xml/menu.xml
  6. 19
      mail_archives/tests/test_js.py

8
mail_archives/README.rst

@ -19,7 +19,7 @@ Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__
To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store <https://apps.odoo.com/apps/modules/11.0/mail_archives/>`__.
To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store <https://apps.odoo.com/apps/modules/12.0/mail_archives/>`__.
Thank you for understanding!
@ -28,12 +28,12 @@ Maintainers
Further information
===================
Demo: http://runbot.it-projects.info/demo/mail_addons/11.0
Demo: http://runbot.it-projects.info/demo/mail_addons/12.0
HTML Description: https://apps.odoo.com/apps/modules/11.0/mail_archives/
HTML Description: https://apps.odoo.com/apps/modules/12.0/mail_archives/
Usage instructions: `<doc/index.rst>`_
Changelog: `<doc/changelog.rst>`_
Tested on Odoo 11.0 ecbf7aa4714479229658d14cce28fa00376ed390
Tested on Odoo 12.0 c423e5fe047a66517a60b68874e18dc5c3697787

6
mail_archives/__manifest__.py

@ -3,7 +3,7 @@
"summary": """Adds menu to find old messages""",
"category": "Discuss",
"images": ['images/1.jpg'],
"version": "11.0.1.0.0",
"version": "12.0.1.0.0",
"author": "IT-Projects LLC, Pavel Romanchenko",
"support": "apps@it-projects.info",
@ -13,7 +13,7 @@
'currency': 'EUR',
"depends": [
"mail_base",
"mail",
],
"data": [
@ -22,5 +22,5 @@
"qweb": [
"static/src/xml/menu.xml",
],
'installable': False,
'installable': True,
}

4
mail_archives/static/description/index.html

@ -59,7 +59,7 @@ This menu shows archive messages, i.e. ones you sent or received.
-o-transform: rotate(6deg);
-moz-transform: rotate(6deg);
-ms-transform: rotate(6deg);">
Tested on Odoo<br/>11.0 community
Tested on Odoo<br/>12.0 community
</div>
<div style="margin-top: 15px;
position: relative;
@ -76,7 +76,7 @@ This menu shows archive messages, i.e. ones you sent or received.
-o-transform: rotate(-7deg);
-moz-transform: rotate(-7deg);
-ms-transform: rotate(-7deg);">
Tested on Odoo<br/>11.0 enterprise
Tested on Odoo<br/>12.0 enterprise
</div>
</div>
</div>

98
mail_archives/static/src/js/archives.js

@ -3,74 +3,48 @@ odoo.define('mail_archives.archives', function (require) {
var core = require('web.core');
var session = require('web.session');
var chat_manager = require('mail_base.base').chat_manager;
var _lt = core._lt;
var ChatAction = core.action_registry.get('mail.chat.instant_messaging');
ChatAction.include({
init: function (parent, action, options) {
this._super.apply(this, arguments);
var channel_name = 'channel_archive';
// Add channel Archive for enable "display_subject" option
this.channels_display_subject.push(channel_name);
var Manager = require('mail.Manager');
var Mailbox = require('mail.model.Mailbox');
var _t = core._t;
Manager.include({
_updateMailboxesFromServer: function (data) {
var self = this;
this._super(data);
if (!_.find(this.getThreads(), function(th){
return th.getID() === 'mailbox_channel_archive';
})) {
this._addMailbox({
id: 'channel_archive',
name: _t("Archive"),
mailboxCounter: data.needaction_inbox_counter || 0,
});
}
},
update_message_on_current_channel: function (current_channel_id, message){
var result = this._super.apply(this, arguments);
var archive = current_channel_id === "channel_archive" && !message.is_archive;
return archive || result;
}
_makeMessage: function (data) {
var message = this._super(data);
message._addThread('mailbox_channel_archive');
return message;
},
});
// Inherit class and override methods
var chat_manager_super = _.clone(chat_manager);
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;
};
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]);
}
// If author or recipient
if (data.author_id[0] === session.partner_id || recipients_ids.indexOf(session.partner_id) !== -1) {
msg.is_archive = true;
Mailbox.include({
_getThreadDomain: function () {
if (this._id === 'mailbox_channel_archive') {
return ['|',
['partner_ids', 'in', [session.partner_id]],
['author_id', 'in', [session.partner_id]]
];
}
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', [session.partner_id]],
['author_id', 'in', [session.partner_id]]]
: chat_manager_super.get_domain.apply(this, arguments);
};
chat_manager.is_ready.then(function () {
chat_manager.add_channel({
id: "channel_archive",
name: _lt("Archive"),
type: "static"
});
return this._super();
},
});
return chat_manager;
return {
'Manager': Manager,
'Mailbox': Mailbox,
};
});

15
mail_archives/static/src/xml/menu.xml

@ -1,17 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!--Inherit Sidebar and add Archive menu item after Starred -->
<t t-extend="mail.chat.Sidebar">
<t t-jquery="div[data-channel-id=channel_starred]" t-operation="after">
<div t-attf-class="o_mail_chat_channel_item o_mail_chat_title_main #{(active_channel_id == 'channel_archive') ? 'o_active': ''}" data-channel-id="channel_archive">
<t t-extend="mail.discuss.Sidebar">
<t t-jquery="div[data-thread-id=mailbox_starred]" t-operation="after">
<div t-attf-class="o_mail_discuss_title_main o_mail_discuss_item #{(activeThreadID == 'channel_archive') ? 'o_active': ''}"
data-thread-id="mailbox_channel_archive">
<span class="o_channel_name mail_archives"> <i class="fa fa-archive"/> Archive </span>
<t t-set="counter" t-value="starredCounter"/>
<t t-call="mail.discuss.SidebarCounter"/>
</div>
</t>
</t>
<!--Add message about empty archive page-->
<t t-extend="mail.EmptyChannel">
<t t-jquery="t:last-child" t-operation="after">
<t t-if="options.channel_id==='channel_archive'">
<t t-extend="mail.widget.Thread.Empty">
<t t-jquery="t:last" t-operation="after">
<t t-if="thread.getID() === 'mailbox_channel_archive'">
<div class="o_thread_title">Archive is empty</div>
</t>
</t>

19
mail_archives/tests/test_js.py

@ -1,17 +1,24 @@
import odoo.tests
from werkzeug import url_encode
@odoo.tests.common.at_install(False)
@odoo.tests.common.at_install(True)
@odoo.tests.common.post_install(True)
class TestUi(odoo.tests.HttpCase):
def test_01_mail_archives(self):
# needed because tests are run before the module is marked as
# installed. In js web will only load qweb coming from modules
# that are returned by the backend in module_boot. Without
# this you end up with js, css but no qweb.
self.env['ir.module.module'].search([('name', '=', 'mail_archives')], limit=1).state = 'installed'
# wait till page loaded and then click and wait again
code = """
setTimeout(function () {
$(".mail_archives").click();
setTimeout(function () {console.log('ok');}, 3000);
}, 1000);
console.log($(".mail_archives").length && 'ok' || 'error');
}, 3000);
"""
link = '/web#action=%s' % self.ref('mail.mail_channel_action_client_chat')
self.phantom_js(link, code, "odoo.__DEBUG__.services['mail_archives.archives']", login="admin")
link = '/web#%s' % url_encode({'action': 'mail.action_discuss'})
self.phantom_js(link, code, "odoo.__DEBUG__.services['web_tour.tour'].tours.mail_tour.ready", login="admin")
Loading…
Cancel
Save