Commit 18208be5 authored by François Billioud's avatar François Billioud

Fix major bugs. stable version

parent 9461e068
......@@ -9,7 +9,7 @@
* 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() {
Xinha = function() {
this.name = "Xinha"; // name to use in dialog boxes
this.objectName = "Xinha" // name of the object reference
this.load = function() {
......@@ -28,7 +28,7 @@ var Xinha = function() {
this.load();
}
var AlohaInterface = function() {
AlohaInterface = function() {
this.name = "Aloha"; // name to use in dialog boxes
this.objectName = "AlohaInterface" // name of the object reference
this.load = function() {
......@@ -54,7 +54,7 @@ var AlohaInterface = function() {
this.load();
}
var NicEdit = function() {
NicEdit = function() {
this.name = "NicEdit"; // name to use in dialog boxes
this.objectName = "NicEdit" // name of the object reference
this.instance = null;
......@@ -77,7 +77,7 @@ var NicEdit = function() {
}
var TinyEdit = function() {
TinyEdit = function() {
this.name = "Tiny"; // name to use in dialog boxes
this.objectName = "TinyEdit" // name of the object reference
this.load = function() {
......
......@@ -42,7 +42,7 @@ var Page = {
Line.loadHTML(function() {
Storage.addEventHandler(function() {
DocumentList.detailedList = Storage.getDocumentList();
DocumentList.display()
DocumentList.display();
},Storage.LIST_READY);
if(DocumentList.getDetailedList()) {DocumentList.display()}
});
......@@ -57,8 +57,8 @@ var Page = {
getContent: function() {return $(this.getXML()).find("content").html();},
getDependencies: function() {return $(this.getXML()).find("dependencies");},
getEditor: function() {return this.editor;},
loadEditor: function() { //load the favourite editor of the user
this.editor = new window[getCurrentUser().getSetting("favouriteEditor")[this.getName()]]();
loadEditor: function(editor) { //load the favourite editor of the user
this.editor = new editor();
},
//loaders
......@@ -76,11 +76,24 @@ var Page = {
// load the user, the editor and the document in the page (wait for the storage being ready)
var initPage = function() {
Page.loadEditor();
Page.displayUserInformation(getCurrentUser());
Page.displayDocumentInformation(getCurrentDocument());
var editor = window[getCurrentUser().getSetting("favouriteEditor")[Page.getName()]];
if(!editor) {// this hack doesn't work and I have no idea why
setTimeout(function() {initPage()},500);console.log("try");
$.ajax({
url: "js/text-editor.js",
type: "GET",
dataType: "text",
success: function(data) {eval(data);},
error: function(type) {alert("Error "+type.status+" : fail while trying to load "+"js/text-editor.js");}
});
}
else {
Page.loadEditor(editor);
Page.displayUserInformation(getCurrentUser());
Page.displayDocumentInformation(getCurrentDocument());
}
}
Storage[Storage.USER_READY] ? initPage() : Storage.addEventHandler(initPage);
Storage[Storage.USER_READY] ? initPage() : Storage.addEventHandler(initPage,Storage.USER_READY);
});
},
......@@ -229,10 +242,9 @@ Storage.load({
storage.user.storageLocation = storage.jio.location;
storage.save(function() {storage.fireEvent(Storage.STORAGE_CREATED);});
}
},
asynchronous: false
}
}
JIO.loadDocument(storage.jio.userName+".profile", option);
JIO.ready(function(){JIO.loadDocument(storage.jio.userName+".profile", option)});
},
......@@ -270,10 +282,22 @@ Storage.load({
};
JIO.loadDocument(fileName, option);
},
getDocumentMetaData: function(fileName, instruction) {
//optimized only if an indexedStorage is included in the storage
var option = {
metaDataOnly: true,
success:function(content) {
var doc = new JSONDocument(JSON.parse(content));
if(instruction) instruction(doc);
}
};
JIO.loadDocument(fileName, option);
},
saveDocument: function(doc, fileName, instruction) {
var metaData = doc.copy();
delete metaData.content;
var option = {
overwrite: true,
success: instruction,
metaData: metaData
};
......@@ -291,28 +315,40 @@ Storage.load({
var option = {
success: function(list) {
delete list[getCurrentUser().getName()+".profile"];//remove the profile file
var documentList = Storage.documentList || [];
//treat JSON documents
for (var element in list) {
list[element].content = new JSONDocument(list[element].content);
if(!documentList[element]) {
documentList[element] = new JSONDocument(list[element]);
} else {
documentList[element].load(list[element])
}
}
Storage.documentList = list;if(Storage.documentList["test.profile"]){debugger;};
Storage.documentList = documentList;
Storage.fireEvent(Storage.LIST_READY);
}
}
JIO.getDocumentList(option);
},
save: function(instruction) { // update and save user information in the localStorage
this.saveDocument(this.user,this.user.getName()+".profile",function() {
var storage = {
jio:Storage.jio,
user:Storage.user,
userName:Storage.userName
}
localStorage.currentStorage = JSON.stringify(storage);
if(instruction) {instruction();}
});
var user = this.user;
var metaData = user.copy();
delete metaData.content;
var option = {
success: function() {
var storage = {
jio:Storage.jio,
user:Storage.user,
userName:Storage.userName
}
localStorage.currentStorage = JSON.stringify(storage);
if(instruction) {instruction();}
},
overwrite: true,
metaData: metaData
};
JIO.saveDocument(JSON.stringify(user), user.getName()+".profile", option);
},
getUser: function() {return this.user;},
......@@ -358,11 +394,14 @@ var Document = {
* @param doc : the document to edit
*/
startDocumentEdition: function(doc) {
getCurrentStorage().getDocument(Document.getAddress(doc), function(data) {
this.setCurrentDocument(data);
if(Document.supportedDocuments[data.getType()].editorPage) {window.location.href = "theme.html";}
else alert("no editor available for this document");
});
if(Document.supportedDocuments[doc.getType()].editorPage) {
getCurrentStorage().getDocument(doc.getAddress(), function(data) {
this.setCurrentDocument(data);
window.location.href = "theme.html";
});
} else {
alert("no editor available for this document");
}
},
/**
......@@ -383,13 +422,6 @@ var Document = {
"table":{editorPage:"table-editor",icon:"images/icons/table.png"},
"other":{editorPage:null,icon:"images/icons/other.gif"},
undefined:{editorPage:null,icon:"images/icons/other.gif"}
},
/**
* generate a unique name for the document
*/
getAddress: function(doc) {
return doc.getCreation();
}
}
function getCurrentDocument() {
......@@ -417,8 +449,8 @@ var JSONDocument = function(arg) {
this.lastUser=getCurrentUser().getName();
this.title="Untitled";
this.content="";
this.creation=getCurrentTime();
this.lastModification=getCurrentTime();
this.creationDate=getCurrentTime();
this.lastModified=getCurrentTime();
this.state=JSONDocument.prototype.states.draft;
this.label = {};
}
......@@ -453,9 +485,9 @@ JSONDocument.prototype.load({//add methods thanks to the UngObject.load method
setLastUser:function(user) {this.lastUser = user;},
//dates
getCreation:function() {return this.creation;},
getLastModification:function() {return (new Date(this.lastModification)).toUTCString();},
setLastModification:function(date) {this.lastModification=date;},
getCreation:function() {return this.creationDate;},
getLastModification:function() {return (new Date(this.lastModified)).toUTCString();},
setLastModification:function(date) {this.lastModified=date;},
//state
getState:function() {return this.state;},
......@@ -471,11 +503,14 @@ JSONDocument.prototype.load({//add methods thanks to the UngObject.load method
setCurrentDocument(this);
},
save: function(instruction) {//save the document
var doc = this;
getCurrentStorage().saveDocument(doc, Document.getAddress(this), instruction);
getCurrentStorage().saveDocument(this, this.getAddress(), instruction);
},
remove: function(instruction) {//remove the document
getCurrentStorage().deleteDocument(Document.getAddress(this), instruction);
getCurrentStorage().deleteDocument(this.getAddress(), instruction);
},
/* generate a unique name for the document */
getAddress: function() {
return this.getCreation()+".json";
}
});
JSONDocument.prototype.states = {
......@@ -483,6 +518,7 @@ JSONDocument.prototype.states = {
saved:{"fr":"Enregistré","en":"Saved"},
deleted:{"fr":"Supprimé","en":"Deleted"}
}
JSONDocument.UPDATED = "updated";
......@@ -522,7 +558,7 @@ share = function() {alert("share");}
editDocumentSettings = function() {
Document.saveCurrentDocument();
loadFile("xml/xmlElements.xml", "html", function(data) {
$("rename", data).dialog({
$(data).find("rename").dialog({
autoOpen: true,
height: 131,
width: 389,
......
......@@ -6,9 +6,7 @@
* Class UngObject
* provides useful general methods
*/
UngObject = function() {
this.listenerList = [];
}
UngObject = function() {}
/* return true if this object implements the interface */
UngObject.prototype.implement = function(myInterface)
{
......@@ -63,24 +61,30 @@ UngObject.prototype.copy = function() {
* @param once : if set to true, the handler is executed only once
*/
UngObject.prototype.addEventHandler = function (handler, event, once) {
if(!this.listenerList) { this.listenerList = [] }
this.listenerList.push({handler:handler,event:event,once:once});
this.getListenerList().push({handler:handler,event:event,once:once});
}
/* fire an event through all the listeners of the object */
UngObject.prototype.fireEvent = function (event) {console.log(event);
for (var i=0; i<this.listenerList.length; i++) {
var listener = this.listenerList[i];
var list = this.getListenerList();
for (var i=0; i<list.length; i++) {
var listener = list[i];
if(listener.event == event) {
listener.handler(event);
if(listener.once) { // remove the listener if supposed to been executed only once
this.listenerList.splice(i,1);
list.splice(i,1);
i--;
}
}
}
}
/* getter for the listenerList */
UngObject.prototype.getListenerList = function() {
if (!this.listenerList) {this.listenerList = []}
return this.listenerList;
}
/**
* convert an object into an array easier to manipulate
* @param object : the object to convert
......
......@@ -24,21 +24,12 @@ DocumentList.load({
//update documentList each 10 seconds
Storage.addEventHandler(function() {DocumentList.detailedList = Storage.getDocumentList();},Storage.LIST_READY);
recursiveTask(function() {Storage.updateDocumentList();},10000);// ! should display it if any change
/* update the list with the modifications of the last edited document
* (this method has to been rewritten if using multi users)
if(getCurrentDocumentID()&&getDocumentList().get(getCurrentDocumentID())) {
getDocumentList().updateDocumentInformation(getCurrentDocumentID());
delete localStorage.currentDocumentID;
getCurrentStorage().save();
}*/
recursiveTask(function() {Storage.updateDocumentList();},10000);
},
removeDocument: function(fileName) {
getCurrentStorage().remove(fileName)//delete the file
delete this.detailedList[fileName];//
this.save();//save changes
getCurrentStorage().deleteDocument(fileName)//delete the file
delete this.getDetailedList()[fileName];
},
get: function(fileName) {return this.getDetailedList()[fileName]},
......@@ -78,8 +69,7 @@ DocumentList.load({
this.getSelectionList().push(fileName);
},
removeFromSelection: function(fileName) {
var selection = getDocumentList().getSelectionList();
selection.splice(selection.indexOf(fileName),1);
this.getSelectionList().splice(this.getSelectionList().indexOf(fileName),1);
},
deleteSelectedDocuments: function() {
......@@ -116,19 +106,13 @@ DocumentList.load({
for(var i=this.getDisplayInformation().first-1;i<this.getDisplayInformation().last;i++) {
var fileName = list[i].fileName;
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,i);
line.updateHTML();
line.display();
if(this.getSelectionList().indexOf(doc.fileName)!=-1) {line.setSelected(true);}//check the box if selected
/*}
})(i)*/
var line = new Line(doc,i);
line.updateHTML();
line.display();
if(!doc.updated) {
line.updateDocumentInformation();
}
if(this.getSelectionList().indexOf(doc.fileName)!=-1) {line.setSelected(true);}//check if selected
}
},
displayListInformation: function(list) {//display number of records, first displayed document, last displayed document...
......@@ -166,15 +150,6 @@ DocumentList.load({
this.displayNavigationElements();
},
/* update the ith document information */
updateDocumentInformation: function(fileName) {console.log(fileName);
var list = this.getDetailedList();
getCurrentStorage().getDocument(fileName, function(doc) {
list[fileName]=doc;
list[fileName].fileName = fileName;
doc.setContent("");
});
},
/* update the variable "displayInformation" (documents to be displayed) */
updateDisplayInformation: function(list) {
var infos = this.getDisplayInformation();
......@@ -208,9 +183,13 @@ var Line = function(doc, i) {
this.html = Line.getOriginalHTML();
}
Line.prototype = {
getDocument: function() {return this.document.content;},
getDocument: function() {return this.document;},
setDocument: function(doc) {
this.document = doc;
this.updateHTML();
},
getID: function() {return this.ID;},
getType: function() {return this.document.content.type || "other";},
getType: function() {return this.document.type || "other";},
getHTML: function() {return this.html;},
setHTML: function(newHTML) {this.html = newHTML;},
setSelected: function(bool) {$("tr td.listbox-table-select-cell input#"+this.getID()).attr("checked",bool)},
......@@ -220,18 +199,29 @@ Line.prototype = {
/* add the document of this line to the list of selected documents */
addToSelection: function() {
getDocumentList().addToSelection(this.getDocument().fileName);
DocumentList.addToSelection(this.getDocument().fileName);
},
/* remove the document of this line from the list of selected documents */
removeFromSelection: function() {
getDocumentList().removeFromSelection(this.getDocument().fileName);
DocumentList.removeFromSelection(this.getDocument().fileName);
},
/* check or uncheck the line */
changeState: function() {
this.isSelected() ? this.addToSelection() : this.removeFromSelection();
$("span#selected_row_number a").html(getDocumentList().getSelectionList().length);//display the selected row number
$("span#selected_row_number a").html(DocumentList.getSelectionList().length);//display the selected row number
},
/* update document information of the line */
updateDocumentInformation: function() {
var line = this;
var list = DocumentList.getDetailedList();
var fileName = this.getDocument().fileName;
getCurrentStorage().getDocumentMetaData(fileName, function(doc) {
doc.fileName = fileName;
doc.updated = true;
list[fileName] = doc;
line.setDocument(list[fileName]);
});
},
/* load the document information in the html of a default line */
updateHTML: function() {
var line = this;
......@@ -250,8 +240,8 @@ Line.prototype = {
.attr("src",Document.supportedDocuments[this.getType()].icon)//icon
.end()
.end()
.find("a.listbox-document-title").html(this.getDocument().getTitle()).end()
.find("a.listbox-document-state").html(this.getDocument().getState()[getCurrentUser().getSetting("language")]).end()
.find("a.listbox-document-title").html(this.getDocument().getTitle()||"unknown").end()
.find("a.listbox-document-state").html(this.getDocument().getState()?this.getDocument().getState()[getCurrentUser().getSetting("language")]:"?").end()
.find("a.listbox-document-date").html(this.getDocument().getLastModification()).end()
.end());
},
......@@ -264,7 +254,6 @@ Line.loadHTML = function(callback) {
Line.originalHTML = $(data).find("line table tbody").html();
callback(Line.getOriginalHTML());
});
return Line.originalHTML;
}
/* return the html code of a default line */
Line.getOriginalHTML = function() {return Line.originalHTML;}
......
......@@ -16,7 +16,6 @@
<link type="text/css" rel="stylesheet" href="css/jquery-ui.css" />
<link type="text/css" rel="stylesheet" href="css/ung.css" />
<script type="text/javascript" src="js/jquery/jquery.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="unhosted/jio.js"></script>
......
......@@ -23,7 +23,6 @@
<link type="text/css" rel="stylesheet" href="css/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="css/ung.css" />
<script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/tools.js"></script>
<script type="text/javascript" src="unhosted/jio.js"></script>
......
......@@ -31,7 +31,7 @@
<script type="text/javascript">
var init = function() {if(Storage.documentList && Storage.documentList["test.profile"]){debugger;};
var init = function() {
//initialize page and storage, then user, and then document List
Page.initialize("ung");//provide methods on the page
Storage.initialize();//initialize storage
......@@ -445,23 +445,23 @@
<div class="input"><div >
<div class="toolbar">
<button class="delete ung_button"
onclick="getDocumentList().deleteSelectedDocuments()">Delete
onclick="DocumentList.deleteSelectedDocuments()">Delete
</button>
<button name="#" class="change_state ung_button">Change State</button>
<div class="listbox-navigation">
<button class="listbox_first_page your_listbox_first_page ung_button" onclick="getDocumentList().changePage(event)">
<button class="listbox_first_page your_listbox_first_page ung_button" onclick="DocumentList.changePage(event)">
<span class="image"> </span>
</button>
<button class="listbox_previous_page your_listbox_previous_page ung_button" onclick="getDocumentList().changePage(event)">
<button class="listbox_previous_page your_listbox_previous_page ung_button" onclick="DocumentList.changePage(event)">
<span class="image"> </span>
</button>
<input class="listbox_set_page your_listbox_set_page" value="1" size="1" onkeypress="if(event.keyCode==13){getDocumentList().changePage(event)}" />
<input class="listbox_set_page your_listbox_set_page" value="1" size="1" onkeypress="if(event.keyCode==13){DocumentList.changePage(event)}" />
/<span class="listbox_last_page">1</span>
<button class="listbox_next_page your_listbox_next_page ung_button" onclick="getDocumentList().changePage(event)">
<button class="listbox_next_page your_listbox_next_page ung_button" onclick="DocumentList.changePage(event)">
<span class="image"> </span>
</button>
<button class="listbox_last_page your_listbox_last_page ung_button" onclick="getDocumentList().changePage(event)">
<button class="listbox_last_page your_listbox_last_page ung_button" onclick="DocumentList.changePage(event)">
<span class="image"> </span>
</button>
</div>
......@@ -546,7 +546,7 @@
name="your_listbox_checkAll:method"
value="1" alt="Check All"
title="Check All"
onclick="getDocumentList().checkAll()"
onclick="DocumentList.checkAll()"
src="images/icons/checkall.png" />
&nbsp;
......@@ -555,7 +555,7 @@
name="your_listbox_uncheckAll:method"
value="1" alt="Uncheck All"
title="Uncheck All"
onclick="getDocumentList().resetSelectionList()"
onclick="DocumentList.resetSelectionList()"
src="images/icons/decheckall.png" />
</th>
......
......@@ -49,7 +49,7 @@
*/
isReady: function() {return this.jioFileContent && this.storage},
ready: function(instruction) {if(instruction) this.ready = instruction},
ready: function(instruction) {if(instruction) this.isReady() ? instruction() : this.ready = instruction},
//IO functions
getLocation: function() {return this.location},
......@@ -309,6 +309,7 @@
this.userName = data.userName;
if(!localStorage.getItem(this.userName)) {localStorage[this.userName] = "{}"}//new user
this.documents = JSON.parse(localStorage.getItem(this.userName));//load documents
// HACK : re-stringify the content :
}
JIO.LocalStorage.prototype = {
......@@ -357,13 +358,13 @@
* oldData : last data downloaded. Used to know if data has changed since last download and has to been merged
*/
saveDocument: function(data, fileName, option) {
if(!this.documents[fileName]) { //create document
if(!this.documents[fileName]) { //create document
this.documents[fileName] = {
fileName:fileName,
content: data,
creationDate: Date.now(),
lastModified: Date.now()
};
}
this.save();
if(option.success) option.success();
} else {
......@@ -407,13 +408,14 @@
* @example {"file1":{fileName:"file1",creationDate:"Tue, 23 Aug 2011 15:18:32 GMT",lastModified:"Tue, 23 Aug 2011 15:18:32 GMT"},...}
*/
getDocumentList: function(option) {
var list = this.documents;
var list = copy(this.documents);
if(option.success) option.success(list);
return list;
},
save: function() {
var s = JSON.stringify(this.documents);
localStorage[this.userName]=JSON.stringify(this.documents);
}
}
......
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