From 8bbb7d7d34b104662409a665a23db264319879f1 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 14 Nov 2013 23:57:06 +0100 Subject: [PATCH] Call () in onError handler to cleanup controller --- src/js/controller/login-existing.js | 1 - src/js/controller/login-initial.js | 11 ++++------- src/js/controller/login-new-device.js | 1 - src/js/controller/mail-list.js | 15 +++++---------- src/js/controller/navigation.js | 8 ++++---- src/js/controller/write.js | 6 ++++-- src/js/util/error.js | 4 ++++ 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/js/controller/login-existing.js b/src/js/controller/login-existing.js index 4214393..de91124 100644 --- a/src/js/controller/login-existing.js +++ b/src/js/controller/login-existing.js @@ -55,7 +55,6 @@ define(function(require) { $scope.incorrect = true; $scope.buttonEnabled = true; $scope.onError(err); - $scope.$apply(); } }; diff --git a/src/js/controller/login-initial.js b/src/js/controller/login-initial.js index ddafc95..800fcee 100644 --- a/src/js/controller/login-initial.js +++ b/src/js/controller/login-initial.js @@ -38,12 +38,13 @@ define(function(require) { setTimeout(function() { emailDao.unlock({}, passphrase, function(err) { if (err) { + $scope.setState(states.IDLE); $scope.onError(err); - $scope.setState(states.IDLE, true); return; } - $scope.setState(states.DONE, true); + $scope.setState(states.DONE); + $scope.$apply(); }); }, 500); }; @@ -78,12 +79,8 @@ define(function(require) { $location.path('/desktop'); }; - $scope.setState = function(state, async) { + $scope.setState = function(state) { $scope.state.ui = state; - - if (async) { - $scope.$apply(); - } }; }; diff --git a/src/js/controller/login-new-device.js b/src/js/controller/login-new-device.js index 9b8f57b..eab846f 100644 --- a/src/js/controller/login-new-device.js +++ b/src/js/controller/login-new-device.js @@ -43,7 +43,6 @@ define(function(require) { if (err) { $scope.incorrect = true; $scope.onError(err); - $scope.$apply(); return; } diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 6e9a851..0c768fd 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -162,9 +162,8 @@ define(function(require) { function moved(err) { if (err) { - $scope.onError(err); $scope.emails.splice(index, 0, email); - $scope.$apply(); + $scope.onError(err); return; } } @@ -227,9 +226,8 @@ define(function(require) { function syncImapFolder(options, callback) { emailDao.unreadMessages(getFolder().path, function(err, unreadCount) { if (err) { - $scope.onError(err); updateStatus('Error on sync!'); - $scope.$apply(); + $scope.onError(err); return; } // set unread count in folder model @@ -238,9 +236,8 @@ define(function(require) { emailDao.imapSync(options, function(err) { if (err) { - $scope.onError(err); updateStatus('Error on sync!'); - $scope.$apply(); + $scope.onError(err); return; } @@ -253,9 +250,8 @@ define(function(require) { firstSelect = true; emailDao.listMessages(options, function(err, emails) { if (err) { - $scope.onError(err); updateStatus('Error listing cache!'); - $scope.$apply(); + $scope.onError(err); return; } @@ -313,9 +309,8 @@ define(function(require) { uid: email.uid }, function(err) { if (err) { - $scope.onError(err); updateStatus('Error marking read!'); - $scope.$apply(); + $scope.onError(err); return; } }); diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index 691b20f..de5d806 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -59,8 +59,8 @@ define(function(require) { // get last item from outbox emailDao._devicestorage.listItems(dbType, 0, null, function(err, pending) { if (err) { - $scope.onError(err); outboxBusy = false; + $scope.onError(err); return; } @@ -82,8 +82,8 @@ define(function(require) { var email = emails.shift(); emailDao.smtpSend(email, function(err) { if (err) { - $scope.onError(err); outboxBusy = false; + $scope.onError(err); return; } @@ -94,10 +94,10 @@ define(function(require) { function removeFromStorage(id) { if (!id) { + outboxBusy = false; $scope.onError({ errMsg: 'Cannot remove email from storage without a valid id!' }); - outboxBusy = false; return; } @@ -105,8 +105,8 @@ define(function(require) { var key = dbType + '_' + id; emailDao._devicestorage.removeList(key, function(err) { if (err) { - $scope.onError(err); outboxBusy = false; + $scope.onError(err); return; } diff --git a/src/js/controller/write.js b/src/js/controller/write.js index 5d802ec..46a8315 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -140,7 +140,8 @@ define(function(require) { to = $scope.to.replace(/\s/g, '').split(/[,;]/); if (!to || to.length < 1) { $scope.onError({ - errMsg: 'Seperate recipients with a comma!' + errMsg: 'Seperate recipients with a comma!', + sync: true }); return; } @@ -148,7 +149,8 @@ define(function(require) { // only allow secure recipients until invitation is implemented if (!$scope.toKey) { $scope.onError({ - errMsg: 'Invitations not yet supported!' + errMsg: 'Invitations not yet supported!', + sync: true }); return; } diff --git a/src/js/util/error.js b/src/js/util/error.js index ead6f38..71c3e7f 100644 --- a/src/js/util/error.js +++ b/src/js/util/error.js @@ -16,6 +16,10 @@ define(function() { title: options.title || 'Error', message: options.errMsg || options.message }; + // don't call apply for synchronous calls + if (!options.sync) { + scope.$apply(); + } }; };