2014-07-17 20:22:26 -04:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/modal/docs'
|
|
|
|
Article = require 'models/Article'
|
2014-03-13 12:02:19 -04:00
|
|
|
utils = require 'lib/utils'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
# let's implement this once we have the docs database schema set up
|
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class LevelGuideModal extends ModalView
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
2014-02-26 18:44:46 -05:00
|
|
|
id: 'docs-modal'
|
2014-03-13 12:02:19 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
shortcuts:
|
|
|
|
'enter': 'hide'
|
|
|
|
|
|
|
|
constructor: (options) ->
|
2014-05-20 01:25:40 -04:00
|
|
|
@firstOnly = options.firstOnly
|
2014-08-29 20:03:02 -04:00
|
|
|
@docs = options?.docs ? {}
|
2014-01-03 13:32:13 -05:00
|
|
|
general = @docs.generalArticles or []
|
|
|
|
specific = @docs.specificArticles or []
|
|
|
|
|
|
|
|
articles = options.supermodel.getModels(Article)
|
|
|
|
articleMap = {}
|
|
|
|
articleMap[article.get('original')] = article for article in articles
|
|
|
|
general = (articleMap[ref.original] for ref in general)
|
|
|
|
general = (article.attributes for article in general when article)
|
|
|
|
|
|
|
|
@docs = specific.concat(general)
|
2014-03-18 16:47:51 -04:00
|
|
|
@docs = $.extend(true, [], @docs)
|
2014-05-20 01:25:40 -04:00
|
|
|
@docs = [@docs[0]] if @firstOnly and @docs[0]
|
2014-03-13 12:02:19 -04:00
|
|
|
doc.html = marked(utils.i18n doc, 'body') for doc in @docs
|
|
|
|
doc.name = (utils.i18n doc, 'name') for doc in @docs
|
2014-01-03 13:32:13 -05:00
|
|
|
doc.slug = _.string.slugify(doc.name) for doc in @docs
|
|
|
|
super()
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
|
|
|
c.docs = @docs
|
|
|
|
c
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
if @docs.length is 1
|
|
|
|
@$el.find('.modal-body').html(@docs[0].html)
|
|
|
|
else
|
|
|
|
# incredible hackiness. Getting bootstrap tabs to work shouldn't be this complex
|
|
|
|
@$el.find('.nav-tabs li:first').addClass('active')
|
|
|
|
@$el.find('.tab-content .tab-pane:first').addClass('active')
|
|
|
|
@$el.find('.nav-tabs a').click(@clickTab)
|
2014-09-05 15:39:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'guide-open', volume: 1
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
clickTab: (e) =>
|
|
|
|
@$el.find('li.active').removeClass('active')
|
2014-09-05 15:39:30 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'guide-tab-switch', volume: 1
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-05-21 17:50:27 -04:00
|
|
|
afterInsert: ->
|
|
|
|
super()
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'level:docs-shown', {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onHidden: ->
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'level:docs-hidden', {}
|