Skip to content

Commit

Permalink
⚡ mail_private New: internal users are flagged automatically. Added b…
Browse files Browse the repository at this point in the history
…utton "Uncheck all"
  • Loading branch information
Ommo73 committed Apr 26, 2019
1 parent 9a78eed commit 10ba230
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 55 deletions.
33 changes: 26 additions & 7 deletions mail_private/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
# -*- coding: utf-8 -*-
# Copyright 2016 x620 <https://github.com/x620>
# Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2016 Ilmir Karamov <https://it-projects.info/team/ilmir-k>
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
{
"name": """Internal Messaging""",
"summary": """Send private messages to specified recipients, regardless of who are in followers list.""",
"category": "Discuss",
"images": ['images/mail_private_image.png'],
"version": "1.0.0",
# "live_test_url": "http://apps.it-projects.info/shop/product/DEMO-URL?version=8.0",
"images": [],
"version": "8.0.1.1.0",
"application": False,

"author": "IT-Projects LLC, Pavel Romanchenko",
"website": "https://it-projects.info",
"license": "GPL-3",
"support": "[email protected]",
"website": "https://it-projects.info/",
"license": "LGPL-3",
"price": 50.00,
"currency": "EUR",

"depends": [
"mail",
"mail"
],
"external_dependencies": {"python": [], "bin": []},
"data": [
'template.xml',
'view.xml',
],
"demo": [
],
"qweb": [
'static/src/xml/mail_private.xml',
],
"demo": [],

"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"uninstall_hook": None,

"auto_install": False,
"installable": True,

# "demo_title": "{MODULE_NAME}",
# "demo_addons": [
# ],
# "demo_addons_hidden": [
# ],
# "demo_url": "DEMO-URL",
# "demo_summary": "{SHORT_DESCRIPTION_OF_THE_MODULE}",
# "demo_images": [
# "images/MAIN_IMAGE",
# ]
}
7 changes: 5 additions & 2 deletions mail_private/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Updates
=======
`1.1.0`
-------

- **New**: internal users are flagged automatically.
- **New**: added button "Uncheck all".

`1.0.0`
-------
Expand Down
16 changes: 13 additions & 3 deletions mail_private/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2016 manawi <https://github.com/manawi>
# Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).

from openerp.osv import osv, fields
from openerp import api
from openerp.http import request


class MailComposeMessage(osv.TransientModel):
_inherit = 'mail.compose.message'

_columns = {
'private': fields.boolean('Send Internal Message'),
}
private = fields.boolean('Send Internal Message')

