summaryrefslogtreecommitdiff
path: root/web-ui
diff options
context:
space:
mode:
authorDuda Dornelles <dudassdornelles@gmail.com>2014-10-20 13:28:07 +0200
committerDuda Dornelles <dudassdornelles@gmail.com>2014-10-20 13:28:07 +0200
commitf82306d6703dcad6d53c9fba64ef652a57d0608c (patch)
tree038091ca4f1ebb14f9c8cf40511b8b07753ceb27 /web-ui
parent9a4dd1a4406fb964ff0fc2dc2a658b45736c2b30 (diff)
parent13dceb0929d5b615742df3d99f868fe49c304c4b (diff)
Merge pull request #116 from pedrovereza/issue-115
#115 - Checked mails depend on current tag
Diffstat (limited to 'web-ui')
-rw-r--r--web-ui/app/js/mail_list/ui/mail_list.js15
-rw-r--r--web-ui/test/spec/mail_list/ui/mail_list.spec.js21
2 files changed, 29 insertions, 7 deletions
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 7b518320..e873d279 100644
--- a/web-ui/app/js/mail_list/ui/mail_list.js
+++ b/web-ui/app/js/mail_list/ui/mail_list.js
@@ -75,7 +75,10 @@ define(
if (data.ident) {
self.attr.currentMailIdent = data.ident;
}
+
self.attr.currentTag = data.tag || self.attr.currentTag;
+
+ self.updateCheckAllCheckbox();
}
function renderMails(mails) {
@@ -132,17 +135,25 @@ 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.checkedMailsForCurrentTag()});
};
this.updateCheckAllCheckbox = function () {
- if (_.keys(this.attr.checkedMails).length > 0) {
+ if (this.checkedMailsForCurrentTag().length > 0) {
this.trigger(document, events.ui.mails.hasMailsChecked, true);
} else {
this.trigger(document, events.ui.mails.hasMailsChecked, false);
}
};
+ this.checkedMailsForCurrentTag = function() {
+ var checkedMailsForCurrentTag = _.filter(self.attr.checkedMails, function(mail) {
+ return _.contains(mail.tags, self.attr.currentTag);
+ });
+
+ return checkedMailsForCurrentTag.length > 0 ? checkedMailsForCurrentTag : {};
+ }
+
this.addToSelectedMails = function (ev, data) {
this.attr.checkedMails[data.mail.ident] = data.mail;
this.updateCheckAllCheckbox();
diff --git a/web-ui/test/spec/mail_list/ui/mail_list.spec.js b/web-ui/test/spec/mail_list/ui/mail_list.spec.js
index 872c7bb4..d90f906c 100644
--- a/web-ui/test/spec/mail_list/ui/mail_list.spec.js
+++ b/web-ui/test/spec/mail_list/ui/mail_list.spec.js
@@ -70,17 +70,18 @@ describeComponent('mail_list/ui/mail_list', function () {
expect(this.component.attr.checkedMails).toEqual(checkedMails);
});
- it('returns the list of checked mails to whomever requests them', function () {
+ it('returns the list of checked mails based on the current tag to whomever requests them', function () {
var caller = {};
- this.component.attr.checkedMails = {'1': {}};
+ this.component.attr.checkedMails = mailList;
+ this.component.attr.currentTag = 'inbox';
var mailHereCheckedEvent = spyOnEvent(caller, Pixelated.events.ui.mail.hereChecked);
$(document).trigger(Pixelated.events.ui.mail.wantChecked, caller);
- expect(mailHereCheckedEvent).toHaveBeenTriggeredOnAndWith(caller, { checkedMails: {'1': {} }});
+ expect(mailHereCheckedEvent).toHaveBeenTriggeredOnAndWith(caller, { checkedMails: mailList });
});
- it('returns an empty list to whomever requests the checked mails if there are no checked mails', function () {
+ it('returns an empty list to whomever requests the checked mails if there are no checked mails with the current tag', function () {
var caller = {};
var mailHereCheckedEvent = spyOnEvent(caller, Pixelated.events.ui.mail.hereChecked);
@@ -101,8 +102,18 @@ describeComponent('mail_list/ui/mail_list', function () {
expect(this.component.attr.checkedMails).toEqual({'2': {}, '3': {} });
});
- it('checks the check all checkbox if at least one mail is checked', function () {
+ it ('does not check the all checkbox if no mail checked has the current tag', function () {
+ var setCheckAllCheckboxEvent = spyOnEvent(document, Pixelated.events.ui.mails.hasMailsChecked);
+ this.component.attr.currentTag = 'inbox';
+
+ $(document).trigger(Pixelated.events.ui.mail.checked, {mail : {'1' : {tags: ['different']}}});
+
+ expect(setCheckAllCheckboxEvent).toHaveBeenTriggeredOnAndWith(document, false);
+ });
+
+ it('checks the check all checkbox if at least one mail is checked with the current tag', function () {
var setCheckAllCheckboxEvent = spyOnEvent(document, Pixelated.events.ui.mails.hasMailsChecked);
+ this.component.attr.currentTag = 'inbox';
$(document).trigger(Pixelated.events.ui.mail.checked, {mail: mailList[0]});