diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 0c6059c..f358ffc 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -41,7 +41,7 @@ ctrl.start = function(options, callback) { } ctrl.started = true; - ctrl.onError = options.onError; + ctrl.onError = options.onError; // TODO: replace by errorService // are we running in a cordova app or in a browser environment? if (window.cordova) { @@ -57,16 +57,21 @@ ctrl.start = function(options, callback) { function onDeviceReady() { axe.debug('Starting app.'); + // TODO: will be replaced by angular dependency management ctrl.buildModules(); + // TODO: move self-contained connection management in emailDao // Handle offline and online gracefully window.addEventListener('online', ctrl.onConnect.bind(ctrl, ctrl.onError)); window.addEventListener('offline', ctrl.onDisconnect.bind(ctrl)); + // TODO: move appConfigService shared singleton ctrl._appConfigStore.init('app-config', callback); } }; +// TODO: will be replaced by angular dependency management + /** * Initialize the dependency tree. */ @@ -121,6 +126,8 @@ ctrl.checkForUpdate = function() { ctrl._updateHandler.checkForUpdate(ctrl.onError); }; +// TODO: move to AccountService + /** * Fire up the database, retrieve the available keys for the user and initialize the email data access object */ @@ -207,6 +214,8 @@ ctrl.isOnline = function() { return navigator.onLine; }; +// TODO: move to AccountService + /** * Event handler that is called when the user agent goes offline. */ @@ -214,6 +223,8 @@ ctrl.onDisconnect = function() { ctrl._emailDao.onDisconnect(); }; +// TODO: move to AccountService + /** * Log the current user out by clear the app config store and deleting instances of imap-client and pgp-mailer. */ @@ -243,6 +254,8 @@ ctrl.logout = function() { }); }; +// TODO: move onConnect to emailDao + /** * Event that is called when the user agent goes online. This create new instances of the imap-client and pgp-mailer and connects to the mail server. */ diff --git a/src/js/app.js b/src/js/app.js index 7480f02..0b52818 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -37,8 +37,7 @@ var DialogCtrl = require('./controller/dialog'), errorUtil = require('./util/error'), backButtonUtil = require('./util/backbutton-handler'); require('./directive/common'), -require('./service/newsletter'), -require('./service/mail-config'); +require('./service'); // init main angular module including dependencies var app = angular.module('mail', [ diff --git a/src/js/service/account.js b/src/js/service/account.js new file mode 100644 index 0000000..fcadb36 --- /dev/null +++ b/src/js/service/account.js @@ -0,0 +1,41 @@ +'use strict'; + +var ngModule = angular.module('woServices'); +ngModule.service('account', Account); + +var EmailDAO = require('../dao/email-dao'); + +function Account() { + this._emailDAOs = []; +} + +/** + * Lists all of the current accounts connected to the app + * @return {Array} The account objects containing folder and message objects + */ +Account.prototype.all = function() { + return this._emailDAOs.map(function(emailDao) { + return emailDao._account; + }); +}; + +/** + * Login to an existing email account. This creates a new email data access object instance for that account and logs in via IMAP. + * @param {String} options.emailAddress The account's email address + */ +Account.prototype.login = function(options) { + var emailDao = new EmailDAO(); + this._emailDAOs.push(emailDao); +}; + +/** + * Create a new whiteout account. This creates a new email data access object instance for that account and logs in via IMAP. + * @param {String} options.emailAddress The account's email address + */ +Account.prototype.create = function(options) {}; + +/** + * Logout of an email account. This creates a new email data access object instance for that account and logs in via IMAP. + * @param {String} options.emailAddress The account's email address + */ +Account.prototype.logout = function(options) {}; \ No newline at end of file diff --git a/src/js/service/index.js b/src/js/service/index.js new file mode 100644 index 0000000..1dea33f --- /dev/null +++ b/src/js/service/index.js @@ -0,0 +1,7 @@ +'use strict'; + +angular.module('woServices', []); + +require('./newsletter'), +require('./mail-config'), +require('./account'); \ No newline at end of file diff --git a/src/js/service/newsletter.js b/src/js/service/newsletter.js index a3c2c4c..ff25f74 100644 --- a/src/js/service/newsletter.js +++ b/src/js/service/newsletter.js @@ -1,6 +1,6 @@ 'use strict'; -var ngModule = angular.module('woServices', []); +var ngModule = angular.module('woServices'); ngModule.service('newsletter', Newsletter); function Newsletter($q) {