732 lines
25 KiB
HTML
732 lines
25 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Actions Code</title>
|
|
<script type="text/javascript" src="../stdFunctions.js"></script>
|
|
<script type="text/javascript" src="../controls.js"></script>
|
|
<script type="text/javascript" src="../propertiesObj.js"></script>
|
|
<script type="text/javascript" src="../PortalCommonJS.js"></script>
|
|
<link rel="stylesheet" href="./editItemEvent.css" />
|
|
<link rel="stylesheet" data-name="vs/editor/editor.main" href="../monaco/resources/editor.main.css" />
|
|
</head>
|
|
<body>
|
|
|
|
<div id="topbar">
|
|
<span class="title">Action Code</span>
|
|
<div class="float_right">
|
|
<a
|
|
id="toolbar_cancel"
|
|
class="action"
|
|
href="javascript:void(0)"
|
|
title="Cancel"
|
|
>CANCEL</a
|
|
>
|
|
</div>
|
|
<div class="float_right">
|
|
<a
|
|
id="toolbar_ok"
|
|
class="action"
|
|
href="javascript:void(0)"
|
|
title="Save and Close"
|
|
>SAVE</a
|
|
>
|
|
</div>
|
|
<div class="action_bar">
|
|
<!--div id='topbar_right' class='topbar_sides float_right'></div-->
|
|
|
|
<!--div id='topbar_left' class='topbar_sides float_left'></div-->
|
|
<div class="float_left topbar_padding">
|
|
<label class="small" for="id_item">Items: </label>
|
|
<div id="selectname" class="select" style="display: inline"></div>
|
|
</div>
|
|
<div class="topbar_separator float_left"></div>
|
|
<div class="float_left topbar_padding">
|
|
<label class="small" for="event_item">Events: </label>
|
|
<div id="selectevent" class="select" style="display: inline"></div>
|
|
</div>
|
|
<div class="topbar_separator float_left"></div>
|
|
<div class="float_left topbar_padding">
|
|
<label class="small" for="function_item">Functions: </label>
|
|
<div id="selectfunction" class="select" style="display: inline"></div>
|
|
</div>
|
|
|
|
<div class="float_right topbar_padding">
|
|
<a
|
|
id="toolbar_search"
|
|
class="title_btn"
|
|
href="javascript:void(0)"
|
|
title="Search"
|
|
></a>
|
|
</div>
|
|
<div class="float_right topbar_padding">
|
|
<a
|
|
id="toolbar_help"
|
|
class="title_btn"
|
|
href="javascript:void(0)"
|
|
title="Help"
|
|
>
|
|
</a>
|
|
<div id="helpkeys_content" class="small">
|
|
<table cellpadding="5" border="0">
|
|
<tbody>
|
|
<tr>
|
|
<td>Search</td>
|
|
<td align="right" class="keys" nowrap>Ctrl-F</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Replace</td>
|
|
<td align="right" class="keys" nowrap>Ctrl-R</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Find Next</td>
|
|
<td align="right" class="keys" nowrap>F3</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Find Prev</td>
|
|
<td align="right" class="keys" nowrap>Shift-F3</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Toggle Bookmark</td>
|
|
<td align="right" class="keys" nowrap>Ctrl-F8</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Next Bookmark</td>
|
|
<td align="right" class="keys" nowrap>F8</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Prev Bookmark</td>
|
|
<td align="right" class="keys" nowrap>Shift-F8</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Full List</td>
|
|
<td align="right" class="keys" nowrap>F1</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Save</td>
|
|
<td align="right" class="keys" nowrap>Ctrl-S</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Quit</td>
|
|
<td align="right" class="keys" nowrap>Ctrl-Q</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="float_right topbar_padding">
|
|
<a
|
|
id="toolbar_style"
|
|
class="title_btn"
|
|
href="javascript:void(0)"
|
|
title="Style"
|
|
></a>
|
|
<div id="opt_pane">
|
|
<div id="opt_pane_wrapper">
|
|
<div id="opt_pane_content">
|
|
<label for="theme-choise">Style: </label>
|
|
<br />
|
|
<select id="theme" title="Select favorite theme">
|
|
<option value="Default Light Modern">Light 1</option>
|
|
<option value="Default High Contrast Light">Light 2</option>
|
|
<option value="Default Dark Modern">Dark 1</option>
|
|
<option value="Default High Contrast">Dark 2</option>
|
|
</select>
|
|
<br />
|
|
<label id="slider">Font size: </label>
|
|
<br />
|
|
<div style="padding: 5px">
|
|
<input
|
|
type="range"
|
|
id="fontSlider"
|
|
name="volume"
|
|
min="8"
|
|
max="35"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="editor">
|
|
<div id="loader"></div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|
|
<script type="module">
|
|
import { configureMonacoWorkers, runActionCodeEditor, getEditor, getMonaco } from "../monaco/monacoLoader.js";
|
|
|
|
var itemsHTML = parent.ACitemsHTML,
|
|
index = parent.index,
|
|
form = parent.formProp,
|
|
bookmarks = parent.actioncodeBookmarks || [],
|
|
z_ac_style = localStorage.getItem("zucchetti_ac_style"),
|
|
ac_style = !Empty(z_ac_style)
|
|
? JSON.parse(z_ac_style)
|
|
: { fontSize: 12, theme: "Default Light Modern" };
|
|
|
|
localStorage.setItem("zucchetti_ac_style", JSON.stringify(ac_style));
|
|
|
|
let editorSetup = {
|
|
htmlContainer: "editor",
|
|
code: parent.actioncode,
|
|
theme: ac_style.theme,
|
|
fontSize: ac_style.fontSize,
|
|
bookmarks: bookmarks,
|
|
tabSize: 2
|
|
}
|
|
|
|
// set theme and font size from the localStorage
|
|
document.getElementById("theme").value = ac_style.theme;
|
|
document.getElementById("fontSlider").value = ac_style.fontSize;
|
|
|
|
configureMonacoWorkers()
|
|
.then(() => {return runActionCodeEditor(editorSetup, itemsHTML, form.objClass)})
|
|
.then(() => {
|
|
|
|
var editor = getEditor();
|
|
var monaco = getMonaco();
|
|
|
|
// SEARCH
|
|
document.getElementById("toolbar_search").addEventListener("click", function () {
|
|
editor.getAction('actions.find').run();
|
|
});
|
|
|
|
// HELP
|
|
document.getElementById("toolbar_help").addEventListener("click", function () {
|
|
[].forEach.call(
|
|
document.querySelectorAll(".visible:not(#helpkeys_content)"),
|
|
(other) => {
|
|
other.classList.remove("visible");
|
|
}
|
|
);
|
|
LibJavascript.CssClassNameUtils.toggleClass(
|
|
document.getElementById("helpkeys_content"),
|
|
"visible"
|
|
);
|
|
});
|
|
|
|
// STYLE
|
|
document.getElementById("toolbar_style").addEventListener("click", function () {
|
|
[].forEach.call(
|
|
document.querySelectorAll(".visible:not(#opt_pane)"),
|
|
(other) => {
|
|
other.classList.remove("visible");
|
|
}
|
|
);
|
|
LibJavascript.CssClassNameUtils.toggleClass(
|
|
document.getElementById("opt_pane"),
|
|
"visible"
|
|
);
|
|
});
|
|
// themes
|
|
document.getElementById("theme").addEventListener("change", function () {
|
|
let theme = this.value;
|
|
monaco.editor.setTheme(theme);
|
|
ac_style.theme = theme;
|
|
localStorage.setItem("zucchetti_ac_style", JSON.stringify(ac_style));
|
|
});
|
|
// font size slider
|
|
document.getElementById("fontSlider").addEventListener("change", function () {
|
|
let editor = getEditor();
|
|
editor.updateOptions({ fontSize: this.value });
|
|
document.getElementById("fontSlider").value = editor.getRawOptions().fontSize;
|
|
ac_style.fontSize = this.value;
|
|
localStorage.setItem("zucchetti_ac_style", JSON.stringify(ac_style));
|
|
});
|
|
|
|
// CLOSE STYLE AND HELP PANELS
|
|
document.getElementById("editor").addEventListener("click", function () {
|
|
if(document.getElementById("opt_pane").classList.contains("visible")){
|
|
document.getElementById("opt_pane").classList.remove("visible");
|
|
}
|
|
if(document.getElementById("helpkeys_content").classList.contains("visible")){
|
|
document.getElementById("helpkeys_content").classList.remove("visible");
|
|
}
|
|
});
|
|
|
|
function findMatches(text){
|
|
let matches = editor.getModel().findMatches(text, false, false, false, null, true);
|
|
return matches;
|
|
}
|
|
|
|
function writeCode(name, obj) {
|
|
let funct_evt = Ctrl("event_item").value;
|
|
if (funct_evt == "-") return;
|
|
let fnc = "function " + name + "_";
|
|
let matches = findMatches(fnc + funct_evt);
|
|
// insert the event only if it is not alredy present
|
|
if(matches.length != 0){
|
|
editor.setPosition({ lineNumber: matches[0].range.startLineNumber, column: 1 });
|
|
editor.focus();
|
|
}
|
|
else{
|
|
let textToInject = [
|
|
fnc + (Empty(funct_evt.match(/\([^\)]*\)/)) ? (funct_evt + "()") : funct_evt) + "{",
|
|
" ",
|
|
"}"
|
|
].join('\n');
|
|
let pos = editor.getPosition().lineNumber;
|
|
let editOperation = {
|
|
range: {
|
|
startLineNumber: pos,
|
|
endLineNumber: pos
|
|
},
|
|
text: textToInject,
|
|
forceMoveMarkers: true
|
|
};
|
|
editor.getModel().pushEditOperations([], [editOperation], () => []);
|
|
editor.setPosition({ lineNumber: (pos + 1), column: 3 });
|
|
editor.focus();
|
|
|
|
jQuery("#id_item").val(null).trigger("change");
|
|
}
|
|
}
|
|
|
|
function stripHtml(html) {
|
|
var stripedHtml = html.replace(/<br>/g, "\n");
|
|
stripedHtml = stripedHtml.replace(/<blockquote>/g, "\n");
|
|
stripedHtml = stripedHtml.replace(/<li>/g, "\n-");
|
|
stripedHtml = stripedHtml.replace(/<[^>]+>/g, "");
|
|
stripedHtml = stripedHtml.replace(/\n\n/g, "\n");
|
|
return stripedHtml;
|
|
}
|
|
|
|
function option(val, descr, long_descr) {
|
|
var txt = !Empty(long_descr)
|
|
? long_descr
|
|
: arguments.length == 1
|
|
? val
|
|
: descr;
|
|
txt = stripHtml(txt);
|
|
return (
|
|
'<option title="' +
|
|
txt +
|
|
'" value="' +
|
|
val +
|
|
'">' +
|
|
(arguments.length == 1 ? val : descr) +
|
|
"</option>"
|
|
);
|
|
}
|
|
|
|
function selectName() {
|
|
var name,
|
|
src,
|
|
i,
|
|
str =
|
|
'<select id="id_item" tabindex="2" accesskey="t">' +
|
|
'<option value="">-</option><option value="this">this</option>';
|
|
if (parent.mode == "HTML" && parent.current_variant > 0) {
|
|
str += '<option value="base_portlet">portlet base</option>';
|
|
}
|
|
if (form.title == "default") {
|
|
str += '<option value="getTitlePortlet">title portlet</option>';
|
|
}
|
|
var comboSelectItems = [];
|
|
for (i = 0; i < itemsHTML.length; i++) {
|
|
comboSelectItems.push(itemsHTML[i]);
|
|
}
|
|
comboSelectItems.sort(function (a, b) {
|
|
var minA = a.name.toLowerCase();
|
|
var minB = b.name.toLowerCase();
|
|
if (minA < minB) {
|
|
return -1;
|
|
} else {
|
|
if (minA > minB) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
});
|
|
for (i = 0; i < comboSelectItems.length; i++) {
|
|
var item_tmp = comboSelectItems[i];
|
|
str += "<option ";
|
|
if (item_tmp.type == "Portlet") {
|
|
if (index != null && item_tmp.name == itemsHTML[index].name) {
|
|
str += "selected ";
|
|
name = item_tmp.name;
|
|
src = item_tmp.src;
|
|
}
|
|
str += 'value="' + item_tmp.src + '">' + item_tmp.name + "</option>";
|
|
} else {
|
|
if (index != null && item_tmp.name == itemsHTML[index].name) {
|
|
str += "selected ";
|
|
name = item_tmp.name;
|
|
}
|
|
str += 'value="' + item_tmp.name + '">' + item_tmp.name + "</option>";
|
|
}
|
|
}
|
|
str += "</select>";
|
|
Ctrl("selectname").innerHTML = str;
|
|
jQuery("#id_item").select2({ dropdownAutoWidth: true });
|
|
jQuery("#id_item").on("change", function () {
|
|
var idx = this.selectedIndex,
|
|
txt = this.options[idx].text,
|
|
val = this.options[idx].value;
|
|
selectEvent(txt, val);
|
|
selectFunction(txt, val);
|
|
});
|
|
selectEvent(name, src);
|
|
selectFunction(name, src);
|
|
}
|
|
|
|
function selectEvent(name, src) {
|
|
var str = '<select id="event_item" tabindex="3" accesskey="e"><option>-</option>',
|
|
es,
|
|
i,
|
|
obj,
|
|
found = false;
|
|
if (!name) name = "-";
|
|
if (name != "this" && name != "-") {
|
|
for (i = 0; i < itemsHTML.length; i++) {
|
|
obj = itemsHTML[i];
|
|
src = obj.src;
|
|
if (obj.name == name || src == name) {
|
|
found = true;
|
|
es = obj;
|
|
break;
|
|
}
|
|
}
|
|
} else if (name == "this") {
|
|
found = true;
|
|
/* Aggiunta delle informazioni per i tab */
|
|
// copia profonda
|
|
es = { objClass: { events: form.objClass.events.slice() } };
|
|
if (form.npages > 1) {
|
|
for (var i = 0; i < form.npages; i++) {
|
|
es.objClass.events.push([
|
|
"EnablePage(" +
|
|
(i + 1) +
|
|
"), return boolean true if validate, false otherwise",
|
|
"EnablePage" + (i + 1) + "()",
|
|
]);
|
|
}
|
|
for (var i = 0; i < form.npages; i++) {
|
|
es.objClass.events.push([
|
|
"ValidatePageChange(" +
|
|
(i + 1) +
|
|
"), return boolean true if validate, false otherwise",
|
|
"ValidatePageChange" + (i + 1) + "(pageTo)",
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
if (found) {
|
|
var _objC = es.objClass;
|
|
es = es.objClass.events;
|
|
if (es) {
|
|
var descr, value, long_descr;
|
|
for (var i = 0; i < es.length; i++) {
|
|
if (_objC.generateSignatureObject) {
|
|
var robj = _objC.generateSignatureObject(es[i], "event");
|
|
descr = robj.name;
|
|
value = robj.signature;
|
|
long_descr = robj.tooltip;
|
|
} else {
|
|
if (IsA(es[i], "C")) value = descr = es[i];
|
|
else if (Array.isArray(es[i])) {
|
|
descr = es[i][0];
|
|
value = es[i][1];
|
|
if (!Empty(es[i][2])) long_descr = es[i][2];
|
|
} else {
|
|
//object
|
|
descr = es[i].name;
|
|
value = es[i].signature ? es[i].signature : es[i].name;
|
|
long_descr = es[i].tooltip;
|
|
}
|
|
}
|
|
str += option(value, descr, long_descr);
|
|
}
|
|
}
|
|
if (obj != null && obj.type == "Portlet" && src) {
|
|
var folder_path = "";
|
|
if (src.indexOf("/") > -1) {
|
|
folder_path = "/" + name.substring(0, src.lastIndexOf("/"));
|
|
src = Strtran(src, src.substring(0, src.lastIndexOf("/") + 1), "");
|
|
}
|
|
//legge gli eventi nei portlet
|
|
var url = new JSURL(
|
|
"../servlet/JSPReader?name=" +
|
|
src +
|
|
"&folder_path=" +
|
|
folder_path +
|
|
"&type=events",
|
|
true
|
|
);
|
|
var eventsList = url.Response().split(";");
|
|
for (var i = 0; i < eventsList.length; i++) {
|
|
if (Trim(eventsList[i]) != "") str += option(eventsList[i]);
|
|
}
|
|
}
|
|
}
|
|
str += "</select>";
|
|
Ctrl("selectevent").innerHTML = str;
|
|
jQuery("#event_item").select2({ dropdownAutoWidth: true });
|
|
jQuery("#event_item").on("change", function () {
|
|
writeCode(name, this);
|
|
});
|
|
|
|
}
|
|
|
|
function selectFunction(name, src) {
|
|
var str ='<select id="function_item" tabindex="4" accesskey="f"><option>-</option>';
|
|
var fs;
|
|
var found = false;
|
|
if (!name) name = "-";
|
|
if (name != "this" && name != "-") {
|
|
for (var i = 0, obj; i < itemsHTML.length; i++) {
|
|
obj = itemsHTML[i];
|
|
src = obj.src;
|
|
if (obj.name == name || src == name) {
|
|
found = true;
|
|
fs = obj;
|
|
break;
|
|
}
|
|
}
|
|
} else if (name == "this") {
|
|
found = true;
|
|
fs = form;
|
|
}
|
|
if (found) {
|
|
var _objC = fs.objClass;
|
|
if (!Empty(fs.objClass.functions)) {
|
|
fs = fs.objClass.functions.sort(function (a, b) {
|
|
if (Array.isArray(a) && a.length > 0) a = a[0];
|
|
else if (!(typeof a === "string")) {
|
|
// object
|
|
a = a.name;
|
|
}
|
|
if (Array.isArray(b) && b.length > 0) b = b[0];
|
|
else if (!(typeof b === "string")) {
|
|
// object
|
|
b = b.name;
|
|
}
|
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
});
|
|
}
|
|
if (fs) {
|
|
var descr, value, long_descr;
|
|
for (var i = 0; i < fs.length; i++) {
|
|
if (_objC.generateSignatureObject) {
|
|
var robj = _objC.generateSignatureObject(fs[i], "function");
|
|
descr = robj.name;
|
|
value = robj.signature;
|
|
long_descr = robj.tooltip;
|
|
} else {
|
|
if (IsA(fs[i], "C")) value = descr = fs[i];
|
|
else if (Array.isArray(fs[i])) {
|
|
descr = fs[i][0];
|
|
value = fs[i][1];
|
|
if (!Empty(fs[i][2])) long_descr = fs[i][2];
|
|
} else {
|
|
//object
|
|
descr = fs[i].name;
|
|
value = fs[i].signature ? fs[i].signature : fs[i].name;
|
|
long_descr = fs[i].tooltip;
|
|
}
|
|
}
|
|
str += option(value, descr, long_descr);
|
|
}
|
|
}
|
|
if (obj != null && obj.type == "Portlet" && src) {
|
|
//legge le functions dei portlet inclusi
|
|
var folder_path = "";
|
|
if (src.indexOf("/") > -1) {
|
|
folder_path = "/" + name.substring(0, src.lastIndexOf("/"));
|
|
src = Strtran(src, src.substring(0, src.lastIndexOf("/") + 1), "");
|
|
}
|
|
//legge gli eventi nei portlet
|
|
var url = new JSURL(
|
|
"../servlet/JSPReader?name=" +
|
|
src +
|
|
"&folder_path=" +
|
|
folder_path +
|
|
"&type=functions",
|
|
true
|
|
);
|
|
var eventsList = url.Response().split(";");
|
|
for (var i = 0; i < eventsList.length; i++)
|
|
if (Trim(eventsList[i]) != "") str += option(eventsList[i]);
|
|
}
|
|
} else if (name == "-") {
|
|
str += option("Trim(#str#)");
|
|
str += option("Strtran(#src#,#find#,#repl#)");
|
|
str += option("Substr(#str#,#pos#,#cnt#)");
|
|
str += option("Left(#str#,#len#)");
|
|
str += option("Right(#str#,#len#)");
|
|
str += option("Str(#p_n#,#len#,#dec#)");
|
|
str += option("Val(#str#)");
|
|
str += option("Upper(#str#)");
|
|
str += option("Lower(#str#)");
|
|
str += option("At(#p_cStrFind#,#p_cStr#,#cnt#)");
|
|
str += option("Len(#obj#)");
|
|
str += option("DateToChar(#obj#)");
|
|
str += option("CharToDate(#obj#)");
|
|
str += option("Day(#obj#)");
|
|
str += option("Month(#obj#)");
|
|
str += option("Year(#obj#)");
|
|
str += option("Hour(#obj#)");
|
|
str += option("Minute(#obj#)");
|
|
str += option("FormatMsg(#msg#)");
|
|
} else if (name == "title portlet") {
|
|
str += option("SetTitle(#title#,#forceChange#)");
|
|
str += option("SetSubTitle(#title#,#forceChange#)");
|
|
str += option("SetImage(#src#,#action#,#forceChange#)");
|
|
str += option(
|
|
"AppendButton({\n id:#id#,\n title:#title#,\n tooltip:#tooltip#,\n image:{fontFamily:#font#, value:#char#, " +
|
|
"size:#size#,color:#color#},\n action:#action#\n},#idx#)",
|
|
"AppendButton(#item#,#idx#) -> Append button to the toolbar"
|
|
);
|
|
str += option(
|
|
"RemoveButtons()",
|
|
"RemoveButtons() -> Empty toolbar content"
|
|
);
|
|
str += option(
|
|
"RemoveButton(#id#)",
|
|
"RemoveButton(#id#) -> Remove the button from the toolbar"
|
|
);
|
|
str += option(
|
|
"UpdateButton(#id#,{\n title:#title#,\n tooltip:#tooltip#,\n image:{fontFamily:#font#, value:#char#, size:#size#, " +
|
|
"color:#color#},\n action:#action#\n})",
|
|
"UpdateButton(#id#,#item#) -> Update the toolbar button"
|
|
);
|
|
str += option(
|
|
"AppendHamburgerItem({\n id:#id#,\n title:#title#,\n tooltip:#tooltip#,\n image:{fontFamily:#font#, value:#char#, size:#size#, color:#color#},\n action:#action#\n},#parentId#,#idx#)",
|
|
"AppendHamburgerItem(#item#,#parentId#,#idx#) -> Append item to the hamburger menu"
|
|
);
|
|
str += option(
|
|
"UpdateHamburgerItem(#id#,{\n title:#title#,\n tooltip:#tooltip#,\n image:{fontFamily:#font#, value:#char#, size:#size#, color:#color#},\n action:#action#\n})",
|
|
"UpdateHamburgerItem(#id#,#item#) -> Update the menu item"
|
|
);
|
|
str += option("CloseMenu()", "CloseMenu() -> Close the hamburger menu");
|
|
str += option("CleanMenu()", "CleanMenu() -> Empty the hamburger menu");
|
|
} else if (name == "portlet base") {
|
|
if (parent.currentname) {
|
|
//legge gli eventi nei portlet base
|
|
var url = new JSURL(
|
|
"../servlet/JSPReader?name=" +
|
|
parent.currentname +
|
|
"&folder_path=" +
|
|
parent.folder_path +
|
|
"&type=functions",
|
|
true
|
|
);
|
|
var eventsList = url.Response().split(";");
|
|
for (var i = 0; i < eventsList.length; i++) {
|
|
if (Trim(eventsList[i]) != "") {
|
|
str += option(eventsList[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
str += "</select>";
|
|
Ctrl("selectfunction").innerHTML = str;
|
|
jQuery("#function_item").select2({
|
|
dropdownAutoWidth: true
|
|
});
|
|
jQuery("#function_item").on("change", function () {
|
|
writeFunction(name, this);
|
|
});
|
|
}
|
|
|
|
function writeFunction(name, obj){
|
|
let str,
|
|
firstParam,
|
|
func = Ctrl("function_item").value,
|
|
cursorPos = editor.getPosition();
|
|
if (func == "-") return;
|
|
if (name == "-") str = func + "\n";
|
|
else if (name == "this") str = "this." + func;
|
|
else if (name == "title portlet") str = "this.getTitlePortlet()." + func;
|
|
else if (name == "portlet base") {
|
|
let matches = search("function " + func);
|
|
if (matches.length != 0) {
|
|
editor.setPosition({ lineNumber: matches[0].range.startLineNumber, column: 1 });
|
|
editor.focus()
|
|
return;
|
|
} else {
|
|
str = "function " + func + "{\n\n}";
|
|
}
|
|
}
|
|
else str = "this." + name + "." + func;
|
|
|
|
firstParam = /[a-zA-Z0-9#]+(?!\()(?=[,)])/.exec(str);
|
|
let editOperation = {
|
|
range: {
|
|
startLineNumber: cursorPos.lineNumber,
|
|
endLineNumber: cursorPos.lineNumber,
|
|
startColumn: cursorPos.column,
|
|
endColumn: cursorPos.column
|
|
},
|
|
text: str,
|
|
forceMoveMarkers: true
|
|
};
|
|
editor.getModel().pushEditOperations([], [editOperation], () => []);
|
|
|
|
jQuery("#id_item").val(null).trigger("change");
|
|
|
|
if (firstParam) {
|
|
editor.setSelection({
|
|
startLineNumber: cursorPos.lineNumber,
|
|
endLineNumber: cursorPos.lineNumber,
|
|
startColumn: (cursorPos.column + firstParam.index),
|
|
endColumn: (cursorPos.column + firstParam.index + firstParam[0].length)
|
|
});
|
|
editor.focus()
|
|
}
|
|
else{
|
|
editor.setPosition({ lineNumber: cursorPos.lineNumber, column: (cursorPos.column + str.length)})
|
|
editor.focus()
|
|
}
|
|
}
|
|
|
|
// initialize the combo box functionalities
|
|
selectName();
|
|
|
|
})
|
|
|
|
// SAVE BUTTON
|
|
function SaveAndClose() {
|
|
let editor = getEditor();
|
|
parent.actioncode = editor.getValue();
|
|
parent.actioncodeBookmarks = editor.bookmarks;
|
|
parent.window.codeOpen = false;
|
|
parent.window.ActionCodeLayer.close();
|
|
}
|
|
document.getElementById("toolbar_ok").addEventListener("click", SaveAndClose);
|
|
|
|
// SAVE
|
|
window.addEventListener("save", Save);
|
|
function Save() {
|
|
let editor = getEditor();
|
|
parent.actioncode = editor.getValue();
|
|
}
|
|
|
|
// CANCEL BUTTON
|
|
document.getElementById("toolbar_cancel").addEventListener("click", function CheckClosefromX() {
|
|
Close();
|
|
});
|
|
|
|
// CLOSE
|
|
function Close() {
|
|
let editor = getEditor();
|
|
if (editor.getValue() != parent.actioncode) {
|
|
if (confirm("Do you want to save Actions code ?\n\nClick OK to save\nClick Cancel to ignore changes")){
|
|
SaveAndClose();
|
|
} else {
|
|
parent.window.codeOpen = false;
|
|
parent.window.ActionCodeLayer.close();
|
|
}
|
|
} else {
|
|
parent.window.codeOpen = false;
|
|
parent.window.ActionCodeLayer.close();
|
|
}
|
|
parent.managed = true;
|
|
}
|
|
|
|
</script> |