mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Handle mods per server instance
This commit is contained in:
parent
94cfb866d0
commit
9a3ba370a9
@ -1,15 +1,15 @@
|
||||
define(function (require) {
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Server = require('app/models/server');
|
||||
|
||||
|
||||
return Backbone.Collection.extend({
|
||||
model: Server,
|
||||
url: '/api/servers/'
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,15 +1,15 @@
|
||||
define(function (require) {
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone');
|
||||
|
||||
|
||||
return Backbone.Model.extend({
|
||||
defaults: {
|
||||
title: ''
|
||||
name: ''
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,16 +1,16 @@
|
||||
define(function (require) {
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone');
|
||||
|
||||
|
||||
return Backbone.Model.extend({
|
||||
defaults: {
|
||||
title: ''
|
||||
},
|
||||
url: '/api/servers'
|
||||
urlRoot: '/api/servers/',
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -58,7 +58,7 @@ define(function (require) {
|
||||
server: function (id) {
|
||||
var server = servers.get(id);
|
||||
if (server) {
|
||||
layoutView.content.show(new ServerView({model: server}));
|
||||
layoutView.content.show(new ServerView({model: server, mods: mods}));
|
||||
} else {
|
||||
this.navigate("#", true)
|
||||
}
|
||||
|
39
public/js/app/views/servers/mods/list.js
Normal file
39
public/js/app/views/servers/mods/list.js
Normal file
@ -0,0 +1,39 @@
|
||||
define(function (require) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
Mods = require('app/collections/mods'),
|
||||
ModsListView = require('app/views/mods/list'),
|
||||
ListItemView = require('app/views/servers/mods/list_item'),
|
||||
tpl = require('text!tpl/servers/mods/list.html');
|
||||
|
||||
return ModsListView.extend({
|
||||
itemView: ListItemView,
|
||||
template: _.template(tpl),
|
||||
|
||||
events: {
|
||||
"submit": "save",
|
||||
},
|
||||
|
||||
buildItemView: function(item, ItemViewType, itemViewOptions){
|
||||
var options = _.extend({model: item, server: this.options.server}, itemViewOptions);
|
||||
var view = new ItemViewType(options);
|
||||
return view;
|
||||
},
|
||||
|
||||
save: function (event) {
|
||||
event.preventDefault();
|
||||
var enabledMods = $('input:checkbox:checked').map(function (idx, el) {
|
||||
return $(el).val();
|
||||
}).get();
|
||||
|
||||
this.options.server.set('mods', enabledMods);
|
||||
this.options.server.save();
|
||||
},
|
||||
});
|
||||
|
||||
});
|
24
public/js/app/views/servers/mods/list_item.js
Normal file
24
public/js/app/views/servers/mods/list_item.js
Normal file
@ -0,0 +1,24 @@
|
||||
define(function (require) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
ModListItemView = require('app/views/mods/list_item'),
|
||||
tpl = require('text!tpl/servers/mods/list_item.html'),
|
||||
|
||||
template = _.template(tpl);
|
||||
|
||||
return ModListItemView.extend({
|
||||
tagName: "tr",
|
||||
template: template,
|
||||
|
||||
templateHelpers: function(){
|
||||
return {
|
||||
enabled: this.options.server.get('mods').indexOf(this.model.get('name')) > -1
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
@ -8,15 +8,15 @@ define(function (require) {
|
||||
Marionette = require('marionette'),
|
||||
Mods = require('app/collections/mods'),
|
||||
InfoView = require('app/views/servers/info'),
|
||||
ModsListView = require('app/views/mods/list'),
|
||||
ModsListView = require('app/views/servers/mods/list'),
|
||||
tpl = require('text!tpl/servers/view.html');
|
||||
|
||||
return Marionette.Layout.extend({
|
||||
template: _.template(tpl),
|
||||
|
||||
regions: {
|
||||
info: "#tab-info",
|
||||
mods: "#tab-mods",
|
||||
infoView: "#tab-info",
|
||||
modsView: "#tab-mods",
|
||||
settings: "#tab-settings"
|
||||
},
|
||||
|
||||
@ -24,9 +24,13 @@ define(function (require) {
|
||||
"click .nav-tabs a" : "tabs",
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
this.mods = options.mods;
|
||||
},
|
||||
|
||||
onRender: function() {
|
||||
this.info.show(new InfoView({model: this.model}));
|
||||
this.mods.show(new ModsListView({collection: new Mods(this.model.get('mods'))}));
|
||||
this.infoView.show(new InfoView({model: this.model}));
|
||||
this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
|
||||
},
|
||||
|
||||
tabs: function(e) {
|
||||
|
14
public/js/tpl/servers/mods/list.html
Normal file
14
public/js/tpl/servers/mods/list.html
Normal file
@ -0,0 +1,14 @@
|
||||
<form>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Mod</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<!-- want to insert collection items, here -->
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
<button class="btn btn-default btn-primary" type="submit">Save</button>
|
||||
</form>
|
4
public/js/tpl/servers/mods/list_item.html
Normal file
4
public/js/tpl/servers/mods/list_item.html
Normal file
@ -0,0 +1,4 @@
|
||||
<td>
|
||||
<input type="checkbox" value="<%-name%>" <%if (enabled) {%>checked<%}%>
|
||||
<a href='#mods/<%-name%>'><%-name%></a>
|
||||
</td>
|
@ -30,7 +30,15 @@ exports.show = function (req, res){
|
||||
};
|
||||
|
||||
exports.update = function(req, res){
|
||||
res.send('update server ' + req.params.server);
|
||||
var server = manager.getServer(req.params.server);
|
||||
|
||||
if (req.body.mods) {
|
||||
server.mods = req.body.mods;
|
||||
}
|
||||
|
||||
manager.save();
|
||||
|
||||
res.send(server);
|
||||
};
|
||||
|
||||
exports.destroy = function(req, res){
|
||||
|
Loading…
Reference in New Issue
Block a user