From 1046814233b33362dc3701d7b5a6ecad54dbe672 Mon Sep 17 00:00:00 2001 From: ommo73 Date: Thu, 21 Mar 2019 16:10:35 +0500 Subject: [PATCH] :zap: mail_private New: internal users are flagged automatically. Added button "Uncheck all" --- mail_private/__openerp__.py | 33 ++++-- mail_private/doc/changelog.rst | 7 +- mail_private/models.py | 16 ++- mail_private/static/src/css/mail_private.css | 8 ++ mail_private/static/src/js/mail_private.js | 110 ++++++++++++------- mail_private/static/src/xml/mail_private.xml | 6 + mail_private/template.xml | 4 + mail_private/view.xml | 5 +- 8 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 mail_private/static/src/css/mail_private.css diff --git a/mail_private/__openerp__.py b/mail_private/__openerp__.py index 90ee881..9c85896 100644 --- a/mail_private/__openerp__.py +++ b/mail_private/__openerp__.py @@ -1,35 +1,54 @@ # -*- coding: utf-8 -*- +# Copyright 2016 x620 +# Copyright 2016 Ivan Yelizariev +# Copyright 2016 Ilmir Karamov +# Copyright 2019 Artem Rafailov +# 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", + # ] } diff --git a/mail_private/doc/changelog.rst b/mail_private/doc/changelog.rst index 5f35720..c3f8e2e 100644 --- a/mail_private/doc/changelog.rst +++ b/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` ------- diff --git a/mail_private/models.py b/mail_private/models.py index 2d4b7ef..0c99eb1 100644 --- a/mail_private/models.py +++ b/mail_private/models.py @@ -1,11 +1,21 @@ # -*- coding: utf-8 -*- +# Copyright 2016 manawi +# Copyright 2016 Ivan Yelizariev +# Copyright 2019 Artem Rafailov +# 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 diff --git a/mail_private/static/src/css/mail_private.css b/mail_private/static/src/css/mail_private.css new file mode 100644 index 0000000..da81239 --- /dev/null +++ b/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; +} diff --git a/mail_private/static/src/js/mail_private.js b/mail_private/static/src/js/mail_private.js index bc0d781..a283905 100644 --- a/mail_private/static/src/js/mail_private.js +++ b/mail_private/static/src/js/mail_private.js @@ -1,3 +1,7 @@ +/* Copyright 2016 x620 + Copyright 2016 Ivan Yelizariev + Copyright 2019 Artem Rafailov + 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,55 +125,65 @@ 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; + }); } }); - + instance.mail.Thread.include({ get_recipients_for_internal_message: function(ids, context){ var self = this; @@ -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] ); } } diff --git a/mail_private/static/src/xml/mail_private.xml b/mail_private/static/src/xml/mail_private.xml index d603d82..6893eab 100644 --- a/mail_private/static/src/xml/mail_private.xml +++ b/mail_private/static/src/xml/mail_private.xml @@ -1,4 +1,7 @@ + diff --git a/mail_private/template.xml b/mail_private/template.xml index 534e53c..b2d5243 100644 --- a/mail_private/template.xml +++ b/mail_private/template.xml @@ -1,4 +1,7 @@ +