From ccbf5c43a954a2f890f9135f671f007de21c86aa Mon Sep 17 00:00:00 2001 From: rafael lisboa Date: Thu, 9 Apr 2015 15:29:42 -0300 Subject: refactor mail item mixin creation and rendering --- web-ui/app/js/mail_list/ui/mail_item_factory.js | 1 + .../app/js/mail_list/ui/mail_items/draft_item.js | 2 -- .../mail_list/ui/mail_items/generic_mail_item.js | 17 +++++++---------- web-ui/app/js/mail_list/ui/mail_items/mail_item.js | 22 +++++----------------- web-ui/app/js/mail_list/ui/mail_items/sent_item.js | 3 --- 5 files changed, 13 insertions(+), 32 deletions(-) (limited to 'web-ui/app/js/mail_list/ui') diff --git a/web-ui/app/js/mail_list/ui/mail_item_factory.js b/web-ui/app/js/mail_list/ui/mail_item_factory.js index 3c815401..ddfa4c62 100644 --- a/web-ui/app/js/mail_list/ui/mail_item_factory.js +++ b/web-ui/app/js/mail_list/ui/mail_item_factory.js @@ -40,6 +40,7 @@ define( var mailItemContainer = $('
  • ', { id: 'mail-' + mail.ident}); nodeToAttachTo.append(mailItemContainer); + mail.currentTag = currentTag; var mailToCreate = MAIL_ITEM_TYPE[mail.mailbox] || GenericMailItem; mailToCreate.attachTo(mailItemContainer, { mail: mail, 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..4c4b2524 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 @@ -40,9 +40,7 @@ define( }; 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 fe77b248..efcb6cf9 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 @@ -26,7 +26,7 @@ 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(); } }; @@ -69,34 +69,22 @@ define( }; 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.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.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..6ab990dd 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 @@ -45,10 +45,7 @@ define( }; 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(); -- cgit v1.2.3 From 57770a2b6a0777656c86c7d464b5e413f904ac0e Mon Sep 17 00:00:00 2001 From: Alexandre Pretto Nunes Date: Thu, 9 Apr 2015 19:32:25 -0300 Subject: Fix mail opening and add some tests --- web-ui/app/js/mail_list/ui/mail_items/draft_item.js | 6 +++--- web-ui/app/js/mail_list/ui/mail_items/sent_item.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'web-ui/app/js/mail_list/ui') 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 4c4b2524..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,9 +33,9 @@ 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 }; 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 6ab990dd..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,16 +32,16 @@ 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 () { -- cgit v1.2.3 From 8d2869fa1fa2018772d4f310c4ba9b9c9373a667 Mon Sep 17 00:00:00 2001 From: rafael lisboa Date: Tue, 14 Apr 2015 15:01:53 -0300 Subject: remove no longer used method on mail_item --- web-ui/app/js/mail_list/ui/mail_items/mail_item.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'web-ui/app/js/mail_list/ui') 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 efcb6cf9..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 @@ -30,10 +30,6 @@ define( 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; }; @@ -72,8 +68,8 @@ define( 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); }; -- cgit v1.2.3