From cd741c3cb6a9c64ad30257240565be884e9084ae Mon Sep 17 00:00:00 2001 From: Alexandre Pretto Nunes Date: Mon, 12 Jan 2015 16:49:07 -0200 Subject: #153 Move duplicated funcion render to just mail_item.js --- web-ui/app/js/mail_list/ui/mail_item_factory.js | 8 +++++++- web-ui/app/js/mail_list/ui/mail_items/draft_item.js | 11 +---------- .../js/mail_list/ui/mail_items/generic_mail_item.js | 13 ++----------- web-ui/app/js/mail_list/ui/mail_items/mail_item.js | 18 ++++++++++++++++-- web-ui/app/js/mail_list/ui/mail_items/sent_item.js | 13 ++----------- .../mail_list/ui/mail_items/generic_mail_item.spec.js | 3 ++- web-ui/test/spec/mail_list/ui/mail_list.spec.js | 1 + 7 files changed, 31 insertions(+), 36 deletions(-) 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 e922a642..8eedcde3 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 @@ -30,6 +30,11 @@ define( 'sent': SentItem }; + var TEMPLATE_TYPE = { + 'drafts': 'sent', + 'sent': 'sent' + }; + var createAndAttach = function (nodeToAttachTo, mail, currentMailIdent, currentTag, isChecked) { var mailItemContainer = $('
  • ', { id: 'mail-' + mail.ident}); nodeToAttachTo.append(mailItemContainer); @@ -44,7 +49,8 @@ define( mail: mail, selected: mail.ident === currentMailIdent, tag: currentTag, - isChecked: isChecked + isChecked: isChecked, + templateType: TEMPLATE_TYPE[currentTag] || 'single' }); }; 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 0037df02..f09add73 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 @@ -19,13 +19,12 @@ define( [ 'flight/lib/component', - 'views/templates', 'helpers/view_helper', 'mail_list/ui/mail_items/mail_item', 'page/events' ], - function (defineComponent, templates, viewHelpers, mailItem, events) { + function (defineComponent, viewHelpers, mailItem, events) { 'use strict'; return defineComponent(draftItem, mailItem); @@ -45,14 +44,6 @@ define( ev.preventDefault(); // don't let the hashchange trigger a popstate }; - this.render = function () { - var mailItemHtml = templates.mails.sent(this.attr); - 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.after('initialize', function () { this.initializeAttributes(); this.render(); 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 eb4d2ca5..1117d44d 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 @@ -19,13 +19,12 @@ define( [ 'flight/lib/component', - 'views/templates', 'helpers/view_helper', 'mail_list/ui/mail_items/mail_item', 'page/events' ], - function (defineComponent, templates, viewHelpers, mailItem, events) { + function (defineComponent, viewHelpers, mailItem, events) { 'use strict'; return defineComponent(genericMailItem, mailItem); @@ -84,17 +83,9 @@ define( } }; - this.render = function () { - this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); - var mailItemHtml = templates.mails.single(this.attr); - 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.after('initialize', function () { this.initializeAttributes(); + this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); this.render(); this.attachListeners(); 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 ed1fd07f..6d37a227 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 @@ -17,8 +17,12 @@ 'use strict'; define( - ['helpers/view_helper', - 'page/events'], function (viewHelper, events) { + [ + 'helpers/view_helper', + 'views/templates', + 'page/events' + ], + function (viewHelper, templates, events) { function mailItem() { this.updateSelected = function (ev, data) { @@ -58,6 +62,16 @@ define( this.triggerMailChecked({'target': {'checked': false}}); }; + this.render = function () { + this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); + debugger; + var mailItemHtml = templates.mails[this.attr.templateType](this.attr); + 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; 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 3682188b..7406b3f3 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 @@ -19,12 +19,11 @@ define( [ 'flight/lib/component', - 'views/templates', 'mail_list/ui/mail_items/mail_item', 'page/events' ], - function (defineComponent, templates, mailItem, events) { + function (defineComponent, mailItem, events) { 'use strict'; return defineComponent(sentItem, mailItem); @@ -50,17 +49,9 @@ define( this.trigger(document, events.ui.mail.updateSelected, { ident: this.attr.ident }); }; - this.render = function () { - this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); - var mailItemHtml = templates.mails.sent(this.attr); - 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.after('initialize', function () { this.initializeAttributes(); + this.attr.tagsForListView = _.without(this.attr.tags, this.attr.tag); this.render(); this.attachListeners(); diff --git a/web-ui/test/spec/mail_list/ui/mail_items/generic_mail_item.spec.js b/web-ui/test/spec/mail_list/ui/mail_items/generic_mail_item.spec.js index 3541506c..88735302 100644 --- a/web-ui/test/spec/mail_list/ui/mail_items/generic_mail_item.spec.js +++ b/web-ui/test/spec/mail_list/ui/mail_items/generic_mail_item.spec.js @@ -11,7 +11,8 @@ describeComponent('mail_list/ui/mail_items/generic_mail_item', function () { this.setupComponent('
  • ', { mail: mail, selected: false, - tag: 'inbox' + tag: 'inbox', + templateType: 'single' }); }); 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 095a2a61..1551643d 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 @@ -136,6 +136,7 @@ describeComponent('mail_list/ui/mail_list', function () { it('should open draft in popstate event if tag is Drafts', function () { var openDraftEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openDraft); + debugger; this.component.$node.trigger(Pixelated.events.mails.available, { mails: mailList, mailIdent: '30', tag: 'drafts' }); expect(openDraftEvent).toHaveBeenTriggeredOnAndWith(document, { ident: '30'}); -- cgit v1.2.3