summaryrefslogtreecommitdiff
path: root/web-ui/app/js/mixins
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2016-01-11 16:55:25 +0100
committerNavaL <mnandri@thoughtworks.com>2016-01-11 16:56:29 +0100
commit058d14143c179d9923eea433fc63094f4f9059aa (patch)
treecef20e046a64cb44ad0d882465411335cf049007 /web-ui/app/js/mixins
parent64106a5d6b589616db5ddd07f383b74c66e0b39d (diff)
merging attachment_list ui and data, and making it into a mixin
Issue #573
Diffstat (limited to 'web-ui/app/js/mixins')
-rw-r--r--web-ui/app/js/mixins/with_mail_edit_base.js218
1 files changed, 112 insertions, 106 deletions
diff --git a/web-ui/app/js/mixins/with_mail_edit_base.js b/web-ui/app/js/mixins/with_mail_edit_base.js
index d0942d4e..d078c582 100644
--- a/web-ui/app/js/mixins/with_mail_edit_base.js
+++ b/web-ui/app/js/mixins/with_mail_edit_base.js
@@ -17,6 +17,7 @@
define(
[
+ 'flight/lib/compose',
'helpers/view_helper',
'mail_view/ui/recipients/recipients',
'mail_view/ui/draft_save_status',
@@ -27,7 +28,7 @@ define(
'mail_view/ui/attachment_list',
'flight/lib/utils'
],
- function (viewHelper, Recipients, DraftSaveStatus, events, i18n, SendButton, AttachmentIcon, AttachmentListUI, utils) {
+ function (compose, viewHelper, Recipients, DraftSaveStatus, events, i18n, SendButton, AttachmentIcon, attachmentList, utils) {
'use strict';
function withMailEditBase() {
@@ -93,12 +94,12 @@ define(
context.recipients = {to: [], cc: [], bcc: []};
}
this.attr.recipientValues = context.recipients;
+ this.attr.attachments = context.attachments || [];
this.attachRecipients(context);
this.on(this.select('trashButton'), 'click', this.discardMail);
SendButton.attachTo(this.select('sendButton'));
AttachmentIcon.attachTo(this.select('attachmentButton'));
- AttachmentListUI.attachTo(this.select('attachmentList'));
this.warnSendButtonOfRecipients();
};
@@ -149,108 +150,113 @@ define(
this.trigger(events.mail.send_failed);
}
};
-
- this.buildAndSaveDraft = function () {
- var mail = this.buildMail();
- this.saveDraft(mail);
- };
-
- this.recipientsUpdated = function (ev, data) {
- this.attr.recipientValues[data.recipientsName] = data.newRecipients;
- this.trigger(document, events.ui.mail.recipientsUpdated);
- if (data.skipSaveDraft) { return; }
-
- var mail = this.buildMail();
- this.postponeSaveDraft(mail);
- };
-
- this.saveDraft = function (mail) {
- this.cancelPostponedSaveDraft();
- this.trigger(document, events.mail.saveDraft, mail);
- };
-
- this.cancelPostponedSaveDraft = function() {
- clearTimeout(this.attr.timeout);
- };
-
- this.postponeSaveDraft = function (mail) {
- this.cancelPostponedSaveDraft();
-
- this.attr.timeout = window.setTimeout(_.bind(function() {
- this.saveDraft(mail);
- }, this), this.attr.saveDraftInterval);
- };
-
- this.draftSaved = function(event, data) {
- this.attr.ident = data.ident;
- };
-
- this.validateAnyRecipient = function () {
- return !_.isEmpty(_.flatten(_.values(this.attr.recipientValues)));
- };
-
- function allRecipientsAreEmails(mail) {
- var allRecipients = mail.header.to.concat(mail.header.cc).concat(mail.header.bcc);
- return _.isEmpty(allRecipients) ? false : _.all(allRecipients, emailFormatChecker);
- }
-
- function emailFormatChecker(email) {
- var emailFormat = /[^\s@]+@[^\s@]+\.[^\s@]+$/;
- return emailFormat.test(email);
- }
-
- this.saveTag = function(ev, data) {
- this.attr.currentTag = data.tag;
- };
-
- this.mailSent = function() {
- this.trigger(document, events.ui.userAlerts.displayMessage, { message: 'Your message was sent!' });
- };
-
- this.enableFloatlabel = function(element) {
- var showClass = 'showfloatlabel';
- $(element).bind('keyup', function() {
- var label = $(this).prev('label');
- if (this.value !== '') {
- label.addClass(showClass);
- $(this).addClass(showClass);
- } else {
- label.removeClass(showClass);
- $(this).removeClass(showClass);
- }
- });
- };
-
- this.toggleRecipientsArrows = function () {
- $('#cc-bcc-collapse').toggleClass('fa-angle-down');
- $('#cc-bcc-collapse').toggleClass('fa-angle-up');
- };
-
- this.before('initialize', function () {
- if (!this.discardDraft){
- this.discardDraft = function () {};
- }
- });
-
- this.bindCollapse = function () {
- this.on($('#cc-bcc-collapse'), 'click', this.toggleRecipientsArrows);
- };
-
- this.after('initialize', function () {
- this.on(document, events.dispatchers.rightPane.clear, this.teardown);
- this.on(document, events.ui.recipients.updated, this.recipientsUpdated);
- this.on(document, events.mail.draftSaved, this.draftSaved);
- this.on(document, events.mail.sent, this.mailSent);
-
- this.on(document, events.ui.mail.send, this.sendMail);
-
- this.on(document, events.ui.mail.discard, this.discardDraft);
- this.on(document, events.ui.tag.selected, this.saveTag);
- this.on(document, events.ui.tag.select, this.saveTag);
- this.bindCollapse();
- });
- }
-
- return withMailEditBase;
- });
+
+ this.buildAndSaveDraft = function () {
+ var mail = this.buildMail();
+ this.saveDraft(mail);
+ };
+
+ this.recipientsUpdated = function (ev, data) {
+ this.attr.recipientValues[data.recipientsName] = data.newRecipients;
+ this.trigger(document, events.ui.mail.recipientsUpdated);
+ if (data.skipSaveDraft) {
+ return;
+ }
+
+ var mail = this.buildMail();
+ this.postponeSaveDraft(mail);
+ };
+
+ this.saveDraft = function (mail) {
+ this.cancelPostponedSaveDraft();
+ this.trigger(document, events.mail.saveDraft, mail);
+ };
+
+ this.cancelPostponedSaveDraft = function () {
+ clearTimeout(this.attr.timeout);
+ };
+
+ this.postponeSaveDraft = function (mail) {
+ this.cancelPostponedSaveDraft();
+
+ this.attr.timeout = window.setTimeout(_.bind(function () {
+ this.saveDraft(mail);
+ }, this), this.attr.saveDraftInterval);
+ };
+
+ this.draftSaved = function (event, data) {
+ this.attr.ident = data.ident;
+ };
+
+ this.validateAnyRecipient = function () {
+ return !_.isEmpty(_.flatten(_.values(this.attr.recipientValues)));
+ };
+
+ function allRecipientsAreEmails(mail) {
+ var allRecipients = mail.header.to.concat(mail.header.cc).concat(mail.header.bcc);
+ return _.isEmpty(allRecipients) ? false : _.all(allRecipients, emailFormatChecker);
+ }
+
+ function emailFormatChecker(email) {
+ var emailFormat = /[^\s@]+@[^\s@]+\.[^\s@]+$/;
+ return emailFormat.test(email);
+ }
+
+ this.saveTag = function (ev, data) {
+ this.attr.currentTag = data.tag;
+ };
+
+ this.mailSent = function () {
+ this.trigger(document, events.ui.userAlerts.displayMessage, {message: 'Your message was sent!'});
+ };
+
+ this.enableFloatlabel = function (element) {
+ var showClass = 'showfloatlabel';
+ $(element).bind('keyup', function () {
+ var label = $(this).prev('label');
+ if (this.value !== '') {
+ label.addClass(showClass);
+ $(this).addClass(showClass);
+ } else {
+ label.removeClass(showClass);
+ $(this).removeClass(showClass);
+ }
+ });
+ };
+
+ this.toggleRecipientsArrows = function () {
+ $('#cc-bcc-collapse').toggleClass('fa-angle-down');
+ $('#cc-bcc-collapse').toggleClass('fa-angle-up');
+ };
+
+ this.before('initialize', function () {
+ if (!this.discardDraft) {
+ this.discardDraft = function () {
+ };
+ }
+ });
+
+ this.bindCollapse = function () {
+ this.on($('#cc-bcc-collapse'), 'click', this.toggleRecipientsArrows);
+ };
+
+ this.after('initialize', function () {
+ this.on(document, events.dispatchers.rightPane.clear, this.teardown);
+ this.on(document, events.ui.recipients.updated, this.recipientsUpdated);
+ this.on(document, events.mail.draftSaved, this.draftSaved);
+ this.on(document, events.mail.sent, this.mailSent);
+
+ this.on(document, events.ui.mail.send, this.sendMail);
+
+ this.on(document, events.ui.mail.discard, this.discardDraft);
+ this.on(document, events.ui.tag.selected, this.saveTag);
+ this.on(document, events.ui.tag.select, this.saveTag);
+ this.bindCollapse();
+ });
+
+ compose.mixin(this, [attachmentList]);
+ }
+
+ return withMailEditBase;
+ });