summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2012-11-05 12:25:17 +0100
committerChristophe Matthieu <chm@openerp.com>2012-11-05 12:25:17 +0100
commit356fc45fac060faeab2a7bf7ac53df0ff3692cf2 (patch)
tree7d7d4792b18062e3e072577cde180478c00c25fd
parent1db87cc080f79121dbb7bc6493f170fdd0c17f2b (diff)
[IMP] mail: add view_inbox options on js. Inside the inbox, when the user mark a message as read/done, don't apply this value, for the stared/favorite message.
bzr revid: chm@openerp.com-20121105112517-tfkao2nuukewvm2y
-rw-r--r--addons/mail/mail_thread_view.xml1
-rw-r--r--addons/mail/static/src/js/mail.js71
2 files changed, 49 insertions, 23 deletions
diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml
index 5e8cb69f146..21746212e3c 100644
--- a/addons/mail/mail_thread_view.xml
+++ b/addons/mail/mail_thread_view.xml
@@ -12,6 +12,7 @@
],
'context': {'default_model': 'res.users', 'default_res_id': uid},
'view_mailbox': True,
+ 'view_inbox': True,
'read_action': 'read', }&quot;"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js
index b4ae809d4ca..1bb0c097d51 100644
--- a/addons/mail/static/src/js/mail.js
+++ b/addons/mail/static/src/js/mail.js
@@ -158,7 +158,7 @@ openerp.mail = function (session) {
this.author_id = datasets.author_id || [this.session.uid],
this.attachment_ids = datasets.attachment_ids || [],
this.partner_ids = datasets.partner_ids || [];
- this.nb_messages = datasets.nb_messages;
+ this.nb_messages = datasets.nb_messages || false;
this._date = datasets.date;
this.format_data();
@@ -205,6 +205,28 @@ openerp.mail = function (session) {
}
},
+
+ /* get all child message id linked.
+ * @return array of id
+ */
+ get_child_ids: function () {
+ return _.map(this.get_childs(), function (val) { return val.id; });
+ },
+
+ /* get all child message linked.
+ * @return array of message object
+ */
+ get_childs: function (nb_thread_level) {
+ var res=[];
+ if (arguments[1]) res.push(this);
+ if ((isNaN(nb_thread_level) || nb_thread_level>0) && this.thread) {
+ _(this.thread.messages).each(function (val, key) {
+ res = res.concat( val.get_childs((isNaN(nb_thread_level) ? undefined : nb_thread_level-1), true) );
+ });
+ }
+ return res;
+ },
+
/**
* call on_message_delete on his parent thread
*/
@@ -214,6 +236,7 @@ openerp.mail = function (session) {
this.parent_thread.on_message_detroy(this);
}
+
});
/**
@@ -741,10 +764,10 @@ openerp.mail = function (session) {
* @param {callback} apply function
*/
check_for_rerender: function () {
- var domain = mail.ChatterUtils.expand_domain( this.options.root_thread.domain ).concat([["id", "=", this.id]]);
+
+ var domain = mail.ChatterUtils.expand_domain( this.options.root_thread.domain ).concat([["id", "in", [this.id].concat(this.get_child_ids()) ]]);
return this.parent_thread.ds_message.call('message_read', [undefined, domain, [], 0, this.context, this.parent_thread.id])
.then( _.bind(function (record) {
-
if (!record || !record.length) {
this.animated_destroy(150);
@@ -774,7 +797,20 @@ openerp.mail = function (session) {
*/
on_message_read_unread: function (read_value) {
var self = this;
- var message_ids = [this.id].concat(this.get_child_ids());
+ var messages = [this].concat(this.get_childs());
+
+ // inside the inbox, when the user mark a message as read/done, don't apply this value
+ // for the stared/favorite message
+ if (this.options.view_inbox && read_value) {
+ var messages = _.filter(messages, function (val) { return !val.is_favorite; });
+ if (!messages.length) {
+ this.check_for_rerender();
+ return false;
+ }
+ }
+
+ var message_ids = _.map(messages, function (val) { return val.id; });
+
this.ds_notification.call('set_message_read', [message_ids, read_value, this.context])
.then(function () {
self.to_read = !read_value;
@@ -820,24 +856,6 @@ openerp.mail = function (session) {
return false;
},
- /* get all child message id linked.
- * @return array of id
- */
- get_child_ids: function () {
- return _.map(this.get_childs(), function (val) { return val.id; });
- },
-
- /* get all child message linked.
- * @return array of message object
- */
- get_childs: function () {
- if (this.thread) {
- return _.map(this.thread.get_childs(), function (val) {return val.parent_message;});
- } else {
- return [];
- }
- },
-
/**
* add or remove a vote for a message and display the result
*/
@@ -869,6 +887,7 @@ openerp.mail = function (session) {
event.stopPropagation();
var self=this;
var button = self.$('.oe_star:first');
+
this.ds_message.call('favorite_toggle', [[self.id]])
.then(function (star) {
self.is_favorite=star;
@@ -876,7 +895,11 @@ openerp.mail = function (session) {
button.addClass('oe_starred');
} else {
button.removeClass('oe_starred');
- // check if the message must be display
+ }
+
+ if (self.options.view_inbox && self.is_favorite) {
+ self.on_message_read_unread(true);
+ } else {
self.check_for_rerender();
}
});
@@ -1377,6 +1400,7 @@ openerp.mail = function (session) {
'show_record_name' : false,
'show_compose_message' : false,
'show_compact_message' : false,
+ 'view_inbox': false,
'message_ids': undefined,
'no_message': false
}, options);
@@ -1578,6 +1602,7 @@ openerp.mail = function (session) {
'show_read_unread_button': true,
'show_compose_message': true,
'show_compact_message': this.context.view_mailbox ? false : 1,
+ 'view_inbox': this.context.view_inbox ? false : true,
})
);
return this.root.replace(this.$('.oe_mail-placeholder'));