diff --git a/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.json.js b/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.json.js index 4d6136b..89ac6f5 100644 --- a/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.json.js +++ b/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.json.js @@ -74,6 +74,14 @@ function findAvailableScripts() } } +var createFile = function createFile(parent, path) { + var name = path.shift(); + if (path.length > 0) { + return createFile(parent.childByNamePath(name) || parent.createFolder(name), path); + } + return parent.createFile(name); +}; + function saveScript() { var scriptFolder, scriptFile, isUpdate; @@ -85,13 +93,17 @@ function saveScript() { if (isUpdate) { - scriptFile = scriptFolder.childByNamePath(args.name); + if (args.name.indexOf("workspace://") === 0) { + scriptFile = search.findNode(args.name); + }else{ + scriptFile = scriptFolder.childByNamePath(args.name); + } } else { try { - scriptFile = scriptFolder.createFile(args.name); + scriptFile = createFile(scriptFolder, ('' + args.name).split(/\//)); } catch (e) { diff --git a/share/src/main/resources/META-INF/resources/components/ootbee-support-tools/jsconsole.js b/share/src/main/resources/META-INF/resources/components/ootbee-support-tools/jsconsole.js index ef41903..1e3e78b 100644 --- a/share/src/main/resources/META-INF/resources/components/ootbee-support-tools/jsconsole.js +++ b/share/src/main/resources/META-INF/resources/components/ootbee-support-tools/jsconsole.js @@ -402,6 +402,15 @@ if (typeof OOTBee === 'undefined' || !OOTBee) this.widgets.docsMenuButton.getMenu().cfg.setProperty('zIndex', 2); }, + initSubmenuIds: function (entry, suffix) { + if (entry.submenu) { + entry.submenu.id = entry.submenu.id + suffix; + entry.submenu.itemdata.forEach(function (f) { + this.initSubmenuIds(f, suffix); + }.bind(this)); + } + }, + createOrUpdateScriptsSaveMenu: function JavaScriptConsole_createOrUpdateScriptsSaveMenu(listOfScripts) { var saveMenuItems = [{ @@ -411,7 +420,12 @@ if (typeof OOTBee === 'undefined' || !OOTBee) if (listOfScripts) { - saveMenuItems.push(listOfScripts); + var scripts = JSON.parse(JSON.stringify(listOfScripts)); + scripts.forEach(function(e) { + this.initSubmenuIds.call(this, e, "-scriptsave"); + }.bind(this)); + + saveMenuItems.push(scripts); } if (this.widgets.saveMenuButton) @@ -444,7 +458,12 @@ if (typeof OOTBee === 'undefined' || !OOTBee) if (listOfScripts) { - loadMenuItems.push(listOfScripts); + var scripts = JSON.parse(JSON.stringify(listOfScripts)); + scripts.forEach(function(e) { + this.initSubmenuIds.call(this, e, "-scriptload"); + }.bind(this)); + + loadMenuItems.push(scripts); } if (this.widgets.loadMenuButton) @@ -2237,7 +2256,7 @@ if (typeof OOTBee === 'undefined' || !OOTBee) saveAsExistingScript: function JavaScriptConsole_saveAsExistingScript(filename, nodeRef) { Alfresco.util.Ajax.jsonPut({ - url: Alfresco.constants.PROXY_URI + 'ootbee/jsconsole/savescript.json?name=' + encodeURIComponent(filename) + '&isUpdate=true', + url: Alfresco.constants.PROXY_URI + 'ootbee/jsconsole/savescript.json?name=' + encodeURIComponent(nodeRef) + '&isUpdate=true', dataObj: { jsScript: this.widgets.codeMirrorScript.getValue(), fmScript: this.widgets.codeMirrorTemplate.getValue()