diff --git a/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.desc.xml b/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.desc.xml index fc02992..6812e40 100644 --- a/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.desc.xml +++ b/repository/src/main/resources/alfresco/templates/webscripts/org/orderofthebee/support-tools/jsconsole/saveScript.put.desc.xml @@ -1,10 +1,10 @@ JSConsole store new Javascript - /ootbee/jsconsole/savescript?name={name} + /ootbee/jsconsole/savescript?namePath={namePath?}&nodeRef={nodeRef?} admin extension internal required OOTBee Support Tools - \ No newline at end of file + 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 89ac6f5..e6cce01 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,49 +74,46 @@ function findAvailableScripts() } } -var createFile = function createFile(parent, path) { - var name = path.shift(); +function createFile(parent, path) { + var name, foundNode; + name = path.shift(); if (path.length > 0) { - return createFile(parent.childByNamePath(name) || parent.createFolder(name), path); + foundNode = parent.childByNamePath(name); + if (foundNode !== null && !foundNode.isContainer){ + throw new Error('Path element is not a folder'); + }else{ + return createFile(foundNode || parent.createFolder(name), path); + } } return parent.createFile(name); -}; +} function saveScript() { - var scriptFolder, scriptFile, isUpdate; - - isUpdate = String(args.isUpdate) === 'true'; + var scriptFolder, scriptFile; scriptFolder = search.selectNodes('/app:company_home/app:dictionary/app:scripts')[0]; if (scriptFolder) { - if (isUpdate) - { - if (args.name.indexOf("workspace://") === 0) { - scriptFile = search.findNode(args.name); - }else{ - scriptFile = scriptFolder.childByNamePath(args.name); - } - } - else - { - try - { - scriptFile = createFile(scriptFolder, ('' + args.name).split(/\//)); - } - catch (e) - { - if (e.message && e.message.indexOf('FileExistsException')) - { - e.code = 409; + if (args.nodeRef !== null || args.namePath !== null) { + if (args.nodeRef !== null) {// now update always with nodeRef + scriptFile = search.findNode(args.nodeRef); + } else if (args.namePath !== null) { + try { + scriptFile = createFile(scriptFolder, ('' + args.namePath).split(/\//)); + } catch (e) { + if (e.message && e.message.indexOf('FileExistsException')) { + e.code = 409; + } + throw e; } - throw e; } + scriptFile.content = json.get('jsScript'); + scriptFile.properties['jsc:freemarkerScript'].content = json.get('fmScript'); + scriptFile.save(); + } else{ + logger.warn('No nodeRef or namePath argument'); } - scriptFile.content = json.get('jsScript'); - scriptFile.properties['jsc:freemarkerScript'].content=json.get('fmScript'); - scriptFile.save(); } else { @@ -125,4 +122,4 @@ function saveScript() } saveScript(); -findAvailableScripts(); \ No newline at end of file +findAvailableScripts(); 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 8c2ef85..a91aa49 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,7 +402,7 @@ if (typeof OOTBee === 'undefined' || !OOTBee) this.widgets.docsMenuButton.getMenu().cfg.setProperty('zIndex', 10); }, - initSubmenuIds: function (entry, suffix) { + initSubmenuIds: function JavaScriptConsole_initSubmenuIds(entry, suffix) { if (entry.submenu) { entry.submenu.id = entry.submenu.id + suffix; entry.submenu.itemdata.forEach(function (f) { @@ -413,14 +413,16 @@ if (typeof OOTBee === 'undefined' || !OOTBee) createOrUpdateScriptsSaveMenu: function JavaScriptConsole_createOrUpdateScriptsSaveMenu(listOfScripts) { - var saveMenuItems = [{ + var scripts, saveMenuItems; + + saveMenuItems = [{ text: this.msg('button.save.create.new'), value: 'NEW' }]; if (listOfScripts) { - var scripts = JSON.parse(JSON.stringify(listOfScripts)); + scripts = JSON.parse(JSON.stringify(listOfScripts)); scripts.forEach(function(e) { this.initSubmenuIds.call(this, e, "-scriptsave"); }.bind(this)); @@ -451,14 +453,16 @@ if (typeof OOTBee === 'undefined' || !OOTBee) createOrUpdateScriptsLoadMenu: function JavaScriptConsole_createOrUpdateScriptsLoadMenu(listOfScripts) { - var loadMenuItems = [{ + var scripts, loadMenuItems; + + loadMenuItems = [{ text: this.msg('button.load.create.new'), value: 'NEW' }]; if (listOfScripts) { - var scripts = JSON.parse(JSON.stringify(listOfScripts)); + scripts = JSON.parse(JSON.stringify(listOfScripts)); scripts.forEach(function(e) { this.initSubmenuIds.call(this, e, "-scriptload"); }.bind(this)); @@ -2256,7 +2260,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(nodeRef) + '&isUpdate=true', + url: Alfresco.constants.PROXY_URI + 'ootbee/jsconsole/savescript.json?nodeRef=' + encodeURIComponent(nodeRef), dataObj: { jsScript: this.widgets.codeMirrorScript.getValue(), fmScript: this.widgets.codeMirrorTemplate.getValue() @@ -2288,10 +2292,14 @@ if (typeof OOTBee === 'undefined' || !OOTBee) }); }, + /** + * + * @param filename either file name or path relative from scripts folder + */ saveAsNewScript: function JavaScriptConsole_saveAsNewScript(filename) { Alfresco.util.Ajax.jsonPut({ - url: Alfresco.constants.PROXY_URI + 'ootbee/jsconsole/savescript.json?name=' + encodeURIComponent(filename) + '&isUpdate=false', + url: Alfresco.constants.PROXY_URI + 'ootbee/jsconsole/savescript.json?namePath=' + encodeURIComponent(filename), dataObj: { jsScript: this.widgets.codeMirrorScript.getValue(), fmScript: this.widgets.codeMirrorTemplate.getValue() diff --git a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get.properties b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get.properties index 2ee9e82..4ecf897 100644 --- a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get.properties +++ b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get.properties @@ -46,7 +46,7 @@ button.save=Save button.cancel=Cancel title.save.choose.filename=Save script as... -message.save.choose.filename=Please enter the name for the new script file: +message.save.choose.filename=Please enter the name or name path for the new script file: error.script.load=Error loading script '{0}'. error.script.save=Error saving script '{0}'. diff --git a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_de.properties b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_de.properties index be0f7be..97cfec6 100644 --- a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_de.properties +++ b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_de.properties @@ -34,7 +34,7 @@ label.title-search = Javascript Konsole label.title-view = Javascript Konsole message.confirm.save = Sind Sie sicher, dass Sie Skript '{0}' \u00FCberschreiben wollen? -message.save.choose.filename = Bitte geben Sie einen Dateinamen f\u00FCr das neue Skript ein: +message.save.choose.filename = Bitte geben Sie einen Dateinamen oder Dateipfad f\u00FCr das neue Skript ein: message.save.successful = Das Skript '{0}' wurde erfolgreich gespeichert! title.confirm.save = Speichern best\u00E4tigen diff --git a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_en.properties b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_en.properties index 203a4c8..c878316 100644 --- a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_en.properties +++ b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_en.properties @@ -44,7 +44,7 @@ button.save=Save button.cancel=Cancel title.save.choose.filename=Save script as... -message.save.choose.filename=Please enter the name for the new script file: +message.save.choose.filename=Please enter the name or name path for the new script file: error.script.load=Error loading script '{0}'. error.script.save=Error saving script '{0}'. diff --git a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_it.properties b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_it.properties index 203a4c8..c878316 100644 --- a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_it.properties +++ b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_it.properties @@ -44,7 +44,7 @@ button.save=Save button.cancel=Cancel title.save.choose.filename=Save script as... -message.save.choose.filename=Please enter the name for the new script file: +message.save.choose.filename=Please enter the name or name path for the new script file: error.script.load=Error loading script '{0}'. error.script.save=Error saving script '{0}'. diff --git a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_pt.properties b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_pt.properties index 203a4c8..c878316 100644 --- a/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_pt.properties +++ b/share/src/main/resources/alfresco/site-webscripts/org/orderofthebee/support-tools/console/support-tools/ootbee-jsconsole.get_pt.properties @@ -44,7 +44,7 @@ button.save=Save button.cancel=Cancel title.save.choose.filename=Save script as... -message.save.choose.filename=Please enter the name for the new script file: +message.save.choose.filename=Please enter the name or name path for the new script file: error.script.load=Error loading script '{0}'. error.script.save=Error saving script '{0}'.