A slight enhancement to #650, plus fixing CocoModels thinking they're modified when schema defaults have been added.

This commit is contained in:
Nick Winter 2014-03-23 10:00:16 -07:00
parent 8ca5f23749
commit 7ba959045a
2 changed files with 9 additions and 3 deletions

View file

@ -86,7 +86,9 @@ class CocoModel extends Backbone.Model
res
markToRevert: ->
if @type() != 'ThangType'
if @type() is 'ThangType'
@_revertAttributes = _.clone @attributes # No deep clones for these!
else
@_revertAttributes = $.extend(true, {}, @attributes)
revert: ->
@ -120,14 +122,18 @@ class CocoModel extends Backbone.Model
addSchemaDefaults: ->
return if @addedSchemaDefaults or not @constructor.hasSchema()
@addedSchemaDefaults = true
addedAnything = false
for prop, defaultValue of @constructor.schema.attributes.default or {}
continue if @get(prop)?
#console.log "setting", prop, "to", defaultValue, "from attributes.default"
@set prop, defaultValue
addedAnything = true
for prop, sch of @constructor.schema.attributes.properties or {}
continue if @get(prop)?
#console.log "setting", prop, "to", sch.default, "from sch.default" if sch.default?
@set prop, sch.default if sch.default?
addedAnything = true
@markToRevert() if addedAnything
getReferencedModels: (data, schema, path='/', shouldLoadProjection=null) ->
# returns unfetched model shells for every referenced doc in this model

View file

@ -8,7 +8,7 @@ module.exports = class SettingsTabView extends View
id: 'editor-level-settings-tab-view'
className: 'tab-pane'
template: template
# not thangs or scripts or the backend stuff
editableSettings: [
'name', 'description', 'documentation', 'nextLevel', 'background', 'victory', 'i18n', 'icon', 'goals',
@ -39,7 +39,7 @@ module.exports = class SettingsTabView extends View
thangIDs: thangIDs
nodeClasses:
thang: nodes.ThangNode
@settingsTreema = @$el.find('#settings-treema').treema treemaOptions
@settingsTreema.build()
@settingsTreema.open()