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() { ...@@ -51,73 +51,3 @@ getCurrentDocument = function() {
doc.load(JSON.parse(localStorage.getItem("currentDocument"))); doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc; 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() { ...@@ -51,70 +51,3 @@ getCurrentDocument = function() {
return doc; 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 = { ...@@ -55,17 +55,22 @@ Page.prototype = {
$(dependencies).find("linkfile").each(function() {currentPage.include($(this).text(),"link");});//includes css $(dependencies).find("linkfile").each(function() {currentPage.include($(this).text(),"link");});//includes css
$(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js $(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js
var doc = null;
switch(this.name) { switch(this.name) {
case "editor": case "editor":
this.editor = new Xinha(); this.editor = new Xinha();
if(!doc) {doc=new JSONTextDocument();}
break; break;
case "table": case "table":
this.editor = new SheetEditor(); this.editor = new SheetEditor();
if(!doc) {doc=new JSONSheetDocument();}
break; break;
case "illustration": case "illustration":
this.editor = new SVGEditor(); this.editor = new SVGEditor();
if(!doc) {doc=new JSONIllustrationDocument();}
break; break;
} }
doc.setCurrentDocument();
}, },
/* include a javascript or a css file */ /* include a javascript or a css file */
...@@ -270,7 +275,7 @@ editDocumentSettings = function() { ...@@ -270,7 +275,7 @@ editDocumentSettings = function() {
saveCurrentDocument = function() { saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition(); getCurrentPage().getEditor().saveEdition();
saveXHR(); saveXHR(address);
//saveJIO(); : JIO function //saveJIO(); : JIO function
} }
......
...@@ -41,4 +41,4 @@ waitBeforeExecution = function(event, func) { ...@@ -41,4 +41,4 @@ waitBeforeExecution = function(event, func) {
if(event) {func.call();} else {setTimeout(waitBefore,1000)} if(event) {func.call();} else {setTimeout(waitBefore,1000)}
} }
setTimeout(waitBefore,1000); setTimeout(waitBefore,1000);
} }
\ No newline at end of file
...@@ -26,21 +26,31 @@ ...@@ -26,21 +26,31 @@
<script type="text/javascript" src="js/base64.js"></script> <script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/tools.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" src="js/theme.js"></script>
<script type="text/javascript"> <script type="text/javascript">
// initialize // initialize
init = function() { var initPage = function() {
setCurrentPage("editor"); var pageIWantToTest = "illustration";
setCurrentPage(pageIWantToTest);
}
var initUser = function() {
var user = getCurrentUser(); var user = getCurrentUser();
if(!user) { user = new User();} if(!user) { user = new User();}
user.setAsCurrentUser(); user.setAsCurrentUser();
}
var doc = getCurrentDocument(); var initDocument = function() {
if(!doc) {doc = new JSONTextDocument();} loadXHR("dav/temp2.json");
doc.setAsCurrentDocument(); }
var init = function() {
initPage();
waitBeforeExecution(getCurrentPage(),initUser);
waitBeforeExecution(getCurrentPage().getEditor(),initDocument);
} }
$(document).ready(init); $(document).ready(init);
</script> </script>
...@@ -262,6 +272,9 @@ ...@@ -262,6 +272,9 @@
<div id="page_content" class="field page" <div id="page_content" class="field page"
title="Contenu de la page web."> title="Contenu de la page web.">
</div> </div>
<div id="document_content" class="field hidden"
title="The content of the document considered as a text string">
</div>
</fieldset> </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