Initial refactoring to use the new version of Treema.

This commit is contained in:
Scott Erickson 2014-08-22 11:11:05 -07:00
parent 76b08f35bb
commit e200889f0b
8 changed files with 109 additions and 108 deletions

View file

@ -5,13 +5,14 @@ locale = require 'locale/locale'
class DateTimeTreema extends TreemaNode.nodeMap.string class DateTimeTreema extends TreemaNode.nodeMap.string
valueClass: 'treema-date-time' valueClass: 'treema-date-time'
buildValueForDisplay: (el) -> el.text(moment(@data).format('llll')) buildValueForDisplay: (el, data) -> el.text(moment(data).format('llll'))
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl) ->
@buildValueForEditingSimply valEl, null, 'date' @buildValueForEditingSimply valEl, null, 'date'
class VersionTreema extends TreemaNode class VersionTreema extends TreemaNode
valueClass: 'treema-version' valueClass: 'treema-version'
buildValueForDisplay: (valEl) -> @buildValueForDisplaySimply(valEl, "#{@data.major}.#{@data.minor}") buildValueForDisplay: (valEl, data) ->
@buildValueForDisplaySimply(valEl, "#{data.major}.#{data.minor}")
class LiveEditingMarkup extends TreemaNode.nodeMap.ace class LiveEditingMarkup extends TreemaNode.nodeMap.ace
valueClass: 'treema-markdown treema-multiline treema-ace' valueClass: 'treema-markdown treema-multiline treema-ace'
@ -85,7 +86,7 @@ class SoundFileTreema extends TreemaNode.nodeMap.string
getFiles: -> getFiles: ->
@settings[@soundCollection]?.models or [] @settings[@soundCollection]?.models or []
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
mimetype = "audio/#{@keyForParent}" mimetype = "audio/#{@keyForParent}"
pickButton = $('<a class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-upload"></span></a>') pickButton = $('<a class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-upload"></span></a>')
.click(=> filepicker.pick {mimetypes:[mimetype]}, @onFileChosen) .click(=> filepicker.pick {mimetypes:[mimetype]}, @onFileChosen)
@ -116,17 +117,17 @@ class SoundFileTreema extends TreemaNode.nodeMap.string
.text(filename) .text(filename)
menu.append(li) menu.append(li)
menu.click (e) => menu.click (e) =>
@data = $(e.target).data('fullPath') or @data @data = $(e.target).data('fullPath') or data
@reset() @reset()
dropdown.append(menu) dropdown.append(menu)
valEl.append(pickButton) valEl.append(pickButton)
if @data if data
valEl.append(playButton) valEl.append(playButton)
valEl.append(stopButton) valEl.append(stopButton)
valEl.append(dropdown) # if files.length and @canEdit() valEl.append(dropdown) # if files.length and @canEdit()
if @data if data
path = @data.split('/') path = data.split('/')
name = path[path.length-1] name = path[path.length-1]
valEl.append($('<span></span>').text(name)) valEl.append($('<span></span>').text(name))
@ -136,7 +137,7 @@ class SoundFileTreema extends TreemaNode.nodeMap.string
@refreshDisplay() @refreshDisplay()
playFile: => playFile: =>
@src = "/file/#{@data}" @src = "/file/#{@getData()}"
if @instance if @instance
@instance.play() @instance.play()
@ -183,14 +184,14 @@ class ImageFileTreema extends TreemaNode.nodeMap.string
return if $(e.target).closest('.btn').length return if $(e.target).closest('.btn').length
super(arguments...) super(arguments...)
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
mimetype = 'image/*' mimetype = 'image/*'
pickButton = $('<a class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-upload"></span> Upload Picture</a>') pickButton = $('<a class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-upload"></span> Upload Picture</a>')
.click(=> filepicker.pick {mimetypes:[mimetype]}, @onFileChosen) .click(=> filepicker.pick {mimetypes:[mimetype]}, @onFileChosen)
valEl.append(pickButton) valEl.append(pickButton)
if @data if data
valEl.append $('<img />').attr('src', "/file/#{@data}") valEl.append $('<img />').attr('src', "/file/#{data}")
onFileChosen: (InkBlob) => onFileChosen: (InkBlob) =>
if not @settings.filePath if not @settings.filePath
@ -226,8 +227,8 @@ class CodeLanguagesObjectTreema extends TreemaNode.nodeMap.object
(key for key in _.keys(codeLanguages) when not @data[key]?) (key for key in _.keys(codeLanguages) when not @data[key]?)
class CodeLanguageTreema extends TreemaNode.nodeMap.string class CodeLanguageTreema extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: _.keys(codeLanguages), minLength: 0, delay: 0, autoFocus: true) valEl.find('input').autocomplete(source: _.keys(codeLanguages), minLength: 0, delay: 0, autoFocus: true)
valEl valEl
@ -236,8 +237,8 @@ class CodeTreema extends TreemaNode.nodeMap.ace
super(arguments...) super(arguments...)
@schema.aceTabSize = 4 @schema.aceTabSize = 4
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
if not @schema.aceMode and mode = codeLanguages[@keyForParent] if not @schema.aceMode and mode = codeLanguages[@keyForParent]
@editor.getSession().setMode mode @editor.getSession().setMode mode
valEl valEl
@ -307,15 +308,15 @@ class LatestVersionReferenceNode extends TreemaNode
@url = "/db/#{parts[1]}" @url = "/db/#{parts[1]}"
@model = require('models/' + _.string.classify(parts[1])) @model = require('models/' + _.string.classify(parts[1]))
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
val = if @data then @formatDocument(@data) else 'None' val = if data then @formatDocument(data) else 'None'
@buildValueForDisplaySimply(valEl, val) @buildValueForDisplaySimply(valEl, val)
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
valEl.html(@searchValueTemplate) valEl.html(@searchValueTemplate)
input = valEl.find('input') input = valEl.find('input')
input.focus().keyup @search input.focus().keyup @search
input.attr('placeholder', @formatDocument(@data)) if @data input.attr('placeholder', @formatDocument(data)) if data
buildSearchURL: (term) -> "#{@url}?term=#{term}&project=true" buildSearchURL: (term) -> "#{@url}?term=#{term}&project=true"
@ -357,7 +358,7 @@ class LatestVersionReferenceNode extends TreemaNode
formatDocument: (docOrModel) -> formatDocument: (docOrModel) ->
return @modelToString(docOrModel) if docOrModel instanceof CocoModel return @modelToString(docOrModel) if docOrModel instanceof CocoModel
return 'Unknown' unless @settings.supermodel? return 'Unknown' unless @settings.supermodel?
m = CocoModel.getReferencedModel(@data, @schema) m = CocoModel.getReferencedModel(@getData(), @schema)
urlGoingFor = m.url() urlGoingFor = m.url()
m = @settings.supermodel.getModel(urlGoingFor) m = @settings.supermodel.getModel(urlGoingFor)
if @instance and not m if @instance and not m
@ -387,9 +388,6 @@ class LatestVersionReferenceNode extends TreemaNode
e.preventDefault() e.preventDefault()
@navigateSearch(-1) @navigateSearch(-1)
onDeletePressed: (e) ->
super(arguments...)
navigateSearch: (offset) -> navigateSearch: (offset) ->
selected = @getSelectedResultEl() selected = @getSelectedResultEl()
func = if offset > 0 then 'next' else 'prev' func = if offset > 0 then 'next' else 'prev'

