From 66ff78361a8ef71bc05e95e614401a114b6ae42c Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Sun, 22 Feb 2015 04:36:40 -0300 Subject: #289 making checked mail tag aware --- web-ui/app/js/mail_list/ui/mail_list.js | 16 ++++++++++------ web-ui/app/js/services/mail_service.js | 21 +++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'web-ui/app') diff --git a/web-ui/app/js/mail_list/ui/mail_list.js b/web-ui/app/js/mail_list/ui/mail_list.js index 69327a57..3f7a4da3 100644 --- a/web-ui/app/js/mail_list/ui/mail_list.js +++ b/web-ui/app/js/mail_list/ui/mail_list.js @@ -43,7 +43,7 @@ define( }); this.appendMail = function (mail) { - var isChecked = mail.ident in this.attr.checkedMails; + var isChecked = this.attr.checkedMails[this.attr.currentTag] && mail.ident in this.attr.checkedMails[this.attr.currentTag]; MailItemFactory.createAndAttach(this.$node, mail, this.attr.currentMailIdent, this.attr.currentTag, isChecked); }; @@ -117,25 +117,29 @@ define( }; this.respondWithCheckedMails = function (ev, caller) { - this.trigger(caller, events.ui.mail.hereChecked, {checkedMails: this.attr.checkedMails}); + this.trigger(caller, events.ui.mail.hereChecked, {checkedMails: this.attr.checkedMails[this.attr.currentTag]}); }; this.updateCheckAllCheckbox = function () { - this.trigger(document, events.ui.mails.hasMailsChecked, _.keys(this.attr.checkedMails).length > 0); + debugger; + this.trigger(document, events.ui.mails.hasMailsChecked, _.keys(this.attr.checkedMails[this.attr.currentTag]).length > 0); }; this.addToCheckedMails = function (ev, data) { - this.attr.checkedMails[data.mail.ident] = data.mail; + if (!this.attr.checkedMails[this.attr.currentTag]) { + this.attr.checkedMails[this.attr.currentTag] = {}; + } + this.attr.checkedMails[this.attr.currentTag][data.mail.ident] = data.mail; this.updateCheckAllCheckbox(); }; this.removeFromCheckedMails = function (ev, data) { if (data.mails) { _.each(data.mails, function (mail) { - delete this.attr.checkedMails[mail.ident]; + delete this.attr.checkedMails[this.attr.currentTag][mail.ident]; }, this); } else { - delete this.attr.checkedMails[data.mail.ident]; + delete this.attr.checkedMails[this.attr.currentTag][data.mail.ident]; } this.updateCheckAllCheckbox(); }; diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js index 1fa41619..b8e72a7f 100644 --- a/web-ui/app/js/services/mail_service.js +++ b/web-ui/app/js/services/mail_service.js @@ -75,7 +75,7 @@ define( }; - this.readMail = function (ev, data) { + function extractMailIds(data) { var mailIdents; if (data.checkedMails) { mailIdents = _.map(data.checkedMails, function (mail) { @@ -84,28 +84,25 @@ define( } else { mailIdents = [data.ident]; } + return mailIdents; + } + + this.readMail = function (ev, data) { + monitoredAjax(this, '/mails/read', { type: 'POST', - data: JSON.stringify({idents: mailIdents}) + data: JSON.stringify({idents: extractMailIds(data)}) }).done(this.triggerMailsRead(data.checkedMails)); }; this.unreadMail = function (ev, data) { - var mailIdents; - if (data.checkedMails) { - mailIdents = _.map(data.checkedMails, function (mail) { - return mail.ident; - }); - } else { - mailIdents = [data.ident]; - } monitoredAjax(this, '/mails/unread', { type: 'POST', - data: JSON.stringify({idents: mailIdents}) + data: JSON.stringify({idents: extractMailIds(data)}) }).done(this.triggerMailsRead(data.checkedMails)); }; - this.triggerMailsRead = function (mails) { + this.triggerMailsRead = function () { return _.bind(function () { this.refreshMails(); this.trigger(document, events.ui.mails.uncheckAll); -- cgit v1.2.3