mail/src/js/app.js

161 lines
4.7 KiB
JavaScript
Raw Normal View History

'use strict';
// Check if a new ApaCache is available on page load.
if (typeof window.applicationCache !== 'undefined') {
window.onload = function() {
window.applicationCache.onupdateready = function() {
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache
if (window.confirm('A new version of Whiteout Mail is available. Restart the app to update?')) {
window.location.reload();
}
}
};
};
}
// hey Angular, we're bootstrapping manually!
window.name = 'NG_DEFER_BOOTSTRAP!';
2014-03-02 17:05:09 -05:00
requirejs([
2013-09-11 15:01:05 -04:00
'angular',
'js/controller/dialog',
'js/controller/popover',
2014-01-27 12:50:13 -05:00
'js/controller/add-account',
2013-10-21 11:10:45 -04:00
'js/controller/account',
'js/controller/set-passphrase',
'js/controller/privatekey-upload',
'js/controller/contacts',
'js/controller/about',
'js/controller/login',
2013-10-21 07:10:42 -04:00
'js/controller/login-initial',
'js/controller/login-new-device',
'js/controller/login-existing',
'js/controller/login-privatekey-download',
'js/controller/login-set-credentials',
'js/controller/mail-list',
'js/controller/read',
2013-09-11 15:01:05 -04:00
'js/controller/write',
2013-09-17 13:11:30 -04:00
'js/controller/navigation',
2014-06-05 09:26:19 -04:00
'js/crypto/util',
'js/util/error',
'js/util/backbutton-handler',
2014-06-17 06:58:53 -04:00
'fastclick',
2013-09-11 15:01:05 -04:00
'angularRoute',
'angularAnimate',
2014-09-15 06:01:13 -04:00
'ngInfiniteScroll',
'ngTagsInput'
2014-03-02 17:05:09 -05:00
], function(
angular,
DialogCtrl,
PopoverCtrl,
AddAccountCtrl,
AccountCtrl,
SetPassphraseCtrl,
PrivateKeyUploadCtrl,
ContactsCtrl,
AboutCtrl,
2014-03-02 17:05:09 -05:00
LoginCtrl,
LoginInitialCtrl,
LoginNewDeviceCtrl,
LoginExistingCtrl,
LoginPrivateKeyDownloadCtrl,
LoginSetCredentialsCtrl,
2014-03-02 17:05:09 -05:00
MailListCtrl,
ReadCtrl,
WriteCtrl,
NavigationCtrl,
util,
2014-06-17 06:58:53 -04:00
errorUtil,
backButtonUtil,
2014-06-17 06:58:53 -04:00
FastClick
) {
2013-11-27 04:40:55 -05:00
// reset window.name
window.name = util.UUID();
// init main angular module including dependencies
var app = angular.module('mail', [
'ngRoute',
'ngAnimate',
'navigation',
'mail-list',
'write',
'read',
'contacts',
'login-new-device',
'privatekey-upload',
'popover',
2014-09-15 06:01:13 -04:00
'infinite-scroll',
'ngTagsInput'
]);
// set router paths
app.config(function($routeProvider) {
2014-01-27 12:50:13 -05:00
$routeProvider.when('/add-account', {
templateUrl: 'tpl/add-account.html',
controller: AddAccountCtrl
});
$routeProvider.when('/login', {
2013-11-04 08:20:14 -05:00
templateUrl: 'tpl/login.html',
controller: LoginCtrl
});
$routeProvider.when('/login-set-credentials', {
templateUrl: 'tpl/login-set-credentials.html',
controller: LoginSetCredentialsCtrl
});
2013-10-21 07:10:42 -04:00
$routeProvider.when('/login-existing', {
templateUrl: 'tpl/login-existing.html',
controller: LoginExistingCtrl
});
$routeProvider.when('/login-initial', {
templateUrl: 'tpl/login-initial.html',
controller: LoginInitialCtrl
});
$routeProvider.when('/login-new-device', {
templateUrl: 'tpl/login-new-device.html',
controller: LoginNewDeviceCtrl
});
$routeProvider.when('/login-privatekey-download', {
templateUrl: 'tpl/login-privatekey-download.html',
controller: LoginPrivateKeyDownloadCtrl
});
2013-09-17 13:11:30 -04:00
$routeProvider.when('/desktop', {
templateUrl: 'tpl/desktop.html',
controller: NavigationCtrl
});
2013-09-06 18:34:36 -04:00
$routeProvider.otherwise({
2013-09-19 09:41:21 -04:00
redirectTo: '/login'
2013-09-06 18:34:36 -04:00
});
});
app.run(function($rootScope) {
// global state... inherited to all child scopes
$rootScope.state = {};
// attach global error handler
errorUtil.attachHandler($rootScope);
// attach the back button handler to the root scope
backButtonUtil.attachHandler($rootScope);
2014-06-17 06:58:53 -04:00
// attach fastclick
FastClick.attach(document.body);
});
// inject controllers from ng-included view templates
app.controller('ReadCtrl', ReadCtrl);
app.controller('WriteCtrl', WriteCtrl);
app.controller('MailListCtrl', MailListCtrl);
2013-10-21 11:10:45 -04:00
app.controller('AccountCtrl', AccountCtrl);
app.controller('SetPassphraseCtrl', SetPassphraseCtrl);
app.controller('PrivateKeyUploadCtrl', PrivateKeyUploadCtrl);
app.controller('ContactsCtrl', ContactsCtrl);
app.controller('AboutCtrl', AboutCtrl);
app.controller('DialogCtrl', DialogCtrl);
app.controller('PopoverCtrl', PopoverCtrl);
// manually bootstrap angular due to require.js
angular.element().ready(function() {
angular.bootstrap(document, ['mail']);
});
});