Initial implementation of tutorial pages
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
###
|
||||
Crafting Guide - markdown_section_controller.coffee
|
||||
|
||||
Copyright (c) 2015 by Redwood Labs
|
||||
All rights reserved.
|
||||
###
|
||||
|
||||
BaseController = require './base_controller'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class MarkdownSectionController extends BaseController
|
||||
|
||||
constructor: (options={})->
|
||||
options.model ?= ''
|
||||
options.title ?= 'Description'
|
||||
options.templateName = 'markdown_section'
|
||||
super options
|
||||
|
||||
@title = options.title
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@$title = @$('h2')
|
||||
@$markdownPanel = @$('.markdown')
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@$title.html @title
|
||||
|
||||
@$markdownPanel.empty()
|
||||
@$markdownPanel.html _.parseMarkdown @model
|
||||
super
|
||||
|
||||
# Backbone.View Overrides ######################################################################
|
||||
|
||||
events: ->
|
||||
return _.extend super,
|
||||
'click .markdown': 'routeLinkClick'
|
||||
@@ -11,6 +11,7 @@ ItemGroupController = require './item_group_controller'
|
||||
Mod = require '../models/mod'
|
||||
ModPack = require '../models/mod_pack'
|
||||
PageController = require './page_controller'
|
||||
TutorialController = require './tutorial_controller'
|
||||
{Duration} = require '../constants'
|
||||
{Text} = require '../constants'
|
||||
{Url} = require '../constants'
|
||||
@@ -55,15 +56,17 @@ module.exports = class ModPageController extends PageController
|
||||
onDidRender: ->
|
||||
@adsenseController = @addChild AdsenseController, '.view__adsense', model:'sidebar_skyscraper'
|
||||
|
||||
@$name = @$('.name')
|
||||
@$byline = @$('.byline p')
|
||||
@$description = @$('.description p')
|
||||
@$documentationLink = @$('.documentation')
|
||||
@$downloadLink = @$('.download')
|
||||
@$homePageLink = @$('.homePage')
|
||||
@$groupContainer = @$('.itemGroups')
|
||||
@$titleImage = @$('.titleImage img')
|
||||
@$versionSelector = @$('select.version')
|
||||
@$name = @$('.name')
|
||||
@$byline = @$('.byline p')
|
||||
@$description = @$('.description p')
|
||||
@$documentationLink = @$('.documentation')
|
||||
@$downloadLink = @$('.download')
|
||||
@$homePageLink = @$('.homePage')
|
||||
@$groupContainer = @$('.itemGroups')
|
||||
@$titleImage = @$('.titleImage img')
|
||||
@$tutorialsSection = @$('.tutorials')
|
||||
@$tutorialsContainer = @$('.tutorials .panel')
|
||||
@$versionSelector = @$('select.version')
|
||||
|
||||
super
|
||||
|
||||
@@ -83,6 +86,7 @@ module.exports = class ModPageController extends PageController
|
||||
@_refreshLink @$downloadLink, @model.downloadUrl
|
||||
|
||||
@_refreshItemGroups()
|
||||
@_refreshTutorials()
|
||||
@_refreshVersions()
|
||||
super
|
||||
|
||||
@@ -128,7 +132,7 @@ module.exports = class ModPageController extends PageController
|
||||
|
||||
while @_groupControllers.length > groupIndex + 1
|
||||
controller = @_groupControllers.pop()
|
||||
controller.$el.slideUp duration:Duration.normal, -> @remove()
|
||||
controller.$el.slideUp duration:Duration.normal, complete:-> @remove()
|
||||
|
||||
_refreshLink: ($link, url)->
|
||||
if url?
|
||||
@@ -137,6 +141,32 @@ module.exports = class ModPageController extends PageController
|
||||
else
|
||||
$link.slideUp duration:Duration.normal
|
||||
|
||||
_refreshTutorials: ->
|
||||
@_tutorialControllers ?= []
|
||||
tutorials = @model.tutorials
|
||||
|
||||
if tutorials.length is 0
|
||||
@$tutorialsSection.addClass 'hidden'
|
||||
else
|
||||
@$tutorialsSection.removeClass 'hidden'
|
||||
|
||||
index = 0
|
||||
for tutorial in tutorials
|
||||
controller = @_tutorialControllers[index]
|
||||
if not controller?
|
||||
controller = new TutorialController model:tutorial
|
||||
controller.render()
|
||||
@$tutorialsContainer.append controller.$el
|
||||
@_tutorialControllers.push controller
|
||||
else
|
||||
controller.model = model
|
||||
|
||||
index += 1
|
||||
|
||||
while @_tutorialControllers.length > index
|
||||
controller = @_tutorialControllers.pop()
|
||||
controller.$el.slideUp duration:Duration.normal, complete:-> @remove()
|
||||
|
||||
_refreshVersions: ->
|
||||
@$versionSelector.empty()
|
||||
return unless @model?
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
###
|
||||
Crafting Guide - tutorial_controller.coffee
|
||||
|
||||
Copyright (c) 2015 by Redwood Labs
|
||||
All rights reserved.
|
||||
###
|
||||
|
||||
BaseController = require './base_controller'
|
||||
{Url} = require '../constants'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class TutorialController extends BaseController
|
||||
|
||||
constructor: (options={})->
|
||||
if not options.model? then throw new Error 'options.model is required'
|
||||
options.templateName = 'tutorial'
|
||||
super options
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@$icon = @$('img')
|
||||
@$link = @$('a')
|
||||
@$title = @$('p')
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
templateData = modSlug:@model.modSlug, tutorialSlug:@model.slug
|
||||
@$icon.attr 'src', Url.tutorialIcon templateData
|
||||
@$link.attr 'href', Url.tutorial templateData
|
||||
@$title.html @model.name
|
||||
super
|
||||
|
||||
# Backbone.View Overrides ######################################################################
|
||||
|
||||
events: ->
|
||||
return _.extend super,
|
||||
'click a': 'routeLinkClick'
|
||||
@@ -0,0 +1,127 @@
|
||||
###
|
||||
Crafting Guide - tutorial_page_controller.coffee
|
||||
|
||||
Copyright (c) 2015 by Redwood Labs
|
||||
All rights reserved.
|
||||
###
|
||||
|
||||
AdsenseController = require './adsense_controller'
|
||||
BaseController = require './base_controller'
|
||||
MarkdownSectionController = require './markdown_section_controller'
|
||||
{Event} = require '../constants'
|
||||
{Url} = require '../constants'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class TutorialPageController extends BaseController
|
||||
|
||||
constructor: (options={})->
|
||||
if not options.modSlug? then throw new Error 'options.modSlug is required'
|
||||
if not options.tutorialSlug? then throw new Error 'options.tutorialSlug is required'
|
||||
if not options.modPack? then throw new Error 'options.modPack is required'
|
||||
|
||||
options.model ?= null
|
||||
options.templateName = 'tutorial_page'
|
||||
super options
|
||||
|
||||
@modPack = options.modPack
|
||||
@imageLoader = options.imageLoader
|
||||
@modSlug = options.modSlug
|
||||
@tutorialSlug = options.tutorialSlug
|
||||
|
||||
@modPack.on Event.change, => @_resolveTutorial()
|
||||
@_resolveTutorial()
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@adsenseController = @addChild AdsenseController, '.view__adsense', model:'sidebar_skyscraper'
|
||||
|
||||
@$byline = @$('.byline')
|
||||
@$bylineLink = @$('.byline a')
|
||||
@$name = @$('.name')
|
||||
@$officialLink = @$('a.officialPage')
|
||||
@$sectionsContainer = @$('.sections')
|
||||
@$title = @$('h1.name')
|
||||
@$titleImage = @$('.titleImage img')
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
if @model? and @model.isLoaded
|
||||
@$el.removeClass 'hidden'
|
||||
else
|
||||
@$el.addClass 'hidden'
|
||||
|
||||
@_refreshByline()
|
||||
@_refreshOfficialUrl()
|
||||
@_refreshSections()
|
||||
@_refreshTitle()
|
||||
super
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_refreshByline: ->
|
||||
if @model?
|
||||
@$byline.removeClass 'hidden'
|
||||
@$bylineLink.html @modPack.getMod(@modSlug).name
|
||||
@$bylineLink.attr 'href', Url.mod modSlug:@modSlug
|
||||
else
|
||||
@$byline.addClass 'hidden'
|
||||
|
||||
_refreshOfficialUrl: ->
|
||||
if @model?.officialUrl?
|
||||
@$officialLink.attr 'href', @model.officialUrl
|
||||
@$officialLink.removeClass 'hidden'
|
||||
else
|
||||
@$officialLink.addClass 'hidden'
|
||||
|
||||
_refreshTitle: ->
|
||||
if @model?
|
||||
@$title.html @model.name
|
||||
@$titleImage.attr 'src', Url.tutorialIcon modSlug:@modSlug, tutorialSlug:@tutorialSlug
|
||||
else
|
||||
@$title.empty()
|
||||
@$titleImage.removeAttr 'src'
|
||||
|
||||
_refreshSections: ->
|
||||
@_sectionControllers ?= []
|
||||
index = 0
|
||||
|
||||
if @model?
|
||||
for section in @model.sections
|
||||
controller = @_sectionControllers[index]
|
||||
if not controller?
|
||||
controller = new MarkdownSectionController title:section.title, model:section.content
|
||||
controller.render()
|
||||
@$sectionsContainer.append controller.$el
|
||||
@_sectionControllers.push controller
|
||||
else
|
||||
controller.title = section.title
|
||||
controller.model = section.model
|
||||
controller.refresh()
|
||||
|
||||
index += 1
|
||||
|
||||
while @_sectionControllers.length > index
|
||||
controller = @_sectionController.pop()
|
||||
controller.$el.fadeOut duration:Duration.normal, complete:-> @remove()
|
||||
|
||||
_resolveTutorial: ->
|
||||
return if @model?
|
||||
|
||||
mod = @modPack.getMod @modSlug
|
||||
if not mod?
|
||||
logger.error => "cannot find the mod for: #{@modSlug}"
|
||||
router.navigate '/', trigger:true
|
||||
return
|
||||
|
||||
if not mod.isLoaded
|
||||
mod.fetch()
|
||||
return
|
||||
|
||||
@model = mod.getTutorial @tutorialSlug
|
||||
if not @model?
|
||||
logger.error => "mod #{@modSlug} doesn't have a tutorial for: #{@tutorialSlug}"
|
||||
return
|
||||
|
||||
@model.fetch()
|
||||
Reference in New Issue
Block a user