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

54 lines
1.4 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-07-26 09:01:53 +00:00
events: {
'click form button': 'submit',
},
2014-04-05 14:50:40 +00:00
initialize: function (options) {
this.missions = options.missions;
this.model = new Mission();
},
2014-07-26 09:01:53 +00:00
onShow: function () {
var $okBtn = this.$el.find('form button[type=submit]');
$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-07-26 09:01:53 +00:00
submit: function () {
2014-04-05 14:50:40 +00:00
var self = this;
var $form = $('form');
2014-04-06 23:01:34 +00:00
this.laddaBtn.start();
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();
2014-07-26 09:01:53 +00:00
self.render();
2014-04-06 23:01:34 +00:00
}});
2014-07-26 09:01:53 +00:00
}).error(function() {
self.laddaBtn.stop();
2014-04-05 14:50:40 +00:00
});
},
});
2014-04-06 23:01:34 +00:00
});