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

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2013-03-13 11:58:46 -04:00
'use strict';
var AppRouter = Backbone.Router.extend({
routes:{
'': 'login',
'compose': 'compose',
'accounts/:userId/folders': 'folders',
'accounts/:userId/folders/:folder': 'messagelist',
'accounts/:userId/folders/:folder/read/:messageId': 'read'
},
initialize: function () {
},
login: function() {
// init email dao and dependencies
var util = new app.crypto.Util(window, null);
var jsonDao = new app.dao.LawnchairDAO(window);
var crypto = new app.crypto.Crypto(window, util);
var cloudstorage = new app.dao.CloudStorage(window, $);
var devicestorage = new app.dao.DeviceStorage(crypto, jsonDao, null);
this.emailDao = new app.dao.EmailDAO(_, crypto, devicestorage, cloudstorage);
var loginView = new app.view.LoginView({dao: this.emailDao});
this.changePage(loginView);
},
compose: function() {
var composeView = new app.view.ComposeView();
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();
},
changePage: function (page) {
// render the page and append it to the DOM
2013-03-13 13:29:57 -04:00
var pageEl = $(page.el);
pageEl.attr('data-role', 'page');
2013-03-13 11:58:46 -04:00
page.render();
2013-03-13 13:29:57 -04:00
$('body').append(pageEl);
// handle back click
pageEl.on('vmousedown', '#backBtn', function(e) {
e.preventDefault();
window.history.back();
});
2013-03-13 11:58:46 -04:00
// 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;
});
2013-03-13 11:58:46 -04:00
$.mobile.changePage(pageEl, {changeHash:false, reverse:false});
2013-03-13 11:58:46 -04:00
}
});