diff --git a/src/js/app.js b/src/js/app.js index f8031fa..2eed706 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -3,16 +3,20 @@ window.name = 'NG_DEFER_BOOTSTRAP!'; require([ 'angular', + 'js/controller/login', 'js/controller/message-list', 'js/controller/write', 'angularRoute', - 'angularTouch', - 'js/app-config' -], function(angular, MessageListCtrl, WriteCtrl) { + 'angularTouch' +], function(angular, LoginCtrl, MessageListCtrl, WriteCtrl) { 'use strict'; var app = angular.module('mail', ['ngRoute', 'ngTouch', 'write']); app.config(function($routeProvider) { + $routeProvider.when('/login', { + templateUrl: 'tpl/login.html', + controller: LoginCtrl + }); $routeProvider.when('/folders/:folder', { templateUrl: 'tpl/message-list-desktop.html', controller: MessageListCtrl @@ -26,7 +30,7 @@ require([ controller: WriteCtrl }); $routeProvider.otherwise({ - redirectTo: '/folders/Inbox' + redirectTo: '/login' }); }); diff --git a/src/js/controller/login.js b/src/js/controller/login.js new file mode 100644 index 0000000..59f9346 --- /dev/null +++ b/src/js/controller/login.js @@ -0,0 +1,27 @@ +define(function(require) { + 'use strict'; + + var appController = require('js/app-controller'); + + var LoginCtrl = function($scope, $location) { + var nextPath = '/folders/INBOX'; + + if (window.chrome && chrome.identity) { + // start the main app controller + appController.fetchOAuthToken('passphrase', function(err) { + if (err) { + console.log(err); + return; + } + + $location.path(nextPath); + $scope.$apply(); + }); + return; + } + + $location.path(nextPath); + }; + + return LoginCtrl; +}); \ No newline at end of file diff --git a/src/js/controller/message-list.js b/src/js/controller/message-list.js index 2b9ed69..16d6b9b 100644 --- a/src/js/controller/message-list.js +++ b/src/js/controller/message-list.js @@ -32,7 +32,7 @@ define(function(require) { }; if (window.chrome && chrome.identity) { - fetchList(function(emails) { + fetchList($scope.folder, function(emails) { $scope.emails = emails; $scope.select($scope.emails[0]); $scope.$apply(); @@ -46,31 +46,22 @@ define(function(require) { }); }; - function fetchList(callback) { - var folder = 'INBOX'; - - appController.fetchOAuthToken('passphrase', function(err) { + function fetchList(folder, callback) { + // fetch imap folder's message list + appController._emailDao.imapListMessages({ + folder: folder, + offset: -6, + num: 0 + }, function(err, emails) { if (err) { console.log(err); return; } - // fetch imap folder's message list - appController._emailDao.imapListMessages({ - folder: folder, - offset: -6, - num: 0 - }, function(err, emails) { - if (err) { - console.log(err); - return; - } - - // fetch message bodies - fetchBodies(emails, folder, function(messages) { - addDisplayDate(messages); - callback(messages); - }); + // fetch message bodies + fetchBodies(emails, folder, function(messages) { + addDisplayDate(messages); + callback(messages); }); }); } diff --git a/src/tpl/login.html b/src/tpl/login.html new file mode 100644 index 0000000..67f8032 --- /dev/null +++ b/src/tpl/login.html @@ -0,0 +1 @@ +
\ No newline at end of file