Commit 77ddcfa2 authored by François Billioud's avatar François Billioud

Try to rewrite bad coded elements and fix asynchronism problem.

There is an infinity loop in with the user profile load and save. It should be fixed
parent 6e643eb0
......@@ -10,7 +10,8 @@
* loadContentFromDocument : display the content of the specified document in the editor
*/
SVGEditor = function() {
this.name = "svg-editor";
this.name = "svg-edit"; // name to use in dialog boxes
this.objectName = "SVGEditor" // name of the object reference
this.load = function() {$("#svgframe").attr("src", "svg-edit/svg-editor.html");}
this.saveEdition = function() {
......@@ -26,39 +27,20 @@ SVGEditor = function() {
/**
* SVG documents
*
* editable documents must implements the following arguments and methods
* editable documents must override the following arguments and methods of JSONDocument prototype
* type : a unique type ID
* 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
*
* @param arg : a json JSONTextDocument object to load
*/
var JSONIllustrationDocument = function(arg) {
JSONDocument.call(this,arg);//inherits properties from JSONDocument
if(arg) {this.load(arg);}
else {
this.type = "illustration";
}
}
JSONIllustrationDocument.prototype = new JSONDocument();//inherits methods from JSONDocument
JSONIllustrationDocument.prototype.saveEdition = function(content) {
JSONDocument.prototype.type = "text";
JSONDocument.prototype.saveEdition = function(content) {
this.setLastUser(getCurrentUser().getName());
this.setContent(content);
this.setLastModification(getCurrentTime());
this.setAsCurrentDocument();
}
JSONIllustrationDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this);
getCurrentPage().displayDocumentContent(this);
getCurrentPage().displayLastUserName(this);
getCurrentPage().displayLastModification(this);
JSONDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentInformation(this);
setCurrentDocument(this);
}
getCurrentDocument = function() {
return new JSONIllustrationDocument(JSON.parse(localStorage.getItem("currentDocument")));
}
......@@ -21,9 +21,9 @@ function logIntoDav(wallet) {
function initStorage(wallet) {
if(!wallet.provider) {//local storage
setCurrentStorage(new LocalStorage(wallet.userName));
Storage.currentStorage = new LocalStorage(wallet.userName);
} else {
setCurrentStorage(new JIOStorage(wallet));
Storage.currentStorage = new JIOStorage(wallet);
}
}
......
......@@ -10,7 +10,8 @@
* loadContentFromDocument : display the content of the specified document in the editor
*/
var Xinha = function() {
this.name = "Xinha";
this.name = "Xinha"; // name to use in dialog boxes
this.objectName = "Xinha" // name of the object reference
this.load = function() {
_editor_url = "xinha/";
getCurrentPage().include("xinha/XinhaCore.js","script");
......@@ -28,7 +29,8 @@ var Xinha = function() {
}
var AlohaInterface = function() {
this.name = "Aloha";
this.name = "Aloha"; // name to use in dialog boxes
this.objectName = "AlohaInterface" // name of the object reference
this.load = function() {
GENTICS_Aloha_base="aloha/aloha/";
loadFile("aloha/aloha/aloha.js", "script", function(data) {
......@@ -53,7 +55,8 @@ var AlohaInterface = function() {
}
var NicEdit = function() {
this.name = "NicEdit";
this.name = "NicEdit"; // name to use in dialog boxes
this.objectName = "NicEdit" // name of the object reference
this.instance = null;
this.load = function() {
var nic = this;
......@@ -75,7 +78,8 @@ var NicEdit = function() {
var TinyEdit = function() {
this.name = "TinyEdit";
this.name = "Tiny"; // name to use in dialog boxes
this.objectName = "TinyEdit" // name of the object reference
this.load = function() {
loadFile("tinyEdit/tinyEdit.js","script",function(data) {
eval(data);
......@@ -114,41 +118,20 @@ var TinyEdit = function() {
/**
* Text documents
*
* editable documents must implements the following arguments and methods
* editable documents must override the following arguments and methods of JSONDocument prototype
* type : a unique type ID
* 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
/**
* class JSONTextDocument
* @param arg : a json JSONTextDocument object to load
*/
var JSONTextDocument = function(arg) {
JSONDocument.call(this,arg);//inherits properties from JSONDocument
if(arg) {this.load(arg);}
else {
this.type = "text";
}
}
JSONTextDocument.prototype = new JSONDocument();//inherits methods from JSONDocument
JSONTextDocument.prototype.saveEdition = function(content) {
JSONDocument.prototype.type = "text";
JSONDocument.prototype.saveEdition = function(content) {
this.setLastUser(getCurrentUser().getName());
this.setContent(content);
this.setLastModification(getCurrentTime());
this.setAsCurrentDocument();
}
JSONTextDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this);
getCurrentPage().displayDocumentContent(this);
getCurrentPage().displayLastUserName(this);
getCurrentPage().displayLastModification(this);
JSONDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentInformation(this);
setCurrentDocument(this);
}
getCurrentDocument = function() {
return new JSONTextDocument(JSON.parse(localStorage.getItem("currentDocument")));
}
This diff is collapsed.
......@@ -29,7 +29,8 @@ UngObject.prototype.load = function(data) {
};
/* Load methods from a class to another class */
UngObject.prototype.inherits = function(superClass) {
UngObject.prototype.inherits = function(superClass,arg) {
superClass.call(this,arg);//or this.load(new superClass(arg));
this.prototype.load(superClass.prototype);
}
......@@ -44,7 +45,7 @@ UngObject.prototype.equals = function(object) {
return true;
}
/* return a copy of the current object */
/* return a deep copy of the current object */
UngObject.prototype.copy = function() {
var copied = new Object();
for (var property in this) {
......@@ -53,123 +54,17 @@ UngObject.prototype.copy = function() {
return copied;
}
/**
* Class List
* this class provides usual API to manipulate list structure
* @param arg : a json list object
* @param contentType : the type of the elements of the list
* convert an object into an array easier to manipulate
* @param object : the object to convert
*/
var List = function(arg, contentType) {
if(arg && arg.headElement) {
if(contentType) {
this.headElement=new contentType(arg.headElement);
} else {
this.headElement = arg.headElement;
}
this.length = arg.length;
this.previous = new List(arg.previous, contentType);
}
else {
this.nullElement();
toArray = function(object) {
var array = [];
for(var element in object) {
if(typeof element != "function") array.push(object[element]);
}
return array
}
List.prototype = new UngObject();
List.prototype.load({
nullElement: function() {
this.headElement = null;
this.previous = undefined;
this.length = 0;
},
size: function() {return this.length;},
head: function() {return this.headElement;},
tail: function() {return this.previous;},
isEmpty: function() {return this.head()===null;},
equals: function(list) {
return this.head().equals(list.head()) && this.tail().equals(list.tail());
},
add: function(value) {
var t = new List();
t.load(this);
this.headElement = value;
this.previous = t;
this.length = t.size()+1;
},
get: function(i) {
if(i>=this.size()) {return null;}
if(i==0) {return this.head();}
return this.tail().get(i-1);
},
set: function(i,element) {
if(i>=this.size()) {errorMessage("set out of bounds, "+i+" : "+this.size(),this);return}
if(i==0) {
this.headElement=element;
} else {
this.tail().set(i-1,element);
}
},
remove: function(i) {
if(i>=this.size()) {errorMessage("remove out of bounds, "+i+" : "+this.size(),this);return}//particular case
if(i==0) {this.pop();return}//particular case
if(i==1) {//init
this.previous = this.tail().tail();
} else {//recursion
this.tail().remove(i-1);
}
this.length--;
},
pop: function() {
if(this.isEmpty()) {errorMessage("pop on empty list",this);return null;}
var h = this.head();
this.load(this.tail())
return h;
},
find: function(object) {
if(this.isEmpty()) {return -1}//init-false
var elt = this.head();
if(object.equals) {//init-true
if(object.equals(this.head())) {return 0;}//with an adapted comparator
} else {
if(object===this.head()) {return 0;}//with usual comparator
}
var recursiveResult = this.tail().find(object);//recursion
return recursiveResult>=0 ? this.tail().find(object)+1 : recursiveResult;
},
contains: function(object) {if(this.isEmpty()) {return false} else {return object===this.head() ? true : this.tail().contains(object)}},
insert: function(element,i) {
if(i>this.size()) {errorMessage("insert out of bounds, "+i+" : "+this.size(),this);return}//particular case
if(i==0) {//init
this.add(element);
} else {//recursion
this.tail().insert(element,i-1);
this.length++;
}
},
replace: function(oldElement,newElement) {
if(this.isEmpty()) {errorMessage("<<element not found>> when trying to replace",this);return}//init-false
if(oldElement===this.head()) {
this.set(0,newElement);//init-true
} else {
this.tail().replace(oldElement,newElement);//recursion
}
},
removeElement: function(element) {//remove each occurence of the element in this list
if(this.isEmpty()) {return}
this.tail().removeElement(element);
if(element.equals) {//init-true
if(element.equals(this.head())) {this.pop();}//with an adapted comparator
} else {
if(element===this.head()) {this.pop();}//with usual comparator
}
},
concat: function(list) {
if(list.size()==0) {return this}
var l1 = this.copy();
var l2 = list.copy();
l1.add(l2.get(l2.size()-1));
return l2;
}
});
/**
* load a public file with a basic ajax request
......@@ -184,7 +79,6 @@ loadFile = function(address, type, instruction) {
dataType: type,
success: instruction,
error: function(type) {alert("Error "+type.status+" : fail while trying to load "+address);}
});
}
......@@ -195,14 +89,16 @@ loadFile = function(address, type, instruction) {
*/
waitBeforeSucceed = function(required, func) {
var nb = 2;//avoid to test too much times
var execute = function() {
(function execute() {
try {
if(!required.call()) {throw 0;}
func.call();}
catch(e) {console.log(e);if(nb<100) {setTimeout(execute,nb*100);}}
catch(e) {
if(console) {console.log(e)}
if(nb<100) {setTimeout(execute,nb*100);}
}
nb*=nb;
}
execute();
})()
}
/*
......@@ -211,12 +107,27 @@ waitBeforeSucceed = function(required, func) {
*/
tryUntilSucceed = function(func) {
var nb = 2;//avoid to test too much times
var execute = function() {
(function execute() {
try {func.call();}
catch(e) {if(nb<100) {setTimeout(execute,nb*200);}console.log(e);}
catch(e) {
if(console) {console.log(e)}
if(nb<100) {setTimeout(execute,nb*200);}
}
nb*=nb;
}
execute();
})()
}
/**
* call a function periodically. Usefull for checking some stuff regularly
* @param task : function to execute each period
* @param period : time to wait before next execution
* @param firstExecution : (optional) if set to false, the task will not be executed at first call
*/
recursiveTask = function(task,period,firstExecution) {
if(firstExecution!==false) {task.call()}
(function recursion() {
setTimeout(function() {task.call();recursion()},period);
})();
}
/**
......@@ -232,7 +143,7 @@ var resize = function() {
*/
errorMessage = function(message,object) {
errorObject = object;
console.log(message);
if(console) {console.log(message)}
}
/**
......@@ -241,7 +152,15 @@ errorMessage = function(message,object) {
function getCurrentTime() {return Date.now();}
/**
* Paste a toolkit at the mouse position
* Paste a toolkit at the mouse position.
* Just add a common css class to your element needing a tooltip, and initialize with :
tooltip = new Tooltip();
$(".myTooltipClass")
.mouseover(function() {tooltip.show("my tooltip text")})
.mouseout(function() {tooltip.hide();})
.mousemove(function(event) {tooltip.move(event);});
*/
Tooltip = function() {
this.visible=false;
......
......@@ -15,32 +15,38 @@ setCurrentDocumentID = function(ID) {return localStorage.setItem("currentDocumen
* @param documentList : documents information loaded from the storage
*/
var DocumentList = function(documentList) {
if(sessionStorage.documentList) {//load from sessionStorage
this.load(JSON.parse(sessionStorage.documentList));
this.detailedList = {}
if(documentList) {
for(var doc in documentList) {
this.detailedList[doc] = new JSONDocument(documentList[doc]);
}
}
else {
if(documentList) {
for(var doc in documentList) {
this.documentList[doc] = new JSONDocument(documentList[doc]);
this.displayInformation = {};
this.displayInformation.page = 1;
this.selectionList = [];
//check the user document list on the remote storage every 10 seconds
var list = this;
var updateDocumentList = function () {
JIO.getDocumentList({
success: function(data) {
list.detailedList = data;
}
} else {this.documentList = {}}
this.list = getCurrentStorage().getDocumentList();
this.displayInformation = {};
this.displayInformation.page = 1;
this.selectionList = [];
});
}
recursiveTask(function() {if(JIO.isReady()){updateDocumentList()}},10000);
}
DocumentList.prototype = new UngObject();
DocumentList.prototype.load({
removeDocument: function(fileName) {
getCurrentStorage().remove(fileName)//delete the file
delete this.list[fileName];//remove from the list
delete this.detailedList[fileName];//
this.save();//save changes
},
getList: function() {return this.list},
get: function(fileName) {return this.getDetailedList()[fileName]},
getList: function() {return getCurrentStorage().getDocumentList();},
getDetailedList: function() {return this.detailedList},
getSelectionList: function() {return this.selectionList;},
resetSelectionList: function() {
......@@ -70,7 +76,7 @@ DocumentList.prototype.load({
for(i=this.getDisplayInformation().first-1; i<this.getDisplayInformation().last; i++) {
$("tr td.listbox-table-select-cell input#"+i).attr("checked",true);//check
}
$("span#selected_row_number a").html(this.size());//display the selected row number
$("span#selected_row_number a").html(list.length);//display the selected row number
},
addToSelection: function(fileName) {
this.getSelectionList().push(fileName);
......@@ -108,27 +114,35 @@ DocumentList.prototype.load({
},
/* display the list of documents in the web page */
displayContent: function() {//display the list of document itself
displayContent: function(list) {//display the list of document itself
$("table.listbox tbody").html("");//empty the previous displayed list
var list = toArray(this.getList());
var detailedList = this.getDetailedList();
for(var i=this.getDisplayInformation().first-1;i<this.getDisplayInformation().last;i++) {
var fileName = list[i].fileName;
if(!detailedList[fileName] || new Date(detailedList[fileName].lastModification+1000)<new Date(list[i].lastModify)) {updateDocumentInformation(fileName)}
var line = new Line(doc,i);
line.updateHTML();
line.display();
if(this.getSelectionList().indexOf(doc.fileName)) {line.setSelected(true);}//check the box if selected
var doc = detailedList[fileName];
var documentList = this;
(function tryToDisplay(j) {//update document information before displaying
if(!doc || new Date(detailedList[fileName].lastModification+1000)<new Date(list[j].lastModify)) {
documentList.updateDocumentInformation(fileName);
setTimeout(function(){tryToDisplay.call(this,j)},500);
} else {
var line = new Line(doc,j);
line.updateHTML();
line.display();
if(this.getSelectionList().indexOf(doc.fileName)) {line.setSelected(true);}//check the box if selected
}
})(i)
}
},
displayListInformation: function() {//display number of records, first displayed document, last displayed document...
if(this.size()>0) {
displayListInformation: function(list) {//display number of records, first displayed document, last displayed document...
if(list.length>0) {
$("div.listbox-number-of-records").css("display","inline");
$("span#page_start_number").html(this.getDisplayInformation().first);
$("span#page_stop_number").html(this.getDisplayInformation().last);
$("span#total_row_number a").html(this.size());
$("span#selected_row_number a").html(this.getSelectionList().size());
$("span#total_row_number a").html(list.length);
$("span#selected_row_number a").html(this.getSelectionList().length);
}
else {$("div.listbox-number-of-records").css("display","none");}
},
......@@ -141,7 +155,7 @@ DocumentList.prototype.load({
if(lastPage>1) {
$("div.listbox-navigation input.listbox_set_page").attr("value",this.getDisplayedPage());
$("div.listbox-navigation span.listbox_last_page").html(lastPage);
disp("div.listbox-navigation button.listbox_first_page",this.getDisplayedPage()>1);
disp("div.listbox-navigation button.listbox_previous_page",this.getDisplayedPage()>1);
disp("div.listbox-navigation button.listbox_next_page",this.getDisplayedPage()<lastPage);
......@@ -149,9 +163,10 @@ DocumentList.prototype.load({
}
},
display: function() {
this.updateDisplayInformation();
this.displayContent();
this.displayListInformation();
var list = toArray(this.getList());
this.updateDisplayInformation(list);
this.displayContent(list);
this.displayListInformation(list);
this.displayNavigationElements();
},
......@@ -165,12 +180,12 @@ DocumentList.prototype.load({
});
},
/* update the document to be displayed */
updateDisplayInformation: function() {
updateDisplayInformation: function(list) {
var infos = this.getDisplayInformation();
infos.step = getCurrentUser().getSetting("displayPreferences"),//documents per page
infos.first = (infos.page-1)*infos.step + 1,//number of the first displayed document
infos.last = (this.size()<(infos.first+infos.step)) ? this.size() : infos.first+infos.step-1//number of the last displayed document
infos.lastPage = Math.ceil(this.size()/infos.step);
infos.last = list.length<(infos.first+infos.step) ? list.length : (infos.first+infos.step-1);//number of the last displayed document
infos.lastPage = Math.ceil(list.length/infos.step);
},
setAsCurrentDocumentList: function() {
......@@ -182,6 +197,8 @@ getDocumentList = function() {
}
/**
* create a line representing a document in the main table
* @param doc : document to represent
......@@ -228,11 +245,11 @@ Line.prototype = {
.find("td.listbox-table-data-cell")
.click(function() {//clic on a line
setCurrentDocumentID(line.getID());
startDocumentEdition(line.getDocument())
Document.startDocumentEdition(line.getDocument())
})
.find("a.listbox-document-icon")
.find("img")
.attr("src",supportedDocuments[this.getType()].icon)//icon
.attr("src",Document.supportedDocuments[this.getType()].icon)//icon
.end()
.end()
.find("a.listbox-document-title").html(this.getDocument().getTitle()).end()
......@@ -243,9 +260,12 @@ Line.prototype = {
/* add the line in the table */
display: function() {$("table.listbox tbody").append($(this.getHTML()));}
}
/* load the html code of a default line */
Line.loadHTML = function() {
loadFile("xml/xmlElements.xml", "html", function(data) {Line.originalHTML = $(data).find("line table tbody").html();});
/* load the html code of a default line and execute the callback */
Line.loadHTML = function(callback) {
loadFile("xml/xmlElements.xml", "html", function(data) {
Line.originalHTML = $(data).find("line table tbody").html();
callback(Line.getOriginalHTML());
});
return Line.originalHTML;
}
/* return the html code of a default line */
......@@ -262,10 +282,11 @@ Line.getOriginalHTML = function() {return Line.originalHTML;}
var createNewDocument = function(type) {
var newDocument = new JSONDocument();
newDocument.setType(type);
var fileName = DOcument.getAddress(newDocument);
newDocument.save(function() {
getDocumentList().add(newDocument);
getDocumentList()[fileName]=newDocument;
getCurrentStorage().save();
startDocumentEdition(newDocument);
Document.startDocumentEdition(newDocument);
});
}
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