arma-server-web-admin/public/js/app/views/servers/add.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-02-09 03:19:48 +00:00
define(function (require) {
2014-04-06 21:03:44 +00:00
2014-02-09 03:19:48 +00:00
"use strict";
2014-04-06 21:03:44 +00:00
2014-02-09 03:19:48 +00:00
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
2014-02-14 01:16:05 +00:00
FormView = require('marionette-formview'),
Server = require('app/models/server'),
2014-04-06 21:03:44 +00:00
tpl = require('text!tpl/servers/add.html');
2014-02-09 03:19:48 +00:00
return Marionette.ItemView.extend({
template: _.template(tpl),
2014-04-06 21:03:44 +00:00
2014-02-14 01:16:05 +00:00
initialize: function (options) {
this.servers = options.servers;
this.model = new Server();
this.bind("ok", this.submit);
},
2014-04-06 21:03:44 +00:00
2014-02-14 01:16:05 +00:00
submit: function (modal) {
modal.preventClose();
2014-04-06 21:03:44 +00:00
2014-02-14 01:16:05 +00:00
this.model.set('title', $("form #title").val());
2014-04-06 21:03:44 +00:00
2014-02-14 01:16:05 +00:00
var self = this;
2014-04-06 21:03:44 +00:00
2014-02-14 01:16:05 +00:00
this.model.save({}, {
success: function() {
modal.close();
2014-04-06 21:03:44 +00:00
self.servers.fetch({success : function () {
Backbone.history.navigate('#servers/' + self.model.get('id'), true);
}});
2014-02-14 01:16:05 +00:00
},
error: function() {
alert("Error :(");
}
});
}
2014-02-09 03:19:48 +00:00
});
2014-04-06 21:03:44 +00:00
});