Fixed loading indicator not working on mission upload and download

This commit is contained in:
Björn Dahlgren 2015-08-15 17:26:30 +02:00
parent f121729211
commit 12cab35055
4 changed files with 12 additions and 22 deletions

View File

@ -24,29 +24,24 @@ define(function (require) {
this.model = new Mission(); this.model = new Mission();
}, },
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));
},
submit: function () { submit: function () {
var self = this; var self = this;
var $form = this.$el.find('form'); var $form = this.$el.find('form');
this.laddaBtn.start(); var $uploadBtn = $form.find('button[type=submit]');
var laddaBtn = Ladda.create($uploadBtn.get(0));
laddaBtn.start();
$.ajax("/api/missions", { $.ajax("/api/missions", {
files: $form.find(":file"), files: $form.find(":file"),
iframe: true iframe: true
}).complete(function(data) { }).complete(function(data) {
self.missions.fetch({success : function () { self.missions.fetch({success : function () {
self.laddaBtn.stop(); laddaBtn.stop();
self.render(); self.render();
}}); }});
}).error(function() { }).error(function() {
self.laddaBtn.stop(); laddaBtn.stop();
}); });
}, },
}); });

View File

@ -23,18 +23,13 @@ define(function (require) {
this.missions = options.missions; this.missions = options.missions;
}, },
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));
},
submit: function () { submit: function () {
var self = this; var self = this;
var $form = this.$el.find('form'); var $form = this.$el.find('form');
this.laddaBtn.start(); var $downloadBtn = $form.find('button[type=submit]');
var laddaBtn = Ladda.create($downloadBtn.get(0));
laddaBtn.start();
$.ajax({ $.ajax({
url: '/api/missions/workshop', url: '/api/missions/workshop',
@ -45,12 +40,12 @@ define(function (require) {
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {
self.missions.fetch({success : function () { self.missions.fetch({success : function () {
self.laddaBtn.stop(); laddaBtn.stop();
self.render(); self.render();
}}); }});
}, },
error: function () { error: function () {
self.laddaBtn.stop(); laddaBtn.stop();
}, },
}); });
}, },

View File

@ -4,5 +4,5 @@
<input type="file" class="form-control path" name="mission" id="mission" data-field="mission"> <input type="file" class="form-control path" name="mission" id="mission" data-field="mission">
<span class="help-block">Only supports missions packed as a PBO</span> <span class="help-block">Only supports missions packed as a PBO</span>
</div> </div>
<button type="submit" class="btn btn-primary">Upload</button> <button type="submit" class="btn btn-primary ladda-button" data-style="expand-left">Upload</button>
</form> </form>

View File

@ -7,5 +7,5 @@
<i>https://steamcommunity.com/workshop/filedetails/?id=$id</i> <i>https://steamcommunity.com/workshop/filedetails/?id=$id</i>
</span> </span>
</div> </div>
<button type="submit" class="btn btn-primary">Download</button> <button type="submit" class="btn btn-primary ladda-button" data-style="expand-left">Download</button>
</form> </form>