View file

@ -107,25 +107,25 @@ JobProfileTreemaView.commonCities = commonCities = ['Tokyo', 'Jakarta', 'Seoul',
autoFocus = true # Not working right now, possibly a Treema bower thing. autoFocus = true # Not working right now, possibly a Treema bower thing.
class SkillTagNode extends TreemaNode.nodeMap.string class SkillTagNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: commonSkills, minLength: 1, delay: 0, autoFocus: autoFocus) valEl.find('input').autocomplete(source: commonSkills, minLength: 1, delay: 0, autoFocus: autoFocus)
valEl valEl
class LinkNameNode extends TreemaNode.nodeMap.string class LinkNameNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: commonLinkNames, minLength: 0, delay: 0, autoFocus: autoFocus) valEl.find('input').autocomplete(source: commonLinkNames, minLength: 0, delay: 0, autoFocus: autoFocus)
valEl valEl
class CityNode extends TreemaNode.nodeMap.string class CityNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: commonCities, minLength: 1, delay: 0, autoFocus: autoFocus) valEl.find('input').autocomplete(source: commonCities, minLength: 1, delay: 0, autoFocus: autoFocus)
valEl valEl
class CountryNode extends TreemaNode.nodeMap.string class CountryNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: commonCountries, minLength: 1, delay: 0, autoFocus: autoFocus) valEl.find('input').autocomplete(source: commonCountries, minLength: 1, delay: 0, autoFocus: autoFocus)
valEl valEl

