Skip to content

Commit

Permalink
JConsole: refactoring Saving/Updating Scripts in Subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
oboldyreva-faw authored and AFaust committed Feb 21, 2024
1 parent 8fb67a7 commit 0c9abcb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<webscript>
<shortname>JSConsole store new Javascript</shortname>
<url>/ootbee/jsconsole/savescript?name={name}</url>
<url>/ootbee/jsconsole/savescript?namePath={namePath?}&amp;nodeRef={nodeRef?}</url>
<authentication>admin</authentication>
<format default="json">extension</format>
<lifecycle>internal</lifecycle>
<transaction allow="readwrite">required</transaction>
<family>OOTBee Support Tools</family>
</webscript>
</webscript>
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -125,4 +122,4 @@ function saveScript()
}

saveScript();
findAvailableScripts();
findAvailableScripts();
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.
Expand Down

0 comments on commit 0c9abcb

Please sign in to comment.