2018-03-12 20:38:33 +01:00
|
|
|
function $(id){
|
|
|
|
return document.getElementById(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pathSplit(path){
|
|
|
|
var s = path.split("/");
|
|
|
|
if (s[0] == ""){
|
|
|
|
s.splice(0,1);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-03-13 08:06:50 +01:00
|
|
|
function pathJoin(path){
|
|
|
|
return path.join("/");
|
|
|
|
}
|
|
|
|
|
2018-03-12 20:38:33 +01:00
|
|
|
|
|
|
|
function callURL(url, content, asyncReceiver = null, method = "GET"){
|
|
|
|
var r = new XMLHttpRequest();
|
|
|
|
var async = asyncReceiver != null;
|
|
|
|
|
|
|
|
r.open(method,url,async);
|
|
|
|
if (async) {
|
|
|
|
r.onload = asyncReceiver;
|
|
|
|
}
|
|
|
|
r.send(content);
|
|
|
|
if (!async){
|
|
|
|
return r.response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function callJson(method, parameters, asyncReceiver = null){
|
|
|
|
var url = "<%=request.self(0)%>_hm_json";
|
|
|
|
var reply = callURL(url, JSON.stringify( { "method": method, "parameters": parameters } ), null, "POST" );
|
|
|
|
return JSON.parse( reply );
|
|
|
|
}
|
|
|
|
|
2018-03-13 08:06:50 +01:00
|
|
|
function loadHTML(container,source){
|
|
|
|
container.innerHTML = source;
|
|
|
|
var scripts = container.getElementsByTagName("script");
|
|
|
|
for (var n=0;n<scripts.length;n++){
|
|
|
|
eval.call(window,scripts[n].innerText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 20:38:33 +01:00
|
|
|
|
|
|
|
function treeRefresh(objPath){
|
|
|
|
var treediv = $("tree");
|
2018-03-13 08:06:50 +01:00
|
|
|
var url = "/_hm_tree";
|
2018-03-12 20:38:33 +01:00
|
|
|
var treesource = callURL(url);
|
|
|
|
treediv.innerHTML = treesource;
|
|
|
|
|
|
|
|
editorLoad(objPath);
|
|
|
|
}
|
|
|
|
|
2018-03-13 21:41:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
function editorClear(){
|
|
|
|
window.editor_fields = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editorDeclareControl(ctl, field = null){
|
|
|
|
if (field == null){
|
|
|
|
field = ctl.getAttribute("name");
|
|
|
|
}
|
|
|
|
|
|
|
|
window.editor_fields[ field ] = ctl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-12 20:38:33 +01:00
|
|
|
function editorLoad(objPath){
|
|
|
|
var editor = $("editor");
|
|
|
|
var url = objPath + "/_hm_edit";
|
|
|
|
var treesource = callURL(url);
|
2018-03-13 21:41:01 +01:00
|
|
|
|
|
|
|
editorClear();
|
2018-03-13 08:06:50 +01:00
|
|
|
loadHTML(editor, treesource);
|
2018-03-12 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 21:41:01 +01:00
|
|
|
function editorApply(objPath){
|
|
|
|
|
|
|
|
var formData = FormData();
|
|
|
|
|
|
|
|
for (var field in window.editor_fields){
|
|
|
|
if (window.editor_fields.hasOwnProperty( field )){
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
formData.append( )
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function editorSave(){
|
|
|
|
alert("Submit");
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-12 20:38:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function objCreate( objPath, objTypeName, objName){
|
|
|
|
var reply = callJson( "objCreate", { "objTypeName" : objTypeName, "objName" : objName, "objPath" : objPath } )
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
function objRemove( objPath ){
|
|
|
|
return callJson( "objRemove", { "objPath": objPath } );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-13 08:06:50 +01:00
|
|
|
function onAddObjectButton(button,objPath,parentID){
|
|
|
|
var ctlObjName = "objName-" + parentID;
|
|
|
|
var objName = $(ctlObjName).value;
|
|
|
|
var objTypeName = $("objTypeName-" + parentID).value;
|
2018-03-12 20:38:33 +01:00
|
|
|
|
2018-03-13 08:06:50 +01:00
|
|
|
var reply = objCreate( pathSplit(objPath), objTypeName, objName );
|
2018-03-12 20:38:33 +01:00
|
|
|
if (reply.result != true){
|
|
|
|
alert("The request didn't return success.\n" + reply.exception);
|
|
|
|
} else {
|
|
|
|
treeRefresh("<%=request.SCRIPT_NAME%>" + objPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 08:06:50 +01:00
|
|
|
function onRemoveButton(button,objPath){
|
|
|
|
var reply = objRemove( pathSplit(objPath) );
|
2018-03-12 20:38:33 +01:00
|
|
|
if (reply.result == true){
|
2018-03-13 08:06:50 +01:00
|
|
|
var path = pathSplit(objPath);
|
|
|
|
path.splice(path.length-1, 1);
|
|
|
|
treeRefresh("<%=request.SCRIPT_NAME%>" + pathJoin( path ) );
|
2018-03-12 20:38:33 +01:00
|
|
|
} else {
|
|
|
|
alert("The request didn't return success.\n" + reply.exception);
|
|
|
|
}
|
|
|
|
}
|