From 0555c2ec1404c3d2f55b9b737cac780be6e6457d Mon Sep 17 00:00:00 2001 From: Jayant Jain <jayantjain1992@gmail.com> Date: Mon, 28 Jul 2014 07:43:18 +0530 Subject: [PATCH 1/4] Initial autocomplete for event checks in scripts tab --- app/views/editor/level/scripts/ScriptsTabView.coffee | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/editor/level/scripts/ScriptsTabView.coffee b/app/views/editor/level/scripts/ScriptsTabView.coffee index 10f4ee248..5c4822a99 100644 --- a/app/views/editor/level/scripts/ScriptsTabView.coffee +++ b/app/views/editor/level/scripts/ScriptsTabView.coffee @@ -124,7 +124,13 @@ class EventPropsNode extends TreemaNode.nodeMap.string joined = '(unset)' if not joined.length @buildValueForDisplaySimply valEl, joined - buildValueForEditing: (valEl) -> @buildValueForEditingSimply(valEl, @arrayToString()) + buildValueForEditing: (valEl) -> + super(valEl) + channel = @getRoot().data.channel + channelSchema = Backbone.Mediator.channelSchemas[channel] + autocompleteValues = ({label: val?.title or key, value: key} for key, val of channelSchema?.properties) + valEl.find('input').autocomplete(source: autocompleteValues, minLength: 0, delay: 0, autoFocus: true) + valEl saveChanges: (valEl) -> @data = (s for s in $('input', valEl).val().split('.') when s.length) From 632d9a666eb3cd01d8ae0a43ff118895fbe48fcb Mon Sep 17 00:00:00 2001 From: Jayant Jain <jayantjain1992@gmail.com> Date: Tue, 29 Jul 2014 01:45:59 +0530 Subject: [PATCH 2/4] Shows all autocomplete values on click instead of having to type initially --- app/views/editor/level/scripts/ScriptsTabView.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/editor/level/scripts/ScriptsTabView.coffee b/app/views/editor/level/scripts/ScriptsTabView.coffee index 5c4822a99..0c08b3a58 100644 --- a/app/views/editor/level/scripts/ScriptsTabView.coffee +++ b/app/views/editor/level/scripts/ScriptsTabView.coffee @@ -128,8 +128,9 @@ class EventPropsNode extends TreemaNode.nodeMap.string super(valEl) channel = @getRoot().data.channel channelSchema = Backbone.Mediator.channelSchemas[channel] - autocompleteValues = ({label: val?.title or key, value: key} for key, val of channelSchema?.properties) - valEl.find('input').autocomplete(source: autocompleteValues, minLength: 0, delay: 0, autoFocus: true) + 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 saveChanges: (valEl) -> From f0940308ea49a321e8b5ee8429483da44949d607 Mon Sep 17 00:00:00 2001 From: Jayant Jain <jayantjain1992@gmail.com> Date: Tue, 29 Jul 2014 20:33:40 +0530 Subject: [PATCH 3/4] Newly inserted scripts are automatically assigned id --- app/views/editor/level/scripts/ScriptsTabView.coffee | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/views/editor/level/scripts/ScriptsTabView.coffee b/app/views/editor/level/scripts/ScriptsTabView.coffee index 0c08b3a58..bc1558f46 100644 --- a/app/views/editor/level/scripts/ScriptsTabView.coffee +++ b/app/views/editor/level/scripts/ScriptsTabView.coffee @@ -39,6 +39,13 @@ module.exports = class ScriptsTabView extends CocoView onScriptsChanged: (e) => @level.set 'scripts', @scriptsTreema.data + lastAction = @scriptsTreema.trackedActions[@scriptsTreema.trackedActions.length - 1] + + if lastAction.action is 'insert' and lastAction.parentPath is '/' + newScript = @scriptsTreema.get lastAction.path + if newScript.id is undefined + @scriptsTreema.set lastAction.path+'/id', 'Script-' + @scriptsTreema.data.length + @scriptTreema.refreshDisplay() onScriptSelected: (e, selected) => selected = if selected.length > 1 then selected[0].getLastSelectedTreema() else selected[0] From 2690ef9a598224f8e5f466a82fcdbccb13fc35d5 Mon Sep 17 00:00:00 2001 From: Jayant Jain <jayantjain1992@gmail.com> Date: Wed, 30 Jul 2014 00:52:26 +0530 Subject: [PATCH 4/4] Reorders script ids upon deletion --- app/views/editor/level/scripts/ScriptsTabView.coffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/views/editor/level/scripts/ScriptsTabView.coffee b/app/views/editor/level/scripts/ScriptsTabView.coffee index bc1558f46..a53b2c383 100644 --- a/app/views/editor/level/scripts/ScriptsTabView.coffee +++ b/app/views/editor/level/scripts/ScriptsTabView.coffee @@ -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) ->