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

Fix major bugs. stable version

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