Reorders script ids upon deletion

This commit is contained in:
Jayant Jain 2014-07-30 00:52:26 +05:30
parent f0940308ea
commit 2690ef9a59

View file

@ -40,6 +40,7 @@ module.exports = class ScriptsTabView extends CocoView
onScriptsChanged: (e) =>
@level.set 'scripts', @scriptsTreema.data
lastAction = @scriptsTreema.trackedActions[@scriptsTreema.trackedActions.length - 1]
return unless lastAction
if lastAction.action is 'insert' and lastAction.parentPath is '/'
newScript = @scriptsTreema.get lastAction.path
@ -47,6 +48,14 @@ module.exports = class ScriptsTabView extends CocoView
@scriptsTreema.set lastAction.path+'/id', 'Script-' + @scriptsTreema.data.length
@scriptTreema.refreshDisplay()
if lastAction.action is 'delete' and lastAction.parentPath[0] is '/'
for key, treema of @scriptsTreema.childrenTreemas
key = parseInt(key)
if /Script-[0-9]*/.test treema.data.id
existingKey = parseInt(treema.data.id.substr(7))
if existingKey isnt key+1
treema.set 'id', 'Script-' + (key+1)
onScriptSelected: (e, selected) =>
selected = if selected.length > 1 then selected[0].getLastSelectedTreema() else selected[0]
unless selected
@ -137,7 +146,7 @@ class EventPropsNode extends TreemaNode.nodeMap.string
channelSchema = Backbone.Mediator.channelSchemas[channel]
autocompleteValues = []
autocompleteValues.push key for key, val of channelSchema?.properties
valEl.find('input').autocomplete(source: autocompleteValues, minLength: 0, delay: 0, autoFocus: true).autocomplete("search", "")
valEl.find('input').autocomplete(source: autocompleteValues, minLength: 0, delay: 0, autoFocus: true).autocomplete('search')
valEl
saveChanges: (valEl) ->