Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSConsole: Saving/Updating Scripts in Subfolder #211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,37 +74,46 @@ function findAvailableScripts()
}
}

function createFile(parent, path) {
var name, foundNode;
name = path.shift();
if (path.length > 0) {
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)
{
scriptFile = scriptFolder.childByNamePath(args.name);
}
else
{
try
{
scriptFile = scriptFolder.createFile(args.name);
}
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 @@ -113,4 +122,4 @@ function saveScript()
}

saveScript();
findAvailableScripts();
findAvailableScripts();
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,32 @@ if (typeof OOTBee === 'undefined' || !OOTBee)
this.widgets.docsMenuButton.getMenu().cfg.setProperty('zIndex', 10);
},

initSubmenuIds: function JavaScriptConsole_initSubmenuIds(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 = [{
var scripts, saveMenuItems;

saveMenuItems = [{
text: this.msg('button.save.create.new'),
value: 'NEW'
}];

if (listOfScripts)
{
saveMenuItems.push(listOfScripts);
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 All @@ -437,14 +453,21 @@ 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)
{
loadMenuItems.push(listOfScripts);
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 +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(filename) + '&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 @@ -2269,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
Loading