From 988cc6c19eb9a214f6d7074df6024dda2904f9b7 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 31 Oct 2012 11:21:15 +0100 Subject: [PATCH 1/8] [IMP] mail: add many2many_tag_email widget for wizard bzr revid: chm@openerp.com-20121031102115-wxmfm27wlz9zsi5j --- addons/mail/wizard/mail_compose_message_view.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/mail/wizard/mail_compose_message_view.xml b/addons/mail/wizard/mail_compose_message_view.xml index 1f00ed419a2..e6f26262a60 100644 --- a/addons/mail/wizard/mail_compose_message_view.xml +++ b/addons/mail/wizard/mail_compose_message_view.xml @@ -14,9 +14,8 @@ - + From 03f8275cdcc9f1f4541d36bffd2518fca862c56a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 31 Oct 2012 16:40:44 +0100 Subject: [PATCH 2/8] [IMP] mail: remove the onchange code in wizard/mail_compose_message.py bzr revid: chm@openerp.com-20121031154044-641rih2zw1jffiem --- addons/mail/wizard/mail_compose_message.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 1bcbb0c2efc..33712847534 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -186,17 +186,6 @@ class mail_compose_message(osv.TransientModel): """ return {'value': {'content_subtype': value}} - def onchange_partner_ids(self, cr, uid, ids, value, context=None): - """ The basic purpose of this method is to check that destination partners - effectively have email addresses. Otherwise a warning is thrown. - :param value: value format: [[6, 0, [3, 4]]] - """ - res = {'value': {}} - if not value or not value[0] or not value[0][0] == 6: - return - res.update(self.check_partners_email(cr, uid, value[0][2], context=context)) - return res - def dummy(self, cr, uid, ids, context=None): """ TDE: defined to have buttons that do basically nothing. It is currently impossible to have buttons that do nothing special From 63a89701122c0457d019848ba1564337b793a3b3 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 6 Nov 2012 10:56:19 +0100 Subject: [PATCH 3/8] [IMP] web: field many2many_tags_email moved to mail addon bzr revid: chm@openerp.com-20121106095619-bl7xg1bhubweetpo --- addons/mail/__openerp__.py | 1 + addons/mail/static/src/js/mail.js | 39 ++++++++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/addons/mail/__openerp__.py b/addons/mail/__openerp__.py index 0c32ba27d6f..9ad3232d396 100644 --- a/addons/mail/__openerp__.py +++ b/addons/mail/__openerp__.py @@ -89,6 +89,7 @@ Main Features 'static/lib/jquery.expander/jquery.expander.js', 'static/src/js/mail.js', 'static/src/js/mail_followers.js', + 'static/src/js/many2many_tags_email.js', ], 'qweb': [ 'static/src/xml/mail.xml', diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 9133e5de257..60a55e79393 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -5,6 +5,7 @@ openerp.mail = function (session) { var mail = session.mail = {}; openerp_mail_followers(session, mail); // import mail_followers.js + openerp_FieldMany2ManyTagsEmail(session); // import manyy2many_tags_email.js /** * ------------------------------------------------------------ @@ -1628,7 +1629,24 @@ openerp.mail = function (session) { bind_events: function () { var self=this; - this.$(".oe_write_full").click(function(){ self.root.thread.compose_message.on_compose_fullmail(); }); + this.$(".oe_write_full").click(function (event) { + event.stopPropagation(); + var action = { + type: 'ir.actions.act_window', + res_model: 'mail.compose.message', + view_mode: 'form', + view_type: 'form', + action_from: 'mail.ThreadComposeMessage', + views: [[false, 'form']], + target: 'new', + context: { + 'default_model': '', + 'default_res_id': false, + 'default_content_subtype': 'html', + }, + }; + session.client.action_manager.do_action(action); + }); this.$(".oe_write_onwall").click(function(){ self.root.thread.on_compose_message(); }); } }); @@ -1644,17 +1662,6 @@ openerp.mail = function (session) { session.web.ComposeMessageTopButton = session.web.Widget.extend({ template:'mail.compose_message.button_top_bar', - init: function (parent, options) { - this._super.apply(this, options); - this.options = this.options || {}; - this.options.domain = this.options.domain || []; - this.options.context = { - 'default_model': false, - 'default_res_id': 0, - 'default_content_subtype': 'html', - }; - }, - start: function (parent, params) { var self = this; this.$el.on('click', 'button', self.on_compose_message ); @@ -1671,11 +1678,11 @@ openerp.mail = function (session) { action_from: 'mail.ThreadComposeMessage', views: [[false, 'form']], target: 'new', - context: _.extend(this.options.context, { - 'default_model': this.context.default_model, - 'default_res_id': this.context.default_res_id, + context: { + 'default_model': '', + 'default_res_id': false, 'default_content_subtype': 'html', - }), + }, }; session.client.action_manager.do_action(action); }, From 065600fe2527112894392a0da95a28560c2a5a07 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 6 Nov 2012 13:51:33 +0100 Subject: [PATCH 4/8] [IMP] web: FieldMany2ManyTagsEmail check id partner on change value. File inside mail addons folder bzr revid: chm@openerp.com-20121106125133-udq68eyek9fhsw83 --- .../static/src/js/many2many_tags_email.js | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 addons/mail/static/src/js/many2many_tags_email.js diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js new file mode 100644 index 00000000000..2e449bd410a --- /dev/null +++ b/addons/mail/static/src/js/many2many_tags_email.js @@ -0,0 +1,87 @@ +openerp_FieldMany2ManyTagsEmail = function(instance) { +var _t = instance.web._t; + +/** + * Extend of FieldMany2ManyTags widget method. + * When the user add a partner and the partner don't have an email, open a popup to purpose to add an email. + * The user can choose to add an email or cancel and close the popup. + */ +instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags.extend({ + + start: function() { + this.values = []; + this.values_checking = []; + + this.on("change:value", this, this.on_change_value_check); + this.trigger("change:value"); + + this._super.apply(this, arguments); + }, + + on_change_value_check : function () { + var self = this; + // filter for removed values + var values_removed = _.difference(self.values, self.get('value')); + + if (values_removed.length) { + self.values = _.difference(self.values, values_removed); + this.set({'value': self.values}); + return false; + } + + // find not checked values + var not_checked = _.difference(self.get('value'), self.values); + + // find not checked values and not on checking + var not_checked = _.difference(not_checked, self.values_checking); + + _.each(not_checked, function (val, key) { + self.values_checking.push(val); + self._check_email_popup(val); + }); + }, + + _check_email_popup: function (id) { + var self = this; + new instance.web.Model('res.partner').call("read", [id, ["email", "notification_email_send"]], {context: this.build_context()}) + .pipe(function (dict) { + if (!dict.email && (dict.notification_email_send == 'all' || dict.notification_email_send == 'comment')) { + var pop = new instance.web.form.FormOpenPopup(self); + pop.show_element( + 'res.partner', + dict.id, + self.build_context(), + { + title: _t("Please complete partner's informations and Email"), + } + ); + pop.on('write_completed', self, function () { + self._checked(dict.id, true); + }); + pop.on('closing', self, function () { + self._checked(dict.id, false); + }); + } else { + self._checked(dict.id, true); + } + }); + }, + + _checked: function (id, access) { + if (access) { + this.values.push(id); + } + this.values_checking = _.without(this.values_checking, id); + this.set({'value': this.values}); + }, +}); + + +/** + * Registry of form fields + */ +instance.web.form.widgets = instance.web.form.widgets.extend({ + 'many2many_tags_email' : 'instance.web.form.FieldMany2ManyTagsEmail', +}); + +}; \ No newline at end of file From 44284ca4a46da5211927f416743129c97259110e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 6 Nov 2012 15:59:58 +0100 Subject: [PATCH 5/8] [REVIEW] trigger closing -> closed, to match the code guidelines. bzr revid: tde@openerp.com-20121106145958-zg11plyzeo5rz6ao --- addons/mail/static/src/js/many2many_tags_email.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js index 2e449bd410a..ae239f3644e 100644 --- a/addons/mail/static/src/js/many2many_tags_email.js +++ b/addons/mail/static/src/js/many2many_tags_email.js @@ -58,7 +58,7 @@ instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags pop.on('write_completed', self, function () { self._checked(dict.id, true); }); - pop.on('closing', self, function () { + pop.on('closed', self, function () { self._checked(dict.id, false); }); } else { From cb11c84fa352d174ee7c823b9e79401aa044b1ed Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 6 Nov 2012 16:50:24 +0100 Subject: [PATCH 6/8] [IMP] web: many2many_tags_email: convert read id by search for load all ID with only one request bzr revid: chm@openerp.com-20121106155024-x3buowqrlnlcv160 --- .../static/src/js/many2many_tags_email.js | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js index ae239f3644e..234dc504682 100644 --- a/addons/mail/static/src/js/many2many_tags_email.js +++ b/addons/mail/static/src/js/many2many_tags_email.js @@ -19,61 +19,67 @@ instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags }, on_change_value_check : function () { - var self = this; + this.values = _.uniq(this.values); + // filter for removed values - var values_removed = _.difference(self.values, self.get('value')); + var values_removed = _.difference(this.values, this.get('value')); if (values_removed.length) { - self.values = _.difference(self.values, values_removed); - this.set({'value': self.values}); + this.values = _.difference(this.values, values_removed); + this.set({'value': this.values}); return false; } // find not checked values - var not_checked = _.difference(self.get('value'), self.values); + var not_checked = _.difference(this.get('value'), this.values); // find not checked values and not on checking - var not_checked = _.difference(not_checked, self.values_checking); + var not_checked = _.difference(not_checked, this.values_checking); - _.each(not_checked, function (val, key) { - self.values_checking.push(val); - self._check_email_popup(val); - }); + if(not_checked.length) { + // remember values on checking for cheked only one time + this.values_checking = this.values_checking.concat(not_checked); + // check values + this._check_email_popup(not_checked); + } }, - _check_email_popup: function (id) { + _check_email_popup: function (ids) { var self = this; - new instance.web.Model('res.partner').call("read", [id, ["email", "notification_email_send"]], {context: this.build_context()}) - .pipe(function (dict) { - if (!dict.email && (dict.notification_email_send == 'all' || dict.notification_email_send == 'comment')) { + new instance.web.Model('res.partner').call("search", [[ + ["id", "in", ids], + ["email", "=", false], + ["notification_email_send", "in", ['all', 'comment']] ]], + {context: this.build_context()}) + .pipe(function (record_ids) { + // valid partner + var valid_partner = _.difference(ids, record_ids); + self.values = self.values.concat(valid_partner); + self.values_checking = _.difference(self.values_checking, valid_partner); + + // unvalid partner + _.each(record_ids, function(id) { var pop = new instance.web.form.FormOpenPopup(self); pop.show_element( 'res.partner', - dict.id, + id, self.build_context(), { title: _t("Please complete partner's informations and Email"), } ); pop.on('write_completed', self, function () { - self._checked(dict.id, true); + this.values.push(id); + this.values_checking = _.without(this.values_checking, id); + this.set({'value': this.values}); }); pop.on('closed', self, function () { - self._checked(dict.id, false); + this.values_checking = _.without(this.values_checking, id); + this.set({'value': this.values}); }); - } else { - self._checked(dict.id, true); - } + }); }); }, - - _checked: function (id, access) { - if (access) { - this.values.push(id); - } - this.values_checking = _.without(this.values_checking, id); - this.set({'value': this.values}); - }, }); From 7b5d0af159ba9cf33f121e56f0cd68521250787e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 6 Nov 2012 16:57:02 +0100 Subject: [PATCH 7/8] [CLEAN] mail.js: removed unnecessary default values in context. bzr revid: tde@openerp.com-20121106155702-bq5xg7z6qmwqjema --- addons/mail/static/src/js/mail.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index a9783c32049..1eb3c29e556 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1642,8 +1642,6 @@ openerp.mail = function (session) { views: [[false, 'form']], target: 'new', context: { - 'default_model': '', - 'default_res_id': false, 'default_content_subtype': 'html', }, }; From 56f04649cc9ea8896d5d6df1f5695d4558d21294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 6 Nov 2012 16:58:13 +0100 Subject: [PATCH 8/8] [REVIEW] Some code cleaning in js. bzr revid: tde@openerp.com-20121106155813-h2zswqc16z6ev2k9 --- addons/mail/static/src/js/many2many_tags_email.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js index 234dc504682..52dcbf7aeb5 100644 --- a/addons/mail/static/src/js/many2many_tags_email.js +++ b/addons/mail/static/src/js/many2many_tags_email.js @@ -23,20 +23,15 @@ instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags // filter for removed values var values_removed = _.difference(this.values, this.get('value')); - if (values_removed.length) { this.values = _.difference(this.values, values_removed); this.set({'value': this.values}); return false; } - // find not checked values - var not_checked = _.difference(this.get('value'), this.values); - - // find not checked values and not on checking - var not_checked = _.difference(not_checked, this.values_checking); - - if(not_checked.length) { + // find not checked values that are not currently on checking + var not_checked = _.difference(this.get('value'), this.values, this.values_checking); + if (not_checked.length) { // remember values on checking for cheked only one time this.values_checking = this.values_checking.concat(not_checked); // check values @@ -58,7 +53,7 @@ instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags self.values_checking = _.difference(self.values_checking, valid_partner); // unvalid partner - _.each(record_ids, function(id) { + _.each(record_ids, function (id) { var pop = new instance.web.form.FormOpenPopup(self); pop.show_element( 'res.partner', @@ -90,4 +85,4 @@ instance.web.form.widgets = instance.web.form.widgets.extend({ 'many2many_tags_email' : 'instance.web.form.FieldMany2ManyTagsEmail', }); -}; \ No newline at end of file +};