Files
website/src/coffee/controllers/mod_pack_controller.coffee
T
Andrew Miner 930b8049a2 Convert site to a single JavaScript archive
* Convert build to use a single JavaScript file on the site (instead
  of downloading each library separately). This also means that all
  global variables (e.g., `$` for JQuery, `_` for Underscore.js) can
  be removed.
* Remove unused scripts and/or move them to a more appropriate repo
* Update the `deploy` script to work with CircleCI's automation
* Update markdown display code to allow images to be located with the
  markdown data files instead of the pre-rendered index pages
2015-04-29 19:58:53 -07:00

73 lines
2.2 KiB
CoffeeScript

###
Crafting Guide - mod_pack_controller.coffee
Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
BaseController = require './base_controller'
ModSelectorController = require './mod_selector_controller'
_ = require 'underscore'
{Duration} = require '../constants'
########################################################################################################################
module.exports = class ModPackController extends BaseController
constructor: (options={})->
if not options.model? then throw new Error 'options.model is required'
options.templateName = 'mod_pack'
super options
@storage = options.storage
# Event Methods ################################################################################
onSuggestModClicked: ->
return unless global.feedbackController?
global.feedbackController.enterFeedback 'Please add mod:\n\n'
# BaseController Overrides #####################################################################
onDidRender: ->
@$mods = @$('.mods')
@$toolbar = @$('.toolbar')
super
refresh: ->
if global.feedbackController?
@$toolbar.show duration:0
else
@$toolbar.hide duration:0
@_refreshMods()
super
# Backbone.View Overrides ######################################################################
events: ->
return _.extend super,
'click button[name="suggestMod"]': 'onSuggestModClicked'
# Private Methods ##############################################################################
_refreshMods: ->
@_modControllers ?= []
index = 0
if @model?
@model.eachMod (mod)=>
controller = @_modControllers[index]
if not controller?
controller = new ModSelectorController model:mod, storage:@storage
controller.render()
@$mods.append controller.$el
@_modControllers.push controller
else
controller.model = mod
index += 1
while @_modControllers.length > index
@_modControllers.pop().remove()