View file

@ -81,15 +81,16 @@ module.exports = class ComponentsTabView extends CocoView
class LevelComponentNode extends TreemaObjectNode class LevelComponentNode extends TreemaObjectNode
valueClass: 'treema-level-component' valueClass: 'treema-level-component'
collection: false collection: false
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
count = if @data.count is 1 then @data.thangs[0] else ((if @data.count >= 100 then '100+' else @data.count) + ' Thangs') count = if data.count is 1 then data.thangs[0] else ((if data.count >= 100 then '100+' else data.count) + ' Thangs')
if @data.original.match ':' if data.original.match ':'
name = 'Old: ' + @data.original.replace('systems/', '') name = 'Old: ' + data.original.replace('systems/', '')
else else
comp = _.find @settings.supermodel.getModels(LevelComponent), (m) => comp = _.find @settings.supermodel.getModels(LevelComponent), (m) =>
m.get('original') is @data.original and m.get('version').major is @data.majorVersion m.get('original') is data.original and m.get('version').major is data.majorVersion
name = "#{comp.get('system')}.#{comp.get('name')} v#{comp.get('version').major}" name = "#{comp.get('system')}.#{comp.get('name')} v#{comp.get('version').major}"
@buildValueForDisplaySimply valEl, "#{name} (#{count})" @buildValueForDisplaySimply valEl, "#{name} (#{count})"
onEnterPressed: -> onEnterPressed: ->
Backbone.Mediator.publish 'edit-level-component', original: @data.original, majorVersion: @data.majorVersion data = @getData()
Backbone.Mediator.publish 'edit-level-component', original: data.original, majorVersion: data.majorVersion

View file

