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

definitely fix the asynchrnous load for text editor and svg editor

parent 4cf62395
/**
* This file provides classes needed by the text editor
*/
/** /**
* Editors * Editors
* editors must implement the following methods :
* load : load the editor in the current page
* saveEdition : save the edition made by this editor to the current document
* loadContentFromDocument : display the content of the specified document in the editor
*/ */
var Xinha = function() { var Xinha = function() {
this.name = "Xinha"; this.name = "Xinha";
...@@ -15,7 +22,7 @@ var Xinha = function() { ...@@ -15,7 +22,7 @@ var Xinha = function() {
} }
this.loadContentFromDocument = function(doc) { this.loadContentFromDocument = function(doc) {
var setText = function() {xinha_editors.input_area.setEditorContent(doc.getContent());} var setText = function() {xinha_editors.input_area.setEditorContent(doc.getContent());}
waitBeforeSucceed(function() {return xinha_editors.input_area;},setText); tryUntilSucceed(setText);
} }
this.load(); this.load();
} }
...@@ -24,6 +31,10 @@ var Xinha = function() { ...@@ -24,6 +31,10 @@ var Xinha = function() {
/** /**
* Text documents * Text documents
* editable documents must implements the following methods
* getType : returns the type of a document
* saveEdition : set the argument as the new content of the document. Change last modification time and display the changes
* setAsCurrentDocument : set the document as currentDocument in the local storage and display its properties in the current page
*/ */
var JSONTextDocument = function() { var JSONTextDocument = function() {
......
/**
* This file provides classes needed by the illustration editor
*/
/** /**
* Editors * Editors
* editors must implement the following methods :
* load : load the editor in the current page
* saveEdition : save the edition made by this editor to the current document
* loadContentFromDocument : display the content of the specified document in the editor
*/ */
SVGEditor = function() { SVGEditor = function() {
this.name = "svg-editor"; this.name = "svg-editor";
this.load = function() {$("#svgframe").attr("src", "svg-editor/svg-editor.html")} this.load = function() {$("#svgframe").attr("src", "svg-edit/svg-editor.html");}
this.saveEdition = function() { this.saveEdition = function() {
var s = "svgframe"; var s = "svgframe";
getCurrentDocument().saveEdition(window.frames[s].svgCanvas.getSvgString()); getCurrentDocument().saveEdition(window.frames[s].svgCanvas.getSvgString());
} }
this.loadContentFromDocument = function(doc) { this.loadContentFromDocument = function(doc) {
var s = "svgframe"; tryUntilSucceed(function() {window.frames["svgframe"].svgEditor.loadFromString(doc.getContent());});
window.frames[s].svgCanvas.setSvgString(doc.getContent());
} }
var s = "svgframe";
this.svgCanvas = window.frames[s].svgCanvas;
this.load(); this.load();
} }
/** /**
* SVG documents * SVG documents
* editable documents must implements the following methods
* getType : returns the type of a document
* saveEdition : set the argument as the new content of the document. Change last modification time and display the changes
* setAsCurrentDocument : set the document as currentDocument in the local storage and display its properties in the current page
*/ */
var JSONIllustrationDocument = function() { var JSONIllustrationDocument = function() {
JSONDocument.call(this);//inherits properties from JSONDocument JSONDocument.call(this);//inherits properties from JSONDocument
......
/**
* This file provides main classes to display the web page
*/
/* /*
* global variables * global variables
*/ */
...@@ -8,7 +12,9 @@ currentPage = null; ...@@ -8,7 +12,9 @@ currentPage = null;
/* /*
* load page functions * Page Class
* used to decompose the page and give access to useful elements
* @param page name of the page to be created
*/ */
var Page = function(page) { var Page = function(page) {
this.name = page; this.name = page;
...@@ -58,6 +64,7 @@ Page.prototype = { ...@@ -58,6 +64,7 @@ Page.prototype = {
var doc = null; var doc = null;
var editor = null; var editor = null;
/* load the editor to work with and a new document to work on */
switch(this.name) { switch(this.name) {
case "editor": case "editor":
editor = new Xinha(); editor = new Xinha();
...@@ -97,7 +104,10 @@ Page.prototype = { ...@@ -97,7 +104,10 @@ Page.prototype = {
var head = $(this.getHTML()).find("head").append(object); var head = $(this.getHTML()).find("head").append(object);
}, },
//printers
/* these methods display dynamically information about the page, user or current document
* at the right place on the web page
*/
//user information //user information
/* display the list of availaible languages */ /* display the list of availaible languages */
displayLanguages: function(user) { displayLanguages: function(user) {
...@@ -134,14 +144,12 @@ Page.prototype = { ...@@ -134,14 +144,12 @@ Page.prototype = {
pageContent.innerHTML = this.getContent(); pageContent.innerHTML = this.getContent();
} }
} }
getCurrentPage = function() {return currentPage;} getCurrentPage = function() {return currentPage;}
setCurrentPage = function(page) { setCurrentPage = function(page) {currentPage = new Page(page);}
currentPage = new Page(page);
}
/* /*
* user class * User Class
* stores useful information about a user and provides methods to manipulate them
*/ */
var User = function(details) { var User = function(details) {
this.name = "unknown"; this.name = "unknown";
...@@ -149,8 +157,8 @@ var User = function(details) { ...@@ -149,8 +157,8 @@ var User = function(details) {
this.storage = "http://www.unhosted-dav.com"; this.storage = "http://www.unhosted-dav.com";
this.identityProvider = "http://www.webfinger.com"; this.identityProvider = "http://www.webfinger.com";
} }
User.prototype = new UngObject(); User.prototype = new UngObject();//inherits from UngObject
User.prototype.load({ User.prototype.load({//add methods thanks to the UngObject.load method
getName: function() {return this.name;}, getName: function() {return this.name;},
setName: function(newName) {this.name = newName;}, setName: function(newName) {this.name = newName;},
getLanguage: function() {return this.language;}, getLanguage: function() {return this.language;},
...@@ -178,6 +186,8 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string ...@@ -178,6 +186,8 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string
/** /**
* Documents * Documents
* This class is used to store information about document and provide methodes
* to manipulate these elements.
*/ */
/* JSON document */ /* JSON document */
...@@ -193,9 +203,9 @@ var JSONDocument = function() { ...@@ -193,9 +203,9 @@ var JSONDocument = function() {
this.lastModification=currentTime(); this.lastModification=currentTime();
this.state=this.states.draft; this.state=this.states.draft;
} }
JSONDocument.prototype = new UngObject(); JSONDocument.prototype = new UngObject();//inherits from UngObject
JSONDocument.prototype.load({ JSONDocument.prototype.load({//add methods thanks to the UngObject.load method
//type //type
getType: function() {return this.type;}, getType: function() {return this.type;},
......
/*** /***
* This file provides some useful element used in the whole web site
*/
/**
* Class UngObject * Class UngObject
* provides useful general methods
*/ */
UngObject = function() {} UngObject = function() {}
/* return true if this object implements the interface */ /* return true if this object implements the interface */
...@@ -71,17 +76,16 @@ saveXHR = function(address) { ...@@ -71,17 +76,16 @@ saveXHR = function(address) {
// load // load
loadXHR = function(address) { loadXHR = function(address) {
alert('loadXHR');
$.ajax({ $.ajax({
url: address, url: address,
type: "GET", type: "GET",
dataType: "json",
cache:false, cache:false,
/* username: "smik", username: "nom",
password: "asdf",*/ password: "test",
success: function(data){ success: function(data){
alert(data);
var cDoc = getCurrentDocument(); var cDoc = getCurrentDocument();
cDoc.load(JSON.parse(data)); cDoc.load(data);
cDoc.setAsCurrentDocument(); cDoc.setAsCurrentDocument();
} }
}); });
...@@ -93,7 +97,6 @@ loadXHR = function(address) { ...@@ -93,7 +97,6 @@ loadXHR = function(address) {
waitBeforeSucceed = function(required, func) { waitBeforeSucceed = function(required, func) {
var nb = 2;//avoid to test too much times var nb = 2;//avoid to test too much times
var execute = function() { var execute = function() {
//if(test()) {tryUntilSucceed(func);}
try { try {
if(!required.call()) {throw 0;} if(!required.call()) {throw 0;}
func.call();} func.call();}
...@@ -103,3 +106,15 @@ waitBeforeSucceed = function(required, func) { ...@@ -103,3 +106,15 @@ waitBeforeSucceed = function(required, func) {
execute(); execute();
} }
/*
* try a function until the execution meets with no error
*/
tryUntilSucceed = function(func) {
var nb = 2;//avoid to test too much times
var execute = function() {
try {func.call();}
catch(e) {if(nb<100) {setTimeout(execute,nb*400);} console.log(e);}
nb*=nb;
}
execute();
}
\ No newline at end of file
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
// initialize // initialize
var initPage = function() { var initPage = function() {
var pageIWantToTest = "editor"; var pageIWantToTest = "illustration";
addressOfTestDocument = "http://sidunhosted.com/webdav/emacs"; addressOfTestDocument = "dav/temp2.json";
setCurrentPage(pageIWantToTest); setCurrentPage(pageIWantToTest);
} }
......
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