Commit 295f7c79 authored by François Billioud's avatar François Billioud

correct DocumentLIst getter and initialization

parent c2112947
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
*/ */
applicationID = window.location.href.split("://")[1].split("/")[0]; //should be removed and better implemented applicationID = window.location.href.split("://")[1].split("/")[0]; //should be removed and better implemented
LANGUAGES = ["fr","en"]; LANGUAGES = ["fr","en"];
function getCurrentStorage() {
return Storage.currentStorage;
}
/* /*
* Page * Page
...@@ -27,20 +29,21 @@ var Page = { ...@@ -27,20 +29,21 @@ var Page = {
this.loadXML("xml/"+page+".xml"); this.loadXML("xml/"+page+".xml");
} else { } else {
//display user information when the storage is ready //display user information when the storage is ready
if (getCurrentStorage()[Storage.USER_READY]) { if (Storage[Storage.USER_READY]) {
Page.displayUserInformation(getCurrentUser()); Page.displayUserInformation(getCurrentUser());
DocumentList.initialize();
} else { } else {
getCurrentStorage().addEventHandler(function() { Storage.addEventHandler(function() {
Page.displayUserInformation(getCurrentUser()); Page.displayUserInformation(getCurrentUser());
getCurrentDocumentList() DocumentList.initialize();
},Storage.USER_READY); },Storage.USER_READY);
} }
//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() {
if (getCurrentStorage()[Storage.LIST_READY]) { if (Storage[Storage.LIST_READY]) {
getCurrentDocumentList().display(); getCurrentDocumentList().display();
} else { } else {
getCurrentStorage().addEventHandler(function() { Storage.addEventHandler(function() {
getCurrentDocumentList().display(); getCurrentDocumentList().display();
},Storage.LIST_READY); },Storage.LIST_READY);
} }
...@@ -74,7 +77,7 @@ var Page = { ...@@ -74,7 +77,7 @@ var Page = {
$(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)
getCurrentStorage().addEventHandler(function() { Storage.addEventHandler(function() {
Page.displayUserInformation(getCurrentUser()); Page.displayUserInformation(getCurrentUser());
Page.displayDocumentInformation(getCurrentDocument()); Page.displayDocumentInformation(getCurrentDocument());
Page.loadEditor(); Page.loadEditor();
...@@ -312,7 +315,7 @@ Storage.load({ ...@@ -312,7 +315,7 @@ Storage.load({
updateUser: function() {localStorage[this.getUser().getName()] = JSON.stringify(this.getUser());} updateUser: function() {localStorage[this.getUser().getName()] = JSON.stringify(this.getUser());}
}); });
getCurrentStorage = function () { function getCurrentStorage() {
return Storage.currentStorage; return Storage.currentStorage;
} }
...@@ -374,13 +377,13 @@ var Document = { ...@@ -374,13 +377,13 @@ var Document = {
return doc.getCreation(); return doc.getCreation();
} }
} }
getCurrentDocument = function() { function getCurrentDocument() {
if(!Document.currentDocument) { if(!Document.currentDocument) {
Document.currentDocument = new JSONDocument(JSON.parse(localStorage.getItem("currentDocument"))); Document.currentDocument = new JSONDocument(JSON.parse(localStorage.getItem("currentDocument")));
} }
return Document.currentDocument; return Document.currentDocument;
} }
setCurrentDocument = function(doc) { function setCurrentDocument(doc) {
localStorage.setItem("currentDocument",JSON.stringify(doc)); localStorage.setItem("currentDocument",JSON.stringify(doc));
Document.currentDocument = doc; Document.currentDocument = doc;
} }
......
...@@ -61,8 +61,8 @@ UngObject.prototype.copy = function() { ...@@ -61,8 +61,8 @@ UngObject.prototype.copy = function() {
* @param once : if set to true, the handler is executed only once * @param once : if set to true, the handler is executed only once
*/ */
UngObject.prototype.addEventHandler = function (handler, event, once) { UngObject.prototype.addEventHandler = function (handler, event, once) {
if(!this.listenerList.length) { this.listnerList = [] } if(!this.listenerList) { this.listenerList = [] }
this.listernerList.push({handler:handler,event:event,once:once}); this.listenerList.push({handler:handler,event:event,once:once});
} }
/* fire an event through all the listeners of the object */ /* fire an event through all the listeners of the object */
......
...@@ -14,33 +14,17 @@ setCurrentDocumentID = function(ID) {return localStorage.setItem("currentDocumen ...@@ -14,33 +14,17 @@ setCurrentDocumentID = function(ID) {return localStorage.setItem("currentDocumen
* the detailedList object is the synchronized list containing more detailed information about documents * the detailedList object is the synchronized list containing more detailed information about documents
* @param documentList : documents information loaded from the storage * @param documentList : documents information loaded from the storage
*/ */
var DocumentList = { var DocumentList = new UngObject();
inititalize: function() { DocumentList.load({
var data = lo initialize: function() {
},
this.detailedList = {}
if(documentList) {
for(var doc in documentList) {
this.detailedList[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 this.displayInformation = {};
var list = this; this.displayInformation.page = 1;
var updateDocumentList = function () { this.selectionList = [];
JIO.getDocumentList({ this.detailedList = getCurrentStorage().getDocumentList();
success: function(data) {
list.detailedList = data; recursiveTask(function() {getCurrentStorage().updateDocumentList()},10000);// ! should display it if any change
} },
});
}
recursiveTask(function() {if(JIO.isReady()){updateDocumentList()}},10000);
}
DocumentList.prototype = new UngObject();
DocumentList.prototype.load({
removeDocument: function(fileName) { removeDocument: function(fileName) {
getCurrentStorage().remove(fileName)//delete the file getCurrentStorage().remove(fileName)//delete the file
...@@ -195,13 +179,15 @@ DocumentList.prototype.load({ ...@@ -195,13 +179,15 @@ DocumentList.prototype.load({
this.display(); this.display();
} }
}); });
getDocumentList = function() { function getCurrentDocumentList() {
return DocumentList;
}
function getDocumentList() {
return getCurrentStorage().getDocumentList(); return getCurrentStorage().getDocumentList();
} }
/** /**
* create a line representing a document in the main table * create a line representing a document in the main table
* @param doc : document to represent * @param doc : document to represent
......
Use of JIO :
Very easy :
1) Call JIO.initialize(jio,applicant)
jio : string representing the content of jio.json file
or function to call to get the content of jio.json
or JSON representation of jio.json
applicant : information about the person/application asking an access to the storage.
you can precise a password, and ID, etc, to identify the applicant
2) use the standard API of the JIO object in the application:
isReady: return true if the storage is ready to be used
userNameAvailable: ...the role of this function should be defined better when subbscription to storage spaces will be implemented...
loadDocument: get data from the storage
saveDocument: save data on the storage
deleteDocument: remove data from the storage
getDocumentList: get the list of documents of the user
MultipleStorage and AsynchronousStorage can't work for the moment and are there only to present ideas
CustomStorage is a storage load from a js file. We should be careful because it uses a synchronous ajax request
to illustrate:
JIO.initialize({jio.json}, {applicant});
if(JIO.isReady()) {JIO.loadDocument(fileName, {success:function() {}})}
************************************************************************
UNGDocs :
CSS : all the css is in the file ung.css
HTML : html fils are directly in the main folder :
- login.html : contains the html to welcome and log users
- ung.html : contains the html to display document list
- theme.html : contains the html to display and edit a document
! html should be factorized, and ung/theme.html should be renamed more clearly
JS : js is contained by the following files :
- tools.js : contains useful tools functions
- login.js : contains the script to log user and create their storage
- ung.js : contains the script to manipulate and display document list
- theme.js : contains the script to load the page, the user information, the storage...
- *-editor.js : contains the script to load editors for each document type
XML : contains html elements to integrate in the page
! only the xmlElements.xml file should be kept
unhosted/ : contains jio files
! should be renamed to jio/
mobile/ : contains mobile app
! we should use a common javascript for mobile app and normal html
*/ : contains editors or external libraries.
! jquery/ should be moved
**********************************************************************
UNGDocs
ung.html is the main page of ung. If there is no default user, redirects to login.html
login.html : loads, asks or creates jio.json, then, create a storage - Storage.create(jio.json) - and redirects to ung.html (the user is saved in the localStorage);
ung.html : load the Page - Page.initialize(pageName) - and the storage - Storage.initialize();
Page : loads the content from xml files, display information about user when the storage is ready. Then, loads the editor and display documents information.
Storage : prepare the storage and load the user
***********************************************************************
Test JIO
unhosted/test-jio.html :
this page contains a GUI to create easily your jio.json file.
there is also some unit test on jio storages. try "UnitTest.all();" in firebug to test all unit tests.
Warning ! The DAVStorage should be configurated before (manually in the file "test-jio.html")
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