mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-11-05 17:15:04 -05:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
/*global app, me, client*/
|
|
"use strict";
|
|
|
|
var Backbone = require('backbone');
|
|
var MainPage = require('./pages/main');
|
|
var ChatPage = require('./pages/chat');
|
|
var GroupChatPage = require('./pages/groupchat');
|
|
|
|
|
|
module.exports = Backbone.Router.extend({
|
|
routes: {
|
|
'': 'main',
|
|
'chat/:jid': 'chat',
|
|
'groupchat/:jid': 'groupchat',
|
|
'logout': 'logout'
|
|
},
|
|
// ------- ROUTE HANDLERS ---------
|
|
main: function () {
|
|
app.renderPage(new MainPage({
|
|
model: me
|
|
}));
|
|
},
|
|
chat: function (jid) {
|
|
var contact = me.contacts.get(jid);
|
|
if (contact) {
|
|
app.renderPage(new ChatPage({
|
|
model: contact
|
|
}));
|
|
} else {
|
|
app.navigate('/');
|
|
}
|
|
},
|
|
groupchat: function (jid) {
|
|
var contact = me.mucs.get(jid);
|
|
if (contact) {
|
|
app.renderPage(new GroupChatPage({
|
|
model: contact
|
|
}));
|
|
} else {
|
|
app.navigate('/');
|
|
}
|
|
},
|
|
logout: function () {
|
|
if (client.sessionStarted) {
|
|
client.disconnect();
|
|
}
|
|
localStorage.clear();
|
|
window.location = '/login';
|
|
}
|
|
});
|