X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=matitaB%2Fmatita%2Fmatitaweb.js;h=81995bb803ed42d8579f05d07d773ca252844b62;hb=bb9c48af6f729b0616a0fc5f1fd9037d4c3f2c89;hp=588643861f3c7b178e2019c05fc378febb63060c;hpb=1d74bd1321f8b95291efb354428d9ddc36cf8716;p=helm.git
diff --git a/matitaB/matita/matitaweb.js b/matitaB/matita/matitaweb.js
index 588643861..81995bb80 100644
--- a/matitaB/matita/matitaweb.js
+++ b/matitaB/matita/matitaweb.js
@@ -11,31 +11,42 @@ var advanceButton;
var retractButton;
var cursorButton;
var bottomButton;
+var dialogBox;
+var dialogTitle;
+var dialogContent;
var metasenv = "";
function initialize()
{
- locked = document.getElementById("locked");
- unlocked = document.getElementById("unlocked");
- workarea = document.getElementById("workarea");
- scriptcell = document.getElementById("scriptcell");
- goalcell = document.getElementById("goalcell");
- goals = document.getElementById("goals");
- goalview = document.getElementById("goalview");
- filename = document.getElementById("filename");
- logarea = document.getElementById("logarea");
- advanceButton = document.getElementById("advance");
- retractButton = document.getElementById("retract");
- cursorButton = document.getElementById("cursor");
- bottomButton = document.getElementById("bottom");
-
- // hide sequent view at start
- hideSequent();
+ if (readCookie("session") == null) {
+ window.location = "/login.html"
+ } else {
+ locked = document.getElementById("locked");
+ unlocked = document.getElementById("unlocked");
+ workarea = document.getElementById("workarea");
+ scriptcell = document.getElementById("scriptcell");
+ goalcell = document.getElementById("goalcell");
+ goals = document.getElementById("goals");
+ goalview = document.getElementById("goalview");
+ filename = document.getElementById("filename");
+ logarea = document.getElementById("logarea");
+ advanceButton = document.getElementById("advance");
+ retractButton = document.getElementById("retract");
+ cursorButton = document.getElementById("cursor");
+ bottomButton = document.getElementById("bottom");
+ dialogBox = document.getElementById("dialogBox");
+ dialogTitle = document.getElementById("dialogTitle");
+ dialogContent = document.getElementById("dialogContent");
+
+ // hide sequent view at start
+ hideSequent();
+ }
}
function debug(txt)
{
- logarea.innerHTML = txt + "\n" + logarea.innerHTML;
+ // internet explorer (v.9) doesn't work with innerHTML
+ logarea.innerText = txt + "\n" + logarea.innerText;
}
function listhd(l)
@@ -149,31 +160,29 @@ function p33 (p)
return (tripletmap (function (a,b,c) { return (c); }, p));
}
-function populate_goalarray(txt)
+function populate_goalarray(menv)
{
- if (txt == "") {
+ debug("metasenv.length = " + menv.length);
+ if (menv.length == 0) {
try {
hideSequent();
} catch (err) { };
} else {
showSequent();
- debug("populate with '" + txt + "'");
goalarray = new Array();
metalist = listnil();
var tmp_goallist = "";
- listiter (function(item)
- {
- debug ("item is '" + item + "'");
- tripletmap (function(a,ahtml,b) {
- debug ("found meta n. " + a);
- debug ("found goal\nBEGIN" + unescape(b) + "\nEND");
- goalarray[a] = unescape(b);
- tmp_goallist = " " + unescape(ahtml) + "" + tmp_goallist;
- metalist = listcons(a,metalist);
- debug ("goalarray[\"" + a + "\"] = " + goalarray[a]);
- },item);
- }, txt);
- // metalist = listmap (p13,txt);
+ for (i = 0; i < menv.length; i++) {
+ metano = menv[i].getAttribute("number");
+ metaname = menv[i].childNodes[0].childNodes[0].data;
+ goal = menv[i].childNodes[1].childNodes[0].data;
+ debug ("found meta n. " + metano);
+ debug ("found goal\nBEGIN" + goal + "\nEND");
+ goalarray[metano] = goal;
+ tmp_goallist = " " + metaname + "" + tmp_goallist;
+ metalist = listcons(metano,metalist);
+ debug ("goalarray[\"" + metano + "\"] = " + goalarray[metano]);
+ }
goals.innerHTML = tmp_goallist;
debug("new metalist is '" + metalist + "'");
if (is_nil(metalist)) {
@@ -196,6 +205,19 @@ function switch_goal(meta)
}
}
+String.prototype.sescape = function() {
+ var patt1 = /%/gi;
+ var patt2 = /=/gi;
+ var patt3 = /&/gi;
+ var patt4 = /\+/gi;
+ var result = this;
+ result = result.replace(patt1,"%25");
+ result = result.replace(patt2,"%3D");
+ result = result.replace(patt3,"%26");
+ result = result.replace(patt4,"%2B");
+ return (result);
+}
+
String.prototype.unescapeHTML = function()
{
var patt1 = /
/gi;
@@ -263,15 +285,26 @@ function callServer(servicename,processResponse,reqbody)
stat = req.status;
stxt = req.statusText;
if(stat == 200)
- {
- processResponse(req.responseText);
+ {
+ debug(req.responseText);
+ if (window.DOMParser) {
+ parser=new DOMParser();
+ xmlDoc=parser.parseFromString(req.responseText,"text/xml");
+ }
+ else // Internet Explorer
+ {
+ xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+ xmlDoc.async="false";
+ xmlDoc.loadXML(req.responseText);
+ }
+ processResponse(xmlDoc);
} else {
- processResponse();
+ processResponse();
}
- // resume();
}
};
- req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
+ req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
+ req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
if (reqbody) {
req.send(reqbody);
} else {
@@ -282,11 +315,10 @@ function callServer(servicename,processResponse,reqbody)
function advanceForm1()
{
- processor = function(responseText) {
- if (is_defined(responseText)) {
+ processor = function(xml) {
+ if (is_defined(xml)) {
// debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
- response = responseText.split("@");
- len = parseInt(response[0]);
+ len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
len0 = unlocked.innerHTML.length;
unescaped = unlocked.innerHTML.unescapeHTML();
parsedtxt = unescaped.substr(0,len);
@@ -295,8 +327,8 @@ function advanceForm1()
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
len2 = len0 - len1;
- metasenv = response[1];
- populate_goalarray(response[1]);
+ metasenv = xml.getElementsByTagName("meta");
+ populate_goalarray(metasenv);
statements = listcons(len2,statements);
unlocked.scrollIntoView(true);
} else {
@@ -305,35 +337,35 @@ function advanceForm1()
resume();
};
pause();
- callServer("advance",processor,unlocked.innerHTML.unescapeHTML());
+ callServer("advance",processor,"body=" + (unlocked.innerHTML.unescapeHTML()).sescape());
}
function gotoBottom()
{
- processor = function(responseText) {
- if (is_defined(responseText)) {
+ processor = function(xml) {
+ if (is_defined(xml)) {
// debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
- response = responseText.split("@");
- len = parseInt(response[0]);
- len0 = unlocked.innerHTML.length;
+ len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
+ len0 = unlocked.innerHTML.length;
unescaped = unlocked.innerHTML.unescapeHTML();
parsedtxt = unescaped.substr(0,len);
unparsedtxt = unescaped.substr(len);
locked.innerHTML = locked.innerHTML + parsedtxt;
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
- len = len0 - len1;
- populate_goalarray(response[1]);
- statements = listcons(len,statements);
- unlocked.scrollIntoView(true);
+ len2 = len0 - len1;
+ metasenv = xml.getElementsByTagName("meta");
+ populate_goalarray(metasenv);
+ statements = listcons(len2,statements);
+ unlocked.scrollIntoView(true);
} else {
debug("goto bottom failed");
}
resume();
};
pause();
- callServer("bottom",processor,unlocked.innerHTML.unescapeHTML());
+ callServer("bottom",processor,"body=" + (unlocked.innerHTML.unescapeHTML()).sescape());
}
@@ -343,11 +375,10 @@ function gotoPos(offset)
if (!is_defined(offset)) {
offset = getCursorPos();
}
- processor = function(responseText) {
- if (is_defined(responseText)) {
- // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
- response = responseText.split("@");
- len = parseInt(response[0]);
+ processor = function(xml) {
+ if (is_defined(xml)) {
+ // debug("goto pos: received response\nBEGIN\n" + req.responseText + "\nEND");
+ len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
len0 = unlocked.innerHTML.length;
unescaped = unlocked.innerHTML.unescapeHTML();
parsedtxt = unescaped.substr(0,len);
@@ -356,11 +387,13 @@ function gotoPos(offset)
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
len2 = len0 - len1;
+ metasenv = xml.getElementsByTagName("meta");
+ // populate_goalarray(metasenv);
statements = listcons(len2,statements);
- metasenv = response[1];
+ unlocked.scrollIntoView(true);
// la populate non andrebbe fatta a ogni passo
if (offset <= len) {
- populate_goalarray(response[1]);
+ populate_goalarray(metasenv);
resume();
} else {
gotoPos(offset - len);
@@ -372,21 +405,22 @@ function gotoPos(offset)
}
}
pause();
- callServer("advance",processor,unlocked.innerHTML.unescapeHTML());
+ callServer("advance",processor,"body=" + (unlocked.innerHTML.unescapeHTML()).sescape());
}
function retract()
{
- processor = function(responseText) {
- if (typeof responseText != "undefined") {
- debug("retract: received response\nBEGIN\n" + responseText + "\nEND");
+ processor = function(xml) {
+ if (typeof xml != "undefined") {
+ // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
statementlen = parseInt(listhd(statements));
statements = listtl(statements);
lockedlen = locked.innerHTML.length - statementlen;
statement = locked.innerHTML.substr(lockedlen, statementlen);
locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
unlocked.innerHTML = statement + unlocked.innerHTML;
- populate_goalarray(responseText);
+ metasenv = xml.getElementsByTagName("meta");
+ populate_goalarray(metasenv);
unlocked.scrollIntoView(true);
} else {
debug("retract failed");
@@ -401,16 +435,57 @@ function retract()
function openFile()
{
- processor = function(responseText)
+ processor = function(xml)
{
- if (responseText) {
+ if (is_defined(xml)) {
locked.innerHTML = "";
- unlocked.innerHTML = responseText;
+ unlocked.innerHTML = xml.documentElement.textContent;
} else {
debug("file open failed");
}
};
- callServer("open?file=" + escape(filename.value),processor);
+ callServer("open",processor,"file=" + escape(filename.value));
+}
+
+function showLibrary()
+{
+ var req = null;
+ // pause();
+ if (window.XMLHttpRequest)
+ {
+ req = new XMLHttpRequest();
+ }
+ else if (window.ActiveXObject)
+ {
+ try {
+ req = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e)
+ {
+ try {
+ req = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e) {}
+ }
+ }
+ req.onreadystatechange = function()
+ {
+
+ rs = req.readyState;
+
+ if(rs == 4)
+ {
+ stat = req.status;
+ stxt = req.statusText;
+ if(stat == 200)
+ {
+ debug(req.responseText);
+ showDialog("