mail/src/js/app.js

133 lines
4.6 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();
}
}
};
};
}
2014-10-02 16:05:44 -04:00
var DialogCtrl = require('./controller/dialog'),
AddAccountCtrl = require('./controller/add-account'),
CreateAccountCtrl = require('./controller/create-account'),
ValidatePhoneCtrl = require('./controller/validate-phone'),
2014-10-02 16:05:44 -04:00
AccountCtrl = require('./controller/account'),
SetPassphraseCtrl = require('./controller/set-passphrase'),
PrivateKeyUploadCtrl = require('./controller/privatekey-upload'),
ContactsCtrl = require('./controller/contacts'),
AboutCtrl = require('./controller/about'),
LoginCtrl = require('./controller/login'),
LoginInitialCtrl = require('./controller/login-initial'),
LoginNewDeviceCtrl = require('./controller/login-new-device'),
LoginExistingCtrl = require('./controller/login-existing'),
LoginPrivateKeyDownloadCtrl = require('./controller/login-privatekey-download'),
LoginSetCredentialsCtrl = require('./controller/login-set-credentials'),
MailListCtrl = require('./controller/mail-list'),
ReadCtrl = require('./controller/read'),
WriteCtrl = require('./controller/write'),
NavigationCtrl = require('./controller/navigation'),
ActionBarCtrl = require('./controller/action-bar'),
2014-10-02 16:05:44 -04:00
errorUtil = require('./util/error'),
backButtonUtil = require('./util/backbutton-handler');
2014-11-11 15:50:01 -05:00
require('./directive/common'),
2014-11-17 12:58:03 -05:00
require('./service');
2014-10-02 16:05:44 -04:00
// init main angular module including dependencies
var app = angular.module('mail', [
'ngRoute',
'ngAnimate',
'navigation',
'mail-list',
'write',
'read',
'contacts',
'login-new-device',
'privatekey-upload',
'infinite-scroll',
2014-09-23 09:41:37 -04:00
'ngTagsInput',
'woDirectives',
'woServices'
2014-10-02 16:05:44 -04:00
]);
2013-11-27 04:40:55 -05:00
2014-10-02 16:05:44 -04:00
// set router paths
app.config(function($routeProvider, $animateProvider) {
$routeProvider.when('/login', {
templateUrl: 'tpl/login.html',
controller: LoginCtrl
});
2014-10-02 16:05:44 -04:00
$routeProvider.when('/add-account', {
templateUrl: 'tpl/add-account.html',
controller: AddAccountCtrl
});
$routeProvider.when('/create-account', {
templateUrl: 'tpl/create-account.html',
controller: CreateAccountCtrl
});
$routeProvider.when('/validate-phone', {
templateUrl: 'tpl/validate-phone.html',
controller: ValidatePhoneCtrl
2014-10-02 16:05:44 -04:00
});
$routeProvider.when('/login-set-credentials', {
templateUrl: 'tpl/login-set-credentials.html',
controller: LoginSetCredentialsCtrl
});
$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
});
$routeProvider.when('/desktop', {
templateUrl: 'tpl/desktop.html',
controller: NavigationCtrl
});
$routeProvider.otherwise({
redirectTo: '/login'
});
// activate ngAnimate for whitelisted classes only
$animateProvider.classNameFilter(/^lightbox$/);
2014-10-02 16:05:44 -04:00
});
2014-10-02 16:05:44 -04:00
app.run(function($rootScope) {
// global state... inherited to all child scopes
$rootScope.state = {};
2014-10-02 16:05:44 -04:00
// attach global error handler
errorUtil.attachHandler($rootScope);
2014-10-02 16:05:44 -04:00
// attach the back button handler to the root scope
backButtonUtil.attachHandler($rootScope);
2014-10-02 16:05:44 -04:00
// attach fastclick
FastClick.attach(document.body);
});
2014-10-02 16:05:44 -04:00
// inject controllers from ng-included view templates
app.controller('ReadCtrl', ReadCtrl);
app.controller('WriteCtrl', WriteCtrl);
app.controller('MailListCtrl', MailListCtrl);
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('ActionBarCtrl', ActionBarCtrl);