From 40b1c95e1a0932f4d1f87bf9894a169b2c9e57ff Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 20 Dec 2012 13:31:22 +0100 Subject: [IMP]mail: display checkbox for allow to add email (from email_from value) for creating partner and send email to this new partners. bzr revid: chm@openerp.com-20121220123122-qsqn8w97t1tre3cq --- addons/mail/static/src/js/mail.js | 70 +++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f873daff9c3..a770b07be17 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -369,6 +369,7 @@ openerp.mail = function (session) { this._super(parent, datasets, options); this.show_compact_message = false; this.show_delete_attachment = true; + this.emails_from = []; }, start: function () { @@ -478,9 +479,11 @@ openerp.mail = function (session) { this.$('.oe_cancel').on('click', _.bind( this.on_cancel, this) ); this.$('.oe_post').on('click', _.bind( this.on_message_post, this) ); this.$('.oe_full').on('click', _.bind( this.on_compose_fullmail, this, this.id ? 'reply' : 'comment') ); - + /* stack for don't close the compose form if the user click on a button */ - this.$('.oe_msg_footer').on('mousedown', _.bind( function () { this.stay_open = true; }, this)); + this.$('.oe_msg_left, .oe_msg_center').on('mousedown', _.bind( function () { this.stay_open = true; }, this)); + this.$('.oe_msg_left, .oe_msg_content').on('mouseup', _.bind( function () { this.$('textarea').focus(); }, this)); + var ev_stay = {}; ev_stay.mouseup = ev_stay.keydown = ev_stay.focus = function () { self.stay_open = false; }; this.$('textarea:not(.oe_compact)').on(ev_stay); @@ -491,6 +494,8 @@ openerp.mail = function (session) { // event: delete child attachments off the oe_msg_attachment_list box this.$(".oe_msg_attachment_list").on('click', '.oe_delete', this.on_attachment_delete); + + this.$(".oe_emails_from").on('change', 'input', this.on_checked_email_from); }, on_compose_fullmail: function (default_composition_mode) { @@ -568,21 +573,23 @@ openerp.mail = function (session) { if (this.do_check_attachment_upload() && (this.attachment_ids.length || body.match(/\S+/))) { //session.web.blockUI(); - this.parent_thread.ds_thread.call('message_post_user_api', [ - this.context.default_res_id, - body, - false, - this.context.default_parent_id, - _.map(this.attachment_ids, function (file) {return file.id;}), - this.parent_thread.context - ]).done(function (record) { + var values = [ + this.context.default_res_id, //thread_id + body, //body + false, //subject + this.context.default_parent_id, //parent_id + _.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids + _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email + this.parent_thread.context, // context + ]; + this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (record) { var thread = self.parent_thread; var root = thread == self.options.root_thread; if (self.options.display_indented_thread < self.thread_level && thread.parent_message) { var thread = thread.parent_message.parent_thread; } // create object and attach to the thread object - thread.message_fetch([['id', 'child_of', [self.id]]], false, [record], function (arg, data) { + thread.message_fetch([["id", "=", record]], false, [record], function (arg, data) { var message = thread.create_message_object( data[0] ); // insert the message on dom thread.insert_message( message, root ? undefined : self.$el, root ); @@ -597,8 +604,8 @@ openerp.mail = function (session) { /* convert the compact mode into the compose message */ on_compose_expandable: function (event) { - - if ((!this.stay_open || (event && event.type == 'click')) && (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/))) { + this.get_emails_from(); + if ((!this.stay_open || (event && event.type == 'click')) && (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/) && !this.attachment_ids.length)) { this.show_composer = !this.show_composer || this.stay_open; this.reinit(); } @@ -620,6 +627,41 @@ openerp.mail = function (session) { if (!this.show_composer) { this.reinit(); } + }, + + get_emails_from: function () { + var self = this; + var messages = []; + + if (this.parent_thread.parent_message) { + // go to the parented message + var message = this.parent_thread.parent_message; + var parent_message = message.parent_id ? message.parent_thread.parent_message : message; + var messages = [parent_message].concat(parent_message.get_childs()); + } else { + // get all wall messages + _.each(this.options.root_thread.messages, function (msg) {messages.push(msg); messages.concat(msg.get_childs());}); + } + + var emails_from = _.map(_.filter(messages, + function (thread) {return thread.author_id && !thread.author_id[0];}), + function (thread) {return thread.author_id[1];}); + + return _.each(emails_from, function (email_from) { + if (!_.find(self.emails_from, function (from) {return from[0] == email_from;})) { + self.emails_from.push([email_from, true]); + } + }); + }, + + on_checked_email_from: function (event) { + var $input = $(event.target); + var email = $input.attr("data"); + _.each(this.emails_from, function (email_from) { + if (email_from[0] == email) { + email_from[1] = $input.is(":checked"); + } + }); } }); @@ -1477,7 +1519,7 @@ openerp.mail = function (session) { $(window).resize( _.bind(this.thread.on_scroll, this.thread) ); this.$el.resize( _.bind(this.thread.on_scroll, this.thread) ); window.setTimeout( _.bind(this.thread.on_scroll, this.thread), 500 ); - } + }, }); -- cgit v1.2.3 From 863c7f421d23af8b12cab1577aed1fb3eb22f182 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 20 Dec 2012 16:46:04 +0100 Subject: [IMP] mail: option to don't display email_from partners on the top composer bzr revid: chm@openerp.com-20121220154604-f6zvrbrqxjawropq --- addons/mail/static/src/js/mail.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index a770b07be17..5b574eada65 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -638,8 +638,8 @@ openerp.mail = function (session) { var message = this.parent_thread.parent_message; var parent_message = message.parent_id ? message.parent_thread.parent_message : message; var messages = [parent_message].concat(parent_message.get_childs()); - } else { - // get all wall messages + } else if (this.options.emails_from_on_composer) { + // get all wall messages if is not a mail.Wall _.each(this.options.root_thread.messages, function (msg) {messages.push(msg); messages.concat(msg.get_childs());}); } @@ -1479,6 +1479,7 @@ openerp.mail = function (session) { 'message_ids': undefined, 'compose_as_todo' : false, 'readonly' : false, + 'emails_from_on_composer': true, }, this.action.params); this.action.params.help = this.action.help || false; @@ -1643,6 +1644,7 @@ openerp.mail = function (session) { 'show_record_name': true, 'show_compact_message': this.action.params.view_mailbox ? false : 1, 'view_inbox': false, + 'emails_from_on_composer': false, }, this.action.params); }, -- cgit v1.2.3 From 507eff8255c2be196931fd8c29d3956ddc85ab1c Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 20 Dec 2012 17:27:54 +0100 Subject: [IMP] mail: after convert email_from into partner, open a dialog box to complete partner informations bzr revid: chm@openerp.com-20121220162754-v5wfxrp39nf0bkla --- addons/mail/static/src/js/mail.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 5b574eada65..0f6323ab923 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -589,12 +589,26 @@ openerp.mail = function (session) { var thread = thread.parent_message.parent_thread; } // create object and attach to the thread object - thread.message_fetch([["id", "=", record]], false, [record], function (arg, data) { + thread.message_fetch([["id", "=", record.message_id]], false, [record.message_id], function (arg, data) { var message = thread.create_message_object( data[0] ); // insert the message on dom thread.insert_message( message, root ? undefined : self.$el, root ); }); self.on_cancel(); + + if (record.new_partner_ids && record.new_partner_ids.length) { + _.each(record.new_partner_ids, function (id) { + var pop = new session.web.form.FormOpenPopup(self); + pop.show_element( + 'res.partner', + id, + self.parent_thread.context, + { + title: _t("Please complete partner's informations"), + } + ); + }); + } //session.web.unblockUI(); }); return true; -- cgit v1.2.3 From e5c67bc1b9f7627a94013e606b4664087ebd2604 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 21 Dec 2012 11:12:32 +0100 Subject: [IMP] mail: open wizard(s) to create partner(s) before send message from email bzr revid: chm@openerp.com-20121221101232-od1owyxhkhmorx5t --- addons/mail/static/src/js/mail.js | 110 ++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 46 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 0f6323ab923..ac53457ee05 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -564,57 +564,75 @@ openerp.mail = function (session) { } }, - /*post a message and fetch the message*/ - on_message_post: function (event) { + check_recipient_partners: function (emails) { var self = this; + var deferreds = []; + _.each(emails, function (email) { + var deferred = $.Deferred(); + var pop = new session.web.form.FormOpenPopup(this); + pop.show_element( + 'res.partner', + 0, + { + 'default_email': email, + 'force_email': true, + 'ref': "compound_context", + }, + { + title: _t("Please complete partner's informations"), + } + ); + pop.on('write_completed, closed', self, function () { + deferred.resolve(); + }); + deferreds.push(deferred); + }); + return $.when.apply( $, deferreds ); + }, - var comment_node = this.$('textarea'); - var body = comment_node.val(); - - if (this.do_check_attachment_upload() && (this.attachment_ids.length || body.match(/\S+/))) { - //session.web.blockUI(); - var values = [ - this.context.default_res_id, //thread_id - body, //body - false, //subject - this.context.default_parent_id, //parent_id - _.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids - _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email - this.parent_thread.context, // context - ]; - this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (record) { - var thread = self.parent_thread; - var root = thread == self.options.root_thread; - if (self.options.display_indented_thread < self.thread_level && thread.parent_message) { - var thread = thread.parent_message.parent_thread; - } - // create object and attach to the thread object - thread.message_fetch([["id", "=", record.message_id]], false, [record.message_id], function (arg, data) { - var message = thread.create_message_object( data[0] ); - // insert the message on dom - thread.insert_message( message, root ? undefined : self.$el, root ); - }); - self.on_cancel(); - - if (record.new_partner_ids && record.new_partner_ids.length) { - _.each(record.new_partner_ids, function (id) { - var pop = new session.web.form.FormOpenPopup(self); - pop.show_element( - 'res.partner', - id, - self.parent_thread.context, - { - title: _t("Please complete partner's informations"), - } - ); - }); - } - //session.web.unblockUI(); - }); - return true; + on_message_post: function (event) { + var self = this; + if (this.do_check_attachment_upload() && (this.attachment_ids.length || this.$('textarea').val().match(/\S+/))) { + // create list of new partners + var extra_email = _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}); + this.check_recipient_partners(extra_email).done(function () { + self.do_send_message_post(); + }); } }, + /*do post a message and fetch the message*/ + do_send_message_post: function () { + console.log(arguments); + return; + var self = this; + //session.web.blockUI(); + var values = [ + this.context.default_res_id, //thread_id + this.$('textarea').val(), //body + false, //subject + this.context.default_parent_id, //parent_id + _.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids + _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email + this.parent_thread.context, // context + ]; + this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (message_id) { + var thread = self.parent_thread; + var root = thread == self.options.root_thread; + if (self.options.display_indented_thread < self.thread_level && thread.parent_message) { + var thread = thread.parent_message.parent_thread; + } + // create object and attach to the thread object + thread.message_fetch([["id", "=", message_id]], false, [message_id], function (arg, data) { + var message = thread.create_message_object( data[0] ); + // insert the message on dom + thread.insert_message( message, root ? undefined : self.$el, root ); + }); + self.on_cancel(); + //session.web.unblockUI(); + }); + }, + /* convert the compact mode into the compose message */ on_compose_expandable: function (event) { -- cgit v1.2.3 From 9df82da7c011aaf6a556413ac5a2723c6db51f9f Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 21 Dec 2012 11:14:16 +0100 Subject: [FIX] mail: remove console and empty return in js bzr revid: chm@openerp.com-20121221101416-ljb3o4h3hxflz8sb --- addons/mail/static/src/js/mail.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index ac53457ee05..8c8bb170453 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -603,8 +603,6 @@ openerp.mail = function (session) { /*do post a message and fetch the message*/ do_send_message_post: function () { - console.log(arguments); - return; var self = this; //session.web.blockUI(); var values = [ -- cgit v1.2.3 From 9fe900791d1388159e600a263bbadc5683267ece Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 21 Dec 2012 12:00:03 +0100 Subject: [IMP] follower: must have access write to invite follower bzr revid: chm@openerp.com-20121221110003-h7h9cie4vcejif7z --- addons/mail/static/src/js/mail.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8c8bb170453..b7592fd8b33 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1587,6 +1587,10 @@ openerp.mail = function (session) { } this.domain = this.node.params && this.node.params.domain || []; + + if (!this.__parentedParent.is_action_enabled('edit')) { + this.node.params.show_link = false; + } }, start: function () { -- cgit v1.2.3 From 8972f7b334a569da26670040f19b7f793c1d2cd0 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 21 Dec 2012 13:11:44 +0100 Subject: [IMP] mail: check if the new email recipient already exist or not, and fix _api bzr revid: chm@openerp.com-20121221121144-o8pbya2rc7v471y0 --- addons/mail/static/src/js/mail.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index b7592fd8b33..32b6e85f118 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -567,25 +567,30 @@ openerp.mail = function (session) { check_recipient_partners: function (emails) { var self = this; var deferreds = []; + var ds_partner = new session.web.DataSetSearch(this, 'res.partner'); _.each(emails, function (email) { - var deferred = $.Deferred(); - var pop = new session.web.form.FormOpenPopup(this); - pop.show_element( - 'res.partner', - 0, - { - 'default_email': email, - 'force_email': true, - 'ref': "compound_context", - }, - { - title: _t("Please complete partner's informations"), + ds_partner.call('search', [[['email', '=', email]]]).then(function (partner_ids) { + if (!partner_ids.length) { + var deferred = $.Deferred(); + var pop = new session.web.form.FormOpenPopup(this); + pop.show_element( + 'res.partner', + 0, + { + 'default_email': email, + 'force_email': true, + 'ref': "compound_context", + }, + { + title: _t("Please complete partner's informations"), + } + ); + pop.on('write_completed, closed', self, function () { + deferred.resolve(); + }); + deferreds.push(deferred); } - ); - pop.on('write_completed, closed', self, function () { - deferred.resolve(); }); - deferreds.push(deferred); }); return $.when.apply( $, deferreds ); }, @@ -1587,7 +1592,7 @@ openerp.mail = function (session) { } this.domain = this.node.params && this.node.params.domain || []; - + if (!this.__parentedParent.is_action_enabled('edit')) { this.node.params.show_link = false; } -- cgit v1.2.3 From f922d9ea1f8124fe7785d8817397c7284e9ee0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 21 Dec 2012 15:40:14 +0100 Subject: [IMP] mail: refactored a bit the code in message_post_user_api, as well as overrides in res_partner and res_users, to use kwargs. Updated mail.js to use kwargs. Updated mail.xml and css to tweak the display. bzr revid: tde@openerp.com-20121221144014-otg03akq4c9grjmz --- addons/mail/static/src/js/mail.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 50d24b93ca4..f9ef9ef371b 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -609,17 +609,14 @@ openerp.mail = function (session) { /*do post a message and fetch the message*/ do_send_message_post: function () { var self = this; - //session.web.blockUI(); - var values = [ - this.context.default_res_id, //thread_id - this.$('textarea').val(), //body - false, //subject - this.context.default_parent_id, //parent_id - _.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids - _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email - this.parent_thread.context, // context - ]; - this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (message_id) { + this.parent_thread.ds_thread._model.call('message_post_user_api', [this.context.default_res_id], { + 'body': this.$('textarea').val(), + 'subject': false, + 'parent_id': this.context.default_parent_id, + 'attachment_ids': _.map(this.attachment_ids, function (file) {return file.id;}), + 'extra_emails': _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), + 'context': this.parent_thread.context, + }).done(function (message_id) { var thread = self.parent_thread; var root = thread == self.options.root_thread; if (self.options.display_indented_thread < self.thread_level && thread.parent_message) { @@ -632,7 +629,6 @@ openerp.mail = function (session) { thread.insert_message( message, root ? undefined : self.$el, root ); }); self.on_cancel(); - //session.web.unblockUI(); }); }, @@ -1060,7 +1056,7 @@ openerp.mail = function (session) { this.author_id = datasets.author_id || false; this.thread_level = (datasets.thread_level+1) || 0; this.partner_ids = datasets.partner_ids || []; - if (datasets.author_id) + if (datasets.author_id && datasets.author_id[0]) this.partner_ids.push(datasets.author_id); this.messages = []; -- cgit v1.2.3 From f9763f5d05166b91962a1a88e97b4a401349e3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 21 Dec 2012 16:30:07 +0100 Subject: [IMP] mail.js, xml: misc cleaning. I hate JS. bzr revid: tde@openerp.com-20121221153007-5o220hdqg9sbt3f3 --- addons/mail/static/src/js/mail.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'addons/mail/static/src/js/mail.js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f9ef9ef371b..29a2e076b19 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1055,9 +1055,11 @@ openerp.mail = function (session) { this.is_private = datasets.is_private || false; this.author_id = datasets.author_id || false; this.thread_level = (datasets.thread_level+1) || 0; - this.partner_ids = datasets.partner_ids || []; - if (datasets.author_id && datasets.author_id[0]) - this.partner_ids.push(datasets.author_id); + datasets.partner_ids = datasets.partner_ids || []; + if (datasets.author_id && ! _.contains(datasets.partner_ids, datasets.author_id) && datasets.author_id[0]) { + datasets.partner_ids.push(datasets.author_id); + } + this.partner_ids = datasets.partner_ids; this.messages = []; this.options.flat_mode = !!(this.options.display_indented_thread > this.thread_level ? this.options.display_indented_thread - this.thread_level : 0); -- cgit v1.2.3