arma-server-web-admin/public/js/app/views/mods/form.js

76 lines
2.0 KiB
JavaScript
Raw Normal View History

2014-05-06 23:35:44 +00:00
define(function (require) {
'use strict';
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
FormView = require('marionette-formview'),
Ladda = require('ladda'),
2014-05-06 23:35:44 +00:00
Mod = require('app/models/mod'),
tpl = require('text!tpl/mods/form.html');
return Marionette.ItemView.extend({
2014-05-21 22:52:20 +00:00
events: {
'submit': 'beforeSubmit',
},
2014-05-06 23:35:44 +00:00
template: _.template(tpl),
initialize: function (options) {
this.mods = options.mods;
this.model = new Mod();
this.bind('ok', this.submit);
this.bind('shown', this.shown);
},
2014-05-21 22:52:20 +00:00
beforeSubmit: function(e) {
e.preventDefault();
this.submit();
},
shown: function (modal) {
var $okBtn = modal.$el.find('.btn.ok');
$okBtn.addClass('ladda-button').attr('data-style', 'expand-left');
this.laddaBtn = Ladda.create($okBtn.get(0));
2014-05-21 22:54:14 +00:00
this.$el.find('form .mod').focus();
2014-05-06 23:35:44 +00:00
},
submit: function (modal) {
var self = this;
var $form = $('form');
2014-05-21 22:52:20 +00:00
if (modal) {
self.modal.preventClose();
}
2014-05-06 23:35:44 +00:00
$form.find('.form-group').removeClass('has-error');
$form.find('.help-block').text('');
this.laddaBtn.start();
2014-05-21 22:52:20 +00:00
self.modal.$el.find('.btn.cancel').addClass('disabled');
2014-05-06 23:35:44 +00:00
this.model.save({ name: $form.find('.mod').val() }, {
success: function () {
self.mods.fetch({
success : function () {
self.laddaBtn.stop();
2014-05-21 22:52:20 +00:00
self.modal.close();
2014-05-06 23:35:44 +00:00
}
});
},
error: function () {
self.laddaBtn.stop();
2014-05-06 23:35:44 +00:00
$form.find('.form-group').addClass('has-error');
$form.find('.help-block').text('Problem downloading mod');
2014-05-21 22:52:20 +00:00
self.modal.$el.find('.btn.cancel').removeClass('disabled');
2014-05-06 23:35:44 +00:00
}
});
},
});
});