@ -121,8 +121,8 @@ class ScriptsNode extends TreemaArrayNode
class ScriptNode extends TreemaObjectNode class ScriptNode extends TreemaObjectNode
valueClass: 'treema-script' valueClass: 'treema-script'
collection: false collection: false
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
val = @data.id or @data.channel val = data.id or data.channel
s = "#{val}" s = "#{val}"
@buildValueForDisplaySimply valEl, s @buildValueForDisplaySimply valEl, s
@ -152,15 +152,15 @@ class PropertiesNode extends TreemaObjectNode
class EventPropsNode extends TreemaNode.nodeMap.string class EventPropsNode extends TreemaNode.nodeMap.string
valueClass: 'treema-event-props' valueClass: 'treema-event-props'
arrayToString: -> (@data or []).join('.') arrayToString: -> (@getData() or []).join('.')
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
joined = @arrayToString() joined = @arrayToString()
joined = '(unset)' if not joined.length joined = '(unset)' if not joined.length
@buildValueForDisplaySimply valEl, joined @buildValueForDisplaySimply valEl, joined
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
channel = @getRoot().data.channel channel = @getRoot().data.channel
channelSchema = Backbone.Mediator.channelSchemas[channel] channelSchema = Backbone.Mediator.channelSchemas[channel]
autocompleteValues = [] autocompleteValues = []
@ -182,11 +182,11 @@ class EventPrereqsNode extends TreemaNode.nodeMap.array
newTreema.childrenTreemas.eventProps?.edit() newTreema.childrenTreemas.eventProps?.edit()
class EventPrereqNode extends TreemaNode.nodeMap.object class EventPrereqNode extends TreemaNode.nodeMap.object
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
eventProp = (@data.eventProps or []).join('.') eventProp = (data.eventProps or []).join('.')
eventProp = '(unset)' unless eventProp.length eventProp = '(unset)' unless eventProp.length
statements = [] statements = []
for key, value of @data for key, value of data
continue if key is 'eventProps' continue if key is 'eventProps'
comparison = @schema.properties[key].title comparison = @schema.properties[key].title
value = value.toString() value = value.toString()
@ -196,8 +196,8 @@ class EventPrereqNode extends TreemaNode.nodeMap.object
@buildValueForDisplaySimply valEl, s @buildValueForDisplaySimply valEl, s
class ChannelNode extends TreemaNode.nodeMap.string class ChannelNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
autocompleteValues = ({label: val?.title or key, value: key} for key, val of Backbone.Mediator.channelSchemas) autocompleteValues = ({label: val?.title or key, value: key} for key, val of Backbone.Mediator.channelSchemas)
valEl.find('input').autocomplete(source: autocompleteValues, minLength: 0, delay: 0, autoFocus: true) valEl.find('input').autocomplete(source: autocompleteValues, minLength: 0, delay: 0, autoFocus: true)
valEl valEl

View file

@ -134,23 +134,25 @@ class LevelSystemNode extends TreemaObjectNode
@collection = @system?.attributes?.configSchema?.properties? @collection = @system?.attributes?.configSchema?.properties?
grabDBComponent: -> grabDBComponent: ->
unless _.isString @data.original data = @getData()
unless _.isString data.original
return alert('Press the "Add System" button at the bottom instead of the "+". Sorry.') return alert('Press the "Add System" button at the bottom instead of the "+". Sorry.')
@system = @settings.supermodel.getModelByOriginalAndMajorVersion(LevelSystem, @data.original, @data.majorVersion) @system = @settings.supermodel.getModelByOriginalAndMajorVersion(LevelSystem, data.original, data.majorVersion)
console.error 'Couldn\'t find system for', @data.original, @data.majorVersion, 'from models', @settings.supermodel.models unless @system console.error 'Couldn\'t find system for', data.original, data.majorVersion, 'from models', @settings.supermodel.models unless @system
getChildSchema: (key) -> getChildSchema: (key) ->
return @system.attributes.configSchema if key is 'config' return @system.attributes.configSchema if key is 'config'
return super(key) return super(key)
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
return super valEl unless @data.original and @system return super valEl unless data.original and @system
name = "#{@system.get('name')} v#{@system.get('version').major}" name = "#{@system.get('name')} v#{@system.get('version').major}"
@buildValueForDisplaySimply valEl, "#{name}" @buildValueForDisplaySimply valEl, "#{name}"
onEnterPressed: (e) -> onEnterPressed: (e) ->
super e super e
Backbone.Mediator.publish 'edit-level-system', original: @data.original, majorVersion: @data.majorVersion data = @getData()
Backbone.Mediator.publish 'edit-level-system', original: data.original, majorVersion: data.majorVersion
open: (depth) -> open: (depth) ->
super depth super depth
@ -161,5 +163,4 @@ class LevelSystemNode extends TreemaObjectNode
class LevelSystemConfigurationNode extends TreemaObjectNode class LevelSystemConfigurationNode extends TreemaObjectNode
valueClass: 'treema-level-system-configuration' valueClass: 'treema-level-system-configuration'
buildValueForDisplay: (valEl) -> buildValueForDisplay: -> return
return

View file

