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

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-04-05 14:50:40 +00:00
define(function (require) {
2014-04-06 23:01:34 +00:00
2014-04-05 14:50:40 +00:00
"use strict";
2014-04-06 23:01:34 +00:00
2014-04-05 14:50:40 +00:00
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
FormView = require('marionette-formview'),
Ladda = require('ladda'),
2014-04-05 14:50:40 +00:00
IframeTransport = require('jquery.iframe-transport'),
Mission = require('app/models/mission'),
2014-04-06 23:01:34 +00:00
tpl = require('text!tpl/missions/form.html');
2014-04-05 14:50:40 +00:00
return Marionette.ItemView.extend({
template: _.template(tpl),
2014-04-06 23:01:34 +00:00
2014-04-05 14:50:40 +00:00
initialize: function (options) {
this.missions = options.missions;
this.model = new Mission();
this.bind("ok", this.submit);
this.bind('shown', this.shown);
},
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-04-05 14:50:40 +00:00
},
2014-04-06 23:01:34 +00:00
2014-04-05 14:50:40 +00:00
submit: function (modal) {
var self = this;
var $form = $('form');
2014-04-06 23:01:34 +00:00
2014-04-05 14:50:40 +00:00
modal.preventClose();
2014-04-06 23:01:34 +00:00
$form.find('.form-group').removeClass('has-error');
$form.find('.help-block').text('');
this.laddaBtn.start();
modal.$el.find('.btn.cancel').addClass('disabled');
2014-04-05 14:50:40 +00:00
$.ajax("/api/missions", {
files: $form.find(":file"),
iframe: true
}).complete(function(data) {
2014-04-06 23:01:34 +00:00
self.missions.fetch({success : function () {
self.laddaBtn.stop();
modal.close();
2014-04-06 23:01:34 +00:00
}});
2014-04-05 14:50:40 +00:00
});
},
});
2014-04-06 23:01:34 +00:00
});