diff --git a/lib/steam_mods.js b/lib/steam_mods.js index b30ee14..dc3db6e 100644 --- a/lib/steam_mods.js +++ b/lib/steam_mods.js @@ -33,15 +33,13 @@ SteamMods.prototype.find = function (id) { SteamMods.prototype.download = function (workshopId, cb) { var self = this this.armaSteamWorkshop.downloadMod(workshopId, function (err) { - self.addStatusForCurrentDowloads() self.updateMods() if (cb) { cb(err) } }) - self.addStatusForCurrentDowloads() - self.emit('mods', this.mods) + self.updateMods() } SteamMods.prototype.search = function (query, cb) { @@ -55,42 +53,9 @@ SteamMods.prototype.updateMods = function () { console.log(err) } else { self.mods = mods - self.addStatusForCurrentDowloads() self.emit('mods', mods) } }) } -SteamMods.prototype.isModDownloading = function (workshopId) { - return this.armaSteamWorkshop.currentDownloads[workshopId] === true -} - -SteamMods.prototype.addStatusForCurrentDowloads = function () { - var self = this - this.mods.forEach(function (mod) { - mod.downloading = self.isModDownloading(mod.id) - }) - - this.addDummyModsForCurrentDowloads() - this.emit('mods', this.mods) -} - -SteamMods.prototype.addDummyModsForCurrentDowloads = function () { - var self = this - for (var workshopId in this.armaSteamWorkshop.currentDownloads) { - var mod = self.mods.find(function (mod) { - return mod.id === workshopId - }) - - if (!mod) { - self.mods.splice(0, 0, { - id: workshopId, - name: workshopId, - path: null, - downloading: true - }) - } - } -} - module.exports = SteamMods diff --git a/package.json b/package.json index 74c8d1b..aa2edeb 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "dependencies": { "arma-server": "0.0.10", - "arma-steam-workshop": "https://github.com/Dahlgren/node-arma-steam-workshop/tarball/0396b9941eb43f714bd11df2bc5a99f0b283313e", + "arma-steam-workshop": "https://github.com/Dahlgren/node-arma-steam-workshop/tarball/57f11ee85ccac0a18a74c5acb5645c9af78ec5c0", "async": "^0.9.0", "backbone": "1.3.3", "backbone.bootstrap-modal": "https://github.com/powmedia/backbone.bootstrap-modal/archive/632210077c2424be2ee6ea2aafe0d3fe016ae524.tar.gz", diff --git a/public/js/app/views/mods/list_item.js b/public/js/app/views/mods/list_item.js index 70de938..df33946 100644 --- a/public/js/app/views/mods/list_item.js +++ b/public/js/app/views/mods/list_item.js @@ -1,4 +1,6 @@ +var $ = require('jquery') var _ = require('underscore') +var Ladda = require('ladda') var Marionette = require('marionette') var sweetAlert = require('sweet-alert') @@ -11,6 +13,7 @@ module.exports = Marionette.ItemView.extend({ template: template, events: { + 'click .install': 'installMod', 'click .destroy': 'deleteMod' }, @@ -18,6 +21,32 @@ module.exports = Marionette.ItemView.extend({ change: 'render' }, + installMod: function (event) { + var self = this + event.preventDefault() + + this.laddaBtn = Ladda.create(this.$el.find('.ladda-button').get(0)) + this.laddaBtn.start() + this.$el.find('.ladda-button').addClass('disabled') + + $.ajax({ + url: '/api/mods/', + type: 'POST', + data: { + id: this.model.get('id') + }, + dataType: 'json', + success: function (resp) { + self.laddaBtn.stop() + self.$el.find('.ladda-button').removeClass('disabled') + }, + error: function (resp) { + self.laddaBtn.stop() + self.$el.find('.ladda-button').removeClass('disabled') + } + }) + }, + deleteMod: function (event) { var self = this sweetAlert({ diff --git a/public/js/tpl/mods/list_item.html b/public/js/tpl/mods/list_item.html index 7f3bf8b..89a565d 100644 --- a/public/js/tpl/mods/list_item.html +++ b/public/js/tpl/mods/list_item.html @@ -7,10 +7,19 @@
<% } else { %> - - - Delete - +
+ <% if (needsUpdate) { %> + + + Update + + <% } %> + + + + Delete + +
<% } %>