Block empty server titles

This commit is contained in:
Björn Dahlgren 2021-02-28 15:26:26 +01:00
parent b7d0aaa6bf
commit da7a71ed7f
3 changed files with 34 additions and 1 deletions

View File

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

View File

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

View File

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