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',
|
2013-06-04 20:33:49 -04:00
|
|
|
'compose/:userId': 'compose',
|
|
|
|
'compose/:userId/folders/:folder': 'compose',
|
2013-04-01 17:23:25 -04:00
|
|
|
'accounts/:userId/folders': 'folders',
|
|
|
|
'accounts/:userId/folders/:folder': 'messagelist',
|
2013-05-04 09:08:54 -04:00
|
|
|
'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() {
|
2013-06-04 17:19:02 -04:00
|
|
|
var loginView = new app.view.LoginView();
|
2013-04-01 17:23:25 -04:00
|
|
|
this.changePage(loginView);
|
|
|
|
},
|
|
|
|
|
2013-05-04 07:02:17 -04:00
|
|
|
compose: function(userId, folder, messageId) {
|
2013-06-04 20:50:56 -04:00
|
|
|
var self = this,
|
|
|
|
composeView;
|
|
|
|
|
|
|
|
composeView = new app.view.ComposeView({
|
2013-06-04 20:33:49 -04:00
|
|
|
account: userId,
|
2013-05-04 07:02:17 -04:00
|
|
|
folder: folder,
|
2013-06-04 20:50:56 -04:00
|
|
|
messageId: (messageId) ? decodeURIComponent(messageId) : null,
|
|
|
|
callback: function(view) {
|
|
|
|
self.changePage(view);
|
|
|
|
}
|
2013-05-03 10:09:13 -04:00
|
|
|
});
|
2013-04-01 17:23:25 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
2013-06-04 17:19:02 -04:00
|
|
|
folder: folder
|
2013-04-01 17:23:25 -04:00
|
|
|
});
|
|
|
|
self.changePage(messageListView);
|
|
|
|
messageListView.loadItems();
|
|
|
|
},
|
|
|
|
|
|
|
|
read: function(userId, folder, messageId) {
|
2013-06-04 21:12:18 -04:00
|
|
|
var self = this,
|
|
|
|
readView;
|
|
|
|
|
|
|
|
readView = new app.view.ReadView({
|
|
|
|
account: userId,
|
2013-04-01 17:23:25 -04:00
|
|
|
folder: folder,
|
2013-06-04 21:12:18 -04:00
|
|
|
messageId: decodeURIComponent(messageId),
|
|
|
|
callback: function(view) {
|
|
|
|
self.changePage(view);
|
|
|
|
view.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);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}());
|