Browse Source
[MIG] mail_tracking
[MIG] mail_tracking
* Improve tests * Show trackings even if partner removed * Disable CSRF protection to webhooks controllerspull/87/head
Antonio Espinosa
8 years ago
committed by
Pedro M. Baeza
14 changed files with 264 additions and 137 deletions
-
2mail_tracking/README.rst
-
2mail_tracking/__openerp__.py
-
4mail_tracking/controllers/main.py
-
27mail_tracking/models/mail_mail.py
-
51mail_tracking/models/mail_message.py
-
9mail_tracking/models/mail_tracking_email.py
-
8mail_tracking/static/src/css/mail_tracking.css
-
152mail_tracking/static/src/js/mail_tracking.js
-
42mail_tracking/static/src/xml/mail_tracking.xml
-
78mail_tracking/tests/test_mail_tracking.py
-
6mail_tracking/views/assets.xml
-
6mail_tracking/views/mail_tracking_email_view.xml
-
6mail_tracking/views/mail_tracking_event_view.xml
-
8mail_tracking/views/res_partner_view.xml
@ -1,63 +1,103 @@ |
|||
/* © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */
|
|||
|
|||
(function ($, window, document) { |
|||
'use strict'; |
|||
odoo.define('mail_tracking.partner_tracking', function(require){ |
|||
"use strict"; |
|||
|
|||
openerp.mail_tracking = function (instance) { |
|||
var _t = instance.web._t, |
|||
_lt = instance.web._lt; |
|||
var QWeb = instance.web.qweb; |
|||
var mail_orig = instance.mail; |
|||
var mail_inherit = function() { |
|||
instance.mail.MessageCommon.include({ |
|||
init: function (parent, datasets, options) { |
|||
this._super(parent, datasets, options); |
|||
this.partner_trackings = datasets.partner_trackings || []; |
|||
} |
|||
}); |
|||
instance.mail.ThreadMessage.include({ |
|||
bind_events: function () { |
|||
this._super(); |
|||
this.$('.oe_mail_action_tracking').on('click', this.on_tracking_status_clicked); |
|||
}, |
|||
on_tracking_status_clicked: function (event) { |
|||
event.preventDefault(); |
|||
var tracking_email_id = $(event.delegateTarget).data('tracking'); |
|||
var state = { |
|||
'model': 'mail.tracking.email', |
|||
'id': tracking_email_id, |
|||
'title': _t("Message tracking"), |
|||
}; |
|||
instance.webclient.action_manager.do_push_state(state); |
|||
console.log('tracking_email_id = ' + tracking_email_id); |
|||
var action = { |
|||
type:'ir.actions.act_window', |
|||
view_type: 'form', |
|||
view_mode: 'form', |
|||
res_model: 'mail.tracking.email', |
|||
views: [[false, 'form']], |
|||
target: 'new', |
|||
res_id: tracking_email_id, |
|||
}; |
|||
this.do_action(action); |
|||
} |
|||
}); |
|||
var $ = require('$'); |
|||
var core = require('web.core'); |
|||
var session = require('web.session'); |
|||
var Model = require('web.Model'); |
|||
var ActionManager = require('web.ActionManager'); |
|||
var chat_manager = require('mail.chat_manager'); |
|||
var ChatThread = require('mail.ChatThread'); |
|||
var Chatter = require('mail.Chatter'); |
|||
|
|||
var _t = core._t; |
|||
var MessageModel = new Model('mail.message', session.context); |
|||
|
|||
// chat_manager is a simple dictionary, not an OdooClass
|
|||
chat_manager._make_message_super = chat_manager.make_message; |
|||
chat_manager.make_message = function(data) { |
|||
var msg = this._make_message_super(data); |
|||
msg.partner_trackings = data.partner_trackings || []; |
|||
return msg; |
|||
}; |
|||
|
|||
ChatThread.include({ |
|||
on_tracking_partner_click: function (event) { |
|||
var partner_id = $(event.currentTarget).data('partner'); |
|||
var state = { |
|||
'model': 'res.partner', |
|||
'id': partner_id, |
|||
'title': _t("Tracking partner"), |
|||
}; |
|||
event.preventDefault(); |
|||
this.action_manager.do_push_state(state); |
|||
var action = { |
|||
type:'ir.actions.act_window', |
|||
view_type: 'form', |
|||
view_mode: 'form', |
|||
res_model: 'res.partner', |
|||
views: [[false, 'form']], |
|||
target: 'current', |
|||
res_id: partner_id, |
|||
}; |
|||
this.do_action(action); |
|||
}, |
|||
on_tracking_status_click: function (event) { |
|||
var tracking_email_id = $(event.currentTarget).data('tracking'); |
|||
var state = { |
|||
'model': 'mail.tracking.email', |
|||
'id': tracking_email_id, |
|||
'title': _t("Message tracking"), |
|||
}; |
|||
event.preventDefault(); |
|||
this.action_manager.do_push_state(state); |
|||
var action = { |
|||
type:'ir.actions.act_window', |
|||
view_type: 'form', |
|||
view_mode: 'form', |
|||
res_model: 'mail.tracking.email', |
|||
views: [[false, 'form']], |
|||
target: 'new', |
|||
res_id: tracking_email_id, |
|||
}; |
|||
this.do_action(action); |
|||
}, |
|||
bind_events: function () { |
|||
this.$el.on('click', '.o_mail_action_tracking_partner', |
|||
this.on_tracking_partner_click); |
|||
this.$el.on('click', '.o_mail_action_tracking_status', |
|||
this.on_tracking_status_click); |
|||
}, |
|||
init: function (parent, options) { |
|||
this._super.apply(this, arguments); |
|||
this.action_manager = this.findAncestor(function(ancestor){ |
|||
return ancestor instanceof ActionManager; |
|||
}); |
|||
}, |
|||
start: function () { |
|||
this._super(); |
|||
this.bind_events(); |
|||
}, |
|||
render: function(messages, options) { |
|||
var self = this, render_super = this._super, |
|||
msgs = {}, |
|||
msg_ids = []; |
|||
// Update trackings (async) each time we re-render thread
|
|||
_.each(messages, function (message) { |
|||
msgs[message.id] = message; |
|||
msg_ids.push(message.id); |
|||
}); |
|||
MessageModel.call('tracking_status', [msg_ids]).then(function (trackings) { |
|||
_.each(trackings, function (tracking, id) { |
|||
msgs[id].partner_trackings = tracking; |
|||
}); |
|||
render_super.apply(self, [messages, options]); |
|||
}); |
|||
}, |
|||
|
|||
// Tricky way to guarantee that this module is loaded always
|
|||
// after mail module.
|
|||
// When --load=web,mail_tracking is specified in init script, then
|
|||
// web and mail_tracking are the first modules to load in JS
|
|||
if (instance.mail.MessageCommon === undefined) { |
|||
instance.mail = function(instance) { |
|||
instance.mail = mail_orig; |
|||
instance.mail(instance, instance.mail); |
|||
mail_inherit(); |
|||
}; |
|||
} else { |
|||
mail_inherit(); |
|||
} |
|||
}; |
|||
}); |
|||
|
|||
}(window.jQuery, window, document)); |
|||
}); // odoo.define
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue