Fix jshint self errors

This commit is contained in:
Tankred Hase 2014-10-09 14:27:10 +02:00 committed by Felix Hammerl
parent 98dfcfcb22
commit b0a186884a
4 changed files with 59 additions and 59 deletions

View File

@ -42,7 +42,7 @@
"pgpbuilder": "~0.4.0", "pgpbuilder": "~0.4.0",
"pgpmailer": "~0.4.0", "pgpmailer": "~0.4.0",
"socket.io": "^1.0.6", "socket.io": "^1.0.6",
"tcp-socket": "https://github.com/whiteout-io/tcp-socket/tarball/dev/browserify", "tcp-socket": "^0.3.11",
"wo-smtpclient": "^0.3.8" "wo-smtpclient": "^0.3.8"
}, },
"devDependencies": { "devDependencies": {

View File

@ -29,18 +29,18 @@ var axe = require('axe-logger'),
config = appConfig.config, config = appConfig.config,
str = appConfig.string; str = appConfig.string;
var self = {}; var ctrl = {};
/** /**
* Start the application. * Start the application.
*/ */
self.start = function(options, callback) { ctrl.start = function(options, callback) {
if (self.started) { if (ctrl.started) {
return callback(); return callback();
} }
self.started = true; ctrl.started = true;
self.onError = options.onError; ctrl.onError = options.onError;
// are we running in a cordova app or in a browser environment? // are we running in a cordova app or in a browser environment?
if (window.cordova) { if (window.cordova) {
@ -56,20 +56,20 @@ self.start = function(options, callback) {
function onDeviceReady() { function onDeviceReady() {
axe.debug('Starting app.'); axe.debug('Starting app.');
self.buildModules(); ctrl.buildModules();
// Handle offline and online gracefully // Handle offline and online gracefully
window.addEventListener('online', self.onConnect.bind(self, self.onError)); window.addEventListener('online', ctrl.onConnect.bind(ctrl, ctrl.onError));
window.addEventListener('offline', self.onDisconnect.bind(self)); window.addEventListener('offline', ctrl.onDisconnect.bind(ctrl));
self._appConfigStore.init('app-config', callback); ctrl._appConfigStore.init('app-config', callback);
} }
}; };
/** /**
* Initialize the dependency tree. * Initialize the dependency tree.
*/ */
self.buildModules = function() { ctrl.buildModules = function() {
var lawnchairDao, restDao, pubkeyDao, privkeyDao, crypto, emailDao, keychain, pgp, userStorage, pgpbuilder, oauth, appConfigStore, auth; var lawnchairDao, restDao, pubkeyDao, privkeyDao, crypto, emailDao, keychain, pgp, userStorage, pgpbuilder, oauth, appConfigStore, auth;
// start the mailreader's worker thread // start the mailreader's worker thread
@ -83,13 +83,13 @@ self.buildModules = function() {
oauth = new OAuth(new RestDAO('https://www.googleapis.com')); oauth = new OAuth(new RestDAO('https://www.googleapis.com'));
crypto = new Crypto(); crypto = new Crypto();
self._pgp = pgp = new PGP(); ctrl._pgp = pgp = new PGP();
self._keychain = keychain = new KeychainDAO(lawnchairDao, pubkeyDao, privkeyDao, crypto, pgp); ctrl._keychain = keychain = new KeychainDAO(lawnchairDao, pubkeyDao, privkeyDao, crypto, pgp);
keychain.requestPermissionForKeyUpdate = function(params, callback) { keychain.requestPermissionForKeyUpdate = function(params, callback) {
var message = params.newKey ? str.updatePublicKeyMsgNewKey : str.updatePublicKeyMsgRemovedKey; var message = params.newKey ? str.updatePublicKeyMsgNewKey : str.updatePublicKeyMsgRemovedKey;
message = message.replace('{0}', params.userId); message = message.replace('{0}', params.userId);
self.onError({ ctrl.onError({
title: str.updatePublicKeyTitle, title: str.updatePublicKeyTitle,
message: message, message: message,
positiveBtnStr: str.updatePublicKeyPosBtn, positiveBtnStr: str.updatePublicKeyPosBtn,
@ -99,40 +99,40 @@ self.buildModules = function() {
}); });
}; };
self._appConfigStore = appConfigStore = new DeviceStorageDAO(new LawnchairDAO()); ctrl._appConfigStore = appConfigStore = new DeviceStorageDAO(new LawnchairDAO());
self._auth = auth = new Auth(appConfigStore, oauth, pgp); ctrl._auth = auth = new Auth(appConfigStore, oauth, pgp);
self._userStorage = userStorage = new DeviceStorageDAO(lawnchairDao); ctrl._userStorage = userStorage = new DeviceStorageDAO(lawnchairDao);
self._invitationDao = new InvitationDAO(restDao); ctrl._invitationDao = new InvitationDAO(restDao);
self._pgpbuilder = pgpbuilder = new PgpBuilder(); ctrl._pgpbuilder = pgpbuilder = new PgpBuilder();
self._emailDao = emailDao = new EmailDAO(keychain, pgp, userStorage, pgpbuilder, mailreader); ctrl._emailDao = emailDao = new EmailDAO(keychain, pgp, userStorage, pgpbuilder, mailreader);
self._outboxBo = new OutboxBO(emailDao, keychain, userStorage); ctrl._outboxBo = new OutboxBO(emailDao, keychain, userStorage);
self._updateHandler = new UpdateHandler(appConfigStore, userStorage, auth); ctrl._updateHandler = new UpdateHandler(appConfigStore, userStorage, auth);
self._adminDao = new AdminDao(new RestDAO(config.adminUrl)); ctrl._adminDao = new AdminDao(new RestDAO(config.adminUrl));
self._doctor = new ConnectionDoctor(); ctrl._doctor = new ConnectionDoctor();
emailDao.onError = self.onError; emailDao.onError = ctrl.onError;
}; };
/** /**
* Calls runtime hooks to check if an app update is available. * Calls runtime hooks to check if an app update is available.
*/ */
self.checkForUpdate = function() { ctrl.checkForUpdate = function() {
self._updateHandler.checkForUpdate(self.onError); ctrl._updateHandler.checkForUpdate(ctrl.onError);
}; };
/** /**
* Instanciate the mail email data access object and its dependencies. Login to imap on init. * Instanciate the mail email data access object and its dependencies. Login to imap on init.
*/ */
self.init = function(options, callback) { ctrl.init = function(options, callback) {
// init user's local database // init user's local database
self._userStorage.init(options.emailAddress, function(err) { ctrl._userStorage.init(options.emailAddress, function(err) {
if (err) { if (err) {
callback(err); callback(err);
return; return;
} }
// Migrate the databases if necessary // Migrate the databases if necessary
self._updateHandler.update(onUpdate); ctrl._updateHandler.update(onUpdate);
}); });
function onUpdate(err) { function onUpdate(err) {
@ -152,7 +152,7 @@ self.init = function(options, callback) {
}; };
// init email dao // init email dao
self._emailDao.init({ ctrl._emailDao.init({
account: account account: account
}, function(err, keypair) { }, function(err, keypair) {
if (err) { if (err) {
@ -168,32 +168,32 @@ self.init = function(options, callback) {
/** /**
* Check if the user agent is online. * Check if the user agent is online.
*/ */
self.isOnline = function() { ctrl.isOnline = function() {
return navigator.onLine; return navigator.onLine;
}; };
/** /**
* Event handler that is called when the user agent goes offline. * Event handler that is called when the user agent goes offline.
*/ */
self.onDisconnect = function() { ctrl.onDisconnect = function() {
self._emailDao.onDisconnect(); ctrl._emailDao.onDisconnect();
}; };
/** /**
* Log the current user out by clear the app config store and deleting instances of imap-client and pgp-mailer. * Log the current user out by clear the app config store and deleting instances of imap-client and pgp-mailer.
*/ */
self.logout = function() { ctrl.logout = function() {
// clear app config store // clear app config store
self._auth.logout(function(err) { ctrl._auth.logout(function(err) {
if (err) { if (err) {
self.onError(err); ctrl.onError(err);
return; return;
} }
// delete instance of imap-client and pgp-mailer // delete instance of imap-client and pgp-mailer
self._emailDao.onDisconnect(function(err) { ctrl._emailDao.onDisconnect(function(err) {
if (err) { if (err) {
self.onError(err); ctrl.onError(err);
return; return;
} }
@ -206,14 +206,14 @@ self.logout = function() {
/** /**
* 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. * 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.
*/ */
self.onConnect = function(callback) { ctrl.onConnect = function(callback) {
if (!self.isOnline() || !self._emailDao || !self._emailDao._account) { if (!ctrl.isOnline() || !ctrl._emailDao || !ctrl._emailDao._account) {
// prevent connection infinite loop // prevent connection infinite loop
callback(); callback();
return; return;
} }
self._auth.getCredentials(function(err, credentials) { ctrl._auth.getCredentials(function(err, credentials) {
if (err) { if (err) {
callback(err); callback(err);
return; return;
@ -226,22 +226,22 @@ self.onConnect = function(callback) {
// add the maximum update batch size for imap folders to the imap configuration // add the maximum update batch size for imap folders to the imap configuration
credentials.imap.maxUpdateSize = config.imapUpdateBatchSize; credentials.imap.maxUpdateSize = config.imapUpdateBatchSize;
var pgpMailer = new PgpMailer(credentials.smtp, self._pgpbuilder); var pgpMailer = new PgpMailer(credentials.smtp, ctrl._pgpbuilder);
var imapClient = new ImapClient(credentials.imap); var imapClient = new ImapClient(credentials.imap);
imapClient.onError = onConnectionError; imapClient.onError = onConnectionError;
pgpMailer.onError = onConnectionError; pgpMailer.onError = onConnectionError;
// certificate update handling // certificate update handling
imapClient.onCert = self._auth.handleCertificateUpdate.bind(self._auth, 'imap', self.onConnect, self.onError); imapClient.onCert = ctrl._auth.handleCertificateUpdate.bind(ctrl._auth, 'imap', ctrl.onConnect, ctrl.onError);
pgpMailer.onCert = self._auth.handleCertificateUpdate.bind(self._auth, 'smtp', self.onConnect, self.onError); pgpMailer.onCert = ctrl._auth.handleCertificateUpdate.bind(ctrl._auth, 'smtp', ctrl.onConnect, ctrl.onError);
// after-setup configuration depending on the provider: // after-setup configuration depending on the provider:
// gmail does not require you to upload to the sent items folder // gmail does not require you to upload to the sent items folder
// after successful sending, whereas most other providers do // after successful sending, whereas most other providers do
self._emailDao.ignoreUploadOnSent = !!(config[self._auth.provider] && config[self._auth.provider].ignoreUploadOnSent); ctrl._emailDao.ignoreUploadOnSent = !!(config[ctrl._auth.provider] && config[ctrl._auth.provider].ignoreUploadOnSent);
// connect to clients // connect to clients
self._emailDao.onConnect({ ctrl._emailDao.onConnect({
imapClient: imapClient, imapClient: imapClient,
pgpMailer: pgpMailer pgpMailer: pgpMailer
}, callback); }, callback);
@ -253,7 +253,7 @@ self.onConnect = function(callback) {
setTimeout(function() { setTimeout(function() {
axe.debug('Reconnecting...'); axe.debug('Reconnecting...');
// re-init client modules on error // re-init client modules on error
self.onConnect(function(err) { ctrl.onConnect(function(err) {
if (err) { if (err) {
axe.error('Reconnect attempt failed! ' + (err.errMsg || err.message) + (err.stack ? ('\n' + err.stack) : '')); axe.error('Reconnect attempt failed! ' + (err.errMsg || err.message) + (err.stack ? ('\n' + err.stack) : ''));
return; return;
@ -265,4 +265,4 @@ self.onConnect = function(callback) {
} }
}; };
module.exports = self; module.exports = ctrl;

View File

@ -4,7 +4,7 @@
'use strict'; 'use strict';
var self = {}; var pbkdf2 = {};
/** /**
* PBKDF2-HMAC-SHA256 key derivation with a random salt and 10000 iterations * PBKDF2-HMAC-SHA256 key derivation with a random salt and 10000 iterations
@ -13,7 +13,7 @@ var self = {};
* @param {String} keySize The key size in bits * @param {String} keySize The key size in bits
* @return {String} The base64 encoded key * @return {String} The base64 encoded key
*/ */
self.getKey = function(password, salt, keySize) { pbkdf2.getKey = function(password, salt, keySize) {
var saltUtf8 = forge.util.decode64(salt); var saltUtf8 = forge.util.decode64(salt);
var md = forge.md.sha256.create(); var md = forge.md.sha256.create();
var key = forge.pkcs5.pbkdf2(password, saltUtf8, 10000, keySize / 8, md); var key = forge.pkcs5.pbkdf2(password, saltUtf8, 10000, keySize / 8, md);
@ -21,4 +21,4 @@ self.getKey = function(password, salt, keySize) {
return forge.util.encode64(key); return forge.util.encode64(key);
}; };
module.exports = self; module.exports = pbkdf2;

View File

@ -2,10 +2,10 @@
var cfg = require('../app-config').config; var cfg = require('../app-config').config;
var self = {}; var notif = {};
if (window.Notification) { if (window.Notification) {
self.hasPermission = Notification.permission === "granted"; notif.hasPermission = Notification.permission === "granted";
} }
/** /**
@ -17,18 +17,18 @@ if (window.Notification) {
* @param {Function} options.onClick (optional) callback when the notification is clicked * @param {Function} options.onClick (optional) callback when the notification is clicked
* @returns {Notification} A notification instance * @returns {Notification} A notification instance
*/ */
self.create = function(options) { notif.create = function(options) {
options.onClick = options.onClick || function() {}; options.onClick = options.onClick || function() {};
if (!window.Notification) { if (!window.Notification) {
return; return;
} }
if (!self.hasPermission) { if (!notif.hasPermission) {
// don't wait until callback returns // don't wait until callback returns
Notification.requestPermission(function(permission) { Notification.requestPermission(function(permission) {
if (permission === "granted") { if (permission === "granted") {
self.hasPermission = true; notif.hasPermission = true;
} }
}); });
} }
@ -51,8 +51,8 @@ self.create = function(options) {
return notification; return notification;
}; };
self.close = function(notification) { notif.close = function(notification) {
notification.close(); notification.close();
}; };
module.exports = self; module.exports = notif;