Update URL param handling for new site

This commit is contained in:
Andrew Miner
2015-01-10 09:40:50 -08:00
parent f01d367024
commit fa29b77746
5 changed files with 30 additions and 22 deletions
+1
View File
@@ -24,6 +24,7 @@ module.exports = class CraftingPlan extends BaseModel
@have.on 'change', => @craft()
@want.on 'change', => @craft()
@modPack.on 'change', => @craft()
@clear()
+16
View File
@@ -16,6 +16,22 @@ module.exports = class ItemPage extends BaseModel
constructor: (attributes={}, options={})->
attributes.modPack ?= new ModPack
attributes.params ?= null
attributes.plan ?= new CraftingPlan modPack:attributes.modPack
attributes.table ?= new CraftingTable plan:attributes.plan
super attributes, options
@modPack.on 'change', => @_consumeParams()
# Private Methods ##############################################################################
_consumeParams: ->
return unless @params?.name?
item = @modPack.findItemByName @params.name, includeDisabled:true
return unless item? and item.isCraftable
quantity = if @params.quantity? then parseInt(@params.quantity) else 1
@plan.want.add item.slug, quantity
@params = null
+11 -3
View File
@@ -19,6 +19,7 @@ module.exports = class ModPack extends BaseModel
attributes.modVersions ?= []
super attributes, options
@loading = w(true)
@_parser = new ModVersionParser
# Public Methods ###############################################################################
@@ -98,8 +99,11 @@ module.exports = class ModPack extends BaseModel
return false
isLoading: ->
return @loading.inspect().state isnt 'pending'
loadModVersion: (url)->
w.promise (resolve, reject)=>
promise = w.promise (resolve, reject)=>
@trigger Event.load.started, this, url
$.ajax
url: url
@@ -109,6 +113,8 @@ module.exports = class ModPack extends BaseModel
error: (xhr, status, error)=>
reject @onModVersionLoadFailed(url, error, status, xhr)
@loading = w.join @loading, promise
loadModVersionData: (data)->
modVersion = @_parser.parse data
@modVersions.push modVersion
@@ -118,8 +124,10 @@ module.exports = class ModPack extends BaseModel
return modVersion
loadAllModVersions: (urlList)->
promises = (@loadModVersion(url) for url in urlList)
return w.settle promises
for url in urlList
@loadModVersion url
return @loading
# Event Methods ################################################################################