mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Get mod status from Steam Workshop
This commit is contained in:
parent
08beb108a4
commit
955b8215a4
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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({
|
||||
|
@ -7,10 +7,19 @@
|
||||
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width: 100%"></div>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<a class="btn btn-danger btn-xs destroy ladda-button pull-right" data-style="expand-left">
|
||||
<div class="btn-group pull-right" role="group">
|
||||
<% if (needsUpdate) { %>
|
||||
<a class="btn btn-primary btn-xs install ladda-button" data-style="expand-left">
|
||||
<span class="glyphicon glyphicon-save"></span>
|
||||
Update
|
||||
</a>
|
||||
<% } %>
|
||||
|
||||
<a class="btn btn-danger btn-xs destroy ladda-button" data-style="expand-left">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
Delete
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
<% } %>
|
||||
|
Loading…
Reference in New Issue
Block a user