@ -512,9 +512,9 @@ class ThangNode extends TreemaObjectNode
collection: false collection: false
@thangNameMap: {} @thangNameMap: {}
@thangKindMap: {} @thangKindMap: {}
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
pos = _.find(@data.components, (c) -> c.config?.pos?)?.config.pos # TODO: hack pos = _.find(data.components, (c) -> c.config?.pos?)?.config.pos # TODO: hack
s = "#{@data.thangType}" s = "#{data.thangType}"
if isObjectID s if isObjectID s
unless name = ThangNode.thangNameMap[s] unless name = ThangNode.thangNameMap[s]
thangType = _.find @settings.supermodel.getModels(ThangType), (m) -> m.get('original') is s and m.get('kind') thangType = _.find @settings.supermodel.getModels(ThangType), (m) -> m.get('original') is s and m.get('kind')
@ -523,7 +523,7 @@ class ThangNode extends TreemaObjectNode
kind = ThangNode.thangKindMap[s] kind = ThangNode.thangKindMap[s]
@$el.addClass "treema-#{kind}" @$el.addClass "treema-#{kind}"
s = name s = name
s += ' - ' + @data.id if @data.id isnt s s += ' - ' + data.id if data.id isnt s
if pos if pos
s += " (#{Math.round(pos.x)}, #{Math.round(pos.y)})" s += " (#{Math.round(pos.x)}, #{Math.round(pos.y)})"
else else
@ -531,4 +531,4 @@ class ThangNode extends TreemaObjectNode
@buildValueForDisplaySimply valEl, s @buildValueForDisplaySimply valEl, s
onEnterPressed: -> onEnterPressed: ->
Backbone.Mediator.publish 'edit-level-thang', thangID: @data.id Backbone.Mediator.publish 'edit-level-thang', thangID: @getData().id

View file

