arma-server-web-admin/public/js/app/views/servers/view.js

91 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-02-09 03:19:48 +00:00
define(function (require) {
2014-04-06 22:28:23 +00:00
2014-02-09 03:19:48 +00:00
"use strict";
2014-04-06 22:28:23 +00:00
2014-02-09 03:19:48 +00:00
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
2014-04-04 08:20:13 +00:00
Mods = require('app/collections/mods'),
FormView = require('app/views/servers/form'),
2014-04-04 08:20:13 +00:00
InfoView = require('app/views/servers/info'),
2015-08-23 22:16:16 +00:00
MissionsView = require('app/views/servers/missions/index'),
2014-04-08 20:59:59 +00:00
ModsListView = require('app/views/servers/mods/list'),
ParametersListView = require('app/views/servers/parameters/list'),
PlayersView = require('app/views/servers/players'),
2014-04-06 22:28:23 +00:00
tpl = require('text!tpl/servers/view.html');
return Marionette.LayoutView.extend({
2014-02-09 03:19:48 +00:00
template: _.template(tpl),
2014-04-06 22:28:23 +00:00
2014-04-04 08:20:13 +00:00
regions: {
2014-04-08 20:59:59 +00:00
infoView: "#tab-info",
2015-08-23 22:16:16 +00:00
missionsView: "#tab-missions",
2014-04-08 20:59:59 +00:00
modsView: "#tab-mods",
parametersView: "#parameters",
playersView: "#tab-players",
settingsView: "#settings",
2014-04-04 08:20:13 +00:00
},
2014-04-06 22:28:23 +00:00
events: {
"click .nav-tabs a" : "tabs",
"submit": "save",
2014-04-06 22:28:23 +00:00
},
modelEvents: {
"change": "serverUpdated",
},
2014-04-08 20:59:59 +00:00
initialize: function (options) {
2015-08-23 22:16:16 +00:00
this.missions = options.missions;
2014-04-08 20:59:59 +00:00
this.mods = options.mods;
},
2014-04-04 08:20:13 +00:00
onRender: function() {
2014-04-08 20:59:59 +00:00
this.infoView.show(new InfoView({model: this.model}));
this.missionsView.show(new MissionsView({missions: this.missions, model: this.model}));
2014-04-08 20:59:59 +00:00
this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
this.parametersView.show(new ParametersListView({model: this.model}));
this.playersView.show(new PlayersView({model: this.model}));
this.settingsView.show(new FormView({model: this.model}));
2014-04-04 08:20:13 +00:00
},
2014-04-06 22:28:23 +00:00
serverUpdated: function() {
this.infoView.currentView.render();
this.modsView.currentView.render();
this.parametersView.currentView.render();
this.playersView.currentView.render();
this.settingsView.currentView.render();
},
save: function (e) {
e.preventDefault();
var self = this;
var oldId = this.model.get('id');
var data = this.settingsView.currentView.serialize();
2015-08-23 22:16:16 +00:00
_.extend(data, this.missionsView.currentView.serialize());
_.extend(data, this.modsView.currentView.serialize());
_.extend(data, this.parametersView.currentView.serialize());
this.model.save(data, {
success: function() {
var newId = self.model.get('id');
if (oldId != newId) {
Backbone.history.navigate('#servers/' + newId, true);
} else {
self.serverUpdated();
}
},
error: function() {
alert("Error :(");
}
});
},
2014-04-06 22:28:23 +00:00
tabs: function(e) {
e.preventDefault();
$($(e.target).attr('href')).tab('show');
2014-04-06 22:28:23 +00:00
},
2014-02-09 03:19:48 +00:00
});
2014-04-06 22:28:23 +00:00
});