1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-18 07:15:08 -05:00
kaiwa/clientapp/router.js
2015-02-23 18:27:05 +01:00

52 lines
1.3 KiB
JavaScript

/*global app, me, client*/
"use strict";
var Backbone = require('backbone');
var SettingsPage = require('./pages/settings');
var ChatPage = require('./pages/chat');
var GroupChatPage = require('./pages/groupchat');
module.exports = Backbone.Router.extend({
routes: {
'': 'settings',
'chat/:jid': 'chat',
'chat/:jid/:resource': 'chat',
'groupchat/:jid': 'groupchat',
'logout': 'logout'
},
// ------- ROUTE HANDLERS ---------
settings: function () {
app.renderPage(new SettingsPage({
model: me
}));
},
chat: function (jid) {
var contact = me.contacts.get(decodeURIComponent(jid));
if (contact) {
app.renderPage(new ChatPage({
model: contact
}));
} else {
app.navigate('/');
}
},
groupchat: function (jid) {
var contact = me.mucs.get(decodeURIComponent(jid));
if (contact) {
app.renderPage(new GroupChatPage({
model: contact
}));
} else {
app.navigate('/');
}
},
logout: function () {
if (client.sessionStarted) {
client.disconnect();
}
localStorage.clear();
window.location = '/login';
}
});