2014-01-03 10:32:13 -08:00
CocoModel = require ' models/CocoModel '
2014-04-22 20:42:26 +01:00
CocoCollection = require ' collections/CocoCollection '
2014-11-28 17:49:41 -08:00
{ me } = require ( ' core/auth ' )
2014-01-03 10:32:13 -08:00
locale = require ' locale/locale '
2014-11-09 17:35:50 -08:00
initializeFilePicker = ->
2014-11-28 17:49:41 -08:00
require ( ' core/services/filepicker ' ) ( ) unless window . application . isIPadApp
2014-11-09 17:35:50 -08:00
2014-01-03 10:32:13 -08:00
class DateTimeTreema extends TreemaNode . nodeMap . string
valueClass: ' treema-date-time '
2014-08-22 11:11:05 -07:00
buildValueForDisplay: (el, data) -> el . text ( moment ( data ) . format ( ' llll ' ) )
2014-06-17 13:03:08 -07:00
buildValueForEditing: (valEl) ->
@ buildValueForEditingSimply valEl , null , ' date '
2014-01-03 10:32:13 -08:00
class VersionTreema extends TreemaNode
valueClass: ' treema-version '
2014-08-22 11:11:05 -07:00
buildValueForDisplay: (valEl, data) ->
@ buildValueForDisplaySimply ( valEl , " #{ data . major } . #{ data . minor } " )
2014-01-03 10:32:13 -08:00
class LiveEditingMarkup extends TreemaNode . nodeMap . ace
valueClass: ' treema-markdown treema-multiline treema-ace '
constructor: ->
super ( arguments . . . )
2014-08-28 17:05:46 -07:00
@workingSchema.aceMode = ' ace/mode/markdown '
2014-11-09 17:35:50 -08:00
initializeFilePicker ( )
2014-01-03 10:32:13 -08:00
2014-08-18 16:04:43 -07:00
initEditor: (valEl) ->
buttonRow = $ ( ' <div class= " buttons " ></div> ' )
valEl . append ( buttonRow )
@ addPreviewToggle ( buttonRow )
@ addImageUpload ( buttonRow )
2014-01-03 10:32:13 -08:00
super ( valEl )
2014-08-26 10:28:01 -07:00
valEl . append ( $ ( ' <div class= " preview " ></div> ' ) . hide ( ) )
2014-01-03 10:32:13 -08:00
addImageUpload: (valEl) ->
2015-02-25 18:41:39 -08:00
return unless me . isAdmin ( ) or me . isArtisan ( )
2014-01-03 10:32:13 -08:00
valEl . append (
2014-08-18 16:04:43 -07:00
$ ( ' <div class= " pick-image-button " ></div> ' ) . append (
2014-01-03 10:32:13 -08:00
$ ( ' <button>Pick Image</button> ' )
2014-04-24 11:38:30 -07:00
. addClass ( ' btn btn-sm btn-primary ' )
2014-01-03 10:32:13 -08:00
. click ( => filepicker . pick @ onFileChosen )
)
)
2014-08-25 14:35:51 -07:00
2014-08-18 16:04:43 -07:00
addPreviewToggle: (valEl) ->
valEl . append ( $ ( ' <div class= " toggle-preview-button " ></div> ' ) . append (
$ ( ' <button>Toggle Preview</button> ' )
. addClass ( ' btn btn-sm btn-primary ' )
. click ( @ togglePreview )
) )
2014-01-03 10:32:13 -08:00
onFileChosen: (InkBlob) =>
body =
url: InkBlob . url
filename: InkBlob . filename
mimetype: InkBlob . mimetype
2014-02-26 19:30:37 -08:00
path: @ settings . filePath
2014-03-03 17:14:13 -08:00
force: true
2014-02-26 19:30:37 -08:00
@uploadingPath = [ @ settings . filePath , InkBlob . filename ] . join ( ' / ' )
2014-01-03 10:32:13 -08:00
$ . ajax ( ' /file ' , { type: ' POST ' , data: body , success: @ onFileUploaded } )
onFileUploaded: (e) =>
2014-02-26 19:30:37 -08:00
@ editor . insert "  "
2014-01-03 10:32:13 -08:00
2014-08-18 16:04:43 -07:00
showingPreview: false
2014-01-03 10:32:13 -08:00
2014-08-18 16:04:43 -07:00
togglePreview: =>
valEl = @ getValEl ( )
if @ showingPreview
valEl . find ( ' .preview ' ) . hide ( )
valEl . find ( ' .pick-image-button ' ) . show ( )
valEl . find ( ' .ace_editor ' ) . show ( )
else
valEl . find ( ' .preview ' ) . html ( marked ( @ data ) ) . show ( )
valEl . find ( ' .pick-image-button ' ) . hide ( )
valEl . find ( ' .ace_editor ' ) . hide ( )
@showingPreview = not @ showingPreview
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
class SoundFileTreema extends TreemaNode . nodeMap . string
valueClass: ' treema-sound-file '
editable: false
soundCollection: ' files '
2014-04-08 17:13:05 -07:00
2014-11-09 17:35:50 -08:00
constructor: ->
super arguments . . .
initializeFilePicker ( )
2014-01-03 10:32:13 -08:00
onClick: (e) ->
return if $ ( e . target ) . closest ( ' .btn ' ) . length
super ( arguments . . . )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
getFiles: ->
@ settings [ @ soundCollection ] ? . models or [ ]
2014-08-22 11:11:05 -07:00
buildValueForDisplay: (valEl, data) ->
2014-01-03 10:32:13 -08:00
mimetype = " audio/ #{ @ keyForParent } "
2015-02-11 15:51:49 -08:00
mimetypes = [ mimetype ]
if mimetype is ' audio/mp3 '
# https://github.com/codecombat/codecombat/issues/445
# http://stackoverflow.com/questions/10688588/which-mime-type-should-i-use-for-mp3
mimetypes . push ' audio/mpeg '
else if mimetype is ' audio/ogg '
mimetypes . push ' application/ogg '
mimetypes . push ' video/ogg ' # huh, that's what it took to be able to upload ogg sounds in Firefox
2014-04-24 11:50:49 -07:00
pickButton = $ ( ' <a class= " btn btn-primary btn-xs " ><span class= " glyphicon glyphicon-upload " ></span></a> ' )
2015-02-11 15:51:49 -08:00
. click ( => filepicker . pick { mimetypes: mimetypes } , @ onFileChosen )
2014-04-24 11:50:49 -07:00
playButton = $ ( ' <a class= " btn btn-primary btn-xs " ><span class= " glyphicon glyphicon-play " ></span></a> ' )
2014-01-03 10:32:13 -08:00
. click ( @ playFile )
2014-04-24 11:50:49 -07:00
stopButton = $ ( ' <a class= " btn btn-primary btn-xs " ><span class= " glyphicon glyphicon-stop " ></span></a> ' )
2014-01-03 10:32:13 -08:00
. click ( @ stopFile )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
dropdown = $ ( ' <div class= " btn-group dropdown " ></div> ' )
dropdownButton = $ ( ' <a></a> ' )
2014-04-24 11:38:30 -07:00
. addClass ( ' btn btn-primary btn-xs dropdown-toggle ' )
2014-01-03 10:32:13 -08:00
. attr ( ' href ' , ' # ' )
2014-04-24 11:38:30 -07:00
. append ( $ ( ' <span class= " glyphicon glyphicon-chevron-down " ></span> ' ) )
2014-01-03 10:32:13 -08:00
. dropdown ( )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
dropdown . append dropdownButton
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
menu = $ ( ' <div class= " dropdown-menu " ></div> ' )
files = @ getFiles ( )
for file in files
2015-02-11 15:51:49 -08:00
continue unless file . get ( ' contentType ' ) in mimetypes
2014-01-03 10:32:13 -08:00
path = file . get ( ' metadata ' ) . path
filename = file . get ' filename '
fullPath = [ path , filename ] . join ( ' / ' )
li = $ ( ' <li></li> ' )
. data ( ' fullPath ' , fullPath )
. text ( filename )
menu . append ( li )
menu . click (e) =>
2014-08-22 11:11:05 -07:00
@data = $ ( e . target ) . data ( ' fullPath ' ) or data
2014-01-03 10:32:13 -08:00
@ reset ( )
dropdown . append ( menu )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
valEl . append ( pickButton )
2014-08-22 11:11:05 -07:00
if data
2014-01-03 10:32:13 -08:00
valEl . append ( playButton )
valEl . append ( stopButton )
2014-04-24 11:38:30 -07:00
valEl . append ( dropdown ) # if files.length and @canEdit()
2014-08-22 11:11:05 -07:00
if data
path = data . split ( ' / ' )
2014-01-03 10:32:13 -08:00
name = path [ path . length - 1 ]
valEl . append ( $ ( ' <span></span> ' ) . text ( name ) )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
reset: ->
@instance = null
@ flushChanges ( )
@ refreshDisplay ( )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
playFile: =>
2014-08-22 11:11:05 -07:00
@src = " /file/ #{ @ getData ( ) } "
2014-01-03 10:32:13 -08:00
if @ instance
@ instance . play ( )
else
createjs.Sound.alternateExtensions = [ ' mp3 ' , ' ogg ' ]
registered = createjs . Sound . registerSound ( @ src )
if registered is true
@instance = createjs . Sound . play ( @ src )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
else
f = (event) =>
@instance = createjs . Sound . play ( event . src ) if event . src is @ src
createjs . Sound . removeEventListener ( ' fileload ' , f )
createjs . Sound . addEventListener ( ' fileload ' , f )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
stopFile: => @ instance ? . stop ( )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
onFileChosen: (InkBlob) =>
if not @ settings . filePath
console . error ( ' Need to specify a filePath for this treema ' , @ getRoot ( ) )
throw Error ( ' cannot upload file ' )
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
body =
url: InkBlob . url
filename: InkBlob . filename
mimetype: InkBlob . mimetype
path: @ settings . filePath
2014-03-03 17:14:13 -08:00
force: true
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
@uploadingPath = [ @ settings . filePath , InkBlob . filename ] . join ( ' / ' )
$ . ajax ( ' /file ' , { type: ' POST ' , data: body , success: @ onFileUploaded } )
onFileUploaded: (e) =>
@data = @ uploadingPath
@ reset ( )
class ImageFileTreema extends TreemaNode . nodeMap . string
valueClass: ' treema-image-file '
editable: false
2014-11-09 17:35:50 -08:00
constructor: ->
super arguments . . .
initializeFilePicker ( )
2014-01-03 10:32:13 -08:00
onClick: (e) ->
return if $ ( e . target ) . closest ( ' .btn ' ) . length
super ( arguments . . . )
2014-08-22 11:11:05 -07:00
buildValueForDisplay: (valEl, data) ->
2014-01-03 10:32:13 -08:00
mimetype = ' image/* '
2014-04-24 11:50:49 -07:00
pickButton = $ ( ' <a class= " btn btn-sm btn-primary " ><span class= " glyphicon glyphicon-upload " ></span> Upload Picture</a> ' )
2014-01-03 10:32:13 -08:00
. click ( => filepicker . pick { mimetypes : [ mimetype ] } , @ onFileChosen )
valEl . append ( pickButton )
2014-08-22 11:11:05 -07:00
if data
valEl . append $ ( ' <img /> ' ) . attr ( ' src ' , " /file/ #{ data } " )
2014-01-03 10:32:13 -08:00
onFileChosen: (InkBlob) =>
if not @ settings . filePath
console . error ( ' Need to specify a filePath for this treema ' , @ getRoot ( ) )
throw Error ( ' cannot upload file ' )
body =
url: InkBlob . url
filename: InkBlob . filename
mimetype: InkBlob . mimetype
path: @ settings . filePath
2014-03-03 17:14:13 -08:00
force: true
2014-01-03 10:32:13 -08:00
@uploadingPath = [ @ settings . filePath , InkBlob . filename ] . join ( ' / ' )
$ . ajax ( ' /file ' , { type: ' POST ' , data: body , success: @ onFileUploaded } )
onFileUploaded: (e) =>
@data = @ uploadingPath
@ flushChanges ( )
@ refreshDisplay ( )
2014-07-09 11:59:21 -07:00
codeLanguages =
javascript: ' ace/mode/javascript '
coffeescript: ' ace/mode/coffee '
python: ' ace/mode/python '
lua: ' ace/mode/lua '
2015-12-23 15:38:00 -03:00
java: ' ace/mode/java '
2014-07-09 11:59:21 -07:00
class CodeLanguagesObjectTreema extends TreemaNode . nodeMap . object
childPropertiesAvailable: ->
2014-08-28 17:05:46 -07:00
( key for key in _ . keys ( codeLanguages ) when not @ data [ key ] ? and not ( key is ' javascript ' and @ workingSchema . skipJavaScript ) )
2014-07-09 11:59:21 -07:00
2014-07-11 18:07:00 -07:00
class CodeLanguageTreema extends TreemaNode . nodeMap . string
2014-08-22 11:11:05 -07:00
buildValueForEditing: (valEl, data) ->
super ( valEl , data )
2014-07-11 18:07:00 -07:00
valEl . find ( ' input ' ) . autocomplete ( source: _ . keys ( codeLanguages ) , minLength: 0 , delay: 0 , autoFocus: true )
valEl
2014-07-09 11:59:21 -07:00
class CodeTreema extends TreemaNode . nodeMap . ace
2014-01-03 10:32:13 -08:00
constructor: ->
super ( arguments . . . )
2014-08-28 17:05:46 -07:00
@workingSchema.aceTabSize = 4
2016-01-06 09:57:58 -08:00
# TODO: Find a less hacky solution for this
@workingSchema.aceMode = mode if mode = codeLanguages [ @ keyForParent ]
@workingSchema.aceMode = mode if mode = codeLanguages [ @ parent ? . data ? . language ]
2014-01-03 10:32:13 -08:00
2014-07-09 11:59:21 -07:00
class CoffeeTreema extends CodeTreema
constructor: ->
super ( arguments . . . )
2014-08-28 17:05:46 -07:00
@workingSchema.aceMode = ' ace/mode/coffee '
@workingSchema.aceTabSize = 2
2014-07-09 11:59:21 -07:00
class JavaScriptTreema extends CodeTreema
2014-01-03 10:32:13 -08:00
constructor: ->
super ( arguments . . . )
2014-08-28 17:05:46 -07:00
@workingSchema.aceMode = ' ace/mode/javascript '
@workingSchema.aceTabSize = 4
2014-01-03 10:32:13 -08:00
class InternationalizationNode extends TreemaNode . nodeMap . object
findLanguageName: (languageCode) ->
2014-09-25 13:17:41 -07:00
# to get around mongoose empty object bug, there's a prop in the object which needs to be ignored
2014-07-13 09:07:58 -07:00
return ' ' if languageCode is ' - '
2014-01-03 10:32:13 -08:00
locale [ languageCode ] ? . nativeDescription or " #{ languageCode } Not Found "
2014-07-13 09:07:58 -07:00
2014-07-12 09:55:26 -07:00
getChildren: ->
res = super ( arguments . . . )
res = ( r for r in res when r [ 0 ] isnt ' - ' )
res
2014-10-28 21:15:41 -07:00
2014-10-28 11:18:36 -07:00
populateData: ->
super ( )
if Object . keys ( @ data ) . length is 0
@ data [ ' - ' ] = { ' - ' : ' - ' } # also to get around mongoose bug
2014-01-03 10:32:13 -08:00
getChildSchema: (key) ->
#construct the child schema here
i18nChildSchema = {
title: @ findLanguageName ( key )
2014-07-01 10:16:26 +08:00
type: ' object '
2014-01-03 10:32:13 -08:00
properties: { }
}
2014-04-22 17:56:41 -07:00
return i18nChildSchema unless @ parent
2014-08-28 17:05:46 -07:00
unless @ workingSchema . props ?
2014-07-01 10:16:26 +08:00
console . warn ' i18n props array is empty! Filling with all parent properties by default '
2014-08-28 17:05:46 -07:00
@workingSchema.props = ( prop for prop , _ of @ parent . schema . properties when prop isnt ' i18n ' )
2014-01-03 10:32:13 -08:00
2014-08-28 17:05:46 -07:00
for i18nProperty in @ workingSchema . props
2014-10-28 21:15:41 -07:00
parentSchemaProperties = @ parent . schema . properties ? { }
for extraSchemas in [ @ parent . schema . oneOf , @ parent . schema . anyOf ]
for extraSchema in extraSchemas ? [ ]
for prop , schema of extraSchema ? . properties ? { }
parentSchemaProperties [ prop ] ? = schema
i18nChildSchema . properties [ i18nProperty ] = parentSchemaProperties [ i18nProperty ]
2014-01-03 10:32:13 -08:00
return i18nChildSchema
#this must be filled out in order for the i18n node to work
childPropertiesAvailable: ->
2014-07-09 11:59:21 -07:00
( key for key in _ . keys ( locale ) when not @ data [ key ] ? )
2014-01-03 10:32:13 -08:00
class LatestVersionCollection extends CocoCollection
2014-12-17 22:53:04 -08:00
module.exports.LatestVersionReferenceNode = class LatestVersionReferenceNode extends TreemaNode
2014-01-03 10:32:13 -08:00
searchValueTemplate: ' <input placeholder= " Search " /><div class= " treema-search-results " ></div> '
valueClass: ' treema-latest-version '
2014-06-13 09:52:34 -07:00
url: ' /db/article '
2014-01-03 10:32:13 -08:00
lastTerm: null
constructor: ->
super ( arguments . . . )
# to dynamically build the search url, inspect the links url that should be included
2014-08-28 17:05:46 -07:00
links = @ workingSchema . links or [ ]
2014-01-03 10:32:13 -08:00
link = ( l for l in links when l . rel is ' db ' ) [ 0 ]
return unless link
parts = ( p for p in link . href . split ( ' / ' ) when p . length )
2014-06-13 09:52:34 -07:00
@url = " /db/ #{ parts [ 1 ] } "
2014-01-03 10:32:13 -08:00
@model = require ( ' models/ ' + _ . string . classify ( parts [ 1 ] ) )
2014-08-22 11:11:05 -07:00
buildValueForDisplay: (valEl, data) ->
val = if data then @ formatDocument ( data ) else ' None '
2014-01-03 10:32:13 -08:00
@ buildValueForDisplaySimply ( valEl , val )
2014-08-22 11:11:05 -07:00
buildValueForEditing: (valEl, data) ->
2014-01-03 10:32:13 -08:00
valEl . html ( @ searchValueTemplate )
input = valEl . find ( ' input ' )
input . focus ( ) . keyup @ search
2014-08-22 11:11:05 -07:00
input . attr ( ' placeholder ' , @ formatDocument ( data ) ) if data
2014-08-25 14:35:51 -07:00
2014-08-07 18:49:39 -07:00
buildSearchURL: (term) -> " #{ @ url } ?term= #{ term } &project=true "
2014-01-03 10:32:13 -08:00
search: =>
term = @ getValEl ( ) . find ( ' input ' ) . val ( )
return if term is @ lastTerm
2014-04-08 17:13:05 -07:00
2014-01-03 10:32:13 -08:00
@ getSearchResultsEl ( ) . empty ( ) if @ lastTerm and not term
return unless term
@lastTerm = term
@ getSearchResultsEl ( ) . empty ( ) . append ( ' Searching ' )
2014-07-13 09:07:58 -07:00
@collection = new LatestVersionCollection ( [ ] , model: @ model )
2014-03-05 15:06:20 -08:00
2014-08-07 18:49:39 -07:00
@collection.url = @ buildSearchURL ( term )
2014-01-03 10:32:13 -08:00
@ collection . fetch ( )
2014-04-08 17:13:05 -07:00
@ collection . once ' sync ' , @ searchCallback , @
2014-01-03 10:32:13 -08:00
2014-03-24 22:28:34 +05:30
searchCallback: ->
2014-01-03 10:32:13 -08:00
container = @ getSearchResultsEl ( ) . detach ( ) . empty ( )
first = true
for model in @ collection . models
row = $ ( ' <div></div> ' ) . addClass ( ' treema-search-result-row ' )
text = @ formatDocument ( model )
continue unless text ?
row . addClass ( ' treema-search-selected ' ) if first
first = false
row . text ( text )
row . data ( ' value ' , model )
container . append ( row )
if not @ collection . models . length
container . append ( $ ( ' <div>No results</div> ' ) )
@ getValEl ( ) . append ( container )
getSearchResultsEl: -> @ getValEl ( ) . find ( ' .treema-search-results ' )
getSelectedResultEl: -> @ getValEl ( ) . find ( ' .treema-search-selected ' )
2014-08-25 14:35:51 -07:00
2014-08-07 18:49:39 -07:00
modelToString: (model) -> model . get ( ' name ' )
2014-01-03 10:32:13 -08:00
formatDocument: (docOrModel) ->
2014-08-07 18:49:39 -07:00
return @ modelToString ( docOrModel ) if docOrModel instanceof CocoModel
2014-01-03 10:32:13 -08:00
return ' Unknown ' unless @ settings . supermodel ?
2014-08-28 17:05:46 -07:00
m = CocoModel . getReferencedModel ( @ getData ( ) , @ workingSchema )
2014-08-26 14:15:21 -07:00
data = @ getData ( )
2014-09-26 02:28:54 -07:00
if _ . isString data # LatestVersionOriginalReferenceNode just uses original
2014-12-17 22:53:04 -08:00
if m . schema ( ) . properties . version
m = @ settings . supermodel . getModelByOriginal ( m . constructor , data )
else
# get by id
m = @ settings . supermodel . getModel ( m . constructor , data )
2014-09-26 02:28:54 -07:00
else
m = @ settings . supermodel . getModelByOriginalAndMajorVersion ( m . constructor , data . original , data . majorVersion )
2014-01-03 10:32:13 -08:00
if @ instance and not m
m = @ instance
2014-04-25 14:30:06 -07:00
@ settings . supermodel . registerModel ( m )
2014-09-26 02:28:54 -07:00
return ' Unknown - ' + ( data . original ? data ) unless m
2014-08-07 18:49:39 -07:00
return @ modelToString ( m )
2014-01-03 10:32:13 -08:00
saveChanges: ->
selected = @ getSelectedResultEl ( )
return unless selected . length
fullValue = selected . data ( ' value ' )
@data = {
original: fullValue . attributes . original
majorVersion: fullValue . attributes . version . major
}
@instance = fullValue
onDownArrowPressed: (e) ->
2014-08-07 18:49:39 -07:00
return super ( arguments . . . ) unless @ isEditing ( )
2014-01-03 10:32:13 -08:00
@ navigateSearch ( 1 )
e . preventDefault ( )
onUpArrowPressed: (e) ->
2014-08-07 18:49:39 -07:00
return super ( arguments . . . ) unless @ isEditing ( )
2014-01-03 10:32:13 -08:00
e . preventDefault ( )
@ navigateSearch ( - 1 )
navigateSearch: (offset) ->
selected = @ getSelectedResultEl ( )
func = if offset > 0 then ' next ' else ' prev '
next = selected [ func ] ( ' .treema-search-result-row ' )
return unless next . length
selected . removeClass ( ' treema-search-selected ' )
next . addClass ( ' treema-search-selected ' )
onClick: (e) ->
newSelection = $ ( e . target ) . closest ( ' .treema-search-result-row ' )
return super ( e ) unless newSelection . length
@ getSelectedResultEl ( ) . removeClass ( ' treema-search-selected ' )
newSelection . addClass ( ' treema-search-selected ' )
@ saveChanges ( )
@ flushChanges ( )
@ display ( )
shouldTryToRemoveFromParent: ->
return if @ data ?
selected = @ getSelectedResultEl ( )
return not selected . length
2014-08-25 14:35:51 -07:00
2014-12-17 22:53:04 -08:00
module.exports.LatestVersionOriginalReferenceNode = class LatestVersionOriginalReferenceNode extends LatestVersionReferenceNode
2014-09-26 02:28:54 -07:00
# Just for saving the original, not the major version.
saveChanges: ->
selected = @ getSelectedResultEl ( )
return unless selected . length
fullValue = selected . data ( ' value ' )
@data = fullValue . attributes . original
@instance = fullValue
2014-12-17 22:53:04 -08:00
module.exports.IDReferenceNode = class IDReferenceNode extends LatestVersionReferenceNode
# Just for saving the _id
saveChanges: ->
selected = @ getSelectedResultEl ( )
return unless selected . length
fullValue = selected . data ( ' value ' )
@data = fullValue . attributes . _id
@instance = fullValue
2014-08-07 18:49:39 -07:00
class LevelComponentReferenceNode extends LatestVersionReferenceNode
# HACK: this list of properties is needed by the thang components edit view and config views.
# need a better way to specify this, or keep the search models from bleeding into those
# supermodels.
buildSearchURL: (term) -> " #{ @ url } ?term= #{ term } &project=name,system,original,version,dependencies,configSchema,description "
modelToString: (model) -> model . get ( ' system ' ) + ' . ' + model . get ( ' name ' )
2014-08-25 20:34:46 -07:00
canEdit: -> not @ getData ( ) . original # only allow editing if the row's data hasn't been set yet
2014-01-03 10:32:13 -08:00
LatestVersionReferenceNode.prototype.search = _ . debounce ( LatestVersionReferenceNode . prototype . search , 200 )
class SlugPropsObject extends TreemaNode . nodeMap . object
getPropertyKey: ->
res = super ( arguments . . . )
2014-08-28 17:05:46 -07:00
return res if @ workingSchema . properties ? [ res ] ?
2014-01-03 10:32:13 -08:00
_ . string . slugify ( res )
2014-12-20 20:01:07 -08:00
class TaskTreema extends TreemaNode . nodeMap . string
buildValueForDisplay: (valEl) ->
@taskCheckbox = $ ( ' <input type= " checkbox " > ' ) . prop ' checked ' , @ data . complete
task = $ ( " <span> #{ @ data . name } </span> " )
valEl . append ( @ taskCheckbox ) . append ( task )
@ taskCheckbox . on ' change ' , @ onTaskChanged
buildValueForEditing: (valEl, data) ->
@nameInput = @ buildValueForEditingSimply ( valEl , data . name )
@ nameInput . parent ( ) . prepend ( @ taskCheckbox )
onTaskChanged: (e) =>
@ markAsChanged ( )
@ saveChanges ( )
@ flushChanges ( )
@ broadcastChanges ( )
onEditInputBlur: (e) =>
@ markAsChanged ( )
@ saveChanges ( )
if @ isValid ( ) then @ display ( ) if @ isEditing ( ) else @ nameInput . focus ( ) . select ( )
@ flushChanges ( )
@ broadcastChanges ( )
saveChanges: (oldData) ->
@ data ? = { }
@data.name = @ nameInput . val ( ) if @ nameInput
@data.complete = Boolean ( @ taskCheckbox . prop ' checked ' )
destroy: ->
@ taskCheckbox . off ( )
super ( )
#class CheckboxTreema extends TreemaNode.nodeMap.boolean
# TODO: try this out
2014-01-03 10:32:13 -08:00
module.exports.setup = ->
TreemaNode . setNodeSubclass ( ' date-time ' , DateTimeTreema )
TreemaNode . setNodeSubclass ( ' version ' , VersionTreema )
TreemaNode . setNodeSubclass ( ' markdown ' , LiveEditingMarkup )
2014-07-09 11:59:21 -07:00
TreemaNode . setNodeSubclass ( ' code-languages-object ' , CodeLanguagesObjectTreema )
2014-07-11 18:07:00 -07:00
TreemaNode . setNodeSubclass ( ' code-language ' , CodeLanguageTreema )
2014-07-09 11:59:21 -07:00
TreemaNode . setNodeSubclass ( ' code ' , CodeTreema )
2014-01-03 10:32:13 -08:00
TreemaNode . setNodeSubclass ( ' coffee ' , CoffeeTreema )
TreemaNode . setNodeSubclass ( ' javascript ' , JavaScriptTreema )
TreemaNode . setNodeSubclass ( ' image-file ' , ImageFileTreema )
TreemaNode . setNodeSubclass ( ' latest-version-reference ' , LatestVersionReferenceNode )
2014-09-26 02:28:54 -07:00
TreemaNode . setNodeSubclass ( ' latest-version-original-reference ' , LatestVersionOriginalReferenceNode )
2014-08-07 18:49:39 -07:00
TreemaNode . setNodeSubclass ( ' component-reference ' , LevelComponentReferenceNode )
2014-01-03 10:32:13 -08:00
TreemaNode . setNodeSubclass ( ' i18n ' , InternationalizationNode )
TreemaNode . setNodeSubclass ( ' sound-file ' , SoundFileTreema )
TreemaNode . setNodeSubclass ' slug-props ' , SlugPropsObject
2014-12-20 20:01:07 -08:00
TreemaNode . setNodeSubclass ' task ' , TaskTreema
#TreemaNode.setNodeSubclass 'checkbox', CheckboxTreema