1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-17 14:45:02 -05:00
mail/src/js/app-router.js

98 lines
2.5 KiB
JavaScript
Raw Normal View History

2013-04-01 17:23:25 -04:00
(function() {
'use strict';
2013-03-13 11:58:46 -04:00
2013-04-01 17:23:25 -04:00
app.Router = Backbone.Router.extend({
2013-03-13 11:58:46 -04:00
2013-04-01 17:23:25 -04:00
routes: {
'': 'login',
'compose': 'compose',
'accounts/:userId/folders': 'folders',
'accounts/:userId/folders/:folder': 'messagelist',
'accounts/:userId/folders/:folder/read/:messageId': 'read',
'accounts/:userId/folders/:folder/reply/:messageId': 'compose'
2013-04-01 17:23:25 -04:00
},
2013-03-13 11:58:46 -04:00
2013-04-01 17:23:25 -04:00
initialize: function() {},
2013-03-13 11:58:46 -04:00
2013-04-01 17:23:25 -04:00
login: function() {
// init email dao and dependencies
2013-05-31 19:45:38 -04:00
var util = new cryptoLib.Util(window, uuid);
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
2013-04-01 17:23:25 -04:00
var crypto = new app.crypto.Crypto(window, util);
var cloudstorage = new app.dao.CloudStorage(window, $);
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
2013-05-31 19:45:38 -04:00
var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage);
this.emailDao = new app.dao.EmailDAO(_, crypto, devicestorage, cloudstorage, util, keychain);
2013-03-13 11:58:46 -04:00
2013-04-01 17:23:25 -04:00
var loginView = new app.view.LoginView({
dao: this.emailDao
});
this.changePage(loginView);
},
2013-05-04 07:02:17 -04:00
compose: function(userId, folder, messageId) {
2013-05-03 10:09:13 -04:00
var composeView = new app.view.ComposeView({
2013-05-04 07:02:17 -04:00
folder: folder,
messageId: decodeURIComponent(messageId),
2013-05-03 10:09:13 -04:00
dao: this.emailDao
});
2013-04-01 17:23:25 -04:00
this.changePage(composeView);
},
folders: function(userId) {
var folderListView = new app.view.FolderListView({
account: userId
});
this.changePage(folderListView);
},
messagelist: function(userId, folder) {
var self = this;
var messageListView = new app.view.MessageListView({
account: userId,
folder: folder,
dao: this.emailDao
});
self.changePage(messageListView);
messageListView.loadItems();
},
read: function(userId, folder, messageId) {
var readView = new app.view.ReadView({
folder: folder,
messageId: decodeURIComponent(messageId),
dao: this.emailDao
});
this.changePage(readView);
2013-05-04 07:02:17 -04:00
readView.renderBody(true);
2013-04-01 17:23:25 -04:00
},
changePage: function(page) {
// render the page and append it to the DOM
var pageEl = $(page.el);
pageEl.attr('data-role', 'page');
page.render();
$('body').append(pageEl);
// handle back click
pageEl.on('vmousedown', '#backBtn', function(e) {
e.preventDefault();
window.history.back();
});
// change page for link buttons on vmousedown instead of waiting on vmouseup
pageEl.on('vmousedown', 'a[data-role="button"]', function(e) {
e.preventDefault();
var href = $(e.currentTarget).attr('href');
window.location = href;
});
$.mobile.changePage(pageEl, {
changeHash: false,
reverse: false
});
}
});
}());