summaryrefslogtreecommitdiff
path: root/web-ui
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-03 14:35:48 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-03 14:35:48 -0300
commit3bd6b15a18d5fc89506fb40becd7ad7b7449d7da (patch)
treeabc3a2eff7ca0adfa1e2bc42271252fd4ed4a852 /web-ui
parent2b35e3c95e239db22fe189f8b0ac09ae02948259 (diff)
reactivating reply/reply all/forward; deactivating reply draft
Diffstat (limited to 'web-ui')
-rw-r--r--web-ui/app/js/mixins/with_mail_edit_base.js2
-rw-r--r--web-ui/app/js/services/mail_service.js93
2 files changed, 50 insertions, 45 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 ea0ecaaf..4710cb74 100644
--- a/web-ui/app/js/mixins/with_mail_edit_base.js
+++ b/web-ui/app/js/mixins/with_mail_edit_base.js
@@ -169,7 +169,7 @@ define(
}
function emailFormatChecker(email) {
- var emailFormat = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+ var emailFormat = /[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailFormat.test(email);
}
diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js
index 3b78b6c5..d9090ee7 100644
--- a/web-ui/app/js/services/mail_service.js
+++ b/web-ui/app/js/services/mail_service.js
@@ -43,33 +43,33 @@ define(
w: 25
});
- this.errorMessage = function(msg) {
- return function() {
+ this.errorMessage = function (msg) {
+ return function () {
that.trigger(document, events.ui.userAlerts.displayMessage, { message: msg });
};
};
- this.updateTags = function(ev, data) {
+ this.updateTags = function (ev, data) {
var that = this;
var ident = data.ident;
$.ajax('/mail/' + ident + '/tags', {
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({newtags: data.tags})
- }).done(function(data) {
+ }).done(function (data) {
that.refreshResults();
$(document).trigger(events.mail.tags.updated, { ident: ident, tags: data });
})
- .fail(this.errorMessage(i18n('Could not update mail tags')));
+ .fail(this.errorMessage(i18n('Could not update mail tags')));
};
- this.readMail = function(ev, data) {
+ this.readMail = function (ev, data) {
var mailIdents;
if (data.checkedMails) {
- mailIdents = _.map(data.checkedMails, function(mail) {
+ mailIdents = _.map(data.checkedMails, function (mail) {
return mail.ident;
});
- $.ajax( '/mails/read', {
+ $.ajax('/mails/read', {
type: 'POST',
data: {idents: JSON.stringify(mailIdents)}
}).done(this.triggerMailsRead(data.checkedMails));
@@ -78,13 +78,13 @@ define(
}
};
- this.unreadMail = function(ev, data) {
+ this.unreadMail = function (ev, data) {
var mailIdents;
if (data.checkedMails) {
- mailIdents = _.map(data.checkedMails, function(mail) {
+ mailIdents = _.map(data.checkedMails, function (mail) {
return mail.ident;
});
- $.ajax( '/mails/unread', {
+ $.ajax('/mails/unread', {
type: 'POST',
data: {idents: JSON.stringify(mailIdents)}
}).done(this.triggerMailsRead(data.checkedMails));
@@ -93,16 +93,16 @@ define(
}
};
- this.triggerMailsRead = function(mails) {
- return _.bind(function() {
+ this.triggerMailsRead = function (mails) {
+ return _.bind(function () {
this.refreshResults();
this.trigger(document, events.ui.mail.unchecked, { mails: mails });
this.trigger(document, events.ui.mails.hasMailsChecked, false);
}, this);
};
- this.triggerDeleted = function(dataToDelete) {
- return _.bind(function() {
+ this.triggerDeleted = function (dataToDelete) {
+ return _.bind(function () {
var mails = dataToDelete.mails || [dataToDelete.mail];
this.refreshResults();
@@ -113,16 +113,16 @@ define(
}, this);
};
- this.deleteMail = function(ev, data) {
+ this.deleteMail = function (ev, data) {
$.ajax('/mail/' + data.mail.ident,
- {type: 'DELETE'})
+ {type: 'DELETE'})
.done(this.triggerDeleted(data))
.fail(this.errorMessage(i18n('Could not delete email')));
};
- this.deleteManyMails = function(ev, data) {
+ this.deleteManyMails = function (ev, data) {
var dataToDelete = data;
- var mailIdents = _.map(data.mails, function(mail) {
+ var mailIdents = _.map(data.mails, function (mail) {
return mail.ident;
});
@@ -142,29 +142,29 @@ define(
return query;
}
- this.fetchByTag = function(ev, data) {
+ this.fetchByTag = function (ev, data) {
this.attr.currentTag = data.tag;
this.updateCurrentPageNumber(0);
this.fetchMail(compileQuery(data), this.attr.currentTag, false, data);
};
- this.refreshResults = function(ev, data) {
+ this.refreshResults = function (ev, data) {
var query = this.attr.lastQuery;
this.fetchMail(query, this.attr.currentTag, true);
};
- this.newSearch = function(ev, data) {
+ this.newSearch = function (ev, data) {
var query = data.query;
this.attr.currentTag = 'all';
this.fetchMail(query, 'all');
};
- this.mailFromJSON = function(mail) {
+ this.mailFromJSON = function (mail) {
return Mail.create(mail);
};
- this.parseMails = function(data) {
+ this.parseMails = function (data) {
data.mails = _.map(data.mails, this.mailFromJSON, this);
return data;
@@ -174,7 +174,7 @@ define(
return encodeURI(s);
}
- this.excludeTrashedEmailsForDraftsAndSent = function(query) {
+ this.excludeTrashedEmailsForDraftsAndSent = function (query) {
if (query === 'tag:"drafts"' || query === 'tag:"sent"') {
return query + ' -in:"trash"';
} else {
@@ -182,31 +182,31 @@ define(
}
};
- this.fetchMail = function(query, tag, fromRefresh, eventData) {
+ this.fetchMail = function (query, tag, fromRefresh, eventData) {
var p = this.attr.currentPage;
var w = this.attr.w;
- var url = this.attr.mailsResource + '?q='+ escaped(this.excludeTrashedEmailsForDraftsAndSent(query)) + '&p=' + p + '&w=' + w;
+ var url = this.attr.mailsResource + '?q=' + escaped(this.excludeTrashedEmailsForDraftsAndSent(query)) + '&p=' + p + '&w=' + w;
this.attr.lastQuery = this.excludeTrashedEmailsForDraftsAndSent(query);
$.ajax(url, { dataType: 'json' })
- .done(function(data) {
+ .done(function (data) {
this.attr.numPages = Math.ceil(data.stats.total / this.attr.w);
var eventToTrigger = fromRefresh ? events.mails.availableForRefresh : events.mails.available;
this.trigger(document, eventToTrigger, _.merge(_.merge({tag: tag }, eventData), this.parseMails(data)));
}.bind(this))
- .fail(function() {
+ .fail(function () {
this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n('Could not fetch messages') });
}.bind(this));
};
- function createSingleMailUrl(mailsResource, ident){
+ function createSingleMailUrl(mailsResource, ident) {
return mailsResource + '/' + ident;
}
- this.fetchSingle = function(event, data) {
+ this.fetchSingle = function (event, data) {
var fetchUrl = createSingleMailUrl(this.attr.singleMailResource, data.mail);
$.ajax(fetchUrl, { dataType: 'json' })
- .done(function(mail) {
+ .done(function (mail) {
if (_.isNull(mail)) {
this.trigger(data.caller, events.mail.notFound);
return;
@@ -216,21 +216,21 @@ define(
}.bind(this));
};
- this.previousPage = function() {
- if(this.attr.currentPage > 0) {
+ this.previousPage = function () {
+ if (this.attr.currentPage > 0) {
this.updateCurrentPageNumber(this.attr.currentPage - 1);
this.refreshResults();
}
};
- this.nextPage = function() {
- if(this.attr.currentPage < (this.attr.numPages - 1)) {
+ this.nextPage = function () {
+ if (this.attr.currentPage < (this.attr.numPages - 1)) {
this.updateCurrentPageNumber(this.attr.currentPage + 1);
this.refreshResults();
}
};
- this.updateCurrentPageNumber = function(newCurrentPage) {
+ this.updateCurrentPageNumber = function (newCurrentPage) {
this.attr.currentPage = newCurrentPage;
this.trigger(document, events.ui.page.changed, {
currentPage: this.attr.currentPage,
@@ -238,9 +238,14 @@ define(
});
};
- this.wantDraftReplyForMail = function(ev, data) {
+ this.wantDraftReplyForMail = function (ev, data) {
+ if (!features.isEnabled('draftReply')) {
+ this.trigger(document, events.mail.draftReply.notFound);
+ return;
+ }
+
$.ajax('/draft_reply_for/' + data.ident, { dataType: 'json' })
- .done(function(mail) {
+ .done(function (mail) {
if (_.isNull(mail)) {
this.trigger(document, events.mail.draftReply.notFound);
return;
@@ -252,17 +257,17 @@ define(
this.after('initialize', function () {
that = this;
+ if (features.isEnabled('tags')) {
+ this.on(events.mail.tags.update, this.updateTags);
+ }
+
+ this.on(events.mail.draftReply.want, this.wantDraftReplyForMail);
this.on(events.mail.want, this.fetchSingle);
this.on(events.mail.read, this.readMail);
this.on(events.mail.unread, this.unreadMail);
- if(features.isEnabled('tags')) {
- this.on(events.mail.tags.update, this.updateTags);
- }
this.on(events.mail.delete, this.deleteMail);
this.on(events.mail.deleteMany, this.deleteManyMails);
this.on(events.search.perform, this.newSearch);
- this.on(events.mail.draftReply.want, this.wantDraftReplyForMail);
-
this.on(events.ui.mails.fetchByTag, this.fetchByTag);
this.on(events.ui.mails.refresh, this.refreshResults);
this.on(events.ui.page.previous, this.previousPage);