Add "Used as Tool to Make" section on item detail

This commit is contained in:
Andrew Miner
2015-02-26 20:04:41 -08:00
parent c78828426f
commit 2aa65d5e34
5 changed files with 67 additions and 35 deletions
@@ -30,31 +30,37 @@ module.exports = class ItemPageController extends BaseController
super options
@_imageLoader = options.imageLoader
@imageLoader = options.imageLoader
@_itemSlug = options.itemSlug
@_modPack = options.modPack
@modPack = options.modPack
@_modPack.on Event.change, => @tryRefresh()
@modPack.on Event.change, => @tryRefresh()
# BaseController Overrides #####################################################################
onDidRender: ->
@_similarItemsController = @addChild ItemGroupController, '.similar .view__item_group',
imageLoader: @_imageLoader
modPack: @_modPack
@_usedToMakeController = @addChild ItemGroupController, '.usedToMake .view__item_group',
imageLoader: @_imageLoader
modPack: @_modPack
@_usedAsToolToMakeController = @addChild ItemGroupController, '.usedAsToolToMake .view__item_group',
imageLoader: @imageLoader
modPack: @modPack
@$byline = @$('.byline')
@$bylineLink = @$('.byline a')
@$craftingPlanLink = @$('a.craftingPlan')
@$name = @$('h1.name')
@$recipeContainer = @$('.recipes .panel')
@$recipesSection = @$('.recipes')
@$similarSection = @$('.similar')
@$titleImage = @$('.titleImage img')
@$usedToMakeSection = @$('.usedToMake')
@_similarItemsController = @addChild ItemGroupController, '.similar .view__item_group',
imageLoader: @imageLoader
modPack: @modPack
@_usedToMakeController = @addChild ItemGroupController, '.usedToMake .view__item_group',
imageLoader: @imageLoader
modPack: @modPack
@$usedAsToolToMakeSection = @$('.usedAsToolToMake')
@$byline = @$('.byline')
@$bylineLink = @$('.byline a')
@$craftingPlanLink = @$('a.craftingPlan')
@$name = @$('h1.name')
@$recipeContainer = @$('.recipes .panel')
@$recipesSection = @$('.recipes')
@$similarSection = @$('.similar')
@$titleImage = @$('.titleImage img')
@$usedToMakeSection = @$('.usedToMake')
super
refresh: ->
@@ -62,10 +68,10 @@ module.exports = class ItemPageController extends BaseController
@_resolveItemSlug()
if @model.item?
display = @_modPack.findItemDisplay @model.item.slug
display = @modPack.findItemDisplay @model.item.slug
@$craftingPlanLink.attr href:display.craftingUrl
@$craftingPlanLink.fadeIn duration:Duration.fast
@_imageLoader.load display.iconUrl, @$titleImage
@imageLoader.load display.iconUrl, @$titleImage
@$name.html display.itemName
@$el.slideDown duration:Duration.normal
@@ -75,6 +81,7 @@ module.exports = class ItemPageController extends BaseController
@_refreshByline()
@_refreshRecipes()
@_refreshSimilarItems()
@_refreshUsedAsToolToMake()
@_refreshUsedToMake()
super
@@ -88,6 +95,15 @@ module.exports = class ItemPageController extends BaseController
# Private Methods ##############################################################################
_refreshUsedAsToolToMake: ->
@_usedAsToolToMakeController.title = 'Used as Tool to Make'
@_usedAsToolToMakeController.model = @model.findToolForRecipes()
if @_usedAsToolToMakeController.model?
@$usedAsToolToMakeSection.slideDown duration:Duration.normal
else
@$usedAsToolToMakeSection.slideUp duration:Duration.normal
_refreshByline: ->
mod = @model.item?.modVersion?.mod
if mod?.name?.length > 0
@@ -117,7 +133,7 @@ module.exports = class ItemPageController extends BaseController
for recipe in @model.findRecipes()
controller = @_recipeControllers[index]
if not controller?
controller = new FullRecipeController imageLoader:@_imageLoader, modPack:@_modPack, model:recipe
controller = new FullRecipeController imageLoader:@imageLoader, modPack:@modPack, model:recipe
@_recipeControllers.push controller
controller.render()
@$recipeContainer.append controller.$el
@@ -145,4 +161,4 @@ module.exports = class ItemPageController extends BaseController
@$similarSection.slideUp duration:Duration.normal
_resolveItemSlug: ->
@model.item = @_modPack.findItem @_itemSlug, includeDisabled:true
@model.item = @modPack.findItem @_itemSlug, includeDisabled:true