mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-15 05:14:53 +00:00
Added Delete and Export features for mailboxes. Initial work for the mobile version.
This commit is contained in:
committed by
Francis Lachapelle
parent
4e9a187c85
commit
61e25184fc
@@ -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);
|
||||
|
||||
@@ -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) });
|
||||
}
|
||||
}])
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user