wordpress-theme-openmamba/scripts/webbuild/webbuild-2.js

234 lines
8.1 KiB
JavaScript
Raw Permalink Normal View History

2014-11-13 21:33:23 +01:00
var lastupdate = 0;
var reloadtime = 15000;
var editor;
var lastxmlhttp;
2014-11-13 21:33:23 +01:00
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&#]+)=([^&#]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
function clearid(id,xmlhttp) {
2014-11-13 21:33:23 +01:00
document.getElementById(id).innerHTML = '';
if (lastxmlhttp != undefined) lastxmlhttp.abort();
2014-11-13 21:33:23 +01:00
}
function editorChanged() {
if (document.getElementById('savebutton') != undefined)
document.getElementById('savebutton').disabled=false;
if (document.getElementById('sendrecreatesrpm') != undefined)
document.getElementById('sendrecreatesrpm').checked=true;
}
function ajax_getvalues(request,confirm) {
2015-04-18 14:59:11 +02:00
var url;
2014-11-13 21:33:23 +01:00
// limit to this function the scope of xmlhttp to avoid sockets left pending
var o = {};
2014-11-13 21:33:23 +01:00
if (host != undefined) {
webbuildhost=host;
} else {
alert("ERROR: webbuildhost is undefined!");
2015-04-18 14:59:11 +02:00
return;
2014-11-13 21:33:23 +01:00
}
2015-04-18 14:59:11 +02:00
url = "/cgi-bin/webbuild-" + webbuildhost + ".cgi";
2014-11-13 21:33:23 +01:00
if (confirm) {
document.getElementById("status").innerHTML =
'<div class=screencontainer><div class=opaquebackground></div>'+
'<div class=questionbox><div style="overflow:auto;max-height:200px;">'+decodeURIComponent(confirm)+'</div>'+
'<br><a href=# onclick=ajax_getvalues("'+request+'")>YES</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=# onclick=clearid("status")>NO</a></div></div>';
return;
}
document.getElementById("webbuildform").disabled = true;
if (request != "")
request=request+"&USER="+user+"&USER_EMAIL="+user_email+"&SECRET="+encodeURIComponent(secret);
else
request="USER="+user+"&USER_EMAIL="+user_email+"&SECRET="+encodeURIComponent(secret);
/* if (window.location.href.indexOf('?') > 0)
url = url + "?" + window.location.href.replace(/.*\?/,"");*/
if (window.XMLHttpRequest)
o.xmlhttp = new XMLHttpRequest();
2014-11-13 21:33:23 +01:00
else if (window.ActiveXObject)
o.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
2014-11-13 21:33:23 +01:00
else
return;
lastxmlhttp = o.xmlhttp;
2014-11-13 21:33:23 +01:00
document.getElementById("noajax_msg").innerHTML = "";
document.getElementById("status").innerHTML =
'<div class=opaquebackground>'+
'<div style="text-align:left;color:white;position:absolute;" id=matrix class=matrix></div>'+
2014-11-13 21:33:23 +01:00
'<div style="position:absolute;left:50%;top:50%;"><img src="/images/wait.gif" title="Attendi..."</div>'+
'<div style="position:fixed;left:95%;top:95%;color:red;"><a href="javascript:clearid(\'status\');">[x] Close</a></div>'+
'</div>';
o.xmlhttp.onreadystatechange = function() {
if (o.xmlhttp.readyState < 4) {
2014-11-13 21:33:23 +01:00
return;
}
if (o.xmlhttp.responseXML == undefined) {
2014-11-13 21:33:23 +01:00
// && xmlhttp.responseText == undefined) {
document.getElementById("status").innerHTML = "";
var errormsg = "<div id=\"outputbottom\" class=\"outputbox\"><pre>";
errormsg += "ERROR: there was an error in the network connection or in the format of the XML response.";
errormsg += "</pre></div>";
document.getElementById("output").innerHTML = errormsg;
console.error(o.xmlhttp.responseText);
o.xmlhttp.abort();
2014-11-13 21:33:23 +01:00
return;
}
var xmldoc = o.xmlhttp.responseXML.documentElement;
2014-11-13 21:33:23 +01:00
if (xmldoc == undefined) {
return;
}
var nodes = xmldoc.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeName == "title") {
document.title = nodes[i].childNodes[0].nodeValue;
} else if (document.getElementById(nodes[i].nodeName) != undefined) {
// var node = document.getElementById(nodes[i].nodeName)
replaceHTML(document.getElementById(nodes[i].nodeName), nodes[i].childNodes[0].nodeValue);
// document.getElementById(nodes[i].nodeName).innerHTML = nodes[i].childNodes[0].nodeValue;
// $("#"+nodes[i].nodeName).html(nodes[i].childNodes[0].nodeValue);
var spectext = document.getElementById("spectext");
2014-11-13 21:33:23 +01:00
if ((nodes[i].nodeName == "editor") && (spectext != undefined) && (spectext.parentNode != undefined))
{
2019-07-28 20:45:29 +02:00
editor = CodeMirror.fromTextArea(spectext, {
lineNumbers:true,
fixedGutter:true,
tabSize:4,
indentUnit:4,
indentWithTabs:true
2019-07-28 20:45:29 +02:00
});
editor.on('change', function() { editorChanged(); });
editor.setSize(null, 500);
2014-11-13 21:33:23 +01:00
} else if ((nodes[i].nodeName == "output") && (document.getElementById("outputbottom") != undefined)) {
document.getElementById("outputbottom").scrollTop = document.getElementById("outputbottom").scrollHeight;
} else if ((nodes[i].nodeName == "processes")) {
$(function() { $('.scroll-pane3').jScrollPane({scrollbarWidth:10}); });
}
}
}
document.getElementById("webbuildform").disabled = false;
document.getElementById("status").innerHTML = "";
}
o.xmlhttp.onprogress = function() {
2014-11-13 21:33:23 +01:00
var end = 0,to;
// save responseText length when entering the function
to = this.responseText.length - 1;
if (start < 0) {
start = this.responseText.substring(0,to).indexOf("<!-- SCROLL -->");
if (start >= 0) start+=15;
}
if (start >= 0) {
end = this.responseText.substring(start+currpos-15,to).indexOf("<!-- ENDSCROLL -->");
if (end >= 0) to = end;
if (to > start) {
var customscroll = document.getElementById("matrix").scrollTop <
(document.getElementById("matrix").scrollHeight - document.getElementById("matrix").clientHeight);
document.getElementById("matrix").innerHTML =
"<div id=matrixoutput><pre>" + this.responseText.substring(start,to).replace("</pre>","&lt;/pre&gt;") + "</pre></div>";
currpos = document.getElementById("matrixoutput").innerHTML.length;
if (!customscroll)
document.getElementById("matrix").scrollTop = document.getElementById("matrix").scrollHeight;
}
}
}
o.xmlhttp.open("POST", url, true);
o.xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
o.xmlhttp.send(request);
// setTimeout(function() { alert ("Timeout expired"); o.xmlhttp.abort(); }, 600000);
2014-11-13 21:33:23 +01:00
var currpos = 0, start = -1;
}
//-->
// ajaxFileUpload
function ajaxFileUpload(request)
{
2015-04-18 14:59:11 +02:00
if (host != undefined) {
webbuildhost=host;
} else {
alert("Error: webbuildhost undefined!");
return;
}
2014-11-13 21:33:23 +01:00
$.ajaxFileUpload
(
{
2015-04-18 14:59:11 +02:00
url:'/cgi-bin/webbuild-' + webbuildhost + '.cgi',
2014-11-13 21:33:23 +01:00
secureuri:false,
fileElementId:'fileToUpload',
dataType: 'xml',
beforeSend:function()
{
$("#loading").show();
},
complete:function()
{
$("#loading").hide();
},
success: function (data, status)
{
ajax_getvalues(request);
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}else
{
alert(data.msg);
}
}
},
error: function (data, status, e)
{
alert(e);
}
}
)
return false;
}
var webbuild_status_lastupdate = 0;
var webbuild_status_reloadtime = 300000;
function webbuild_status_getvalues() {
var url = "/cgi-bin/autodist";
var xmlhttp;
if (window.location.href.indexOf("?") > 0) url += "?"+window.location.href.replace(/.*\?/,"");
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
else
return;
document.getElementById("noajax_msg").innerHTML = "";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState != 4)
return;
2019-02-02 11:18:39 +01:00
if (xmlhttp.responseXML == undefined) {
console.log("RESPONSE ERROR: check URL " + url);
return;
}
var xmldoc = xmlhttp.responseXML.documentElement;
if (xmldoc == undefined) {
return;
}
document.getElementById("output").innerHTML = xmldoc.getElementsByTagName("output")[0].childNodes[0].nodeValue;
webbuild_status_reloadtime = xmldoc.getElementsByTagName("reloadtime")[0].childNodes[0].nodeValue;
webbuild_status_lastupdate = (+new Date());
}
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
setTimeout("webbuild_status_getvalues()", webbuild_status_reloadtime);
}