Commit 9461e068 authored by François Billioud's avatar François Billioud

correct issues in documentList downloading

parent 01496da5
......@@ -40,18 +40,11 @@ var Page = {
}
//display the document list when the line factory is ready
Line.loadHTML(function() {
var list = getCurrentDocumentList();
if (list && list.detailedList) {
list.display();
list.resetSelectionList();
resize();
} else {
Storage.addEventHandler(function() {
list.display();
list.resetSelectionList();
resize();
},Storage.LIST_READY);
}
Storage.addEventHandler(function() {
DocumentList.detailedList = Storage.getDocumentList();
DocumentList.display()
},Storage.LIST_READY);
if(DocumentList.getDetailedList()) {DocumentList.display()}
});
}
......@@ -65,7 +58,7 @@ var Page = {
getDependencies: function() {return $(this.getXML()).find("dependencies");},
getEditor: function() {return this.editor;},
loadEditor: function() { //load the favourite editor of the user
this.editor = new (getCurrentUser().getSetting("favouriteEditor")[this.getName()])();
this.editor = new window[getCurrentUser().getSetting("favouriteEditor")[this.getName()]]();
},
//loaders
......@@ -75,18 +68,19 @@ var Page = {
var page = this;
loadFile(source,"html",function(data) {
page.xml = data;
this.displayPageinformation();
Page.displayPageInformation();
var dependencies = this.getDependencies();
var dependencies = Page.getDependencies();
$(dependencies).find("linkfile").each(function() {page.include($(this).text(),"link");});//includes css
$(dependencies).find("scriptfile").each(function() {page.include($(this).text(),"script");});//includes js
// load the user, the editor and the document in the page (wait for the storage being ready)
Storage.addEventHandler(function() {
var initPage = function() {
Page.loadEditor();
Page.displayUserInformation(getCurrentUser());
Page.displayDocumentInformation(getCurrentDocument());
Page.loadEditor();
},Storage.USER_READY);
}
Storage[Storage.USER_READY] ? initPage() : Storage.addEventHandler(initPage);
});
},
......@@ -215,7 +209,7 @@ var Storage = new UngObject();
Storage.load({
/* create the storage from storage. Used in the login page */
create: function (jioFileContent) {
this.jio = jioFileContent;
this.jio = typeof jioFileContent == "string" ? JSON.parse(jioFileContent) : jioFileContent;
JIO.initialize(jioFileContent,{"ID":"www.ungproject.com"});
Storage.currentStorage = this;
//try to load user parameters
......@@ -229,16 +223,16 @@ Storage.load({
errorHandler: function(errorEvent) {//fail
if(errorEvent.status==404){//create a new user if there was no such one
var user = new User();
user.setName(jioFileContent.userName);
user.setName(storage.jio.userName);
storage.user = user;
storage.userName = storage.user.getName();
storage.user.storageLocation = jioFileContent.location;
storage.user.storageLocation = storage.jio.location;
storage.save(function() {storage.fireEvent(Storage.STORAGE_CREATED);});
}
},
asynchronous: false
}
JIO.loadDocument(jioFileContent.userName+".profile", option);
JIO.loadDocument(storage.jio.userName+".profile", option);
},
......@@ -297,14 +291,19 @@ Storage.load({
var option = {
success: function(list) {
delete list[getCurrentUser().getName()+".profile"];//remove the profile file
getCurrentStorage().documentList = list;
//treat JSON documents
for (var element in list) {
list[element].content = new JSONDocument(list[element].content);
}
Storage.documentList = list;if(Storage.documentList["test.profile"]){debugger;};
Storage.fireEvent(Storage.LIST_READY);
}
}
JIO.getDocumentList(option);
},
save: function(instruction) { // update and save user information in the localStorage
this.updateUser();
this.saveDocument(this.user,this.user.getName()+".profile",function() {
var storage = {
jio:Storage.jio,
......@@ -322,14 +321,12 @@ Storage.load({
this.userName = user.getName();
Storage.fireEvent(Storage.USER_READY);
this.updateDocumentList();
getCurrentStorage().save();
},
fireEvent: function(event) {
Storage[event] = true;
UngObject.prototype.fireEvent.call(this,event);
},
updateUser: function() {localStorage[this.getUser().getName()] = JSON.stringify(this.getUser());}
}
});
function getCurrentStorage() {
......@@ -353,6 +350,7 @@ var Document = {
saveCurrentDocument: function() {
getCurrentPage().getEditor().saveEdition();
getCurrentDocument().save();
localStorage.currentDocument = JSON.stringify(getCurrentDocument());
},
/**
......@@ -360,7 +358,7 @@ var Document = {
* @param doc : the document to edit
*/
startDocumentEdition: function(doc) {
getCurrentStorage().getDocument(doc.fileName, function(data) {
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");
......
......@@ -68,7 +68,7 @@ UngObject.prototype.addEventHandler = function (handler, event, once) {
}
/* fire an event through all the listeners of the object */
UngObject.prototype.fireEvent = function (event) {
UngObject.prototype.fireEvent = function (event) {console.log(event);
for (var i=0; i<this.listenerList.length; i++) {
var listener = this.listenerList[i];
if(listener.event == event) {
......
......@@ -20,10 +20,19 @@ DocumentList.load({
this.displayInformation = {};
this.displayInformation.page = 1;
this.selectionList = [];
this.detailedList = getCurrentStorage().getDocumentList();
this.resetSelectionList();
recursiveTask(function() {getCurrentStorage().updateDocumentList()},10000);// ! should display it if any change
//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();
}*/
},
removeDocument: function(fileName) {
......@@ -47,7 +56,7 @@ DocumentList.load({
},
checkAll: function() {
this.selectionList = [];
var list = toArray(this.getList());
var list = toArray(this.getDetailedList());
var begin = 0;
var end = list.length;
......@@ -107,18 +116,18 @@ 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;
/*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);
} else {*/
var line = new Line(doc,i);
line.updateHTML();
line.display();
if(this.getSelectionList().indexOf(doc.fileName)) {line.setSelected(true);}//check the box if selected
}
})(i)
if(this.getSelectionList().indexOf(doc.fileName)!=-1) {line.setSelected(true);}//check the box if selected
/*}
})(i)*/
}
},
......@@ -150,7 +159,7 @@ DocumentList.load({
}
},
display: function() {
var list = toArray(this.getList());
var list = toArray(this.getDetailedList());
this.updateDisplayInformation(list);
this.displayContent(list);
this.displayListInformation(list);
......@@ -158,7 +167,7 @@ DocumentList.load({
},
/* update the ith document information */
updateDocumentInformation: function(fileName) {
updateDocumentInformation: function(fileName) {console.log(fileName);
var list = this.getDetailedList();
getCurrentStorage().getDocument(fileName, function(doc) {
list[fileName]=doc;
......@@ -166,7 +175,7 @@ DocumentList.load({
doc.setContent("");
});
},
/* update the document to be displayed */
/* update the variable "displayInformation" (documents to be displayed) */
updateDisplayInformation: function(list) {
var infos = this.getDisplayInformation();
infos.step = getCurrentUser().getSetting("displayPreferences"),//documents per page
......@@ -183,7 +192,7 @@ function getCurrentDocumentList() {
return DocumentList;
}
function getDocumentList() {
return getCurrentStorage().getDocumentList();
return getCurrentStorage().getDocumentList();//equivalent to return DocumentList.getDetailedList();
}
......@@ -199,9 +208,9 @@ var Line = function(doc, i) {
this.html = Line.getOriginalHTML();
}
Line.prototype = {
getDocument: function() {return this.document;},
getDocument: function() {return this.document.content;},
getID: function() {return this.ID;},
getType: function() {return this.document.getType() || "other";},
getType: function() {return this.document.content.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)},
......@@ -271,11 +280,8 @@ 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()[fileName]=newDocument;
getCurrentStorage().save();
Document.startDocumentEdition(newDocument);
});
}
......@@ -31,19 +31,11 @@
<script type="text/javascript">
// initialize
var initPage = function() {
new Page(supportedDocuments[getCurrentDocument().getType()].editorPage);
}
var initUser = function() {
var user = getCurrentUser();
user.setAsCurrentUser();
}
var init = function() {
initPage();
waitBeforeSucceed(function() {return getCurrentPage().getXML();},initUser);
Page.initialize(Document.supportedDocuments[getCurrentDocument().getType()].editorPage);
Storage.initialize();
}
$(document).ready(init);
</script>
......@@ -67,7 +59,7 @@
<div class="input"><div >
<a class="email" href="ung/mail.html" lang="en">Email</a>
<a class="document" href="ung.html" onclick="stopDocumentEdition()" lang="en">Documents</a>
<a class="document" href="ung.html" onclick="Document.stopDocumentEdition()" lang="en">Documents</a>
<a class="calendar" href="ung/calendar.html" lang="en">Calendar</a>
</div></div>
......@@ -139,7 +131,7 @@
<label>search_bar</label>
<div class="input"><div >
<a class="ung_docs" href="ung.html" onclick="stopDocumentEdition()">
<a class="ung_docs" href="ung.html" onclick="Document.stopDocumentEdition()">
<img src="images/ung/ung-logo.gif" alt="logo"/>
</a>
......@@ -167,7 +159,7 @@
<a id="last_update">Updated ... by</a>
<a id="author">Unknown</a>
<button type="button" onclick="saveCurrentDocument()">Save</button>
<button type="button" onclick="Document.saveCurrentDocument()">Save</button>
<div class="action_menu">
......
......@@ -31,18 +31,10 @@
<script type="text/javascript">
var init = function() {
var init = function() {if(Storage.documentList && Storage.documentList["test.profile"]){debugger;};
//initialize page and storage, then user, and then document List
Page.initialize("ung");//provide methods on the page
Storage.initialize();//initialize storage
if(getCurrentDocumentID()&&getDocumentList().get(getCurrentDocumentID())) {
/* update the list with the modifications of the last edited document
* (this method has to been rewritten if using multi users) */
getDocumentList().updateDocumentInformation(getCurrentDocumentID());
delete localStorage.currentDocumentID;
getCurrentStorage().save();
}
resize();
}
......
......@@ -49,7 +49,7 @@
*/
isReady: function() {return this.jioFileContent && this.storage},
ready: function(instruction) {this.ready = instruction},
ready: function(instruction) {if(instruction) this.ready = instruction},
//IO functions
getLocation: function() {return this.location},
......
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