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

96 lines
2.6 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'),
Settings = require('app/models/settings'),
2014-02-09 03:19:48 +00:00
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(),
settings = new Settings(),
2014-02-09 03:19:48 +00:00
servers = new Servers(),
layoutView = new LayoutView({el: $body}).render();
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(new NavigationView({settings: settings, servers: servers}));
var initialized = false;
2014-06-08 12:29:38 +00:00
var socket = io.connect();
2018-08-18 11:04:33 +00:00
socket.on('missions', function (_missions) {
missions.set(_missions);
});
socket.on('mods', function (_mods) {
mods.set(_mods);
});
socket.on('servers', function (_servers) {
servers.set(_servers);
if (!initialized) {
initialized = true;
Backbone.history.start();
}
});
2018-08-18 10:31:41 +00:00
socket.on('settings', function (_settings) {
settings.set(_settings);
});
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 () {
layoutView.content.show(new ServersView({collection: servers}));
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 () {
layoutView.content.show(new MissionsView({missions: missions}));
2014-04-04 09:28:33 +00:00
},
2014-02-09 03:19:48 +00:00
mods: function () {
layoutView.content.show(new ModsListView({collection: mods}));
2014-02-09 03:19:48 +00:00
},
2014-04-06 21:09:52 +00:00
server: function (id) {
var server = servers.get(id);
if (server) {
2015-08-23 22:16:16 +00:00
layoutView.content.show(new ServerView({
model: server,
missions: missions,
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
});