Skip to content

Commit

Permalink
(js) Add batch operations in advanced search
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Jun 23, 2016
1 parent cf3a9b8 commit 13e826b
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 175 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -7,6 +7,7 @@ New features
Enhancements
- [eas] use the preferred email identity in EAS if valid (#3698)
- [eas] handle inline attachments during EAS content generation
- [web] all batch operations can now be performed on selected messages in advanced search mode

Bug fixes
- [web] fixed crash when an attachment filename has no extension
Expand Down
6 changes: 3 additions & 3 deletions UI/Templates/MailerUI/UIxMailFolderTemplate.wox
Expand Up @@ -65,11 +65,11 @@
<!-- sort mode (default) -->
<div class="md-toolbar-tools" ng-hide="mailbox.mode.search">
<md-button class="sg-icon-button" label:aria-label="Search"
ng-click="mailbox.mode.search = true">
ng-click="mailbox.searchMode()">
<md-icon>search</md-icon>
</md-button>
<a href="javascript:void(0)" class="sg-folder-name"
ng-click="mailbox.mode.search = true">{{mailbox.selectedFolder.name}}</a>
ng-click="mailbox.searchMode()">{{mailbox.selectedFolder.name}}</a>
<md-menu>
<md-button class="sg-icon-button" label:aria-label="Sort"
ng-click="$mdOpenMenu()">
Expand Down Expand Up @@ -128,7 +128,7 @@
<md-icon>arrow_back</md-icon>
</md-button>
<md-input-container class="md-flex" md-no-float="md-no-float">
<input name="folderSearch" type="search" var:minlength="minimumSearchLength" label:placeholder="Search"/>
<input name="folderSearch" type="search" var:minlength="minimumSearchLength" label:placeholder="Search" sg-focus-on="search" />
<div ng-messages="searchForm.folderSearch.$error" ng-show="searchForm.folderSearch.$dirty">
<div ng-message="minlength"><var:string value="minimumSearchLengthLabel"/></div>
</div>
Expand Down
37 changes: 22 additions & 15 deletions UI/WebServerResources/js/Mailer/Mailbox.service.js
Expand Up @@ -221,20 +221,24 @@
return Mailbox.$absolutePath(this.$account.id, this.path);
};

/**
* @function $selectedMessages
* @memberof Mailbox.prototype
* @desc Return the messages selected by the user.
* @returns Message instances
*/
Mailbox.prototype.$selectedMessages = function() {
return _.filter(this.$messages, function(message) { return message.selected; });
};

/**
* @function $selectedCount
* @memberof Mailbox.prototype
* @desc Return the number of messages selected by the user.
* @returns the number of selected messages
*/
Mailbox.prototype.$selectedCount = function() {
var count;

count = 0;
if (this.$messages) {
count = (_.filter(this.$messages, function(message) { return message.selected; })).length;
}
return count;
return this.$selectedMessages().length;
};

/**
Expand Down Expand Up @@ -542,12 +546,14 @@
* @desc Add or remove a flag on a message set
* @returns a promise of the HTTP operation
*/
Mailbox.prototype.$flagMessages = function(uids, flags, operation) {
var data = {msgUIDs: uids,
Mailbox.prototype.$flagMessages = function(messages, flags, operation) {
var data = {msgUIDs: _.map(messages, 'uid'),
flags: flags,
operation: operation};

return Mailbox.$$resource.post(this.id, 'addOrRemoveLabel', data);
return Mailbox.$$resource.post(this.id, 'addOrRemoveLabel', data).then(function() {
return messages;
});
};

/**
Expand Down Expand Up @@ -656,9 +662,9 @@
* @return a promise of the HTTP operation
*/
Mailbox.prototype.$markOrUnMarkMessagesAsJunk = function(messages) {
var _this = this, uids;
var method = (this.type == 'junk' ? 'markMessagesAsNotJunk' : 'markMessagesAsJunk');
uids = _.map(messages, 'uid');
var _this = this,
uids = _.map(messages, 'uid'),
method = (this.type == 'junk' ? 'markMessagesAsNotJunk' : 'markMessagesAsJunk');

return Mailbox.$$resource.post(this.id, method, {uids: uids});
};
Expand All @@ -669,8 +675,9 @@
* @desc Copy multiple messages from the current mailbox to a target one
* @return a promise of the HTTP operation
*/
Mailbox.prototype.$copyMessages = function(uids, folder) {
var _this = this;
Mailbox.prototype.$copyMessages = function(messages, folder) {
var _this = this,
uids = _.map(messages, 'uid');

return Mailbox.$$resource.post(this.id, 'copyMessages', {uids: uids, folder: folder})
.then(function(data) {
Expand Down

0 comments on commit 13e826b

Please sign in to comment.