[WO-29] delete messages asynchronously

This commit is contained in:
Felix Hammerl 2013-10-24 15:18:51 +02:00
parent d4398ebbb8
commit 9d1b2e33ef
1 changed files with 33 additions and 23 deletions

View File

@ -50,10 +50,33 @@ define(function(require) {
};
$scope.remove = function(email) {
if (!email) {
return;
}
var index;
removeLocalAndShowNext();
removeRemote();
function removeLocalAndShowNext() {
index = $scope.emails.indexOf(email);
// show the next mail
if ($scope.emails.length > 1) {
// if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list),
// otherwise show the next one (i.e. the one above in the list)
$scope.select(_.last($scope.emails) === email ? $scope.emails[index - 1] : $scope.emails[index + 1]);
} else {
// if we have only one email in the array, show nothing
$scope.select();
$scope.selected = undefined;
}
$scope.emails.splice(index, 1);
}
function removeRemote() {
var trashFolder = _.findWhere($scope.folders, {
type: 'Trash'
});
if ($scope.currentFolder === trashFolder) {
emailDao.imapDeleteMessage({
folder: $scope.currentFolder.path,
@ -67,28 +90,15 @@ define(function(require) {
uid: email.uid,
destination: trashFolder.path
}, moved);
}
function moved(err) {
var index;
if (err) {
console.error(err);
$scope.emails.splice(index, 0, email);
$scope.$apply();
return;
}
index = $scope.emails.indexOf(email);
// show the next mail
if ($scope.emails.length > 1) {
// if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list),
// otherwise show the next one (i.e. the one above in the list)
$scope.select(_.last($scope.emails) === email ? $scope.emails[index - 1] : $scope.emails[index + 1]);
} else {
// if we have only one email in the array, show nothing
$scope.select();
$scope.selected = undefined;
}
$scope.emails.splice(index, 1);
$scope.$apply();
}
};