diff --git a/public/js/app/views/servers/form.js b/public/js/app/views/servers/form.js index b49de4c..e0ffb63 100644 --- a/public/js/app/views/servers/form.js +++ b/public/js/app/views/servers/form.js @@ -37,7 +37,18 @@ module.exports = Marionette.ItemView.extend({ submit: function (modal) { modal.preventClose() - this.model.set(this.serialize()) + var data = this.serialize() + + if (!data.title) { + sweetAlert({ + title: 'Error', + text: 'Server title cannot be empty', + type: 'error' + }) + return + } + + this.model.set(data) var self = this diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index 51dd3a7..d93123a 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -57,12 +57,24 @@ module.exports = Marionette.LayoutView.extend({ save: function (e) { e.preventDefault() + var self = this var oldId = this.model.get('id') var data = this.settingsView.currentView.serialize() + + if (!data.title) { + sweetAlert({ + title: 'Error', + text: 'Server title cannot be empty', + type: 'error' + }) + return + } + _.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') diff --git a/routes/servers.js b/routes/servers.js index c63aa6f..8a64cb8 100644 --- a/routes/servers.js +++ b/routes/servers.js @@ -8,6 +8,11 @@ module.exports = function (manager, mods) { }) router.post('/', function (req, res) { + if (!req.body.title) { + res.status(400).send('Server title cannot be empty') + return + } + var server = manager.addServer(req.body) res.json(server) }) @@ -18,6 +23,11 @@ module.exports = function (manager, mods) { }) router.put('/:server', function (req, res) { + if (!req.body.title) { + res.status(400).send('Server title cannot be empty') + return + } + var server = manager.getServer(req.params.server) server.update(req.body) manager.save()