Browse Source

[FIX] archives.js, base.js - corrections related to inheritance

[FIX] README.rst - more precisely worded description and added sha value
[FIX] models.py, res_partner_mails_count.xml, views.xml - removed unused code
[FIX] __openerp__.py - styling
pull/6/head
x620 9 years ago
parent
commit
37196765fb
  1. 4
      mail_archives/README.rst
  2. 2
      mail_archives/__openerp__.py
  3. 12
      mail_archives/models/models.py
  4. 15
      mail_archives/static/src/js/archives.js
  5. 14
      mail_archives/static/src/xml/menu.xml
  6. 55
      mail_archives/views/views.xml
  7. 5
      mail_base/README.rst
  8. 8
      mail_base/__openerp__.py
  9. 137
      mail_base/static/src/js/base.js
  10. 2
      res_partner_mails_count/README.rst
  11. 14
      res_partner_mails_count/views/res_partner_mails_count.xml

4
mail_archives/README.rst

@ -5,11 +5,11 @@ Adds Archive menu, which shows all messages
Usage Usage
----- -----
Click by archive menu item and receive all messages
Click Messaing/Arhive menu -- all messages are displayed
Further information Further information
------------------- -------------------
HTML Description: https://apps.odoo.com/apps/modules/9.0/mail_archives/ HTML Description: https://apps.odoo.com/apps/modules/9.0/mail_archives/
Tested on Odoo 9.0
Tested on Odoo 9.0 b9f206953e3f877adf18643f154d1262842564ee

2
mail_archives/__openerp__.py

@ -7,7 +7,7 @@
"version": "1.0.0", "version": "1.0.0",
"author": "IT-Projects LLC, Pavel Romanchenko", "author": "IT-Projects LLC, Pavel Romanchenko",
"website": "http://www.it-projects.info",
"website": "https://www.it-projects.info",
"license": "LGPL-3", "license": "LGPL-3",
"depends": [ "depends": [

12
mail_archives/models/models.py

@ -1,15 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import models, fields, api from openerp import models, fields, api
# class mail_arhives(models.Model):
# _name = 'mail_arhives.mail_arhives'
# name = fields.Char()
# value = fields.Integer()
# value2 = fields.Float(compute="_value_pc", store=True)
# description = fields.Text()
#
# @api.depends('value')
# def _value_pc(self):
# self.value2 = float(self.value) / 100

15
mail_archives/static/src/js/archives.js

@ -37,24 +37,21 @@ base_obj.MailTools.include({
get_domain: function(channel){ get_domain: function(channel){
return (channel.id === "channel_archive") ? [] : this._super.apply(this, arguments); return (channel.id === "channel_archive") ? [] : this._super.apply(this, arguments);
},
}
});
start: function(){
// Change chat_manager with override methods
base_obj.chat_manager.is_ready.then(function(){
// Add archive channel // Add archive channel
this.add_channel({
base_obj.chat_manager.mail_tools.add_channel({
id: "channel_archive", id: "channel_archive",
name: _t("Archive"), name: _t("Archive"),
type: "static" type: "static"
}); });
return $.when(this._super.apply(this, arguments));
}
return $.when();
}); });
// Change chat_manager with override methods
var cls = new base_obj.MailTools(base_obj.chat_manager);
base_obj.chat_manager.is_ready = cls.start();
return base_obj.chat_manager; return base_obj.chat_manager;
}); });

14
mail_archives/static/src/xml/menu.xml

@ -9,17 +9,11 @@
</t> </t>
</t> </t>
<!--Add message about empty archive page--> <!--Add message about empty archive page-->
<div t-name="mail.EmptyChannel" class="o_mail_no_content">
<t t-if="options.channel_id==='channel_inbox'">
<div class="o_thread_title">Congratulations, your inbox is empty</div>
<div>New messages appear here.</div>
</t>
<t t-if="options.channel_id==='channel_starred'">
<div class="o_thread_title">No starred message</div>
<div> You can mark any message as 'starred', and it shows up in this channel.</div>
</t>
<t t-extend="mail.EmptyChannel">
<t t-jquery="t:last-child" t-operation="after">
<t t-if="options.channel_id==='channel_archive'"> <t t-if="options.channel_id==='channel_archive'">
<div class="o_thread_title">Archive is empty</div> <div class="o_thread_title">Archive is empty</div>
</t> </t>
</div>
</t>
</t>
</template> </template>

55
mail_archives/views/views.xml

@ -1,59 +1,4 @@
<openerp> <openerp>
<data> <data>
<!-- explicit list view definition -->
<!--
<record model="ir.ui.view" id="mail_arhives.list">
<field name="name">mail_arhives list</field>
<field name="model">mail_arhives.mail_arhives</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="value"/>
<field name="value2"/>
</tree>
</field>
</record>
-->
<!-- actions opening views on models -->
<!--
<record model="ir.actions.act_window" id="mail_arhives.action_window">
<field name="name">mail_arhives window</field>
<field name="res_model">mail_arhives.mail_arhives</field>
<field name="view_mode">tree,form</field>
</record>
-->
<!-- server action to the one above -->
<!--
<record model="ir.actions.server" id="mail_arhives.action_server">
<field name="name">mail_arhives server</field>
<field name="model_id" ref="model_mail_arhives_mail_arhives"/>
<field name="code">
action = {
"type": "ir.actions.act_window",
"view_mode": "tree,form",
"res_model": self._name,
}
</field>
</record>
-->
<!-- Top menu item -->
<!--
<menuitem name="mail_arhives" id="mail_arhives.menu_root"/>
-->
<!-- menu categories -->
<!--
<menuitem name="Menu 1" id="mail_arhives.menu_1" parent="mail_arhives.menu_root"/>
<menuitem name="Menu 2" id="mail_arhives.menu_2" parent="mail_arhives.menu_root"/>
-->
<!-- actions -->
<!--
<menuitem name="List" id="mail_arhives.menu_1_list" parent="mail_arhives.menu_1"
action="mail_arhives.action_window"/>
<menuitem name="Server to list" id="mail_arhives" parent="mail_arhives.menu_2"
action="mail_arhives.action_server"/>
-->
</data> </data>
</openerp> </openerp>

5
mail_base/README.rst

@ -1,11 +1,12 @@
Mail Base Mail Base
========= =========
Module contain common code for other mail modules
Modules doesn't introduce new features, but make built-in mail js features extendable.
Usage Usage
----- -----
To use this module you need either install module that depends on it or create new module.
Further information Further information
------------------- -------------------
Due to odoo restrictions, module makes mail initialization again. That is browser loads emoji and other chat data twice. This is the only way to make Mail feature extendable.

8
mail_base/__openerp__.py

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
{ {
"name": "mail_base",
"summary": """Contain common code for other mail modules""",
"category": "Uncategorized",
"name": "Mail Base",
"summary": """Makes Mail extendable""",
"category": "Discuss",
"images": [], "images": [],
"version": "1.0.0", "version": "1.0.0",
"author": "IT-Projects LLC, Pavel Romanchenko", "author": "IT-Projects LLC, Pavel Romanchenko",
"website": "http://www.it-projects.info",
"website": "https://www.it-projects.info",
"license": "LGPL-3", "license": "LGPL-3",
"depends": [ "depends": [

137
mail_base/static/src/js/base.js

@ -60,7 +60,6 @@ var channel_seen = _.throttle(function (channel) {
return ChannelModel.call('channel_seen', [[channel.id]], {}, {shadow: true}); return ChannelModel.call('channel_seen', [[channel.id]], {}, {shadow: true});
}, 3000); }, 3000);
var MailTools = core.Class.extend({ var MailTools = core.Class.extend({
send_native_notification: function (title, content) { send_native_notification: function (title, content) {
@ -319,7 +318,7 @@ var MailTools = core.Class.extend({
chat_manager.bus.trigger("channel_toggle_fold", channel); chat_manager.bus.trigger("channel_toggle_fold", channel);
} }
} else { } else {
channel = chat_manager.make_channel(data, options);
channel = chat_manager.mail_tools.make_channel(data, options);
channels.push(channel); channels.push(channel);
channels = _.sortBy(channels, function (channel) { return channel.name.toLowerCase(); }); channels = _.sortBy(channels, function (channel) { return channel.name.toLowerCase(); });
if (!options.silent) { if (!options.silent) {
@ -696,49 +695,6 @@ var MailTools = core.Class.extend({
dm.status = data.im_status; dm.status = data.im_status;
chat_manager.bus.trigger('update_dm_presence', dm); chat_manager.bus.trigger('update_dm_presence', dm);
} }
},
start: function(){
this.add_channel({
id: "channel_inbox",
name: _t("Inbox"),
type: "static"
}, { display_needactions: true });
this.add_channel({
id: "channel_starred",
name: _t("Starred"),
type: "static"
});
var load_channels = session.rpc('/mail/client_action').then(function (result) {
_.each(result.channel_slots, function (channels) {
_.each(channels, cls.add_channel);
});
needaction_counter = result.needaction_inbox_counter;
mention_partner_suggestions = result.mention_partner_suggestions;
});
var load_emojis = session.rpc("/mail/chat_init").then(function (result) {
emojis = result.emoji;
_.each(emojis, function(emoji) {
emoji_substitutions[_.escape(emoji.source)] = emoji.substitution;
});
});
var ir_model = new Model("ir.model.data");
var load_menu_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_menu_root_chat"], {}, {shadow: true});
var load_action_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_action_client_chat"], {}, {shadow: true});
bus.on('notification', null, cls.on_notification);
return $.when(load_menu_id, load_action_id, load_channels, load_emojis).then(function (menu_id, action_id) {
discuss_ids = {
menu_id: menu_id,
action_id: action_id
};
bus.start_polling();
});
} }
}); });
@ -746,9 +702,14 @@ var cls = new MailTools();
// Public interface // Public interface
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// these two functions are exposed for extensibility purposes and shouldn't be called by other modules
chat_manager.make_message = cls.make_message;
chat_manager.make_channel = cls.make_channel;
chat_manager.mail_tools = cls;
// we add this function this way in order to make them extendable via MailTools.include({...})
chat_manager.make_message = function(){
chat_manager.mail_tools.make_message.apply(chat_manager.mail_tools, arguments)
};
chat_manager.make_channel = function(){
chat_manager.mail_tools.make_channel.apply(chat_manager.mail_tools, arguments)
};
chat_manager.post_message = function (data, options) { chat_manager.post_message = function (data, options) {
options = options || {}; options = options || {};
var msg = { var msg = {
@ -782,7 +743,7 @@ chat_manager.post_message = function (data, options) {
return MessageModel.call('message_format', [msg_id]).then(function (msgs) { return MessageModel.call('message_format', [msg_id]).then(function (msgs) {
msgs[0].model = options.model; msgs[0].model = options.model;
msgs[0].res_id = options.res_id; msgs[0].res_id = options.res_id;
cls.add_message(msgs[0]);
chat_manager.mail_tools.add_message(msgs[0]);
}); });
}); });
} }
@ -796,21 +757,21 @@ chat_manager.get_messages = function (options) {
if ('channel_id' in options && options.load_more) { if ('channel_id' in options && options.load_more) {
// get channel messages, force load_more // get channel messages, force load_more
channel = this.get_channel(options.channel_id); channel = this.get_channel(options.channel_id);
return cls.fetch_from_channel(channel, {domain: options.domain || {}, load_more: true});
return chat_manager.mail_tools.fetch_from_channel(channel, {domain: options.domain || {}, load_more: true});
} }
if ('channel_id' in options) { if ('channel_id' in options) {
// channel message, check in cache first // channel message, check in cache first
channel = this.get_channel(options.channel_id); channel = this.get_channel(options.channel_id);
var channel_cache = cls.get_channel_cache(channel, options.domain);
var channel_cache = chat_manager.mail_tools.get_channel_cache(channel, options.domain);
if (channel_cache.loaded) { if (channel_cache.loaded) {
return $.when(channel_cache.messages); return $.when(channel_cache.messages);
} else { } else {
return cls.fetch_from_channel(channel, {domain: options.domain});
return chat_manager.mail_tools.fetch_from_channel(channel, {domain: options.domain});
} }
} }
if ('ids' in options) { if ('ids' in options) {
// get messages from their ids (chatter is the main use case) // get messages from their ids (chatter is the main use case)
return cls.fetch_document_messages(options.ids, options).then(function(result) {
return chat_manager.mail_tools.fetch_document_messages(options.ids, options).then(function(result) {
chat_manager.mark_as_read(options.ids); chat_manager.mark_as_read(options.ids);
return result; return result;
}); });
@ -820,7 +781,7 @@ chat_manager.get_messages = function (options) {
// case is when using the full composer) // case is when using the full composer)
var domain = [['model', '=', options.model], ['res_id', '=', options.res_id]]; var domain = [['model', '=', options.model], ['res_id', '=', options.res_id]];
MessageModel.call('message_fetch', [domain], {limit: 30}).then(function (msgs) { MessageModel.call('message_fetch', [domain], {limit: 30}).then(function (msgs) {
return _.map(msgs, cls.add_message);
return _.map(msgs, chat_manager.mail_tools.add_message);
}); });
} }
}; };
@ -855,8 +816,8 @@ chat_manager.undo_mark_as_read = function (message_ids, channel) {
}; };
chat_manager.mark_channel_as_seen = function (channel) { chat_manager.mark_channel_as_seen = function (channel) {
if (channel.unread_counter > 0 && channel.type !== 'static') { if (channel.unread_counter > 0 && channel.type !== 'static') {
cls.update_channel_unread_counter(channel, 0);
cls.channel_seen(channel);
chat_manager.mail_tools.update_channel_unread_counter(channel, 0);
chat_manager.mail_tools.channel_seen(channel);
} }
}; };
chat_manager.get_channels = function () { chat_manager.get_channels = function () {
@ -869,7 +830,7 @@ chat_manager.get_dm_from_partner_id = function (partner_id) {
return _.findWhere(channels, {direct_partner_id: partner_id}); return _.findWhere(channels, {direct_partner_id: partner_id});
}; };
chat_manager.all_history_loaded = function (channel, domain) { chat_manager.all_history_loaded = function (channel, domain) {
return cls.get_channel_cache(channel, domain).all_history_loaded;
return chat_manager.mail_tools.get_channel_cache(channel, domain).all_history_loaded;
}; };
chat_manager.get_mention_partner_suggestions = function (channel) { chat_manager.get_mention_partner_suggestions = function (channel) {
if (!channel) { if (!channel) {
@ -935,7 +896,7 @@ chat_manager.create_channel = function (name, type) {
return ChannelModel return ChannelModel
.call(method, args) .call(method, args)
.then(cls.add_channel);
.then(chat_manager.mail_tools.add_channel);
}; };
chat_manager.join_channel = function (channel_id, options) { chat_manager.join_channel = function (channel_id, options) {
if (channel_id in channel_defs) { if (channel_id in channel_defs) {
@ -950,13 +911,13 @@ chat_manager.join_channel = function (channel_id, options) {
channel_defs[channel_id] = ChannelModel channel_defs[channel_id] = ChannelModel
.call('channel_join_and_get_info', [[channel_id]]) .call('channel_join_and_get_info', [[channel_id]])
.then(function (result) { .then(function (result) {
return cls.add_channel(result, options);
return chat_manager.mail_tools.add_channel(result, options);
}); });
} }
return channel_defs[channel_id]; return channel_defs[channel_id];
}; };
chat_manager.open_and_detach_dm = function (partner_id) { chat_manager.open_and_detach_dm = function (partner_id) {
return ChannelModel.call('channel_get_and_minimize', [[partner_id]]).then(cls.add_channel);
return ChannelModel.call('channel_get_and_minimize', [[partner_id]]).then(chat_manager.mail_tools.add_channel);
}; };
chat_manager.open_channel = function (channel) { chat_manager.open_channel = function (channel) {
chat_manager.bus.trigger(client_action_open ? 'open_channel' : 'detach_channel', channel); chat_manager.bus.trigger(client_action_open ? 'open_channel' : 'detach_channel', channel);
@ -969,7 +930,7 @@ chat_manager.unsubscribe = function (channel) {
def = ChannelModel.call('channel_pin', [channel.uuid, false]); def = ChannelModel.call('channel_pin', [channel.uuid, false]);
} }
return def.then(function () { return def.then(function () {
cls.remove_channel(channel);
chat_manager.mail_tools.remove_channel(channel);
}); });
}; };
chat_manager.close_chat_session = function (channel_id) { chat_manager.close_chat_session = function (channel_id) {
@ -1045,7 +1006,7 @@ chat_manager.get_channels_preview = function (channels) {
_.each(missing_channels, function (channel_preview) { _.each(missing_channels, function (channel_preview) {
var channel = _.findWhere(channels, {id: channel_preview.id}); var channel = _.findWhere(channels, {id: channel_preview.id});
if (channel) { if (channel) {
channel_preview.last_message = cls.add_message(channel.last_message);
channel_preview.last_message = chat_manager.mail_tools.add_message(channel.last_message);
} }
}); });
return _.filter(channels_preview, function (channel) { return _.filter(channels_preview, function (channel) {
@ -1054,7 +1015,7 @@ chat_manager.get_channels_preview = function (channels) {
}); });
}; };
chat_manager.get_message_body_preview = function (message_body) { chat_manager.get_message_body_preview = function (message_body) {
return cls.parse_and_transform(message_body, inline);
return chat_manager.mail_tools.parse_and_transform(message_body, inline);
}; };
chat_manager.search_partner = function (search_val, limit) { chat_manager.search_partner = function (search_val, limit) {
return PartnerModel.call('im_search', [search_val, limit || 20], {}, {shadow: true}).then(function(result) { return PartnerModel.call('im_search', [search_val, limit || 20], {}, {shadow: true}).then(function(result) {
@ -1069,12 +1030,58 @@ chat_manager.search_partner = function (search_val, limit) {
return values; return values;
}); });
}; };
chat_manager.send_native_notification = cls.send_native_notification;
chat_manager.send_native_notification = function(){
chat_manager.mail_tools.send_native_notification.apply(chat_manager.mail_tools, arguments)
};
chat_manager.bus.on('client_action_open', null, function (open) { chat_manager.bus.on('client_action_open', null, function (open) {
client_action_open = open; client_action_open = open;
}); });
chat_manager.is_ready = cls.start();
// In order to extend init use chat_manager.is_ready Derrered object. See example in mail_arhive module
function init(){
chat_manager.mail_tools.add_channel({
id: "channel_inbox",
name: _t("Inbox"),
type: "static"
}, { display_needactions: true });
chat_manager.mail_tools.add_channel({
id: "channel_starred",
name: _t("Starred"),
type: "static"
});
var load_channels = session.rpc('/mail/client_action').then(function (result) {
_.each(result.channel_slots, function (channels) {
_.each(channels, chat_manager.mail_tools.add_channel);
});
needaction_counter = result.needaction_inbox_counter;
mention_partner_suggestions = result.mention_partner_suggestions;
});
var load_emojis = session.rpc("/mail/chat_init").then(function (result) {
emojis = result.emoji;
_.each(emojis, function(emoji) {
emoji_substitutions[_.escape(emoji.source)] = emoji.substitution;
});
});
var ir_model = new Model("ir.model.data");
var load_menu_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_menu_root_chat"], {}, {shadow: true});
var load_action_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_action_client_chat"], {}, {shadow: true});
bus.on('notification', null, chat_manager.mail_tools.on_notification);
return $.when(load_menu_id, load_action_id, load_channels, load_emojis).then(function (menu_id, action_id) {
discuss_ids = {
menu_id: menu_id,
action_id: action_id
};
bus.start_polling();
});
}
chat_manager.is_ready = init();
return { return {
chat_manager: chat_manager, chat_manager: chat_manager,
MailTools: MailTools MailTools: MailTools

2
res_partner_mails_count/README.rst

@ -13,4 +13,4 @@ Further information
HTML Description: https://apps.odoo.com/apps/modules/9.0/res_partner_mails_count/ HTML Description: https://apps.odoo.com/apps/modules/9.0/res_partner_mails_count/
Tested on Odoo 9.0
Tested on Odoo 9.0 b9f206953e3f877adf18643f154d1262842564ee

14
res_partner_mails_count/views/res_partner_mails_count.xml

@ -14,19 +14,5 @@
</p> </p>
</field> </field>
</record> </record>
<!--<record id="action_mails" model="ir.actions.act_window">-->
<!--<field name="name">Mails</field>-->
<!--<field name="res_model">mail.message</field>-->
<!--<field name="context">{-->
<!--'ignore_search_model': True,-->
<!--}</field>-->
<!--<field name="help" type="html">-->
<!--<p>-->
<!--Mails not found. Probably, they exist, but you don't have access.-->
<!--</p>-->
<!--</field>-->
<!--</record>-->
</data> </data>
</openerp> </openerp>
Loading…
Cancel
Save