mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Create new server form
This commit is contained in:
parent
9f8995001c
commit
dec3056ef8
3
main.js
3
main.js
@ -47,8 +47,7 @@ app.get('/api/servers', function (req, res){
|
|||||||
app.post('/api/servers', function (req, res){
|
app.post('/api/servers', function (req, res){
|
||||||
var title = req.body.title;
|
var title = req.body.title;
|
||||||
var id = slug(title);
|
var id = slug(title);
|
||||||
manager.addServer(id, title);
|
res.send(manager.addServer(id, title));
|
||||||
res.send(manager.servers);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/servers/:id/start', function (req, res){
|
app.get('/api/servers/:id/start', function (req, res){
|
||||||
|
@ -47,7 +47,9 @@ function Manager() {
|
|||||||
Manager.prototype.addServer = (function (id, title) {
|
Manager.prototype.addServer = (function (id, title) {
|
||||||
mods = [];
|
mods = [];
|
||||||
port = 2302;
|
port = 2302;
|
||||||
this.servers.push(new Server(id, title, port, mods));
|
var server = new Server(id, title, port, mods)
|
||||||
|
this.servers.push(server);
|
||||||
|
return server;
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = Manager;
|
module.exports = Manager;
|
@ -9,7 +9,8 @@ define(function (require) {
|
|||||||
return Backbone.Model.extend({
|
return Backbone.Model.extend({
|
||||||
defaults: {
|
defaults: {
|
||||||
title: ''
|
title: ''
|
||||||
}
|
},
|
||||||
|
url: '/api/servers'
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -21,7 +21,7 @@ define(function (require) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addServer: function () {
|
addServer: function () {
|
||||||
var view = new AddServerView();
|
var view = new AddServerView({servers: this.servers});
|
||||||
new Backbone.BootstrapModal({ content: view, servers: this.servers }).open()
|
new Backbone.BootstrapModal({ content: view, servers: this.servers }).open()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -6,10 +6,37 @@ define(function (require) {
|
|||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
Backbone = require('backbone'),
|
Backbone = require('backbone'),
|
||||||
Marionette = require('marionette'),
|
Marionette = require('marionette'),
|
||||||
|
FormView = require('marionette-formview'),
|
||||||
|
Server = require('app/models/server'),
|
||||||
tpl = require('text!tpl/servers/add.html');
|
tpl = require('text!tpl/servers/add.html');
|
||||||
|
|
||||||
return Marionette.ItemView.extend({
|
return Marionette.ItemView.extend({
|
||||||
template: _.template(tpl),
|
template: _.template(tpl),
|
||||||
|
|
||||||
|
initialize: function (options) {
|
||||||
|
this.servers = options.servers;
|
||||||
|
this.model = new Server();
|
||||||
|
this.bind("ok", this.submit);
|
||||||
|
},
|
||||||
|
|
||||||
|
submit: function (modal) {
|
||||||
|
modal.preventClose();
|
||||||
|
|
||||||
|
this.model.set('title', $("form #title").val());
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.model.save({}, {
|
||||||
|
success: function() {
|
||||||
|
modal.close();
|
||||||
|
self.servers.fetch();
|
||||||
|
Backbone.history.navigate('#servers/' + self.model.get('id'), true);
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert("Error :(");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -1,14 +1,8 @@
|
|||||||
<form class="form-horizontal" role="form">
|
<form class="form-horizontal" role="form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
|
<label for="title" class="col-sm-2 control-label">Title</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
|
<input type="text" class="form-control title" data-field="title" id="title" placeholder="Title">
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user