Browse Source

mail_private New: internal users are flagged automatically. Added button "Uncheck all"

pull/183/head
ommo73 6 years ago
parent
commit
1046814233
No known key found for this signature in database GPG Key ID: E7E1F5C23505AFF8
  1. 33
      mail_private/__openerp__.py
  2. 7
      mail_private/doc/changelog.rst
  3. 16
      mail_private/models.py
  4. 8
      mail_private/static/src/css/mail_private.css
  5. 108
      mail_private/static/src/js/mail_private.js
  6. 6
      mail_private/static/src/xml/mail_private.xml
  7. 4
      mail_private/template.xml
  8. 3
      mail_private/view.xml

33
mail_private/__openerp__.py

@ -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": "apps@it-projects.info",
"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
mail_private/doc/changelog.rst

@ -1,5 +1,8 @@
Updates
=======
`1.1.0`
-------
- **New**: internal users are flagged automatically.
- **New**: added button "Uncheck all".
`1.0.0`
-------

16
mail_private/models.py

@ -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
mail_private/static/src/css/mail_private.css

@ -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;
}

108
mail_private/static/src/js/mail_private.js

@ -1,3 +1,7 @@
/* 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;
@ -5,11 +9,23 @@ openerp.mail_private = function(instance){
instance.mail.ThreadComposeMessage.include({
init: function (parent, datasets, options) {
this._super.apply(this, arguments);
var 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) {
@ -109,52 +125,62 @@ 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': _.intersection(self.internal_users_ids, recipient[3]).length > 0,
'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');
return ResUser.call('get_internal_users_ids', [[]]).then( function (users_ids) {
return users_ids;
});
}
});
@ -187,7 +213,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]
);
}
}

6
mail_private/static/src/xml/mail_private.xml

@ -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">
@ -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
mail_private/template.xml

@ -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>
<template
@ -6,6 +9,7 @@
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>

3
mail_private/view.xml

@ -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">

Loading…
Cancel
Save