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

49 lines
1.3 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'),
2015-08-15 15:12:50 +00:00
tpl = require('text!tpl/missions/upload.html');
2014-04-06 23:01:34 +00:00
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
submit: function () {
2014-04-05 14:50:40 +00:00
var self = this;
2015-08-15 15:12:50 +00:00
var $form = this.$el.find('form');
2014-04-06 23:01:34 +00:00
var $uploadBtn = $form.find('button[type=submit]');
var laddaBtn = Ladda.create($uploadBtn.get(0));
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 () {
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() {
laddaBtn.stop();
2014-04-05 14:50:40 +00:00
});
},
});
2014-04-06 23:01:34 +00:00
});