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'),
|
2014-09-12 23:51:31 +00:00
|
|
|
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'),
|
2016-11-19 22:31:38 +00:00
|
|
|
ParametersListView = require('app/views/servers/parameters/list'),
|
2014-11-09 18:07:00 +00:00
|
|
|
PlayersView = require('app/views/servers/players'),
|
2014-04-06 22:28:23 +00:00
|
|
|
tpl = require('text!tpl/servers/view.html');
|
|
|
|
|
2014-04-04 08:20:13 +00:00
|
|
|
return Marionette.Layout.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",
|
2016-11-19 22:31:38 +00:00
|
|
|
parametersView: "#parameters",
|
2014-11-09 18:07:00 +00:00
|
|
|
playersView: "#tab-players",
|
2016-11-19 22:31:38 +00:00
|
|
|
settingsView: "#settings",
|
2014-04-04 08:20:13 +00:00
|
|
|
},
|
2014-04-06 22:28:23 +00:00
|
|
|
|
|
|
|
events: {
|
|
|
|
"click .nav-tabs a" : "tabs",
|
2014-09-12 23:51:31 +00:00
|
|
|
"submit": "save",
|
2014-04-06 22:28:23 +00:00
|
|
|
},
|
|
|
|
|
2014-05-21 23:44:39 +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}));
|
2015-08-23 22:16:16 +00:00
|
|
|
this.missionsView.show(new MissionsView({missions: this.missions, server: this.model}));
|
2014-04-08 20:59:59 +00:00
|
|
|
this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
|
2016-11-19 22:31:38 +00:00
|
|
|
this.parametersView.show(new ParametersListView({server: this.model}));
|
2014-11-09 18:07:00 +00:00
|
|
|
this.playersView.show(new PlayersView({model: this.model}));
|
2014-09-12 23:51:31 +00:00
|
|
|
this.settingsView.show(new FormView({model: this.model}));
|
2014-04-04 08:20:13 +00:00
|
|
|
},
|
2014-04-06 22:28:23 +00:00
|
|
|
|
2014-05-21 23:44:39 +00:00
|
|
|
serverUpdated: function() {
|
2014-06-04 22:19:54 +00:00
|
|
|
this.infoView.currentView.render();
|
2014-05-21 23:44:39 +00:00
|
|
|
this.modsView.currentView.render();
|
2016-11-19 22:31:38 +00:00
|
|
|
this.parametersView.currentView.render();
|
2014-11-09 18:07:00 +00:00
|
|
|
this.playersView.currentView.render();
|
2014-09-12 23:51:31 +00:00
|
|
|
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());
|
2014-09-12 23:51:31 +00:00
|
|
|
_.extend(data, this.modsView.currentView.serialize());
|
2016-11-19 22:31:38 +00:00
|
|
|
_.extend(data, this.parametersView.currentView.serialize());
|
2014-09-12 23:51:31 +00:00
|
|
|
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-05-21 23:44:39 +00:00
|
|
|
},
|
|
|
|
|
2014-04-06 22:28:23 +00:00
|
|
|
tabs: function(e) {
|
2014-09-12 23:51:31 +00:00
|
|
|
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
|
|
|
|
|
|
|
});
|