Added Delete and Export features for mailboxes. Initial work for the mobile version.

This commit is contained in:
Ludovic Marcotte
2014-11-30 08:50:26 -05:00
committed by Francis Lachapelle
parent 4e9a187c85
commit 61e25184fc
7 changed files with 120 additions and 32 deletions
+4 -4
View File
@@ -218,15 +218,15 @@
<!-- dropdown menu for addressbook options button -->
<div id="folderProperties" class="f-dropdown icons-dropdown" data-dropdown-content="dropdown-content">
<ul class="button-group">
<li>
<span class="button"><i class="icon-hyperlink"><!-- links --></i></span>
</li>
<li data-ng-show="currentFolder.type == 'folder'">
<span class="button" data-ng-click="edit()"><i class="icon-pencil"><!-- rename --></i></span>
</li>
<li data-ng-show="currentFolder.type == 'folder'">
<span class="button" data-ng-click="share()"><i class="icon-earth"><!-- share --></i></span>
</li>
<li>
<span class="button" data-ng-click="exportMails()"><i class="icon-ion-ios7-upload-outline"><!-- export --></i></span>
</li>
<li data-ng-show="currentFolder.type == 'folder'">
<span class="button" data-ng-click="confirmDelete()"><i class="icon-trash"><!-- delete --></i></span>
</li>
@@ -236,7 +236,7 @@
<div id="mailboxesList" class="folders-list">
<ul data-ng-repeat="account in accounts">
<li><label>{{account.name}}</label></li>
<sg-folder-tree data-ng-repeat="folder in account.mailboxes track by folder.id"
<sg-folder-tree data-ng-repeat="folder in account.$mailboxes track by folder.id"
data-sg-root="account"
data-sg-folder="folder"
data-sg-set-folder="setCurrentFolder"><!-- tree --></sg-folder-tree>
@@ -31,7 +31,7 @@
<!-- sgFamilyTree -->
<ion-list ng-repeat="account in accounts">
<ion-item class="item-divider">{{account.name}}</ion-item>
<sg-folder-tree ng-repeat="folder in account.mailboxes track by folder.id"
<sg-folder-tree ng-repeat="folder in account.$mailboxes track by folder.id"
sg-root="account"
sg-folder="folder"
sg-set-folder="setCurrentFolder"><!-- tree --></sg-folder-tree>
@@ -66,7 +66,11 @@
* @returns a promise of the HTTP operation
*/
Account.prototype.$getMailboxes = function() {
var mailboxes = Account.$Mailbox.$find(this.id);
var _this = this;
var mailboxes = Account.$Mailbox.$find(this).then(function(data) {
_this.$mailboxes = data;
});
return mailboxes;
};
@@ -8,8 +8,8 @@
* @constructor
* @param {object} futureMailboxData - either an object literal or a promise
*/
function Mailbox(accountId, futureMailboxData) {
this.accountId = accountId;
function Mailbox(account, futureMailboxData) {
this.$account = account;
// Data is immediately available
if (typeof futureMailboxData.then !== 'function') {
angular.extend(this, futureMailboxData);
@@ -49,34 +49,56 @@
/* Factory registration in Angular module */
.factory('sgMailbox', Mailbox.$factory);
/**
* @function $delete
* @memberof Mailbox.prototype
* @desc Delete the mailbox from the server
* @returns a promise of the HTTP operation
*/
Mailbox.prototype.$delete = function() {
var _this = this,
d = Mailbox.$q.defer(),
promise;
promise = Mailbox.$$resource.remove(this.id);
promise.then(function() {
_this.$account.$getMailboxes();
d.resolve(true);
}, function(data, status) {
d.reject(data);
});
return d.promise;
};
/**
* @memberof Mailbox
* @desc Fetch list of mailboxes of a specific account
* @param {string} accountId - the account ID
* @param {string} accountId - the account
* @see {@link Account.$getMailboxes}
*/
Mailbox.$find = function(accountId) {
Mailbox.$find = function(account) {
var path, futureMailboxData;
path = Mailbox.$absolutePath(accountId);
path = Mailbox.$absolutePath(account.id);
futureMailboxData = this.$$resource.post(path, 'view', {sortingAttributes: {sort: 'date', asc: false}});
return Mailbox.$unwrapCollection(accountId, futureMailboxData); // a collection of mailboxes
return Mailbox.$unwrapCollection(account, futureMailboxData); // a collection of mailboxes
};
/**
* @memberof Mailbox
* @desc Unwrap to a collection of Mailbox instances.
* @param {string} accountId - the account ID
* @param {string} account - the account
* @param {promise} futureMailboxData - a promise of the mailboxes metadata
* @returns a promise of a collection of Mailbox objects
*/
Mailbox.$unwrapCollection = function(accountId, futureMailboxData) {
Mailbox.$unwrapCollection = function(account, futureMailboxData) {
var collection = [],
// Local recursive function
createMailboxes = function(mailbox) {
for (var i = 0; i < mailbox.children.length; i++) {
mailbox.children[i] = new Mailbox(accountId, mailbox.children[i]);
mailbox.children[i] = new Mailbox(account, mailbox.children[i]);
createMailboxes(mailbox.children[i]);
}
};
@@ -86,7 +108,7 @@
return Mailbox.$timeout(function() {
// Each entry is spun up as a Mailbox instance
angular.forEach(data.mailboxes, function(data, index) {
var mailbox = new Mailbox(accountId, data);
var mailbox = new Mailbox(account, data);
createMailboxes(mailbox); // recursively create all sub-mailboxes
collection.push(mailbox);
});
@@ -123,7 +145,7 @@
* @returns a string representing the path relative to the mail module
*/
Mailbox.prototype.$id = function() {
return Mailbox.$absolutePath(this.accountId, this.path);
return Mailbox.$absolutePath(this.$account.id, this.path);
};
/**
@@ -245,7 +267,7 @@
// Build map of UID <=> index
_this.uidsMap[data.uid] = i;
msgs.push(new Mailbox.$Message(_this.accountId, _this.path, data));
msgs.push(new Mailbox.$Message(_this.$account.id, _this.path, data));
return msgs;
}, _this.$messages);
+23 -4
View File
@@ -34,9 +34,10 @@
var promises = [];
// Fetch list of mailboxes for each account
angular.forEach(accounts, function(account, i) {
console.debug(i);
var mailboxes = account.$getMailboxes();
console.debug(mailboxes);
promises.push(mailboxes.then(function(objects) {
accounts[i].mailboxes = objects;
return account;
}));
});
@@ -81,7 +82,7 @@
}
return mailbox;
};
return _find(stateAccount.mailboxes);
return _find(stateAccount.$mailboxes);
}],
stateMessages: ['stateMailbox', function(stateMailbox) {
return stateMailbox.$update();
@@ -146,10 +147,28 @@
$rootScope.currentFolder = folder;
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(folder.path) });
};
$scope.exportMails = function() {
window.location.href = ApplicationBaseURL + '/' + $rootScope.currentFolder.id + '/exportFolder';
};
$scope.confirmDelete = function() {
Dialog.confirm(l('Confirmation'), l('Do you really want to move this folder into the trash ?'))
.then(function(res) {
if (res) {
$rootScope.currentFolder.$delete()
.then(function() {
$rootScope.currentFolder = null;
}, function(data, status) {
Dialog.alert(l('An error occured while deleting the mailbox "%{0}".',
$rootScope.currentFolder.name),
l(data.error));
});
}
});
};
if (_.isEmpty($state.params) && $scope.accounts.length > 0 && $scope.accounts[0].mailboxes.length > 0) {
if (_.isEmpty($state.params) && $scope.accounts.length > 0 && $scope.accounts[0].$mailboxes.length > 0) {
var account = $scope.accounts[0];
var mailbox = account.mailboxes[0];
var mailbox = account.$mailboxes[0];
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(mailbox.path) });
}
}])
+31 -10
View File
@@ -50,7 +50,6 @@
angular.forEach(accounts, function(account, i) {
var mailboxes = account.$getMailboxes();
promises.push(mailboxes.then(function(objects) {
accounts[i].mailboxes = objects;
return account;
}));
});
@@ -94,7 +93,7 @@
}
return mailbox;
};
return _find(stateAccount.mailboxes);
return _find(stateAccount.$mailboxes);
}],
stateMessages: ['stateMailbox', function(stateMailbox) {
return stateMailbox.$update();
@@ -130,19 +129,41 @@
$scope.ApplicationBaseURL = ApplicationBaseURL;
}])
.controller('MailboxesCtrl', ['$scope', '$http', '$state', 'sgAccount', 'sgMailbox', 'encodeUriFilter', 'stateAccounts', function($scope, $http, $state, Account, Mailbox, encodeUriFilter, stateAccounts) {
.controller('MailboxesCtrl', ['$scope', '$http', '$state', '$ionicActionSheet', 'sgAccount', 'sgMailbox', 'encodeUriFilter', 'stateAccounts', function($scope, $http, $state, $ionicActionSheet, Account, Mailbox, encodeUriFilter, stateAccounts) {
$scope.accounts = stateAccounts
angular.forEach($scope.accounts, function(account, i) {
var mailboxes = account.$getMailboxes();
mailboxes.then(function(objects) {
$scope.accounts[i].mailboxes = objects;
});
});
$scope.setCurrentFolder = function(account, folder) {
$state.go('app.mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(folder.path) });
};
$scope.edit = function(folder) {
$ionicActionSheet.show({
buttons: [
{ text: l('Rename') },
{ text: l('Set Access Rights') }
],
destructiveText: l('Delete'),
cancelText: l('Cancel'),
buttonClicked: function(index) {
// TODO
return true;
},
destructiveButtonClicked: function() {
// Delete mailbox
folder.$delete()
.then(function() {
folder = null;
}, function(data) {
Dialog.alert(l('An error occured while deleting the mailbox "%{0}".',
folder.name),
l(data.error));
});
return true;
}
// cancel: function() {
// },
});
$ionicListDelegate.closeOptionButtons();
};
}])
.controller('MailboxCtrl', ['$scope', 'stateAccount', 'stateMailbox', function($scope, stateAccount, stateMailbox) {
+22
View File
@@ -112,6 +112,28 @@ $topbar-link-bg-hover: scale-color($module-color, $lightness: -14%);
}
}
.f-dropdown {
width: auto;
max-width: 300px;
white-space: nowrap;
&.icons-dropdown {
height: inherit;
//background-color: $primary-color;
.button {
margin: 0;
padding: $f-dropdown-list-padding;
border-color: $primary-color;
//color: scale-color($secondary-color, $lightness: 52%);
color: #fff;
}
background-color: $primary-color;
border-color: $primary-color;
&:before {
border-color: transparent transparent $primary-color transparent;
}
}
}
$i: 1;
@while $i < 12 {
.folders-list ul li .folder-container .folder-content > .childLevel#{$i} { padding-left: 15px * $i; }