From 2007fbcc0f5576adf11effe5ff7577ea5a174601 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 11 Jun 2013 03:14:57 +0200 Subject: [PATCH] tested mobile.html... works --- .jshintrc | 1 - src/index.js | 2 +- src/js/app-config.js | 29 ++---------- src/js/app-controller.js | 33 +++++++++---- src/js/app-router.js | 20 ++++---- src/js/crypto/crypto.js | 4 +- src/js/crypto/rsa.js | 6 +-- src/js/dao/cloudstorage-dao.js | 2 +- src/js/dao/email-dao.js | 4 +- src/js/jqm-config.js | 6 +-- src/js/model/account-model.js | 2 +- src/js/model/email-model.js | 2 +- src/js/model/folder-model.js | 2 +- src/js/view/accounts-view.js | 9 ++-- src/js/view/compose-view.js | 7 +-- src/js/view/folderlist-view.js | 9 ++-- src/js/view/login-view.js | 11 +++-- src/js/view/messagelist-view.js | 11 +++-- src/js/view/messagelistitem-view.js | 7 +-- src/js/view/read-view.js | 7 +-- src/mobile.html | 42 +---------------- src/mobile.js | 56 ++++++++++++----------- src/require-config.js | 4 ++ test/integration/cloudstorage-dao-test.js | 4 +- test/integration/main.js | 2 +- test/test-data.js | 2 +- test/unit/email-dao-test.js | 4 +- test/unit/main.js | 2 +- 28 files changed, 132 insertions(+), 158 deletions(-) diff --git a/.jshintrc b/.jshintrc index a690bc2..baa57aa 100644 --- a/.jshintrc +++ b/.jshintrc @@ -33,6 +33,5 @@ ], "globals": { - "app": true } } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 8af0f76..61ebb98 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ require(['require-config'], function() { 'use strict'; // Start the main app logic. - require(['jquery', 'js/app-controller', 'js/app-config'], function($, controller) { + require(['jquery', 'js/app-controller', 'js/app-config'], function($, controller, app) { /** * Load templates and start the application diff --git a/src/js/app-config.js b/src/js/app-config.js index 6a9cb80..57fc8bf 100644 --- a/src/js/app-config.js +++ b/src/js/app-config.js @@ -1,4 +1,4 @@ -(function() { +define([], function() { 'use strict'; /** @@ -6,9 +6,6 @@ */ var app = { model: {}, - view: {}, - dao: {}, - crypto: {}, util: {} }; @@ -31,28 +28,8 @@ get: function(name) { return this.templates[name]; - }, - - loadTemplates: function(names, callback) { - var that = this; - - var loadTemplate = function(index) { - var name = names[index]; - console.log('Loading template: ' + name); - $.get('tpl/' + name + '.html', function(data) { - that.templates[name] = data; - index++; - if (index < names.length) { - loadTemplate(index); - } else { - callback(); - } - }); - }; - loadTemplate(0); } }; - window.app = app; - -}()); \ No newline at end of file + return app; +}); \ No newline at end of file diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 402340a..972dd0f 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -1,21 +1,21 @@ /** * The main application controller */ -define(['js/dao/email-dao'], function(emailDao) { +define(['jquery', 'js/dao/email-dao', 'js/dao/keychain-dao', 'js/dao/cloudstorage-dao', + 'js/app-config', 'cordova' +], function($, EmailDAO, KeychainDAO, cloudstorage, app) { 'use strict'; var self = {}; + var emailDao; + /** * Initializes modules through dependecy injection */ self.init = function(callback) { - // var crypto = new app.crypto.Crypto(window, util); - // var cloudstorage = new app.dao.CloudStorage(window, $); - // var jsonDao = new app.dao.LawnchairDAO(Lawnchair); - // var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null); - // var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage); - // emailDao = new app.dao.EmailDAO(jsonDao, crypto, devicestorage, cloudstorage, util, keychain); + var keychain = new KeychainDAO(cloudstorage); + emailDao = new EmailDAO(cloudstorage, keychain); callback(); }; @@ -39,7 +39,7 @@ define(['js/dao/email-dao'], function(emailDao) { function onDeviceReady() { console.log('Starting app.'); - app.util.tpl.loadTemplates(views, callback); + loadTemplates(views, callback); } }; @@ -112,5 +112,22 @@ define(['js/dao/email-dao'], function(emailDao) { emailDao.init(account, password, callback); } + function loadTemplates(names, callback) { + var loadTemplate = function(index) { + var name = names[index]; + console.log('Loading template: ' + name); + $.get('tpl/' + name + '.html', function(data) { + app.util.tpl.templates[name] = data; + index++; + if (index < names.length) { + loadTemplate(index); + } else { + callback(); + } + }); + }; + loadTemplate(0); + } + return self; }); \ No newline at end of file diff --git a/src/js/app-router.js b/src/js/app-router.js index b459f6b..2009037 100644 --- a/src/js/app-router.js +++ b/src/js/app-router.js @@ -1,7 +1,10 @@ -(function() { +define(['jquery', 'backbone', 'js/view/login-view', 'js/view/compose-view', + 'js/view/folderlist-view', 'js/view/messagelist-view', 'js/view/read-view', + 'jquerymobile' +], function($, Backbone, LoginView, ComposeView, FolderListView, MessageListView, ReadView) { 'use strict'; - app.Router = Backbone.Router.extend({ + var Router = Backbone.Router.extend({ routes: { '': 'login', @@ -16,7 +19,7 @@ initialize: function() {}, login: function() { - var loginView = new app.view.LoginView(); + var loginView = new LoginView(); this.changePage(loginView); }, @@ -24,7 +27,7 @@ var self = this, composeView; - composeView = new app.view.ComposeView({ + composeView = new ComposeView({ account: userId, folder: folder, messageId: (messageId) ? decodeURIComponent(messageId) : null, @@ -35,7 +38,7 @@ }, folders: function(userId) { - var folderListView = new app.view.FolderListView({ + var folderListView = new FolderListView({ account: userId }); this.changePage(folderListView); @@ -43,7 +46,7 @@ messagelist: function(userId, folder) { var self = this; - var messageListView = new app.view.MessageListView({ + var messageListView = new MessageListView({ account: userId, folder: folder }); @@ -55,7 +58,7 @@ var self = this, readView; - readView = new app.view.ReadView({ + readView = new ReadView({ account: userId, folder: folder, messageId: decodeURIComponent(messageId), @@ -88,4 +91,5 @@ }); -}()); \ No newline at end of file + return Router; +}); \ No newline at end of file diff --git a/src/js/crypto/crypto.js b/src/js/crypto/crypto.js index 840f273..1460525 100644 --- a/src/js/crypto/crypto.js +++ b/src/js/crypto/crypto.js @@ -3,8 +3,8 @@ * gracefully degrades to JS crypto (if unavailable) */ define(['cryptoLib/util', 'cryptoLib/aes-cbc', 'cryptoLib/rsa', 'cryptoLib/crypto-batch', - 'js/crypto/pbkdf2' -], function(util, aes, rsa, cryptoBatch, pbkdf2) { + 'js/crypto/pbkdf2', 'js/app-config' +], function(util, aes, rsa, cryptoBatch, pbkdf2, app) { 'use strict'; var self = {}; diff --git a/src/js/crypto/rsa.js b/src/js/crypto/rsa.js index 206c7b7..73b4df5 100644 --- a/src/js/crypto/rsa.js +++ b/src/js/crypto/rsa.js @@ -4,7 +4,7 @@ /** * A Wrapper for Forge's RSA encryption */ - var RSA = function(forge, util) { + var RSA = function(forge, util, app) { var utl = forge.util; @@ -129,8 +129,8 @@ if (typeof define !== 'undefined' && define.amd) { // AMD - define(['forge', 'cryptoLib/util'], function(forge, util) { - return new RSA(forge, util); + define(['forge', 'cryptoLib/util', 'js/app-config'], function(forge, util, app) { + return new RSA(forge, util, app); }); } else if (typeof module !== 'undefined' && module.exports) { // node.js diff --git a/src/js/dao/cloudstorage-dao.js b/src/js/dao/cloudstorage-dao.js index c22c797..bc03914 100644 --- a/src/js/dao/cloudstorage-dao.js +++ b/src/js/dao/cloudstorage-dao.js @@ -2,7 +2,7 @@ * High level storage api for handling syncing of data to * and from the cloud. */ -define(['jquery'], function($) { +define(['jquery', 'js/app-config'], function($, app) { 'use strict'; var self = {}; diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 73c6f5a..78a33dc 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -3,8 +3,8 @@ * between the cloud service and the device's local storage */ define(['underscore', 'cryptoLib/util', 'js/crypto/crypto', 'js/dao/lawnchair-dao', - 'js/dao/devicestorage-dao', 'js/model/account-model' -], function(_, util, crypto, jsonDB, devicestorage) { + 'js/dao/devicestorage-dao', 'js/app-config', 'js/model/account-model' +], function(_, util, crypto, jsonDB, devicestorage, app) { 'use strict'; var EmailDAO = function(cloudstorage, keychain) { diff --git a/src/js/jqm-config.js b/src/js/jqm-config.js index e9bdb47..c3a22be 100644 --- a/src/js/jqm-config.js +++ b/src/js/jqm-config.js @@ -1,4 +1,4 @@ -(function() { +define(['jquery'], function($) { 'use strict'; $(document).on('mobileinit', function() { @@ -10,9 +10,9 @@ $.mobile.defaultPageTransition = 'none'; // Remove page from DOM when it's being replaced - $(document).on('pagehide', 'div[data-role="page"]', function(event, ui) { + $(document).on('pagehide', 'div[data-role="page"]', function(event) { $(event.currentTarget).remove(); }); }); -}()); \ No newline at end of file +}); \ No newline at end of file diff --git a/src/js/model/account-model.js b/src/js/model/account-model.js index 33cb6e5..f78439d 100644 --- a/src/js/model/account-model.js +++ b/src/js/model/account-model.js @@ -1,4 +1,4 @@ -define(['backbone', 'js/model/folder-model'], function(Backbone) { +define(['backbone', 'js/app-config', 'js/model/folder-model'], function(Backbone, app) { 'use strict'; app.model.Account = Backbone.Model.extend({ diff --git a/src/js/model/email-model.js b/src/js/model/email-model.js index f4d6b7e..22492eb 100644 --- a/src/js/model/email-model.js +++ b/src/js/model/email-model.js @@ -1,4 +1,4 @@ -define(['backbone'], function(Backbone) { +define(['backbone', 'js/app-config'], function(Backbone, app) { 'use strict'; app.model.Email = Backbone.Model.extend({ diff --git a/src/js/model/folder-model.js b/src/js/model/folder-model.js index 9ad1408..11777df 100644 --- a/src/js/model/folder-model.js +++ b/src/js/model/folder-model.js @@ -1,4 +1,4 @@ -define(['backbone'], function(Backbone) { +define(['backbone', 'js/app-config'], function(Backbone, app) { 'use strict'; app.model.Folder = Backbone.Model.extend({ diff --git a/src/js/view/accounts-view.js b/src/js/view/accounts-view.js index 1acd00b..4edb2c8 100644 --- a/src/js/view/accounts-view.js +++ b/src/js/view/accounts-view.js @@ -1,16 +1,17 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) { 'use strict'; - app.view.AccountsView = Backbone.View.extend({ + var AccountsView = Backbone.View.extend({ initialize: function() { this.template = _.template(app.util.tpl.get('accounts')); }, - render: function(eventName) { + render: function() { $(this.el).html(this.template()); return this; } }); -}()); \ No newline at end of file + return AccountsView; +}); \ No newline at end of file diff --git a/src/js/view/compose-view.js b/src/js/view/compose-view.js index 0ad854a..b78fb99 100644 --- a/src/js/view/compose-view.js +++ b/src/js/view/compose-view.js @@ -1,7 +1,7 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) { 'use strict'; - app.view.ComposeView = Backbone.View.extend({ + var ComposeView = Backbone.View.extend({ initialize: function(args) { var self = this; @@ -140,4 +140,5 @@ } }); -}()); \ No newline at end of file + return ComposeView; +}); \ No newline at end of file diff --git a/src/js/view/folderlist-view.js b/src/js/view/folderlist-view.js index 93f20b5..5ca1fc7 100644 --- a/src/js/view/folderlist-view.js +++ b/src/js/view/folderlist-view.js @@ -1,13 +1,13 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) { 'use strict'; - app.view.FolderListView = Backbone.View.extend({ + var FolderListView = Backbone.View.extend({ initialize: function() { this.template = _.template(app.util.tpl.get('folderlist')); }, - render: function(eventName) { + render: function() { var page = $(this.el); page.html(this.template(this.options)); @@ -23,4 +23,5 @@ } }); -}()); \ No newline at end of file + return FolderListView; +}); \ No newline at end of file diff --git a/src/js/view/login-view.js b/src/js/view/login-view.js index fca63e8..e58d1ba 100644 --- a/src/js/view/login-view.js +++ b/src/js/view/login-view.js @@ -1,7 +1,7 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) { 'use strict'; - app.view.LoginView = Backbone.View.extend({ + var LoginView = Backbone.View.extend({ initialize: function() { this.template = _.template(app.util.tpl.get('login')); @@ -23,7 +23,7 @@ login: function() { var page = $(this.el), - userId = page.find('#userId').val(), + userId = page.find('#userId').val() + '@mail.whiteout.io', password = page.find('#password').val(); // show loading msg during init @@ -35,7 +35,7 @@ // post message to main window app.util.postMessage('login', { - userId: userId + '@mail.whiteout.io', + userId: userId, password: password }, function(resArgs) { var err = resArgs.err; @@ -51,4 +51,5 @@ } }); -}()); \ No newline at end of file + return LoginView; +}); \ No newline at end of file diff --git a/src/js/view/messagelist-view.js b/src/js/view/messagelist-view.js index 55a9525..12c2ea3 100644 --- a/src/js/view/messagelist-view.js +++ b/src/js/view/messagelist-view.js @@ -1,7 +1,9 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config', + 'js/view/messagelistitem-view' +], function($, _, Backbone, app, MessageListItemView) { 'use strict'; - app.view.MessageListView = Backbone.View.extend({ + var MessageListView = Backbone.View.extend({ initialize: function(args) { this.template = _.template(app.util.tpl.get('messagelist')); @@ -92,7 +94,7 @@ folder: self.folder, model: email }; - list.append(new app.view.MessageListItemView(listItemArgs).render().el); + list.append(new MessageListItemView(listItemArgs).render().el); } // refresh list view @@ -103,4 +105,5 @@ }); -}()); \ No newline at end of file + return MessageListView; +}); \ No newline at end of file diff --git a/src/js/view/messagelistitem-view.js b/src/js/view/messagelistitem-view.js index 59aa33c..70238b9 100644 --- a/src/js/view/messagelistitem-view.js +++ b/src/js/view/messagelistitem-view.js @@ -1,7 +1,7 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) { 'use strict'; - app.view.MessageListItemView = Backbone.View.extend({ + var MessageListItemView = Backbone.View.extend({ tagName: "li", @@ -25,4 +25,5 @@ } }); -}()); \ No newline at end of file + return MessageListItemView; +}); \ No newline at end of file diff --git a/src/js/view/read-view.js b/src/js/view/read-view.js index ba3a20a..d85df98 100644 --- a/src/js/view/read-view.js +++ b/src/js/view/read-view.js @@ -1,7 +1,7 @@ -(function() { +define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) { 'use strict'; - app.view.ReadView = Backbone.View.extend({ + var ReadView = Backbone.View.extend({ initialize: function(args) { var self = this; @@ -67,4 +67,5 @@ }); -}()); \ No newline at end of file + return ReadView; +}); \ No newline at end of file diff --git a/src/mobile.html b/src/mobile.html index 75248aa..68ed8ed 100644 --- a/src/mobile.html +++ b/src/mobile.html @@ -8,47 +8,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/mobile.js b/src/mobile.js index c4ed1a9..b94ce08 100644 --- a/src/mobile.js +++ b/src/mobile.js @@ -1,31 +1,35 @@ -(function() { +require(['require-config'], function() { 'use strict'; - var controller, - router; + // Start the main app logic. + require(['jquery', 'backbone', 'js/app-controller', 'js/app-router', + 'js/app-config' + ], function($, Backbone, controller, Router, app) { - /** - * Load templates and start the application - */ - $(document).ready(function() { - controller = new app.Controller(); - controller.init(function() { - controller.start(startApp); + var router; + + /** + * Load templates and start the application + */ + $(document).ready(function() { + controller.init(function() { + controller.start(startApp); + }); }); + + function startApp() { + // start backone.js router + router = new Router(); + Backbone.history.start(); + } + + /** + * Helper method shim to ease message posting between sandbox and main window + */ + app.util.postMessage = function(cmd, args, callback) { + // handle the workload in the main window + controller.execute(cmd, args, callback); + }; + }); - - function startApp() { - // start backone.js router - router = new app.Router(); - Backbone.history.start(); - } - - /** - * Helper method shim to ease message posting between sandbox and main window - */ - app.util.postMessage = function(cmd, args, callback) { - // handle the workload in the main window - controller.execute(cmd, args, callback); - }; - -}()); \ No newline at end of file +}); \ No newline at end of file diff --git a/src/require-config.js b/src/require-config.js index e4d3357..5765809 100644 --- a/src/require-config.js +++ b/src/require-config.js @@ -8,6 +8,7 @@ test: '../../test', cryptoLib: '../js/crypto', jquery: 'jquery-1.8.2.min', + jquerymobile: 'jquery.mobile-1.2.0.min', underscore: 'underscore-1.4.4.min', backbone: 'backbone-1.0.0.min', lawnchair: 'lawnchair/lawnchair-git', @@ -31,6 +32,9 @@ }, underscore: { exports: '_' + }, + jquerymobile: { + deps: ['jquery', 'js/jqm-config'] } } }); diff --git a/test/integration/cloudstorage-dao-test.js b/test/integration/cloudstorage-dao-test.js index 5251aa5..e26f4cf 100644 --- a/test/integration/cloudstorage-dao-test.js +++ b/test/integration/cloudstorage-dao-test.js @@ -1,6 +1,6 @@ define(['js/dao/email-dao', 'js/dao/keychain-dao', 'js/dao/lawnchair-dao', - 'js/dao/cloudstorage-dao' -], function(EmailDAO, KeychainDAO, jsonDao, cloudstorage) { + 'js/dao/cloudstorage-dao', 'js/app-config' +], function(EmailDAO, KeychainDAO, jsonDao, cloudstorage, app) { 'use strict'; module("CloudStorage DAO"); diff --git a/test/integration/main.js b/test/integration/main.js index 3ef4007..79e27bd 100644 --- a/test/integration/main.js +++ b/test/integration/main.js @@ -7,7 +7,7 @@ require(['../../src/require-config'], function() { }); // Start the main app logic. - require(['cordova', 'js/app-config'], function() { + require(['js/app-config', 'cordova'], function(app) { // clear session storage of failed tests, so async order is correct after fail & refresh window.sessionStorage.clear(); window.Worker = undefined; diff --git a/test/test-data.js b/test/test-data.js index 21f4627..8f45eb8 100644 --- a/test/test-data.js +++ b/test/test-data.js @@ -1,4 +1,4 @@ -define(['cryptoLib/util', 'js/model/email-model'], function(util) { +define(['cryptoLib/util', 'js/app-config', 'js/model/email-model'], function(util, app) { 'use strict'; var self = {}; diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js index fb00ecd..dc03d69 100644 --- a/test/unit/email-dao-test.js +++ b/test/unit/email-dao-test.js @@ -1,6 +1,6 @@ define(['js/dao/email-dao', 'js/dao/keychain-dao', 'js/dao/lawnchair-dao', - 'js/crypto/crypto', 'js/dao/devicestorage-dao', 'test/test-data' -], function(EmailDAO, KeychainDAO, jsonDao, crypto, storage, testData) { + 'js/crypto/crypto', 'js/dao/devicestorage-dao', 'test/test-data', 'js/app-config' +], function(EmailDAO, KeychainDAO, jsonDao, crypto, storage, testData, app) { 'use strict'; module("Email DAO"); diff --git a/test/unit/main.js b/test/unit/main.js index 5b32cad..b45ad26 100644 --- a/test/unit/main.js +++ b/test/unit/main.js @@ -7,7 +7,7 @@ require(['../../src/require-config'], function() { }); // Start the main app logic. - require(['cordova', 'js/app-config'], function() { + require(['js/app-config', 'cordova'], function(app) { // clear session storage of failed tests, so async order is correct after fail & refresh window.sessionStorage.clear(); window.Worker = undefined;