Skip to content

Commit

Permalink
Saving/Updating Scripts in Subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
simonholzapfel committed Nov 2, 2023
1 parent d5e86da commit b22be15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b22be15

Please sign in to comment.