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

View file

@ -81,15 +81,16 @@ module.exports = class ComponentsTabView extends CocoView
class LevelComponentNode extends TreemaObjectNode
valueClass: 'treema-level-component'
collection: false
buildValueForDisplay: (valEl) ->
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 ':'
name = 'Old: ' + @data.original.replace('systems/', '')
buildValueForDisplay: (valEl, data) ->
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 ':'
name = 'Old: ' + data.original.replace('systems/', '')
else
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}"
@buildValueForDisplaySimply valEl, "#{name} (#{count})"
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
valueClass: 'treema-script'
collection: false
buildValueForDisplay: (valEl) ->
val = @data.id or @data.channel
buildValueForDisplay: (valEl, data) ->
val = data.id or data.channel
s = "#{val}"
@buildValueForDisplaySimply valEl, s
@ -152,15 +152,15 @@ class PropertiesNode extends TreemaObjectNode
class EventPropsNode extends TreemaNode.nodeMap.string
valueClass: 'treema-event-props'
arrayToString: -> (@data or []).join('.')
arrayToString: -> (@getData() or []).join('.')
buildValueForDisplay: (valEl) ->
buildValueForDisplay: (valEl, data) ->
joined = @arrayToString()
joined = '(unset)' if not joined.length
@buildValueForDisplaySimply valEl, joined
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
channel = @getRoot().data.channel
channelSchema = Backbone.Mediator.channelSchemas[channel]
autocompleteValues = []
@ -182,11 +182,11 @@ class EventPrereqsNode extends TreemaNode.nodeMap.array
newTreema.childrenTreemas.eventProps?.edit()
class EventPrereqNode extends TreemaNode.nodeMap.object
buildValueForDisplay: (valEl) ->
eventProp = (@data.eventProps or []).join('.')
buildValueForDisplay: (valEl, data) ->
eventProp = (data.eventProps or []).join('.')
eventProp = '(unset)' unless eventProp.length
statements = []
for key, value of @data
for key, value of data
continue if key is 'eventProps'
comparison = @schema.properties[key].title
value = value.toString()
@ -196,8 +196,8 @@ class EventPrereqNode extends TreemaNode.nodeMap.object
@buildValueForDisplaySimply valEl, s
class ChannelNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
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

View file

@ -134,23 +134,25 @@ class LevelSystemNode extends TreemaObjectNode
@collection = @system?.attributes?.configSchema?.properties?
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.')
@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
@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
getChildSchema: (key) ->
return @system.attributes.configSchema if key is 'config'
return super(key)
buildValueForDisplay: (valEl) ->
return super valEl unless @data.original and @system
buildValueForDisplay: (valEl, data) ->
return super valEl unless data.original and @system
name = "#{@system.get('name')} v#{@system.get('version').major}"
@buildValueForDisplaySimply valEl, "#{name}"
onEnterPressed: (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) ->
super depth
@ -161,5 +163,4 @@ class LevelSystemNode extends TreemaObjectNode
class LevelSystemConfigurationNode extends TreemaObjectNode
valueClass: 'treema-level-system-configuration'
buildValueForDisplay: (valEl) ->
return
buildValueForDisplay: -> return

View file

@ -512,9 +512,9 @@ class ThangNode extends TreemaObjectNode
collection: false
@thangNameMap: {}
@thangKindMap: {}
buildValueForDisplay: (valEl) ->
pos = _.find(@data.components, (c) -> c.config?.pos?)?.config.pos # TODO: hack
s = "#{@data.thangType}"
buildValueForDisplay: (valEl, data) ->
pos = _.find(data.components, (c) -> c.config?.pos?)?.config.pos # TODO: hack
s = "#{data.thangType}"
if isObjectID s
unless name = ThangNode.thangNameMap[s]
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]
@$el.addClass "treema-#{kind}"
s = name
s += ' - ' + @data.id if @data.id isnt s
s += ' - ' + data.id if data.id isnt s
if pos
s += " (#{Math.round(pos.x)}, #{Math.round(pos.y)})"
else
@ -531,4 +531,4 @@ class ThangNode extends TreemaObjectNode
@buildValueForDisplaySimply valEl, s
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 RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) ->
@ -24,7 +24,7 @@ module.exports.WorldPointNode = class WorldPointNode extends TreemaNode.nodeMap.
if btn.length then @openMap() else super(arguments...)
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
@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 RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
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 RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) ->
@ -92,7 +92,8 @@ module.exports.WorldViewportNode = class WorldViewportNode extends TreemaNode.no
openMap: ->
# can't really get the bounds from this data, so will have to hack this solution
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
modal = new WorldSelectModal(options)
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 RootView included in the settings.' unless @settings.view?
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
valEl.find('.treema-shortened').prepend(makeButton())
onClick: (e) ->
@ -131,7 +132,7 @@ module.exports.WorldBoundsNode = class WorldBoundsNode extends TreemaNode.nodeMa
if btn.length then @openMap() else super(arguments...)
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.callback = @callback
@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)}
module.exports.ThangNode = class ThangNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.find('input').autocomplete(source: @settings.thangIDs, minLength: 0, delay: 0, autoFocus: true)
valEl
module.exports.TeamNode = class TeamNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.find('input').autocomplete(source: @settings.teams, minLength: 0, delay: 0, autoFocus: true)
valEl
module.exports.SuperteamNode = class SuperteamNode extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
valEl.find('input').autocomplete(source: @settings.superteams, minLength: 0, delay: 0, autoFocus: true)
valEl
module.exports.RadiansNode = class RadiansNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
deg = @data / Math.PI * 180
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
deg = data / Math.PI * 180
valEl.text valEl.text() + "rad (#{deg.toFixed(0)}˚)"
module.exports.MetersNode = class MetersNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.text valEl.text() + 'm'
module.exports.KilogramsNode = class KilogramsNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.text valEl.text() + 'kg'
module.exports.SecondsNode = class SecondsNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.text valEl.text() + 's'
module.exports.MillisecondsNode = class MillisecondsNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.text valEl.text() + 'ms'
module.exports.SpeedNode = class SpeedNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.text valEl.text() + 'm/s'
module.exports.AccelerationNode = class AccelerationNode extends TreemaNode.nodeMap.number
buildValueForDisplay: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
valEl.text valEl.text() + 'm/s^2'
module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.string
valueClass: 'treema-thang-type'
constructor: (args...) ->
super args...
@thangType = _.find @settings.supermodel.getModels(ThangType), (m) => m.get('original') is @data if @data
#console.log 'ThangTypeNode found ThangType', @thangType, 'for data', @data
data = @getData()
@thangType = _.find @settings.supermodel.getModels(ThangType), (m) => m.get('original') is data if data
buildValueForDisplay: (valEl) ->
@buildValueForDisplaySimply(valEl, @thangType?.get('name') or 'None')
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForEditing: (valEl, data) ->
super(valEl, data)
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.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
valueClass: 'treema-item-thang-type'
buildValueForEditing: (valEl) ->
super(valEl)
buildValueForDisplay: (valEl, data) ->
super(valEl, data)
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.val(@thangType?.get('name') or 'None')

View file

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