Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
ad9d385a
Commit
ad9d385a
authored
Sep 01, 2011
by
François Billioud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comment and debug IndexedStorage
parent
360f62d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
84 deletions
+132
-84
UNGProject/unhosted/jio.js
UNGProject/unhosted/jio.js
+132
-84
No files found.
UNGProject/unhosted/jio.js
View file @
ad9d385a
...
@@ -395,114 +395,162 @@
...
@@ -395,114 +395,162 @@
},
},
/***************************************************************
*********************** IndexedStorage *************************/
/**
/**
* Class IndexedStorage
* load the list of the documents in this storage
* @class provides usual API to create an index while storing documents
* @param option : optional object containing
* @param data : object containing every element needed to build the storage
* "success" : the function to execute when the load is done
* "storage" : the storage to index
* "errorHandler" : the function to execute if an error occures
* @param applicant : object containing inforamtion about the person/application needing this JIO object
* @return null if the request is asynchronous, the list of documents otherwise.
* @example {"file1":{fileName:"file1",creationDate:"Tue, 23 Aug 2011 15:18:32 GMT",lastModified:"Tue, 23 Aug 2011 15:18:32 GMT"},...}
*/
*/
JIO
.
IndexedStorage
=
function
(
data
,
applicant
)
{
getDocumentList
:
function
(
option
)
{
this
.
storage
=
createStorage
(
data
.
storage
,
applicant
)
//create the object allowing IO in storages
var
list
=
this
.
documents
;
this
.
index
=
null
;
if
(
option
.
success
)
option
.
success
(
list
);
return
list
;
},
//initialize the index
var
storage
=
this
;
save
:
function
()
{
(
function
initialize
()
{
//try to download jio.index
localStorage
[
this
.
userName
]
=
JSON
.
stringify
(
this
.
documents
);
if
(
this
.
storage
)
{
}
this
.
storage
.
loadDocument
(
"
jio.index
"
,
"
text
"
,
function
(
data
)
{
storage
.
index
=
this
;},
function
(
error
)
{
}
if
(
error
.
status
==
404
)
{
createIndex
()}
else
{
alert
(
"
error
"
+
error
.
status
+
"
while trying to download jio.index
"
)}
});
/***************************************************************
}
else
{
//if the storage is not ready
*********************** IndexedStorage *************************/
setTimeout
(
initialize
,
50
);
/**
* Class IndexedStorage
* @class provides usual API to create an index while storing documents
* @param data : object containing every element needed to build the storage
* "storage" : the storage to index
* @param applicant : object containing inforamtion about the person/application needing this JIO object
*/
JIO
.
IndexedStorage
=
function
(
data
,
applicant
)
{
this
.
storage
=
createStorage
(
data
.
storage
,
applicant
)
//create the object allowing IO in storages
this
.
index
=
null
;
//initialize the index
var
storage
=
this
;
(
function
initialize
()
{
//try to download jio.index
if
(
storage
.
storage
)
{
var
loadOption
=
{
success
:
function
(
data
)
{
storage
.
index
=
JSON
.
parse
(
data
);},
errorHandler
:
function
(
error
)
{
if
(
error
.
status
==
404
)
{
storage
.
createIndex
()}
else
{
alert
(
"
error
"
+
error
.
status
+
"
while trying to download jio.index
"
)}
}
}
}
})()
storage
.
storage
.
loadDocument
(
"
jio.index
"
,
loadOption
);
function
createIndex
()
{
//create a new index if doesn't exist
}
else
{
//if the storage is not ready
s
torage
.
index
=
{}
//for the moment, just consider that the folder is empty
s
etTimeout
(
initialize
,
50
);
}
}
}
})()
JIO
.
IndexedStorage
.
prototype
=
{
}
/* delegate the call to the indexed storage */
JIO
.
IndexedStorage
.
prototype
=
{
userNameAvailable
:
function
()
{
return
this
.
storage
.
userNameAvailable
.
apply
(
this
.
storage
,
arguments
)},
/* delegate the call to the indexed storage */
userNameAvailable
:
function
()
{
return
this
.
storage
.
userNameAvailable
.
apply
(
this
.
storage
,
arguments
)},
/**
/**
* load either a document or only its metaData
* load either a document or only its metaData
* @param fileName : the name of the file where the data will be stored
* @param fileName : the name of the file where the data will be stored
* @param option : optional object containing
* @param option : optional object containing
* "metaDataOnly" : set to true if only metaData are wanted
* "metaDataOnly" : set to true if only metaData are wanted
* @return the content of metaData, or the content of the document
* @return the content of metaData, or the content of the document
*/
*/
loadDocument
:
function
(
fileName
,
option
)
{
loadDocument
:
function
(
fileName
,
option
)
{
var
indexedStorage
=
this
;
if
(
this
.
getIndex
()
===
undefined
)
{
setTimeout
(
function
()
{
indexedStorage
.
loadDocument
(
fileName
,
option
)},
50
);
return
null
;
}
else
{
return
option
.
metaDataOnly
?
this
.
getIndex
()[
fileName
]
:
this
.
storage
.
loadDocument
.
apply
(
this
.
storage
,
arguments
)
return
option
.
metaDataOnly
?
this
.
getIndex
()[
fileName
]
:
this
.
storage
.
loadDocument
.
apply
(
this
.
storage
,
arguments
)
},
}
},
/**
/**
* save a document in the storage and update its metaData
* save a document in the storage and update its metaData
* @param data : the data to store
* @param data : the data to store
* @param fileName : the name of the file where the data will be stored
* @param fileName : the name of the file where the data will be stored
* @param option : optional object containing
* @param option : optional object containing
* "success" : the function to execute when the save is done
* "success" : the function to execute when the save is done
* "metaData" : information to store about the document
* "metaData" : information to store about the document
*/
*/
saveDocument
:
function
(
data
,
fileName
,
option
)
{
saveDocument
:
function
(
data
,
fileName
,
option
)
{
var
fileAlreadyExist
=
this
.
getIndex
()[
fileName
];
var
indexedStorage
=
this
;
return
this
.
storage
.
saveDocument
(
data
,
fileName
,
generateSaveOption
(
fileAlreadyExist
));
if
(
this
.
getIndex
()
==
null
)
{
setTimeout
(
function
()
{
indexedStorage
.
saveDocument
(
data
,
fileName
,
option
)},
50
);
function
generateSaveOption
(
fileAlreadyExist
)
{
return
null
;
var
indexedStorage
=
this
;
}
else
{
var
saveOption
=
copy
(
option
);
var
fileAlreadyExist
=
this
.
getIndex
()[
fileName
]
!==
undefined
;
saveOption
.
success
=
function
(
data
)
{
var
instruction
=
function
()
{
var
time
=
Date
.
now
();
var
time
=
Date
.
now
();
indexedStorage
.
getIndex
()[
fileName
]
=
option
.
metaData
;
indexedStorage
.
getIndex
()[
fileName
]
=
option
.
metaData
||
{};
indexedStorage
.
getIndex
()[
fileName
].
lastModified
=
time
;
indexedStorage
.
getIndex
()[
fileName
].
lastModified
=
time
;
indexedStorage
.
getIndex
()[
fileName
].
fileName
=
fileName
;
indexedStorage
.
getIndex
()[
fileName
].
fileName
=
fileName
;
if
(
!
fileAlreadyExist
)
{
indexedStorage
.
getIndex
()[
fileName
].
creationDate
=
time
;}
if
(
!
fileAlreadyExist
)
{
indexedStorage
.
getIndex
()[
fileName
].
creationDate
=
time
;}
indexedStorage
.
save
();
indexedStorage
.
save
();
option
.
success
(
data
);
}
return
saveOption
}
}
},
option
.
success
=
addInstruction
(
instruction
,
option
.
success
,
true
);
return
this
.
storage
.
saveDocument
(
data
,
fileName
,
option
);
}
},
/**
/**
* Delete a document or a list of documents from the storage and remove its metaData from the index
* Delete a document or a list of documents from the storage and remove its metaData from the index
* Data are deleted only if the delete is successful
* Data are deleted only if the delete is successful
* @param file : fileName or array of fileNames to delete
* @param file : fileName or array of fileNames to delete
* @param option : optional object containing
* @param option : optional object containing
* "success" : the function to execute when the delete is done
* "success" : the function to execute when the delete is done
*/
*/
deleteDocument
:
function
(
file
,
option
)
{
deleteDocument
:
function
(
file
,
option
)
{
var
indexedStorage
=
this
;
var
indexedStorage
=
this
;
if
(
this
.
getIndex
()
===
undefined
)
{
setTimeout
(
function
()
{
indexedStorage
.
deleteDocument
.
call
(
indexedStorage
,
file
,
option
)},
50
);
return
null
;
}
else
{
var
newOption
=
copy
(
option
);
var
newOption
=
copy
(
option
);
newOption
.
success
=
function
()
{
newOption
.
success
=
function
()
{
if
(
option
.
success
)
{
option
.
success
()}
oneOrEach
(
file
,
deleteFileData
);
oneOrEach
(
file
,
deleteFileData
);
indexedStorage
.
save
();
indexedStorage
.
save
();
if
(
option
.
success
)
{
option
.
success
()}
}
}
return
this
.
storage
.
deleteDocument
(
file
,
newOption
);
return
this
.
storage
.
deleteDocument
(
file
,
newOption
);
}
function
deleteFileData
(
fileName
)
{
function
deleteFileData
(
fileName
)
{
delete
this
.
getIndex
()[
fileName
];
delete
indexedStorage
.
getIndex
()[
fileName
];
}
}
},
},
/**
/**
* return the list of the documents in the index
* return the list of the documents in the index
* @param option : optional object containing
* @param option : optional object containing
* "success" : the function to execute on the list
* "success" : the function to execute on the list
* @return the list of documents.
* @return the list of documents.
* @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
indexedStorage
=
this
;
if
(
this
.
getIndex
()
===
undefined
)
{
setTimeout
(
function
()
{
indexedStorage
.
getDocumentList
.
call
(
indexedStorage
,
fileName
,
option
)},
50
);
return
null
;
}
else
{
var
list
=
this
.
getIndex
();
var
list
=
this
.
getIndex
();
if
(
option
.
success
)
option
.
success
(
list
);
if
(
option
.
success
)
option
.
success
(
list
);
return
list
;
return
list
;
},
}
},
getIndex
:
function
()
{
return
this
.
index
},
save
:
function
()
{
this
.
storage
.
saveDocument
(
JSON
.
stringify
(
this
.
getIndex
()),
"
jio.index
"
,
"
text
"
,
true
);
},
createIndex
:
function
()
{
//create a new index if doesn't exist
this
.
index
=
{}
//for the moment, just consider that the folder is empty
}
}
getIndex
:
function
()
{
return
this
.
index
},
getIndex
:
function
()
{
return
this
.
index
},
save
:
function
()
{
save
:
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment