Browse Source

Merge pull request #36 from x620/9.0-mail_move_message

[PORT] 9.0-mail_move_message
pull/40/head
Ivan Yelizariev 9 years ago
committed by GitHub
parent
commit
d565bea72d
  1. 6
      mail_archives/static/src/js/archives.js
  2. 37
      mail_base/static/src/js/base.js
  3. 2
      mail_move_message/README.rst
  4. 8
      mail_move_message/__openerp__.py
  5. 14
      mail_move_message/controllers/main.py
  6. BIN
      mail_move_message/images/inbox.png
  7. 42
      mail_move_message/mail_move_message_models.py
  8. BIN
      mail_move_message/static/description/delete-message.png
  9. BIN
      mail_move_message/static/description/html-message-viewer.png
  10. BIN
      mail_move_message/static/description/html-message-viewer1.png
  11. BIN
      mail_move_message/static/description/html-message.png
  12. BIN
      mail_move_message/static/description/icon.png
  13. BIN
      mail_move_message/static/description/inbox-move.png
  14. BIN
      mail_move_message/static/description/inbox.png
  15. 20
      mail_move_message/static/description/index.html
  16. BIN
      mail_move_message/static/description/record-move-back.png
  17. BIN
      mail_move_message/static/description/record1.png
  18. BIN
      mail_move_message/static/description/record2.png
  19. 23
      mail_move_message/static/src/css/mail_move_message.css
  20. 137
      mail_move_message/static/src/js/mail_move_message.js
  21. 7
      mail_move_message/static/src/xml/mail_move_message_main.xml
  22. 6
      mail_sent/static/src/js/sent.js
  23. 8
      mail_to/static/src/css/mail_to.css

6
mail_archives/static/src/js/archives.js

@ -23,6 +23,12 @@ ChatAction.include({
var channel_name = 'channel_archive';
// Add channel Archive for enable "display_subject" option
this.channels_display_subject.push(channel_name);
},
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;
}
});

37
mail_base/static/src/js/base.js

@ -112,6 +112,25 @@ ChatAction.include({
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();
}
}
});
@ -476,6 +495,20 @@ var MailTools = core.Class.extend({
});
},
remove_from_cache: function(message, domain){
var self = this;
_.each(message.channel_ids, function (channel_id) {
var channel = chat_manager.get_channel(channel_id);
if (channel) {
var channel_cache = self.get_channel_cache(channel, domain);
var index = _.sortedIndex(channel_cache.messages, message, 'id');
if (channel_cache.messages[index] === message) {
channel_cache.messages.splice(index, 1);
}
}
});
},
remove_message_from_channel: function (channel_id, message) {
message.channel_ids = _.without(message.channel_ids, channel_id);
var channel = _.findWhere(channels, { id: channel_id });
@ -1128,7 +1161,9 @@ function init(){
// unsubscribe and then subscribe to the event, to avoid duplication of new messages
bus.off('notification');
bus.on('notification', null, chat_manager.mail_tools.on_notification);
bus.on('notification', null, function(){
chat_manager.mail_tools.on_notification.apply(chat_manager.mail_tools, arguments)
});
return $.when(load_menu_id, load_action_id, load_channels, load_emojis).then(function (menu_id, action_id) {
discuss_ids = {

2
mail_move_message/README.rst

@ -1,6 +1,8 @@
Mail relocation
===============
Demo: http://runbot.it-projects.info/demo/mail-addons/9.0
Description: https://www.odoo.com/apps/modules/8.0/mail_move_message/
Further information and discussion: http://yelizariev.github.io/odoo/module/2015/04/10/mail-relocation.html

8
mail_move_message/__openerp__.py

@ -1,13 +1,13 @@
{
'name' : 'Mail relocation',
'version' : '1.0.4',
'author' : 'IT-Projects LLC, Ivan Yelizariev',
'author' : 'IT-Projects LLC, Ivan Yelizariev, Pavel Romanchenko',
'license': 'LGPL-3',
'category' : 'Social Network',
'category' : 'Discuss',
'website' : 'https://twitter.com/yelizariev',
'price': 100.00,
'currency': 'EUR',
'depends' : ['mail', 'web_polymorphic_field'],
'depends' : ['mail_all', 'web_polymorphic_field'],
'images': ['images/inbox.png'],
'data':[
'mail_move_message_views.xml',
@ -16,5 +16,5 @@
'qweb': [
'static/src/xml/mail_move_message_main.xml',
],
'installable': False
'installable': True,
}

14
mail_move_message/controllers/main.py

@ -2,6 +2,20 @@ from openerp.addons.web.controllers.main import DataSet
from openerp.tools.translate import _
from openerp import http
from openerp.http import request
import openerp
class MailChatController(openerp.addons.bus.controllers.main.BusController):
# -----------------------------
# Extends BUS Controller Poll
# -----------------------------
def _poll(self, dbname, channels, last, options):
if request.session.uid:
registry, cr, uid, context = request.registry, request.cr, request.session.uid, request.context
channels.append((request.db, 'mail_move_message'))
channels.append((request.db, 'mail_move_message.delete_message'))
return super(MailChatController, self)._poll(dbname, channels, last, options)
class DataSetCustom(DataSet):

BIN
mail_move_message/images/inbox.png

Before

Width: 861  |  Height: 628  |  Size: 128 KiB

After

Width: 861  |  Height: 628  |  Size: 58 KiB

42
mail_move_message/mail_move_message_models.py

@ -74,7 +74,7 @@ class wizard(models.TransientModel):
message_email_from = fields.Char()
message_name_from = fields.Char()
# FIXME message_to_read should be True even if current message or any his childs are unread
message_to_read = fields.Boolean(related='message_id.to_read')
message_to_read = fields.Boolean(related='message_id.needaction')
uid = fields.Integer()
move_followers = fields.Boolean(
'Move Followers',
@ -176,13 +176,12 @@ class wizard(models.TransientModel):
r.message_id.move(r.parent_id.id, r.res_id, r.model, r.move_back, r.move_followers)
if not ( r.model and r.res_id ):
obj = self.pool.get('ir.model.data').get_object_reference(self._cr, SUPERUSER_ID, 'mail', 'mail_archivesfeeds')[1]
if not (r.model and r.res_id):
r.message_id.needaction = False
return {
'type' : 'ir.actions.client',
'name' : 'Archive',
'tag' : 'reload',
'params' : {'menu_id': obj},
'type': 'ir.actions.client',
'name': 'All messages',
'tag': 'reload',
}
return {
'name': _('Record'),
@ -196,6 +195,12 @@ class wizard(models.TransientModel):
@api.one
def delete(self):
msg_id = self.message_id.id
# Send notification
notification = {'id': msg_id}
self.env['bus.bus'].sendone((self._cr.dbname, 'mail_move_message.delete_message'), notification)
self.message_id.unlink()
return {}
@ -287,6 +292,9 @@ class mail_message(models.Model):
vals['moved_by_user_id'] = self.env.user.id
vals['moved_by_message_id'] = self.id
# Update record_name in message
vals['record_name'] = self._get_record_name(vals)
for r in self.all_child_ids:
r_vals = vals.copy()
if not r.is_moved:
@ -308,6 +316,16 @@ class mail_message(models.Model):
'res_model': r_vals.get('model')
})
# Send notification
notification = {
'id': self.id,
'res_id': vals.get('res_id'),
'model': vals.get('model'),
'is_moved': vals['is_moved'],
'record_name': vals['record_name']
}
self.env['bus.bus'].sendone((self._cr.dbname, 'mail_move_message'), notification)
def name_get(self, cr, uid, ids, context=None):
if not (context or {}).get('extended_name'):
return super(mail_message, self).name_get(cr, uid, ids, context=context)
@ -328,6 +346,16 @@ class mail_message(models.Model):
res['is_moved'] = message.is_moved
return res
@api.multi
def message_format(self):
message_values = super(mail_message, self).message_format()
message_index = {message['id']: message for message in message_values}
for item in self:
msg = message_index.get(item.id)
if msg:
msg['is_moved'] = item.is_moved
return message_values
class mail_move_message_configuration(models.TransientModel):
_name = 'mail_move_message.config.settings'

BIN
mail_move_message/static/description/delete-message.png

Before

Width: 1012  |  Height: 546  |  Size: 73 KiB

After

Width: 1012  |  Height: 546  |  Size: 39 KiB

BIN
mail_move_message/static/description/html-message-viewer.png

Before

Width: 1012  |  Height: 546  |  Size: 62 KiB

After

Width: 1012  |  Height: 546  |  Size: 40 KiB

BIN
mail_move_message/static/description/html-message-viewer1.png

Before

Width: 1012  |  Height: 546  |  Size: 51 KiB

After

Width: 1012  |  Height: 546  |  Size: 39 KiB

BIN
mail_move_message/static/description/html-message.png

Before

Width: 890  |  Height: 473  |  Size: 58 KiB

After

Width: 890  |  Height: 473  |  Size: 73 KiB

BIN
mail_move_message/static/description/icon.png

Before

Width: 120  |  Height: 120  |  Size: 3.0 KiB

After

Width: 149  |  Height: 149  |  Size: 1.5 KiB

BIN
mail_move_message/static/description/inbox-move.png

Before

Width: 1054  |  Height: 562  |  Size: 85 KiB

After

Width: 1054  |  Height: 562  |  Size: 57 KiB

BIN
mail_move_message/static/description/inbox.png

Before

Width: 750  |  Height: 400  |  Size: 69 KiB

After

Width: 750  |  Height: 400  |  Size: 54 KiB

20
mail_move_message/static/description/index.html

@ -95,28 +95,10 @@
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2>Tips and tricks</h2>
<p class="oe_mt32">
Also, the module can be used as a viewer for wide html messages
</p>
</div>
<div class="oe_span12">
<div class="oe_demo oe_picture oe_screenshot">
<img src="html-message.png?1"/>
</div>
<p class="oe_mt32">
Check message and then close window.
</p>
<div class="oe_demo oe_picture oe_screenshot">
<img src="html-message-viewer1.png"/>
</div>
<p class="oe_mt32">
Also, you can mark as read and close
</p>
<div class="oe_demo oe_picture oe_screenshot">
<img src="html-message-viewer.png?2"/>
</div>
<p class="oe_mt32">
In addition, the module can be used to delete a message (it's available for superuser only)
The module can be used to delete a message (it's available for superuser only)
</p>
<div class="oe_demo oe_picture oe_screenshot">
<img src="delete-message.png"/>

BIN
mail_move_message/static/description/record-move-back.png

Before

Width: 904  |  Height: 482  |  Size: 68 KiB

After

Width: 904  |  Height: 482  |  Size: 42 KiB

BIN
mail_move_message/static/description/record1.png

Before

Width: 1007  |  Height: 537  |  Size: 58 KiB

After

Width: 1007  |  Height: 537  |  Size: 32 KiB

BIN
mail_move_message/static/description/record2.png

Before

Width: 750  |  Height: 400  |  Size: 70 KiB

After

Width: 750  |  Height: 400  |  Size: 29 KiB

23
mail_move_message/static/src/css/mail_move_message.css

@ -1,13 +1,20 @@
.openerp .oe_mail .oe_msg .oe_msg_icons .oe_move.oe_moved a {
color: #ffefe;
i.oe_moved {
color: #ED6F6A;
text-shadow: 0px 1px #961b1b,0px -1px #961b1b, -1px 0px #961b1b, 1px 0px #961b1b, 0px 3px 3px rgba(0,0,0,0.1);
}
.mail_move_message {
width: 864px;
}
.openerp .oe_mail .oe_msg .oe_msg_icons .oe_move:hover a {
color: #ffa1a1;
text-shadow: 0px 1px #ff0000,0px -1px #ff0000, -1px 0px #ff0000, 1px 0px #ff0000, 0px 3px 3px rgba(0,0,0,0.1);
.o_mail_thread .o_thread_message i.oe_move {
cursor: pointer;
opacity: 0;
padding: 4px;
}
.o_mail_thread .o_thread_message:hover i.oe_move {
opacity: 0.6;
}
.openerp.mail_move_message{
width: 864px;
}
.o_mail_thread .o_thread_message:hover i.oe_move:hover {
opacity: 1;
}

137
mail_move_message/static/src/js/mail_move_message.js

@ -1,19 +1,28 @@
openerp.mail_move_message = function (session) {
var _t = session.web._t,
_lt = session.web._lt;
odoo.define('mail_move_message.relocate', function (require) {
"use strict";
var mail = session.mail;
var bus = require('bus.bus').bus;
var chat_manager = require('mail.chat_manager');
var base_obj = require('mail_base.base');
var thread = require('mail.ChatThread');
var chatter = require('mail.Chatter');
var Model = require('web.Model');
var form_common = require('web.form_common');
var widgets = require('web.form_widgets');
var core = require('web.core');
mail.ThreadMessage.include({
bind_events: function(){
var _t = core._t;
thread.include({
init: function(){
this._super.apply(this, arguments);
this.$('.oe_move').on('click', this.on_move_message)
},
on_move_message: function(event){
var self = this;
var context = {
'default_message_id': this.id
// Add click reaction in the events of the thread object
this.events['click .oe_move'] = function(event) {
var message_id = $(event.currentTarget).data('message-id');
this.trigger("move_message", message_id);
}
},
on_move_message: function(message_id){
var action = {
name: _t('Relocate Message'),
type: 'ir.actions.act_window',
@ -22,37 +31,85 @@ openerp.mail_move_message = function (session) {
view_type: 'form',
views: [[false, 'form']],
target: 'new',
context: context,
context: {'default_message_id': message_id}
};
self.do_action(action, {
'on_close': function(){
self.check_for_rerender();
}
this.do_action(action, {
'on_close': function(){}
});
}
})
});
chatter.include({
start: function() {
var result = this._super.apply(this, arguments);
// For show wizard in the form
this.thread.on('move_message', this, this.thread.on_move_message);
return $.when(result).done(function() {});
}
});
var ChatAction = core.action_registry.get('mail.chat.instant_messaging');
ChatAction.include({
start: function() {
var result = this._super.apply(this, arguments);
// For show wizard in the channels
this.thread.on('move_message', this, this.thread.on_move_message);
return $.when(result).done(function() {});
}
});
mail.MessageCommon.include({
init: function (parent, datasets, options) {
this._super(parent, datasets, options);
this.is_moved = datasets.is_moved || false;
base_obj.MailTools.include({
make_message: function(data){
var msg = this._super(data);
// Mark msg as moved after reload
msg.is_moved = data.is_moved || false;
return msg;
},
on_notification: function(notifications){
this._super(notifications);
var self = this;
_.each(notifications, function (notification) {
var model = notification[0][1];
var message_id = notification[1].id;
var message = base_obj.chat_manager.get_message(message_id);
if (model === 'mail_move_message' && message) {
message.res_id = notification[1].res_id;
message.model = notification[1].model;
message.record_name = notification[1].record_name;
// Mark message as moved after move
message.is_moved = notification[1].is_moved;
// Update cache and accordingly message in the thread
self.add_to_cache(message, []);
// Call thread.on_update_message(message)
chat_manager.bus.trigger('update_message', message);
} else if (model === 'mail_move_message.delete_message') {
self.remove_from_cache(message, []);
chat_manager.bus.trigger('update_message', message);
}
});
}
})
});
session.web.form.WidgetButton.include({
on_click: function() {
widgets.WidgetButton.include({
on_click: function(){
if(this.node.attrs.special == 'quick_create'){
var self = this;
var related_field = this.field_manager.fields[this.node.attrs['field']];
var context_built = $.Deferred();
if(this.node.attrs.use_for_mail_move_message) {
var model = new session.web.Model(this.view.dataset.model);
var model = new Model(this.view.dataset.model);
var partner_id = self.field_manager.fields['partner_id'].get_value();
var message_name_from = self.field_manager.fields['message_name_from'].get_value();
var message_email_from = self.field_manager.fields['message_email_from'].get_value();
context_built = model.call('create_partner', [self.view.dataset.context.default_message_id,
related_field.field.relation, partner_id, message_name_from, message_email_from]);
context_built = model.call('create_partner', [
self.view.dataset.context.default_message_id,
related_field.field.relation,
partner_id,
message_name_from,
message_email_from
]);
}
else {
context_built.resolve(this.build_context());
@ -61,20 +118,17 @@ openerp.mail_move_message = function (session) {
if(self.node.attrs.use_for_mail_move_message) {
self.field_manager.fields['partner_id'].set_value(context['partner_id']);
}
var pop = new session.web.form.FormOpenPopup(this);
pop.show_element(
related_field.field.relation,
false,
context,
{
title: _t("Create new record"),
}
);
pop.on('closed', self, function () {
var dialog = new form_common.FormViewDialog(self, {
res_model: related_field.field.relation,
res_id: false,
context: context,
title: _t("Create new record")
}).open();
dialog.on('closed', self, function () {
self.force_disabled = false;
self.check_disable();
});
pop.on('create_completed', self, function(id) {
dialog.on('create_completed', self, function(id) {
related_field.set_value(id);
if(self.field_manager.fields['filter_by_partner']) {
self.field_manager.fields['filter_by_partner'].set_value(true);
@ -85,7 +139,6 @@ openerp.mail_move_message = function (session) {
else {
this._super.apply(this, arguments);
}
},
}
});
}
});

7
mail_move_message/static/src/xml/mail_move_message_main.xml

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<t t-extend="mail.thread.message">
<t t-jquery=".oe_msg_icons" t-operation="append">
<span t-attf-class="oe_move #{widget.is_moved?'oe_moved':''}"><a title="Move to thread" class="oe_e">f</a></span>
<t t-extend="mail.ChatThread.Message">
<t t-jquery='p.o_mail_info>span>i:first-child' t-operation="before">
<i t-att-class="'fa fa-exchange oe_move' + (message.is_moved ? ' oe_moved' : '')"
t-att-data-message-id="message.id" title="Move to thread"/>
</t>
</t>
</template>

6
mail_sent/static/src/js/sent.js

@ -25,6 +25,12 @@ ChatAction.include({
this.channels_show_send_button.push(channel_name);
// Add channel Sent for enable "display_subject" option
this.channels_display_subject.push(channel_name);
},
update_message_on_current_channel: function(current_channel_id, message){
var result = this._super.apply(this, arguments);
var sent = current_channel_id === "channel_sent" && !message.is_sent;
return sent || result;
}
});

8
mail_to/static/src/css/mail_to.css

@ -6,15 +6,11 @@
}
.o_mail_thread .o_thread_message span.recipients_info,
.o_mail_thread .o_thread_message i.o_thread_message_star,
.o_mail_thread .o_thread_message i.o_thread_message_reply,
.o_mail_thread .o_thread_message i.o_thread_message_needaction {
.o_mail_thread .o_thread_message i.fa {
opacity: 0.4;
}
.o_mail_thread .o_thread_message:hover i.o_thread_message_star,
.o_mail_thread .o_thread_message:hover i.o_thread_message_reply,
.o_mail_thread .o_thread_message:hover i.o_thread_message_needaction {
.o_mail_thread .o_thread_message:hover i.fa {
opacity: 0.7;
}

Loading…
Cancel
Save