mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
c58ec6f308
Backbone to 1.3.3 Marionette to 2.4.7 Underscore to 1.8.3 Fixes collection sorting when new items are added
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
define(function (require) {
|
|
|
|
"use strict";
|
|
|
|
var $ = require('jquery'),
|
|
_ = require('underscore'),
|
|
Backbone = require('backbone'),
|
|
Marionette = require('marionette'),
|
|
Mods = require('app/collections/mods'),
|
|
FormView = require('app/views/servers/form'),
|
|
InfoView = require('app/views/servers/info'),
|
|
MissionsView = require('app/views/servers/missions/index'),
|
|
ModsListView = require('app/views/servers/mods/list'),
|
|
ParametersListView = require('app/views/servers/parameters/list'),
|
|
PlayersView = require('app/views/servers/players'),
|
|
tpl = require('text!tpl/servers/view.html');
|
|
|
|
return Marionette.LayoutView.extend({
|
|
template: _.template(tpl),
|
|
|
|
regions: {
|
|
infoView: "#tab-info",
|
|
missionsView: "#tab-missions",
|
|
modsView: "#tab-mods",
|
|
parametersView: "#parameters",
|
|
playersView: "#tab-players",
|
|
settingsView: "#settings",
|
|
},
|
|
|
|
events: {
|
|
"click .nav-tabs a" : "tabs",
|
|
"submit": "save",
|
|
},
|
|
|
|
modelEvents: {
|
|
"change": "serverUpdated",
|
|
},
|
|
|
|
initialize: function (options) {
|
|
this.missions = options.missions;
|
|
this.mods = options.mods;
|
|
},
|
|
|
|
onRender: function() {
|
|
this.infoView.show(new InfoView({model: this.model}));
|
|
this.missionsView.show(new MissionsView({missions: this.missions, model: this.model}));
|
|
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}));
|
|
},
|
|
|
|
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();
|
|
_.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 :(");
|
|
}
|
|
});
|
|
},
|
|
|
|
tabs: function(e) {
|
|
e.preventDefault();
|
|
$($(e.target).attr('href')).tab('show');
|
|
},
|
|
});
|
|
|
|
});
|