1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-25 10:42:17 -05:00
kaiwa/clientapp/router.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-09-17 14:19:37 -04:00
/*global app, me, client*/
2013-08-29 23:38:28 -04:00
"use strict";
2013-06-03 18:51:30 -04:00
2013-08-29 23:38:28 -04:00
var Backbone = require('backbone');
2015-02-23 12:24:16 -05:00
var SettingsPage = require('./pages/settings');
2013-08-29 23:38:28 -04:00
var ChatPage = require('./pages/chat');
2013-09-16 19:12:00 -04:00
var GroupChatPage = require('./pages/groupchat');
2013-06-03 18:51:30 -04:00
module.exports = Backbone.Router.extend({
routes: {
2015-02-23 12:24:16 -05:00
'': 'settings',
2013-09-05 19:53:23 -04:00
'chat/:jid': 'chat',
2013-12-20 06:39:06 -05:00
'chat/:jid/:resource': 'chat',
2013-09-16 19:12:00 -04:00
'groupchat/:jid': 'groupchat',
2013-09-05 19:53:23 -04:00
'logout': 'logout'
2013-06-03 18:51:30 -04:00
},
// ------- ROUTE HANDLERS ---------
2015-02-23 12:24:16 -05:00
settings: function () {
app.renderPage(new SettingsPage({
2013-06-03 18:51:30 -04:00
model: me
}));
},
2013-08-23 19:07:37 -04:00
chat: function (jid) {
2014-12-10 05:25:19 -05:00
var contact = me.contacts.get(decodeURIComponent(jid));
2013-08-20 13:45:06 -04:00
if (contact) {
2013-08-29 23:38:28 -04:00
app.renderPage(new ChatPage({
2013-08-20 13:45:06 -04:00
model: contact
}));
} else {
app.navigate('/');
}
2013-09-05 19:53:23 -04:00
},
2013-09-16 19:12:00 -04:00
groupchat: function (jid) {
2014-12-10 05:25:19 -05:00
var contact = me.mucs.get(decodeURIComponent(jid));
2013-09-16 19:12:00 -04:00
if (contact) {
app.renderPage(new GroupChatPage({
model: contact
}));
} else {
app.navigate('/');
}
},
2013-09-05 19:53:23 -04:00
logout: function () {
2013-09-17 14:19:37 -04:00
if (client.sessionStarted) {
client.disconnect();
}
2013-09-05 19:53:23 -04:00
localStorage.clear();
window.location = '/login';
2013-06-03 18:51:30 -04:00
}
});