1
0
mirror of https://github.com/moparisthebest/mail synced 2025-01-31 07:00:17 -05:00

init app controller centrally before login

This commit is contained in:
Tankred Hase 2013-09-15 16:24:14 +02:00
parent 63d1d12d71
commit 836456f0d0
4 changed files with 48 additions and 25 deletions

View File

@ -3,16 +3,20 @@ window.name = 'NG_DEFER_BOOTSTRAP!';
require([ require([
'angular', 'angular',
'js/controller/login',
'js/controller/message-list', 'js/controller/message-list',
'js/controller/write', 'js/controller/write',
'angularRoute', 'angularRoute',
'angularTouch', 'angularTouch'
'js/app-config' ], function(angular, LoginCtrl, MessageListCtrl, WriteCtrl) {
], function(angular, MessageListCtrl, WriteCtrl) {
'use strict'; 'use strict';
var app = angular.module('mail', ['ngRoute', 'ngTouch', 'write']); var app = angular.module('mail', ['ngRoute', 'ngTouch', 'write']);
app.config(function($routeProvider) { app.config(function($routeProvider) {
$routeProvider.when('/login', {
templateUrl: 'tpl/login.html',
controller: LoginCtrl
});
$routeProvider.when('/folders/:folder', { $routeProvider.when('/folders/:folder', {
templateUrl: 'tpl/message-list-desktop.html', templateUrl: 'tpl/message-list-desktop.html',
controller: MessageListCtrl controller: MessageListCtrl
@ -26,7 +30,7 @@ require([
controller: WriteCtrl controller: WriteCtrl
}); });
$routeProvider.otherwise({ $routeProvider.otherwise({
redirectTo: '/folders/Inbox' redirectTo: '/login'
}); });
}); });

View File

@ -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;
});

View File

@ -32,7 +32,7 @@ define(function(require) {
}; };
if (window.chrome && chrome.identity) { if (window.chrome && chrome.identity) {
fetchList(function(emails) { fetchList($scope.folder, function(emails) {
$scope.emails = emails; $scope.emails = emails;
$scope.select($scope.emails[0]); $scope.select($scope.emails[0]);
$scope.$apply(); $scope.$apply();
@ -46,31 +46,22 @@ define(function(require) {
}); });
}; };
function fetchList(callback) { function fetchList(folder, callback) {
var folder = 'INBOX'; // fetch imap folder's message list
appController._emailDao.imapListMessages({
appController.fetchOAuthToken('passphrase', function(err) { folder: folder,
offset: -6,
num: 0
}, function(err, emails) {
if (err) { if (err) {
console.log(err); console.log(err);
return; return;
} }
// fetch imap folder's message list // fetch message bodies
appController._emailDao.imapListMessages({ fetchBodies(emails, folder, function(messages) {
folder: folder, addDisplayDate(messages);
offset: -6, callback(messages);
num: 0
}, function(err, emails) {
if (err) {
console.log(err);
return;
}
// fetch message bodies
fetchBodies(emails, folder, function(messages) {
addDisplayDate(messages);
callback(messages);
});
}); });
}); });
} }

1
src/tpl/login.html Normal file
View File

@ -0,0 +1 @@
<div class="message">Logging in...</div>