{{state.dialog.title}}
+ +{{state.dialog.message}}
+diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 372bc64..15c95e8 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -40,11 +40,17 @@ define(function(require) { } }; - self.checkForUpdate = function() { - // check for update and restart app automatically + self.checkForUpdate = function(callback) { + if (!chrome || !chrome.runtime || !chrome.runtime.onUpdateAvailable) { + return; + } + + // check for update and restart on confirmation chrome.runtime.onUpdateAvailable.addListener(function(details) { - console.log("Updating to version " + details.version); - chrome.runtime.reload(); + callback(function() { + console.log("Updating to version " + details.version); + chrome.runtime.reload(); + }); }); chrome.runtime.requestUpdateCheck(function(status) { if (status === "update_found") { diff --git a/src/js/app.js b/src/js/app.js index 0408105..3cf57ba 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -3,6 +3,7 @@ window.name = 'NG_DEFER_BOOTSTRAP!'; require([ 'angular', + 'js/controller/dialog', 'js/controller/account', 'js/controller/login', 'js/controller/login-initial', @@ -14,7 +15,7 @@ require([ 'js/controller/navigation', 'angularRoute', 'angularTouch' -], function(angular, AccountCtrl, LoginCtrl, LoginInitialCtrl, LoginNewDeviceCtrl, LoginExistingCtrl, MailListCtrl, ReadCtrl, WriteCtrl, NavigationCtrl) { +], function(angular, DialogCtrl, AccountCtrl, LoginCtrl, LoginInitialCtrl, LoginNewDeviceCtrl, LoginExistingCtrl, MailListCtrl, ReadCtrl, WriteCtrl, NavigationCtrl) { 'use strict'; var app = angular.module('mail', ['ngRoute', 'ngTouch', 'navigation', 'mail-list', 'write', 'read', 'login-new-device']); @@ -51,6 +52,7 @@ require([ app.controller('WriteCtrl', WriteCtrl); app.controller('MailListCtrl', MailListCtrl); app.controller('AccountCtrl', AccountCtrl); + app.controller('DialogCtrl', DialogCtrl); // manually bootstrap angular due to require.js angular.element().ready(function() { diff --git a/src/js/controller/dialog.js b/src/js/controller/dialog.js new file mode 100644 index 0000000..45108c1 --- /dev/null +++ b/src/js/controller/dialog.js @@ -0,0 +1,16 @@ +define(function() { + 'use strict'; + + var DialogCtrl = function($scope) { + $scope.confirm = function(ok) { + $scope.state.dialog.open = false; + + if ($scope.state.dialog.callback) { + $scope.state.dialog.callback(ok); + } + $scope.state.dialog.callback = undefined; + }; + }; + + return DialogCtrl; +}); \ No newline at end of file diff --git a/src/js/controller/login.js b/src/js/controller/login.js index 444cefd..aa5e386 100644 --- a/src/js/controller/login.js +++ b/src/js/controller/login.js @@ -16,8 +16,6 @@ define(function(require) { return; } - // check for app update - appController.checkForUpdate(); // login to imap initializeUser(); }); diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 66a3a4c..09033a2 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -145,7 +145,7 @@ define(function(require) { function syncImapFolder(options, callback) { emailDao.unreadMessages(getFolder().path, function(err, unreadCount) { if (err) { - console.log(err); + $scope.onError(err); updateStatus('Error on sync!'); $scope.$apply(); return; @@ -156,7 +156,7 @@ define(function(require) { emailDao.imapSync(options, function(err) { if (err) { - console.log(err); + $scope.onError(err); updateStatus('Error on sync!'); $scope.$apply(); return; @@ -171,7 +171,7 @@ define(function(require) { firstSelect = true; emailDao.listMessages(options, function(err, emails) { if (err) { - console.log(err); + $scope.onError(err); updateStatus('Error listing cache!'); $scope.$apply(); return; @@ -233,7 +233,7 @@ define(function(require) { uid: email.uid }, function(err) { if (err) { - console.log(err); + $scope.onError(err); updateStatus('Error marking read!'); $scope.$apply(); return; diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index f6a2292..114b22e 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -13,6 +13,7 @@ define(function(require) { // var NavigationCtrl = function($scope) { + $scope.$root.state = {}; $scope.navOpen = false; $scope.writerOpen = false; $scope.accountOpen = false; @@ -23,11 +24,20 @@ define(function(require) { // scope functions // - $scope.openNav = function() { - $scope.navOpen = true; + $scope.$root.onError = function(options) { + console.error(options); + $scope.state.dialog = { + open: true, + title: options.title || 'Error', + message: options.message || options.errMsg + }; }; - $scope.closeNav = function() { - $scope.navOpen = false; + + $scope.state.nav = { + open: false, + toggle: function(to) { + this.open = to; + } }; $scope.openWriter = function(replyTo) { @@ -40,7 +50,7 @@ define(function(require) { $scope.openFolder = function(folder) { $scope.currentFolder = folder; - $scope.closeNav(); + $scope.state.nav.toggle(false); }; $scope.openAccount = function() { @@ -188,6 +198,22 @@ define(function(require) { // Start // + function onUpdateAvailable(doUpdate) { + $scope.state.dialog = { + open: true, + title: 'Update available', + message: 'Would you like to update the application now?', + callback: function(confirm) { + if (confirm) { + doUpdate(); + } + } + }; + } + // check for app update + appController.checkForUpdate(onUpdateAvailable); + + // init folders initFolders(function(folders) { $scope.folders = folders; // select inbox as the current folder on init diff --git a/src/sass/all.scss b/src/sass/all.scss index 91d6a5f..b5fcae2 100755 --- a/src/sass/all.scss +++ b/src/sass/all.scss @@ -21,6 +21,7 @@ // Views @import "views/shared"; @import "views/account"; +@import "views/dialog"; @import "views/navigation"; @import "views/mail-list"; @import "views/read"; diff --git a/src/sass/views/_dialog.scss b/src/sass/views/_dialog.scss new file mode 100644 index 0000000..fb1f7d4 --- /dev/null +++ b/src/sass/views/_dialog.scss @@ -0,0 +1,29 @@ +.view-dialog { + padding: 0px; + color: $color-grey-dark; + max-width: 350px; + height: auto; + top: 30%; + + @include respond-to(mobile) { + top: 0; + max-width: 100%; + } + + p { + text-align: center; + max-width: 80%; + margin: 50px auto 90px auto; + } + + .control { + position: absolute; + bottom: 15px; + right: 15px; + + button { + width: 100px; + border: 0!important; + } + } +} \ No newline at end of file diff --git a/src/tpl/desktop.html b/src/tpl/desktop.html index 312978f..5381bc7 100644 --- a/src/tpl/desktop.html +++ b/src/tpl/desktop.html @@ -1,10 +1,10 @@ -