1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-17 22:55:11 -05:00
mail/src/js/app-router.js
2013-05-04 15:08:54 +02:00

98 lines
2.5 KiB
JavaScript

(function() {
'use strict';
app.Router = Backbone.Router.extend({
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'
},
initialize: function() {},
login: function() {
// init email dao and dependencies
var util = new app.crypto.Util(window, uuid);
var jsonDao = new app.dao.LawnchairDAO(window);
var crypto = new app.crypto.Crypto(window, util);
var naclCrypto = new app.crypto.NaclCrypto(nacl, util);
var cloudstorage = new app.dao.CloudStorage(window, $);
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
this.emailDao = new app.dao.EmailDAO(_, crypto, devicestorage, cloudstorage, naclCrypto, util);
var loginView = new app.view.LoginView({
dao: this.emailDao
});
this.changePage(loginView);
},
compose: function(userId, folder, messageId) {
var composeView = new app.view.ComposeView({
folder: folder,
messageId: decodeURIComponent(messageId),
dao: this.emailDao
});
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);
readView.renderBody(true);
},
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
});
}
});
}());