arma-server-web-admin/public/js/app/router.js

85 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-02-09 03:19:48 +00:00
define(function (require) {
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
"use strict";
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
var $ = require('jquery'),
Backbone = require('backbone'),
LayoutView = require('app/views/layout'),
NavigationView = require('app/views/navigation'),
2014-04-13 17:10:40 +00:00
ServersView = require('app/views/servers/list'),
LogsListView = require('app/views/logs/list'),
2014-07-26 09:01:53 +00:00
MissionsView = require('app/views/missions/index'),
2014-02-09 03:19:48 +00:00
ModsListView = require('app/views/mods/list'),
ServerView = require('app/views/servers/view'),
Logs = require('app/collections/logs'),
2014-04-04 09:28:33 +00:00
Missions = require('app/collections/missions'),
2014-02-09 03:19:48 +00:00
Mods = require('app/collections/mods'),
Servers = require('app/collections/servers'),
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
$body = $('body'),
2014-04-04 09:28:33 +00:00
missions = new Missions(),
2014-02-09 03:19:48 +00:00
mods = new Mods(),
servers = new Servers(),
layoutView = new LayoutView({el: $body}).render(),
navigationView = new NavigationView({servers: servers}),
2014-04-13 17:10:40 +00:00
serversView = new ServersView({collection: servers}),
2014-07-26 09:01:53 +00:00
missionsView = new MissionsView({missions: missions}),
2014-02-09 03:19:48 +00:00
modsListView = new ModsListView({collection: mods});
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
return Backbone.Router.extend({
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
routes: {
"logs": "logs",
2014-04-04 09:28:33 +00:00
"missions": "missions",
2014-02-09 03:19:48 +00:00
"mods": "mods",
"servers/:id": "server",
"": "home",
},
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
initialize: function () {
layoutView.navigation.show(navigationView);
2014-04-04 09:28:33 +00:00
missions.fetch();
2014-06-08 12:29:38 +00:00
var socket = io.connect();
socket.on('mods', function (_mods) {
mods.set(_mods);
});
socket.on('servers', function (_servers) {
servers.set(_servers);
});
2014-02-09 03:19:48 +00:00
},
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
home: function () {
2014-04-13 17:10:40 +00:00
layoutView.content.show(serversView);
serversView.delegateEvents();
2014-02-09 03:19:48 +00:00
},
2014-04-06 21:09:52 +00:00
logs: function () {
var logs = new Logs();
logs.fetch();
layoutView.content.show(new LogsListView({collection: logs}));
},
2014-04-04 09:28:33 +00:00
missions: function () {
2014-07-26 09:01:53 +00:00
layoutView.content.show(missionsView);
missionsView.delegateEvents();
2014-04-04 09:28:33 +00:00
},
2014-02-09 03:19:48 +00:00
mods: function () {
layoutView.content.show(modsListView);
modsListView.delegateEvents();
},
2014-04-06 21:09:52 +00:00
server: function (id) {
var server = servers.get(id);
if (server) {
2014-04-08 20:59:59 +00:00
layoutView.content.show(new ServerView({model: server, mods: mods}));
} else {
this.navigate("#", true)
}
2014-02-09 03:19:48 +00:00
}
2014-04-06 21:09:52 +00:00
2014-02-09 03:19:48 +00:00
});
2014-04-06 21:09:52 +00:00
});