Commit e50d7ab5 authored by François Billioud's avatar François Billioud

prepare the jio implementation

move xhr functions to jio.js
parent 769179ee
......@@ -51,73 +51,3 @@ getCurrentDocument = function() {
doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc;
}
// save
saveXHR = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {alert("Please install a more recent browser")}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr.open("PUT", "dav/temp.json", true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
}
}
}
xhr.withCredentials = "true";
xhr.send(JSON.stringify(getCurrentDocument()));
}
// load
loadXHR = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {}
}
}
xhr.open("GET", "dav/temp.json", false);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var cDoc = new JSONTextDocument();
if(xhr.status == 200) {
cDoc.load(JSON.parse(xhr.responseText));
} else {
alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText);
}
cDoc.setAsCurrentDocument();
}
}
xhr.send();
}
......@@ -51,70 +51,3 @@ getCurrentDocument = function() {
return doc;
}
// save
saveXHR = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {alert("Please install a more recent browser")}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr.open("PUT", "dav/temp2.json", true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
}
}
}
xhr.withCredentials = "true";
xhr.send(JSON.stringify(getCurrentDocument()));
}
// load
loadXHR = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {}
}
}
xhr.open("GET", "dav/temp2.json", false);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var cDoc = new JSONIllustrationDocument();
if(xhr.status == 200) {
cDoc.load(JSON.parse(xhr.responseText));
} else {
alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText);
}
cDoc.setAsCurrentDocument();
}
}
xhr.send();
}
\ No newline at end of file
// save
saveXHR = function(address) {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {alert("Please install a more recent browser")}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr.open("PUT", address, true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
}
}
}
xhr.withCredentials = "true";
xhr.send(JSON.stringify(getCurrentDocument()));
}
// load
loadXHR = function(address) {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {}
}
}
xhr.open("GET", address, false);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var cDoc = getCurrentDocument();
if(xhr.status == 200) {
cDoc.load(JSON.parse(xhr.responseText));
} else {
alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText);
}
cDoc.setAsCurrentDocument();
}
}
xhr.send();
}
\ No newline at end of file
......@@ -55,17 +55,22 @@ Page.prototype = {
$(dependencies).find("linkfile").each(function() {currentPage.include($(this).text(),"link");});//includes css
$(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js
var doc = null;
switch(this.name) {
case "editor":
this.editor = new Xinha();
if(!doc) {doc=new JSONTextDocument();}
break;
case "table":
this.editor = new SheetEditor();
if(!doc) {doc=new JSONSheetDocument();}
break;
case "illustration":
this.editor = new SVGEditor();
if(!doc) {doc=new JSONIllustrationDocument();}
break;
}
doc.setCurrentDocument();
},
/* include a javascript or a css file */
......@@ -270,7 +275,7 @@ editDocumentSettings = function() {
saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition();
saveXHR();
saveXHR(address);
//saveJIO(); : JIO function
}
......
......@@ -41,4 +41,4 @@ waitBeforeExecution = function(event, func) {
if(event) {func.call();} else {setTimeout(waitBefore,1000)}
}
setTimeout(waitBefore,1000);
}
\ No newline at end of file
}
......@@ -26,21 +26,31 @@
<script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/tools.js"></script>
<script type="text/javascript" src="js/jio.js"></script>
<script type="text/javascript" src="js/theme.js"></script>
<script type="text/javascript">
// initialize
init = function() {
setCurrentPage("editor");
var initPage = function() {
var pageIWantToTest = "illustration";
setCurrentPage(pageIWantToTest);
}
var initUser = function() {
var user = getCurrentUser();
if(!user) { user = new User();}
user.setAsCurrentUser();
}
var doc = getCurrentDocument();
if(!doc) {doc = new JSONTextDocument();}
doc.setAsCurrentDocument();
var initDocument = function() {
loadXHR("dav/temp2.json");
}
var init = function() {
initPage();
waitBeforeExecution(getCurrentPage(),initUser);
waitBeforeExecution(getCurrentPage().getEditor(),initDocument);
}
$(document).ready(init);
</script>
......@@ -262,6 +272,9 @@
<div id="page_content" class="field page"
title="Contenu de la page web.">
</div>
<div id="document_content" class="field hidden"
title="The content of the document considered as a text string">
</div>
</fieldset>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment