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