@ -11,12 +11,12 @@ module.exports.WorldPointNode = class WorldPointNode extends TreemaNode.nodeMap.
console.error 'Point Treema node needs a World included in the settings.' unless @settings.world? console.error 'Point Treema node needs a World included in the settings.' unless @settings.world?
console.error 'Point Treema node needs a RootView included in the settings.' unless @settings.view? console.error 'Point Treema node needs a RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) -> onClick: (e) ->
@ -24,7 +24,7 @@ module.exports.WorldPointNode = class WorldPointNode extends TreemaNode.nodeMap.
if btn.length then @openMap() else super(arguments...) if btn.length then @openMap() else super(arguments...)
openMap: -> openMap: ->
modal = new WorldSelectModal(world: @settings.world, dataType: 'point', default: @data, supermodel: @settings.supermodel) modal = new WorldSelectModal(world: @settings.world, dataType: 'point', default: @getData(), supermodel: @settings.supermodel)
modal.callback = @callback modal.callback = @callback
@settings.view.openModalView modal @settings.view.openModalView modal
@ -42,12 +42,12 @@ class WorldRegionNode extends TreemaNode.nodeMap.object
console.error 'Region Treema node needs a World included in the settings.' unless @settings.world? console.error 'Region Treema node needs a World included in the settings.' unless @settings.world?
console.error 'Region Treema node needs a RootView included in the settings.' unless @settings.view? console.error 'Region Treema node needs a RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) -> onClick: (e) ->
@ -77,12 +77,12 @@ module.exports.WorldViewportNode = class WorldViewportNode extends TreemaNode.no
console.error 'Viewport Treema node needs a World included in the settings.' unless @settings.world? console.error 'Viewport Treema node needs a World included in the settings.' unless @settings.world?
console.error 'Viewport Treema node needs a RootView included in the settings.' unless @settings.view? console.error 'Viewport Treema node needs a RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) -> onClick: (e) ->
@ -92,7 +92,8 @@ module.exports.WorldViewportNode = class WorldViewportNode extends TreemaNode.no
openMap: -> openMap: ->
# can't really get the bounds from this data, so will have to hack this solution # can't really get the bounds from this data, so will have to hack this solution
options = world: @settings.world, dataType: 'ratio-region' options = world: @settings.world, dataType: 'ratio-region'
options.defaultFromZoom = @data if @data?.target?.x? data = @getData()
options.defaultFromZoom = data if data?.target?.x?
options.supermodel = @settings.supermodel options.supermodel = @settings.supermodel
modal = new WorldSelectModal(options) modal = new WorldSelectModal(options)
modal.callback = @callback modal.callback = @callback
@ -118,12 +119,12 @@ module.exports.WorldBoundsNode = class WorldBoundsNode extends TreemaNode.nodeMa
console.error 'Bounds Treema node needs a World included in the settings.' unless @settings.world? console.error 'Bounds Treema node needs a World included in the settings.' unless @settings.world?
console.error 'Bounds Treema node needs a RootView included in the settings.' unless @settings.view? console.error 'Bounds Treema node needs a RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton()) valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) -> onClick: (e) ->
@ -131,7 +132,7 @@ module.exports.WorldBoundsNode = class WorldBoundsNode extends TreemaNode.nodeMa
if btn.length then @openMap() else super(arguments...) if btn.length then @openMap() else super(arguments...)
openMap: -> openMap: ->
bounds = @data or [{x: 0, y: 0}, {x: 100, y: 80}] bounds = @getData() or [{x: 0, y: 0}, {x: 100, y: 80}]
modal = new WorldSelectModal(world: @settings.world, dataType: 'region', default: bounds, supermodel: @settings.supermodel) modal = new WorldSelectModal(world: @settings.world, dataType: 'region', default: bounds, supermodel: @settings.supermodel)
modal.callback = @callback modal.callback = @callback
@settings.view.openModalView modal @settings.view.openModalView modal
@ -142,71 +143,71 @@ module.exports.WorldBoundsNode = class WorldBoundsNode extends TreemaNode.nodeMa
@set '/1', {x: shorten(e.points[1].x), y: shorten(e.points[1].y)} @set '/1', {x: shorten(e.points[1].x), y: shorten(e.points[1].y)}
module.exports.ThangNode = class ThangNode extends TreemaNode.nodeMap.string module.exports.ThangNode = class ThangNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: @settings.thangIDs, minLength: 0, delay: 0, autoFocus: true) valEl.find('input').autocomplete(source: @settings.thangIDs, minLength: 0, delay: 0, autoFocus: true)
valEl valEl
module.exports.TeamNode = class TeamNode extends TreemaNode.nodeMap.string module.exports.TeamNode = class TeamNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: @settings.teams, minLength: 0, delay: 0, autoFocus: true) valEl.find('input').autocomplete(source: @settings.teams, minLength: 0, delay: 0, autoFocus: true)
valEl valEl
module.exports.SuperteamNode = class SuperteamNode extends TreemaNode.nodeMap.string module.exports.SuperteamNode = class SuperteamNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.find('input').autocomplete(source: @settings.superteams, minLength: 0, delay: 0, autoFocus: true) valEl.find('input').autocomplete(source: @settings.superteams, minLength: 0, delay: 0, autoFocus: true)
valEl valEl
module.exports.RadiansNode = class RadiansNode extends TreemaNode.nodeMap.number module.exports.RadiansNode = class RadiansNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
deg = @data / Math.PI * 180 deg = data / Math.PI * 180
valEl.text valEl.text() + "rad (#{deg.toFixed(0)}˚)" valEl.text valEl.text() + "rad (#{deg.toFixed(0)}˚)"
module.exports.MetersNode = class MetersNode extends TreemaNode.nodeMap.number module.exports.MetersNode = class MetersNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.text valEl.text() + 'm' valEl.text valEl.text() + 'm'
module.exports.KilogramsNode = class KilogramsNode extends TreemaNode.nodeMap.number module.exports.KilogramsNode = class KilogramsNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.text valEl.text() + 'kg' valEl.text valEl.text() + 'kg'
module.exports.SecondsNode = class SecondsNode extends TreemaNode.nodeMap.number module.exports.SecondsNode = class SecondsNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.text valEl.text() + 's' valEl.text valEl.text() + 's'
module.exports.MillisecondsNode = class MillisecondsNode extends TreemaNode.nodeMap.number module.exports.MillisecondsNode = class MillisecondsNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.text valEl.text() + 'ms' valEl.text valEl.text() + 'ms'
module.exports.SpeedNode = class SpeedNode extends TreemaNode.nodeMap.number module.exports.SpeedNode = class SpeedNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.text valEl.text() + 'm/s' valEl.text valEl.text() + 'm/s'
module.exports.AccelerationNode = class AccelerationNode extends TreemaNode.nodeMap.number module.exports.AccelerationNode = class AccelerationNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
valEl.text valEl.text() + 'm/s^2' valEl.text valEl.text() + 'm/s^2'
module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.string module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.string
valueClass: 'treema-thang-type' valueClass: 'treema-thang-type'
constructor: (args...) -> constructor: (args...) ->
super args... super args...
@thangType = _.find @settings.supermodel.getModels(ThangType), (m) => m.get('original') is @data if @data data = @getData()
#console.log 'ThangTypeNode found ThangType', @thangType, 'for data', @data @thangType = _.find @settings.supermodel.getModels(ThangType), (m) => m.get('original') is data if data
buildValueForDisplay: (valEl) -> buildValueForDisplay: (valEl) ->
@buildValueForDisplaySimply(valEl, @thangType?.get('name') or 'None') @buildValueForDisplaySimply(valEl, @thangType?.get('name') or 'None')
buildValueForEditing: (valEl) -> buildValueForEditing: (valEl, data) ->
super(valEl) super(valEl, data)
thangTypeNames = (m.get('name') for m in @settings.supermodel.getModels ThangType) thangTypeNames = (m.get('name') for m in @settings.supermodel.getModels ThangType)
input = valEl.find('input').autocomplete(source: thangTypeNames, minLength: 0, delay: 0, autoFocus: true) input = valEl.find('input').autocomplete(source: thangTypeNames, minLength: 0, delay: 0, autoFocus: true)
input.val(@thangType?.get('name') or 'None') input.val(@thangType?.get('name') or 'None')
@ -222,8 +223,8 @@ module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.st
module.exports.ItemThangTypeNode = class ThangTypeNode extends ThangTypeNode module.exports.ItemThangTypeNode = class ThangTypeNode extends ThangTypeNode
valueClass: 'treema-item-thang-type' valueClass: 'treema-item-thang-type'
buildValueForEditing: (valEl) -> buildValueForDisplay: (valEl, data) ->
super(valEl) super(valEl, data)
thangTypeNames = (m.get('name') for m in @settings.supermodel.getModels ThangType when m.get('kind') is 'Item') thangTypeNames = (m.get('name') for m in @settings.supermodel.getModels ThangType when m.get('kind') is 'Item')
input = valEl.find('input').autocomplete(source: thangTypeNames, minLength: 0, delay: 0, autoFocus: true) input = valEl.find('input').autocomplete(source: thangTypeNames, minLength: 0, delay: 0, autoFocus: true)
input.val(@thangType?.get('name') or 'None') input.val(@thangType?.get('name') or 'None')

View file

@ -40,7 +40,7 @@
"jsondiffpatch": "~0.1.5", "jsondiffpatch": "~0.1.5",
"nanoscroller": "~0.8.0", "nanoscroller": "~0.8.0",
"jquery.tablesorter": "~2.15.13", "jquery.tablesorter": "~2.15.13",
"treema": "~0.0.14", "treema": "~0.1.0",
"bootstrap": "~3.1.1", "bootstrap": "~3.1.1",
"validated-backbone-mediator": "~0.1.3", "validated-backbone-mediator": "~0.1.3",
"jquery.browser": "~0.0.6", "jquery.browser": "~0.0.6",