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){
|
||||
var title = req.body.title;
|
||||
var id = slug(title);
|
||||
manager.addServer(id, title);
|
||||
res.send(manager.servers);
|
||||
res.send(manager.addServer(id, title));
|
||||
});
|
||||
|
||||
app.get('/api/servers/:id/start', function (req, res){
|
||||
|
@ -47,7 +47,9 @@ function Manager() {
|
||||
Manager.prototype.addServer = (function (id, title) {
|
||||
mods = [];
|
||||
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;
|
@ -9,7 +9,8 @@ define(function (require) {
|
||||
return Backbone.Model.extend({
|
||||
defaults: {
|
||||
title: ''
|
||||
}
|
||||
},
|
||||
url: '/api/servers'
|
||||
});
|
||||
|
||||
});
|
@ -21,7 +21,7 @@ define(function (require) {
|
||||
},
|
||||
|
||||
addServer: function () {
|
||||
var view = new AddServerView();
|
||||
var view = new AddServerView({servers: this.servers});
|
||||
new Backbone.BootstrapModal({ content: view, servers: this.servers }).open()
|
||||
},
|
||||
});
|
||||
|
@ -6,10 +6,37 @@ define(function (require) {
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
FormView = require('marionette-formview'),
|
||||
Server = require('app/models/server'),
|
||||
tpl = require('text!tpl/servers/add.html');
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
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">
|
||||
<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">
|
||||
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
|
||||
</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">
|
||||
<input type="text" class="form-control title" data-field="title" id="title" placeholder="Title">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user