Handle mods per server instance

This commit is contained in:
Björn Dahlgren 2014-04-08 22:59:59 +02:00
parent 94cfb866d0
commit 9a3ba370a9
10 changed files with 117 additions and 24 deletions

View File

@ -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/'
});
});
});

View File

@ -1,15 +1,15 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
title: ''
name: ''
}
});
});
});

View File

@ -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/',
});
});
});

View File

@ -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)
}

View 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();
},
});
});

View 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
}
},
});
});

View File

@ -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) {

View 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>

View File

@ -0,0 +1,4 @@
<td>
<input type="checkbox" value="<%-name%>" <%if (enabled) {%>checked<%}%>
<a href='#mods/<%-name%>'><%-name%></a>
</td>

View File

@ -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){