Add nascent version of the mod detail page

* Create a nascent version of the mod detail page
* Make the slug mandatory for Mod instead of name, and load the name
  from the data file
* Make the Feedback view universal on all pages
* Refactor the use of mod pack to have a single global object at the
  router level which is shared between pages. Further, make this one
  object load itself immediately and have it automatically load any
  activated mod version
* Refactor the use of Storage related to mod pack versions into the
  router as well.
* Add trace logging back in for events, but allow individual classes
  to suppress it (as opposed to actually supressing the events)
* Fix a bug in ModVersion.eachItem where it would suggest so-called
  items which are merely registered slugs without associated items
This commit is contained in:
Andrew Miner
2015-01-20 10:55:38 -08:00
parent d33723b3c2
commit 164c0d4892
25 changed files with 151 additions and 26 deletions
@@ -87,7 +87,7 @@ module.exports = class BaseController extends Backbone.View
logger.error "Default render called for #{@constructor.name} without a template"
return this
logger.verbose "#{this} rendering with data: #{data}"
logger.verbose "#{this} rendering with data: #{util.inspect(data)}"
@onWillRender()
$oldEl = @$el
$newEl = Backbone.$(@_template(data))
@@ -20,7 +20,7 @@ Storage = require '../models/storage'
module.exports = class ItemPageController extends BaseController
constructor: (options={})->
options.model ?= new ItemPage
options.model ?= new ItemPage modPack:options.modPack
options.imageLoader ?= new ImageLoader defaultUrl:'/images/unknown.png'
options.storage ?= new Storage storage:window.localStorage
options.templateName = 'item_page'
@@ -36,12 +36,6 @@ module.exports = class ModController extends BaseController
# BaseController Overrides #####################################################################
onWillRender: ->
@model.fetch()
if @_storage? then @_storage.register "mod:#{@model.slug}", @model, 'activeVersion'
@model.on Event.change + ':activeModVersion', (mod, modVersion)=>
if modVersion? then modVersion.fetch()
onDidRender: ->
@$enabled = @$('td:nth-child(1) input')
@$name = @$('td:nth-child(2) p')
@@ -33,10 +33,6 @@ module.exports = class ModPackController extends BaseController
# BaseController Overrides #####################################################################
onWillRender: ->
for name in DefaultMods
@model.addMod new Mod name:name
onDidRender: ->
@$table = @$('table')
@$toolbar = @$('.toolbar')
@@ -0,0 +1,55 @@
###
Crafting Guide - mod_page_controller.coffee
Copyright (c) 2015 by Redwood Labs
All rights reserved.
###
BaseController = require './base_controller'
{Duration} = require '../constants'
ModPack = require '../models/mod_pack'
RecipeController = require './recipe_controller'
########################################################################################################################
module.exports = class ModPageController extends BaseController
constructor: (options={})->
if not options.modPack? then throw new Error 'options.modPack is required'
options.templateName = 'mod_page'
super options
@_modPack = options.modPack
@_recipeControllers = []
# BaseController Overrides #####################################################################
onDidRender: ->
@$title = @$('h1')
@$recipes = @$('.recipes')
super
refresh: ->
@$title.html if @model? then @model.name else ''
controllerIndex = 0
if @model?.activeModVersion?.isLoaded
@$recipes.show duration:Duration.fast
@model.eachItem (item)=>
controller = @_recipeControllers[controllerIndex]
if not controller?
controller = new RecipeController modPack:@_modPack
controller.render()
@_recipeControllers.push controller
@$recipes.append controller.$el
controller.model = item.getPrimaryRecipe()
controllerIndex += 1
else
@$recipes.hide duration:Duration.fast
while @_recipeControllers.length > controllerIndex
controller = @_recipeControllers.pop()
controller.$el.slideUp duration:Duration.fast, complete:-> @remove()
super