Resolve dependencies server side and update mod view as needed

This commit is contained in:
Björn Dahlgren 2014-05-22 01:44:39 +02:00
parent 165f9de675
commit eb5c43e0e5
2 changed files with 23 additions and 5 deletions

View File

@ -24,6 +24,10 @@ define(function (require) {
"click .nav-tabs a" : "tabs",
},
modelEvents: {
"change": "serverUpdated",
},
initialize: function (options) {
this.mods = options.mods;
},
@ -33,6 +37,10 @@ define(function (require) {
this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
},
serverUpdated: function() {
this.modsView.currentView.render();
},
tabs: function(e) {
e.preventDefault()
$($(e.target).attr('href')).tab('show')

View File

@ -1,3 +1,4 @@
var playwithsix = require('playwithsix');
var slug = require('slug');
var Manager = require('./../manager');
@ -27,7 +28,7 @@ exports.create = function (req, res){
};
exports.show = function (req, res){
var server = manager.getServer(req.params.server)
var server = manager.getServer(req.params.server);
res.send({
id: server.id,
title: server.title,
@ -42,11 +43,20 @@ exports.update = function(req, res){
if (req.body.mods) {
server.mods = req.body.mods;
manager.save();
playwithsix.resolveDependencies(server.mods, function (err, mods) {
if (!err && mods) {
server.mods = mods;
}
manager.save();
res.send(server);
});
} else {
manager.save();
res.send(server);
}
};
exports.destroy = function(req, res){