diff options
Diffstat (limited to 'web-ui/app/js/mail_list/ui/mail_items')
4 files changed, 32 insertions, 52 deletions
diff --git a/web-ui/app/js/mail_list/ui/mail_items/draft_item.js b/web-ui/app/js/mail_list/ui/mail_items/draft_item.js index fda6c3f8..57fbafd5 100644 --- a/web-ui/app/js/mail_list/ui/mail_items/draft_item.js +++ b/web-ui/app/js/mail_list/ui/mail_items/draft_item.js @@ -33,16 +33,14 @@ define( if (this.isOpeningOnANewTab(ev)) { return; } - this.trigger(document, events.dispatchers.rightPane.openDraft, { ident: this.attr.ident }); - this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.ident }); - this.trigger(document, events.router.pushState, { mailIdent: this.attr.ident }); + this.trigger(document, events.dispatchers.rightPane.openDraft, { ident: this.attr.mail.ident }); + this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.mail.ident }); + this.trigger(document, events.router.pushState, { mailIdent: this.attr.mail.ident }); ev.preventDefault(); // don't let the hashchange trigger a popstate }; this.after('initialize', function () { - this.initializeAttributes(); this.render(); - this.attachListeners(); if (this.attr.isChecked) { this.checkCheckbox(); diff --git a/web-ui/app/js/mail_list/ui/mail_items/generic_mail_item.js b/web-ui/app/js/mail_list/ui/mail_items/generic_mail_item.js index b700eeeb..939f7e1b 100644 --- a/web-ui/app/js/mail_list/ui/mail_items/generic_mail_item.js +++ b/web-ui/app/js/mail_list/ui/mail_items/generic_mail_item.js @@ -38,14 +38,14 @@ define( updateMailStatusToRead.call(this); return; } - this.trigger(document, events.ui.mail.open, { ident: this.attr.ident }); - this.trigger(document, events.router.pushState, { mailIdent: this.attr.ident }); + this.trigger(document, events.ui.mail.open, { ident: this.attr.mail.ident }); + this.trigger(document, events.router.pushState, { mailIdent: this.attr.mail.ident }); ev.preventDefault(); // don't let the hashchange trigger a popstate }; function updateMailStatusToRead() { if (!_.contains(this.attr.mail.status, this.status.READ)) { - var mail_read_data = { ident: this.attr.ident, tags: this.attr.tags, mailbox: this.attr.mailbox }; + var mail_read_data = { ident: this.attr.mail.ident, tags: this.attr.mail.tags, mailbox: this.attr.mail.mailbox }; this.trigger(document, events.mail.read, mail_read_data); this.attr.mail.status.push(this.status.READ); this.$node.addClass(viewHelpers.formatStatusClasses(this.attr.mail.status)); @@ -53,16 +53,16 @@ define( } this.openMail = function (ev, data) { - if (data.ident !== this.attr.ident) { + if (data.ident !== this.attr.mail.ident) { return; } updateMailStatusToRead.call(this); - this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.ident }); + this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.mail.ident }); }; this.updateTags = function(ev, data) { - if(data.ident === this.attr.ident){ + if(data.ident === this.attr.mail.ident){ this.attr.tags = data.tags; if(!_.contains(this.attr.tags, this.attr.tag)) { this.teardown(); @@ -73,16 +73,13 @@ define( }; this.deleteMail = function(ev, data) { - if(data.mail.ident === this.attr.ident){ + if(data.mail.ident === this.attr.mail.ident){ this.teardown(); } }; this.after('initialize', function () { - this.initializeAttributes(); - this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); this.render(); - this.attachListeners(); if (this.attr.isChecked) { this.checkCheckbox(); diff --git a/web-ui/app/js/mail_list/ui/mail_items/mail_item.js b/web-ui/app/js/mail_list/ui/mail_items/mail_item.js index bcd0444b..266db926 100644 --- a/web-ui/app/js/mail_list/ui/mail_items/mail_item.js +++ b/web-ui/app/js/mail_list/ui/mail_items/mail_item.js @@ -1,6 +1,6 @@ /* * Copyright (c) 2014 ThoughtWorks, Inc. - * + * * Pixelated is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -26,14 +26,10 @@ define( function mailItem() { this.updateSelected = function (ev, data) { - if(data.ident === this.attr.ident) { this.doSelect(); } + if (data.ident === this.attr.mail.ident) { this.doSelect(); } else { this.doUnselect(); } }; - this.formattedDate = function (date) { - return viewHelper.getFormattedDate(new Date(date)); - }; - this.isOpeningOnANewTab = function (ev) { return ev.metaKey || ev.ctrlKey || ev.which === 2; }; @@ -46,9 +42,12 @@ define( this.$node.removeClass('selected'); }; - this.triggerMailChecked = function (ev, data) { - var eventToTrigger = ev.target.checked ? events.ui.mail.checked : events.ui.mail.unchecked; - this.trigger(document, eventToTrigger, { mail: this.attr.mail}); + this.doMailChecked = function (ev) { + if (ev.target.checked) { + this.checkCheckbox(); + } else { + this.uncheckCheckbox(); + } }; this.checkboxElement = function () { @@ -57,42 +56,31 @@ define( this.checkCheckbox = function () { this.checkboxElement().prop('checked', true); - this.triggerMailChecked({'target': {'checked': true}}); + this.trigger(document, events.ui.mail.checked, { mail: this.attr.mail}); }; this.uncheckCheckbox = function () { this.checkboxElement().prop('checked', false); - this.triggerMailChecked({'target': {'checked': false}}); + this.trigger(document, events.ui.mail.unchecked, { mail: this.attr.mail}); }; this.render = function () { - this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); - var mailItemHtml = templates.mails[this.attr.templateType](this.attr); + this.attr.mail.tagsForListView = _.without(this.attr.mail.tags, this.attr.tag); + var mailItemHtml = templates.mails[this.attr.templateType](this.attr.mail); this.$node.html(mailItemHtml); - this.$node.addClass(this.attr.statuses); - if(this.attr.selected) { this.doSelect(); } + this.$node.addClass(viewHelper.formatStatusClasses(this.attr.mail.status)); + if (this.attr.selected) { this.doSelect(); } this.on(this.$node.find('a'), 'click', this.triggerOpenMail); }; - this.initializeAttributes = function () { - var mail = this.attr.mail; - this.attr.ident = mail.ident; - this.attr.header = mail.header; - this.attr.ident = mail.ident; - this.attr.statuses = viewHelper.formatStatusClasses(mail.status); - this.attr.tags = mail.tags; - this.attr.attachments = mail.attachments; - this.attr.mailbox = mail.mailbox; - this.attr.header.formattedDate = this.formattedDate(mail.header.date); - }; - - this.attachListeners = function () { - this.on(this.$node.find('input[type=checkbox]'), 'change', this.triggerMailChecked); + this.after('initialize', function () { + this.on(this.$node.find('input[type=checkbox]'), 'change', this.doMailChecked); this.on(document, events.ui.mails.cleanSelected, this.doUnselect); this.on(document, events.ui.tag.select, this.doUnselect); + this.on(document, events.ui.tag.select, this.uncheckCheckbox); this.on(document, events.ui.mails.uncheckAll, this.uncheckCheckbox); this.on(document, events.ui.mails.checkAll, this.checkCheckbox); - }; + }); } return mailItem; diff --git a/web-ui/app/js/mail_list/ui/mail_items/sent_item.js b/web-ui/app/js/mail_list/ui/mail_items/sent_item.js index 3cfa25bd..9e511068 100644 --- a/web-ui/app/js/mail_list/ui/mail_items/sent_item.js +++ b/web-ui/app/js/mail_list/ui/mail_items/sent_item.js @@ -32,23 +32,20 @@ define( if (this.isOpeningOnANewTab(ev)) { return; } - this.trigger(document, events.ui.mail.open, { ident: this.attr.ident }); - this.trigger(document, events.router.pushState, { mailIdent: this.attr.ident }); + this.trigger(document, events.ui.mail.open, { ident: this.attr.mail.ident }); + this.trigger(document, events.router.pushState, { mailIdent: this.attr.mail.ident }); ev.preventDefault(); // don't let the hashchange trigger a popstate }; this.openMail = function (ev, data) { - if (data.ident !== this.attr.ident) { + if (data.ident !== this.attr.mail.ident) { return; } - this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.ident }); + this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.mail.ident }); }; this.after('initialize', function () { - this.initializeAttributes(); - this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); this.render(); - this.attachListeners(); if (this.attr.isChecked) { this.checkCheckbox(); |