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

correct DocumentLIst getter and initialization

parent c2112947
......@@ -7,7 +7,9 @@
*/
applicationID = window.location.href.split("://")[1].split("/")[0]; //should be removed and better implemented
LANGUAGES = ["fr","en"];
function getCurrentStorage() {
return Storage.currentStorage;
}
/*
* Page
......@@ -27,20 +29,21 @@ var Page = {
this.loadXML("xml/"+page+".xml");
} else {
//display user information when the storage is ready
if (getCurrentStorage()[Storage.USER_READY]) {
if (Storage[Storage.USER_READY]) {
Page.displayUserInformation(getCurrentUser());
DocumentList.initialize();
} else {
getCurrentStorage().addEventHandler(function() {
Storage.addEventHandler(function() {
Page.displayUserInformation(getCurrentUser());
getCurrentDocumentList()
DocumentList.initialize();
},Storage.USER_READY);
}
//display the document list when the line factory is ready
Line.loadHTML(function() {
if (getCurrentStorage()[Storage.LIST_READY]) {
if (Storage[Storage.LIST_READY]) {
getCurrentDocumentList().display();
} else {
getCurrentStorage().addEventHandler(function() {
Storage.addEventHandler(function() {
getCurrentDocumentList().display();
},Storage.LIST_READY);
}
......@@ -74,7 +77,7 @@ var Page = {
$(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)
getCurrentStorage().addEventHandler(function() {
Storage.addEventHandler(function() {
Page.displayUserInformation(getCurrentUser());
Page.displayDocumentInformation(getCurrentDocument());
Page.loadEditor();
......@@ -312,7 +315,7 @@ Storage.load({
updateUser: function() {localStorage[this.getUser().getName()] = JSON.stringify(this.getUser());}
});
getCurrentStorage = function () {
function getCurrentStorage() {
return Storage.currentStorage;
}
......@@ -374,13 +377,13 @@ var Document = {
return doc.getCreation();
}
}
getCurrentDocument = function() {
function getCurrentDocument() {
if(!Document.currentDocument) {
Document.currentDocument = new JSONDocument(JSON.parse(localStorage.getItem("currentDocument")));
}
return Document.currentDocument;
}
setCurrentDocument = function(doc) {
function setCurrentDocument(doc) {
localStorage.setItem("currentDocument",JSON.stringify(doc));
Document.currentDocument = doc;
}
......
......@@ -61,8 +61,8 @@ 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.length) { this.listnerList = [] }
this.listernerList.push({handler:handler,event:event,once:once});
if(!this.listenerList) { this.listenerList = [] }
this.listenerList.push({handler:handler,event:event,once:once});
}
/* fire an event through all the listeners of the object */
......
......@@ -14,33 +14,17 @@ setCurrentDocumentID = function(ID) {return localStorage.setItem("currentDocumen
* the detailedList object is the synchronized list containing more detailed information about documents
* @param documentList : documents information loaded from the storage
*/
var DocumentList = {
inititalize: function() {
var data = lo
},
this.detailedList = {}
if(documentList) {
for(var doc in documentList) {
this.detailedList[doc] = new JSONDocument(documentList[doc]);
}
}
var DocumentList = new UngObject();
DocumentList.load({
initialize: function() {
this.displayInformation = {};
this.displayInformation.page = 1;
this.selectionList = [];
this.detailedList = getCurrentStorage().getDocumentList();
//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;
}
});
}
recursiveTask(function() {if(JIO.isReady()){updateDocumentList()}},10000);
}
DocumentList.prototype = new UngObject();
DocumentList.prototype.load({
recursiveTask(function() {getCurrentStorage().updateDocumentList()},10000);// ! should display it if any change
},
removeDocument: function(fileName) {
getCurrentStorage().remove(fileName)//delete the file
......@@ -195,13 +179,15 @@ DocumentList.prototype.load({
this.display();
}
});
getDocumentList = function() {
function getCurrentDocumentList() {
return DocumentList;
}
function getDocumentList() {
return getCurrentStorage().getDocumentList();
}
/**
* create a line representing a document in the main table
* @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