diff --git a/src/js/email/pgpbuilder.js b/src/js/email/pgpbuilder.js index 2f25d67..f728470 100644 --- a/src/js/email/pgpbuilder.js +++ b/src/js/email/pgpbuilder.js @@ -1,9 +1,8 @@ 'use strict'; var PgpBuilder = require('pgpbuilder'); -var instance = new PgpBuilder(); var ngModule = angular.module('woEmail'); ngModule.factory('pgpbuilder', function() { - return instance; + return new PgpBuilder(); }); \ No newline at end of file diff --git a/src/js/service/admin.js b/src/js/service/admin.js index 5a3549b..af794bb 100644 --- a/src/js/service/admin.js +++ b/src/js/service/admin.js @@ -4,9 +4,8 @@ var ngModule = angular.module('woServices'); ngModule.service('admin', Admin); module.exports = Admin; -function Admin(restDao, appConfig) { - this._restDao = restDao; - this._restDao.setBaseUri(appConfig.config.adminUrl); +function Admin(adminRestDao) { + this._restDao = adminRestDao; } /** diff --git a/src/js/service/devicestorage.js b/src/js/service/devicestorage.js index 607bb5b..99b2433 100644 --- a/src/js/service/devicestorage.js +++ b/src/js/service/devicestorage.js @@ -1,23 +1,20 @@ 'use strict'; var ngModule = angular.module('woServices'); -ngModule.factory('deviceStorage', function(lawnchairDAO) { - return new DeviceStorage(lawnchairDAO); -}); -module.exports = DeviceStorage; - -// -// Export special device storage singletons -// // expose an instance with the static dbName 'app-config' to store configuration data -ngModule.factory('appConfigStore', function(deviceStorage) { +ngModule.factory('appConfigStore', function(appConfigLawnchair) { + var deviceStorage = new DeviceStorage(appConfigLawnchair); deviceStorage.init('app-config'); return deviceStorage; }); // expose a singleton instance of DeviceStorage called 'accountStore' to persist user data -ngModule.service('accountStore', DeviceStorage); +ngModule.factory('accountStore', function(accountLawnchair) { + return new DeviceStorage(accountLawnchair); +}); + +module.exports = DeviceStorage; // // Implementation diff --git a/src/js/service/invitation.js b/src/js/service/invitation.js index 75916cd..96e380f 100644 --- a/src/js/service/invitation.js +++ b/src/js/service/invitation.js @@ -8,9 +8,8 @@ module.exports = Invitation; * The Invitation is a high level Data Access Object that access the invitation service REST endpoint. * @param {Object} restDao The REST Data Access Object abstraction */ -function Invitation(restDao, appConfig) { - this._restDao = restDao; - this._restDao.setBaseUri(appConfig.config.cloudUrl); +function Invitation(invitationRestDao) { + this._restDao = invitationRestDao; } // diff --git a/src/js/service/keychain.js b/src/js/service/keychain.js index 9e49d0a..192af95 100644 --- a/src/js/service/keychain.js +++ b/src/js/service/keychain.js @@ -15,8 +15,8 @@ var DB_PUBLICKEY = 'publickey', * A high-level Data-Access Api for handling Keypair synchronization * between the cloud service and the device's local storage */ -function Keychain(lawnchairDAO, publicKey, privateKey, crypto, pgp, dialog, appConfig) { - this._lawnchairDAO = lawnchairDAO; +function Keychain(accountLawnchair, publicKey, privateKey, crypto, pgp, dialog, appConfig) { + this._lawnchairDAO = accountLawnchair; this._publicKeyDao = publicKey; this._privateKeyDao = privateKey; this._crypto = crypto; diff --git a/src/js/service/lawnchair.js b/src/js/service/lawnchair.js index 4d5e07b..2cfde80 100644 --- a/src/js/service/lawnchair.js +++ b/src/js/service/lawnchair.js @@ -1,9 +1,9 @@ 'use strict'; var ngModule = angular.module('woServices'); -ngModule.factory('lawnchairDAO', function() { - return new LawnchairDAO(); -}); +ngModule.service('appConfigLawnchair', LawnchairDAO); +ngModule.service('accountLawnchair', LawnchairDAO); +ngModule.service('keychainLawnchair', LawnchairDAO); module.exports = LawnchairDAO; /** diff --git a/src/js/service/oauth.js b/src/js/service/oauth.js index a13913d..178960b 100644 --- a/src/js/service/oauth.js +++ b/src/js/service/oauth.js @@ -4,9 +4,8 @@ var ngModule = angular.module('woServices'); ngModule.service('oauth', OAuth); module.exports = OAuth; -function OAuth(restDao) { - this._googleApi = restDao; - this._googleApi.setBaseUri('https://www.googleapis.com'); +function OAuth(oauthRestDao) { + this._googleApi = oauthRestDao; } /** diff --git a/src/js/service/privatekey.js b/src/js/service/privatekey.js index 5f00ee5..e15d81f 100644 --- a/src/js/service/privatekey.js +++ b/src/js/service/privatekey.js @@ -4,9 +4,8 @@ var ngModule = angular.module('woServices'); ngModule.service('privateKey', PrivateKey); module.exports = PrivateKey; -function PrivateKey(restDao, appConfig) { - this._restDao = restDao; - this._restDao.setBaseUri(appConfig.config.privkeyServerUrl); +function PrivateKey(privateKeyRestDao) { + this._restDao = privateKeyRestDao; } // diff --git a/src/js/service/publickey.js b/src/js/service/publickey.js index e162138..b2c451b 100644 --- a/src/js/service/publickey.js +++ b/src/js/service/publickey.js @@ -4,9 +4,8 @@ var ngModule = angular.module('woServices'); ngModule.service('publicKey', PublicKey); module.exports = PublicKey; -function PublicKey(restDao, appConfig) { - this._restDao = restDao; - this._restDao.setBaseUri(appConfig.config.cloudUrl); +function PublicKey(publicKeyRestDao) { + this._restDao = publicKeyRestDao; } /** diff --git a/src/js/service/rest.js b/src/js/service/rest.js index f4a765f..82e8be6 100644 --- a/src/js/service/rest.js +++ b/src/js/service/rest.js @@ -1,9 +1,42 @@ 'use strict'; var ngModule = angular.module('woServices'); -ngModule.factory('restDao', function() { - return new RestDAO(); + +// rest dao for use in the public key service +ngModule.factory('publicKeyRestDao', function(appConfig) { + var dao = new RestDAO(); + dao.setBaseUri(appConfig.config.cloudUrl); + return dao; }); + +// rest dao for use in the private key service +ngModule.factory('privateKeyRestDao', function(appConfig) { + var dao = new RestDAO(); + dao.setBaseUri(appConfig.config.privkeyServerUrl); + return dao; +}); + +// rest dao for use in the invitation service +ngModule.factory('invitationRestDao', function(appConfig) { + var dao = new RestDAO(); + dao.setBaseUri(appConfig.config.cloudUrl); + return dao; +}); + +// rest dao for use in the admin service +ngModule.factory('adminRestDao', function(appConfig) { + var dao = new RestDAO(); + dao.setBaseUri(appConfig.config.adminUrl); + return dao; +}); + +// rest dao for use in the oauth service +ngModule.factory('oauthRestDao', function() { + var dao = new RestDAO(); + dao.setBaseUri('https://www.googleapis.com'); + return dao; +}); + module.exports = RestDAO; function RestDAO() {} diff --git a/src/js/util/dialog.js b/src/js/util/dialog.js index ec38523..81454d7 100644 --- a/src/js/util/dialog.js +++ b/src/js/util/dialog.js @@ -10,6 +10,13 @@ module.exports = Dialog; function Dialog($q, axe) { this._q = $q; this._axe = axe; + + // binds the methods to the instance of the dialog service so that we can e.g. + // pass dialog.error as a callback to asynchronous functions without having to + // do dialog.error.bind(dialog) every time + this.info = this.info.bind(this); + this.error = this.error.bind(this); + this.confirm = this.confirm.bind(this); } /** @@ -19,7 +26,7 @@ function Dialog($q, axe) { * @return {Promise} */ Dialog.prototype.info = function(options) { - return this._handle(options, this.displayInfo, 'displayInfo'); + return this._handle(options, this.displayInfo.bind(this), 'displayInfo'); }; /** @@ -30,8 +37,10 @@ Dialog.prototype.info = function(options) { */ Dialog.prototype.error = function(options) { // log the error - this._axe.error((options.errMsg || options.message) + (options.stack ? ('\n' + options.stack) : '')); - return this._handle(options, this.displayError, 'displayError'); + if (options) { + this._axe.error((options.errMsg || options.message) + (options.stack ? ('\n' + options.stack) : '')); + } + return this._handle(options, this.displayError.bind(this), 'displayError'); }; /** @@ -42,7 +51,7 @@ Dialog.prototype.error = function(options) { * @return {Promise} */ Dialog.prototype.confirm = function(options) { - return this._handle(options, this.displayConfirm, 'displayConfirm'); + return this._handle(options, this.displayConfirm.bind(this), 'displayConfirm'); }; /**