mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 16:17:57 -05:00
46 lines
1.5 KiB
CoffeeScript
46 lines
1.5 KiB
CoffeeScript
View = require 'views/kinds/ModalView'
|
|
template = require 'templates/modal/model'
|
|
|
|
module.exports = class ModelModal extends View
|
|
id: 'model-modal'
|
|
template: template
|
|
|
|
constructor: (options) ->
|
|
super options
|
|
@models = options.models
|
|
for model in @models when not model.loaded
|
|
@supermodel.loadModel model, 'source_document'
|
|
model.fetch()
|
|
|
|
getRenderData: ->
|
|
c = super()
|
|
c.models = @models
|
|
c
|
|
|
|
afterRender: ->
|
|
return unless @supermodel.finished()
|
|
for model in @models
|
|
data = $.extend true, {}, model.attributes
|
|
schema = $.extend true, {}, model.schema()
|
|
treemaOptions =
|
|
schema: schema
|
|
data: data
|
|
readOnly: false
|
|
modelTreema = @$el.find(".model-treema[data-model-id='#{model.id}']").treema treemaOptions
|
|
modelTreema?.build()
|
|
modelTreema?.open()
|
|
@openTastyTreemas modelTreema, model
|
|
|
|
openTastyTreemas: (modelTreema, model) ->
|
|
# To save on quick inspection, let's auto-open the properties we're most likely to want to see.
|
|
delicacies = ['code']
|
|
for dish in delicacies
|
|
child = modelTreema.childrenTreemas[dish]
|
|
child?.open()
|
|
if child and dish is 'code' and model.type() is 'LevelSession' and team = modelTreema.get('team')
|
|
desserts = {
|
|
humans: ['programmable-tharin', 'programmable-librarian']
|
|
ogres: ['programmable-brawler', 'programmable-shaman']
|
|
}[team]
|
|
for dessert in desserts
|
|
child.childrenTreemas[dessert]?.open()
|