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 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() {
this.name = "Xinha";
......@@ -15,7 +22,7 @@ var Xinha = function() {
}
this.loadContentFromDocument = function(doc) {
var setText = function() {xinha_editors.input_area.setEditorContent(doc.getContent());}
waitBeforeSucceed(function() {return xinha_editors.input_area;},setText);
tryUntilSucceed(setText);
}
this.load();
}
......@@ -24,6 +31,10 @@ var Xinha = function() {
/**
* 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() {
......
/**
* This file provides classes needed by the illustration editor
*/
/**
* 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() {
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() {
var s = "svgframe";
getCurrentDocument().saveEdition(window.frames[s].svgCanvas.getSvgString());
}
this.loadContentFromDocument = function(doc) {
var s = "svgframe";
window.frames[s].svgCanvas.setSvgString(doc.getContent());
tryUntilSucceed(function() {window.frames["svgframe"].svgEditor.loadFromString(doc.getContent());});
}
var s = "svgframe";
this.svgCanvas = window.frames[s].svgCanvas;
this.load();
}
/**
* 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() {
JSONDocument.call(this);//inherits properties from JSONDocument
......
/**
* This file provides main classes to display the web page
*/
/*
* global variables
*/
......@@ -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) {
this.name = page;
......@@ -58,6 +64,7 @@ Page.prototype = {
var doc = null;
var editor = null;
/* load the editor to work with and a new document to work on */
switch(this.name) {
case "editor":
editor = new Xinha();
......@@ -97,7 +104,10 @@ Page.prototype = {
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
/* display the list of availaible languages */
displayLanguages: function(user) {
......@@ -134,14 +144,12 @@ Page.prototype = {
pageContent.innerHTML = this.getContent();
}
}
getCurrentPage = function() {return currentPage;}
setCurrentPage = function(page) {
currentPage = new Page(page);
}
setCurrentPage = function(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) {
this.name = "unknown";
......@@ -149,8 +157,8 @@ var User = function(details) {
this.storage = "http://www.unhosted-dav.com";
this.identityProvider = "http://www.webfinger.com";
}
User.prototype = new UngObject();
User.prototype.load({
User.prototype = new UngObject();//inherits from UngObject
User.prototype.load({//add methods thanks to the UngObject.load method
getName: function() {return this.name;},
setName: function(newName) {this.name = newName;},
getLanguage: function() {return this.language;},
......@@ -178,6 +186,8 @@ setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.string
/**
* Documents
* This class is used to store information about document and provide methodes
* to manipulate these elements.
*/
/* JSON document */
......@@ -193,9 +203,9 @@ var JSONDocument = function() {
this.lastModification=currentTime();
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
getType: function() {return this.type;},
......
/***
* This file provides some useful element used in the whole web site
*/
/**
* Class UngObject
* provides useful general methods
*/
UngObject = function() {}
/* return true if this object implements the interface */
......@@ -71,17 +76,16 @@ saveXHR = function(address) {
// load
loadXHR = function(address) {
alert('loadXHR');
$.ajax({
url: address,
type: "GET",
dataType: "json",
cache:false,
/* username: "smik",
password: "asdf",*/
username: "nom",
password: "test",
success: function(data){
alert(data);
var cDoc = getCurrentDocument();
cDoc.load(JSON.parse(data));
cDoc.load(data);
cDoc.setAsCurrentDocument();
}
});
......@@ -93,7 +97,6 @@ loadXHR = function(address) {
waitBeforeSucceed = function(required, func) {
var nb = 2;//avoid to test too much times
var execute = function() {
//if(test()) {tryUntilSucceed(func);}
try {
if(!required.call()) {throw 0;}
func.call();}
......@@ -103,3 +106,15 @@ waitBeforeSucceed = function(required, func) {
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 @@
// initialize
var initPage = function() {
var pageIWantToTest = "editor";
addressOfTestDocument = "http://sidunhosted.com/webdav/emacs";
var pageIWantToTest = "illustration";
addressOfTestDocument = "dav/temp2.json";
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