From eb5c43e0e534e9cb35ae65e4f52fb90673935cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Thu, 22 May 2014 01:44:39 +0200 Subject: [PATCH] Resolve dependencies server side and update mod view as needed --- public/js/app/views/servers/view.js | 8 ++++++++ routes/servers.js | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index 3000cd9..d6e6c97 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -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') diff --git a/routes/servers.js b/routes/servers.js index d468cd8..977db06 100644 --- a/routes/servers.js +++ b/routes/servers.js @@ -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); } - - manager.save(); - - res.send(server); }; exports.destroy = function(req, res){