@api.model
def get_internal_users_ids(self, vals):
cr, uid, context = request.cr, request.uid, request.context
ids = self.pool['res.users'].search(cr, uid, [('share', '=', False)], context=context)
return ids
8 changes: 8 additions & 0 deletions mail_private/static/src/css/mail_private.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.oe_mail .oe_msg_composer .oe_msg_content .oe_composer_uncheck {
margin-top: 3px;
margin-bottom: 15px;
margin-left: 0px;
}
.oe_mail .oe_msg_composer .oe_msg_content .oe_recipients {
margin-left: 0px;
}
112 changes: 70 additions & 42 deletions mail_private/static/src/js/mail_private.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
/* Copyright 2016 x620 <https://github.com/x620>
Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). */
openerp.mail_private = function(instance){

var mail = instance.mail;

instance.mail.ThreadComposeMessage.include({
init: function (parent, datasets, options) {
this._super.apply(this, arguments);
self = this;
this.private = false;
self.recipients = [];
},
on_uncheck_recipients: function () {
this.$(".oe_recipients")
.find("input:checked").each(function() {
$(this).prop("checked", false);
});
_.each(self.recipients, function(res) {
res["checked"] = false;
});
},
bind_events: function(){
var self = this;
this.$('.oe_compose_post_private').on('click', self.on_toggle_quick_composer_private);
this.$('.oe_composer_uncheck').on('click', self.on_uncheck_recipients);
this._super.apply(this, arguments);
},
on_compose_fullmail: function (default_composition_mode) {
Expand Down Expand Up @@ -109,59 +125,71 @@ openerp.mail_private = function(instance){
var $input = $(event.target);
this.compute_emails_from();
var email_addresses = _.pluck(this.recipients, 'email_address');
var suggested_partners = $.Deferred();
this.get_internal_users_ids().then(function(res_ids){
self.internal_users_ids = res_ids;
var suggested_partners = $.Deferred();

// if clicked: call for suggested recipients
if (event.type == 'click') {
this.private = $input.hasClass('oe_compose_post_private');
this.is_log = false;
suggested_partners = this.parent_thread.get_recipients_for_internal_message([this.context.default_res_id], this.context)
.done(function (additional_recipients) {
var thread_recipients = additional_recipients[self.context.default_res_id];
_.each(thread_recipients, function (recipient) {
var parsed_email = mail.ChatterUtils.parse_email(recipient[1]);
if (_.indexOf(email_addresses, parsed_email[1]) == -1) {
self.recipients.push({
'checked': false,
'partner_id': recipient[0],
'full_name': recipient[1],
'name': parsed_email[0],
'email_address': parsed_email[1],
'reason': recipient[2],
});
}
// if clicked: call for suggested recipients
if (event.type === 'click') {
self.private = $input.hasClass('oe_compose_post_private');
self.is_log = false;
suggested_partners = self.parent_thread.get_recipients_for_internal_message([self.context.default_res_id], self.context)
.done(function (additional_recipients) {
var thread_recipients = additional_recipients[self.context.default_res_id];
_.each(thread_recipients, function (recipient) {
var parsed_email = mail.ChatterUtils.parse_email(recipient[1]);
if (_.indexOf(email_addresses, parsed_email[1]) === -1) {
self.recipients.push({
'checked': (self.internal_users_ids.indexOf( recipient[3][0] ) !== -1),
'partner_id': recipient[0],
'full_name': recipient[1],
'name': parsed_email[0],
'email_address': parsed_email[1],
'reason': recipient[2],
});
}
});
});
});
}
else {
suggested_partners.resolve({});
}
// uncheck partners from compute_emails_from
_.each(this.recipients, function(r){
if (!r.partner_id){
r.checked = false;
}
});

// when call for suggested partners finished: re-render the widget
$.when(suggested_partners).pipe(function (additional_recipients) {
if ((!self.stay_open || (event && event.type == 'click')) && (!self.show_composer || !self.$('textarea:not(.oe_compact)').val().match(/\S+/) && !self.attachment_ids.length)) {
self.show_composer = !self.show_composer || self.stay_open;
self.reinit();
}
if (!self.stay_open && self.show_composer && (!event || event.type != 'blur')) {
self.$('textarea:not(.oe_compact):first').focus();
else {
suggested_partners.resolve({});
}
// uncheck partners from compute_emails_from
_.each(self.recipients, function(r){
if (!r.partner_id){
r.checked = false;
}
});

// when call for suggested partners finished: re-render the widget
$.when(suggested_partners).pipe(function (additional_recipients) {
if ((!self.stay_open || (event && event.type === 'click')) && (!self.show_composer || !self.$('textarea:not(.oe_compact)').val().match(/\S+/) && !self.attachment_ids.length)) {
self.show_composer = !self.show_composer || self.stay_open;
self.reinit();
}
if (!self.stay_open && self.show_composer && (!event || event.type !== 'blur')) {
self.$('textarea:not(.oe_compact):first').focus();
}
});

return suggested_partners;
});

return suggested_partners;
},
get_internal_users_ids: function () {
var ResUser = new instance.web.Model('mail.compose.message');
this.users_ids = ResUser.call('get_internal_users_ids', [[]]).then( function (users_ids) {
return users_ids;
});
return this.users_ids;
}
});

instance.mail.Thread.include({
get_recipients_for_internal_message: function(ids, context){
var self = this;
self.result = {};
self.res_users = {};
return new instance.web.Model(context.default_model).call(
'read', [ids, ['message_follower_ids', 'partner_id'], context]
).then(function (thread) {
Expand All @@ -187,7 +215,7 @@ openerp.mail_private = function(instance){
reason = 'Partner';
}
self.result[res_id].push(
[partner.id, partner.name + '<' + partner.email + '>', reason]
[partner.id, partner.name + '<' + partner.email + '>', reason, partner.user_ids]
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions mail_private/static/src/xml/mail_private.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<template>
<t t-extend="mail.compose_message">
<t t-jquery="a[title='Send a message to all followers of the document']" t-operation="after">
Expand All @@ -17,5 +20,8 @@
</span>
</t>
</t>
<t t-jquery="div[class='oe_recipients']" t-operation="after">
<button class="oe_composer_uncheck" t-if="widget.private">Uncheck all</button>
</t>
</t>
</template>
4 changes: 4 additions & 0 deletions mail_private/template.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright 2016 x620 <https://github.com/x620>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<openerp>
<data>
<template
id="assets_backend"
name="mail_private_assets_backend"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/mail_private/static/src/css/mail_private.css"/>
<script
type="text/javascript"
src="/mail_private/static/src/js/mail_private.js"></script>
Expand Down
5 changes: 4 additions & 1 deletion mail_private/view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright 2016 x620 <https://github.com/x620>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<openerp>
<data>
<record id="mail_private_email_compose_message_wizard_form" model="ir.ui.view">
Expand All @@ -24,4 +27,4 @@
</field>
</record>
</data>
</openerp>
</openerp>

0 comments on commit 10ba230

Please sign in to comment.