Commit df16f201 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Rename vars.

parent 4a4b4a5b
...@@ -49,7 +49,7 @@ $().ready(function() { ...@@ -49,7 +49,7 @@ $().ready(function() {
<div> <div>
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_fileName" id="input_file_name"
value="" value=""
placeholder="File name here" />&nbsp; placeholder="File name here" />&nbsp;
<button type="submit" <button type="submit"
......
...@@ -208,7 +208,7 @@ function goToObj(s){ ...@@ -208,7 +208,7 @@ function goToObj(s){
<div> <div>
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_fileName" id="input_file_name"
value="" value=""
placeholder="File name here" />&nbsp; placeholder="File name here" />&nbsp;
<button type="submit" <button type="submit"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<li class="texteditor left-nav-tools"> <li class="texteditor left-nav-tools">
<a href="#/texteditor" <a href="#/texteditor"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'textEditor'}); OfficeJS.open({app:'text_editor'});
return false;"> return false;">
<i class="icon-font"></i> <i class="icon-font"></i>
New Text Document New Text Document
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<li class="imgeditor left-nav-tools"> <li class="imgeditor left-nav-tools">
<a href="#/imgeditor" <a href="#/imgeditor"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'imgEditor'}); OfficeJS.open({app:'img_editor'});
return false;"> return false;">
<i class="icon-pencil"></i> <i class="icon-pencil"></i>
New Image New Image
...@@ -38,16 +38,16 @@ ...@@ -38,16 +38,16 @@
<li class="spreadsheet left-nav-tools"> <li class="spreadsheet left-nav-tools">
<a href="#/spreadsheet" <a href="#/spreadsheet"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'speadsheet'}); OfficeJS.open({app:'spreadsheet'});
return false;"> return false;">
<i class="icon-signal"></i> <i class="icon-signal"></i>
New Spreadsheet New Spreadsheet
</a> </a>
</li> </li>
<!-- <li class="editpreferences left-nav-tools"> --> <!-- <li class="editpreferences left-nav-tools"> -->
<!-- <a href="#/editpreferences" --> <!-- <a href="#/edit_preferences" -->
<!-- onclick="javascript: --> <!-- onclick="javascript: -->
<!-- OfficeJS.open({app:'editpreferences'}); --> <!-- OfficeJS.open({app:'edit_preferences'}); -->
<!-- return false;"> --> <!-- return false;"> -->
<!-- <i class="icon-check"></i> --> <!-- <i class="icon-check"></i> -->
<!-- Edit Preferences --> <!-- Edit Preferences -->
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<li id="nav_document_list_header left-nav-tools"> <li id="nav_document_list_header left-nav-tools">
<a href="#/doclist" <a href="#/doclist"
onclick="javascript: onclick="javascript:
OfficeJS.open({app:'documentLister'}); OfficeJS.open({app:'document_lister'});
return false;"> return false;">
<i class="icon-list"></i> <i class="icon-list"></i>
Document List Document List
......
...@@ -43,9 +43,9 @@ ...@@ -43,9 +43,9 @@
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
(function () { (function () {
var grid, onSortFunction, onClickFunction, checkboxselector, var grid, onSortFunction, onClickFunction, check_box_selector,
onRemoveSeveral, showIconFormatter, onRemoveSeveral, showIconFormatter,
documentlist = OfficeJS.cloneCurrentDocumentList(), document_list = OfficeJS.cloneCurrentDocumentList(),
columns = [], columns = [],
options = { options = {
enableCellNavigation: true, enableCellNavigation: true,
...@@ -62,18 +62,18 @@ ...@@ -62,18 +62,18 @@
var i, lm, cd, split, mime; var i, lm, cd, split, mime;
for (i = 0; i < array.length; i += 1) { for (i = 0; i < array.length; i += 1) {
// file names // file names
split = array[i].fileName.split('.'); split = array[i].name.split('.');
array[i].fileExt = ''; array[i].ext = '';
if (split.length > 1) { if (split.length > 1) {
array[i].fileExt = split[split.length-1]; array[i].ext = split[split.length-1];
split.length -= 1; split.length -= 1;
} }
array[i].fileBaseName = split.join('.'); array[i].base_name = split.join('.');
// app & icon // app & icon
mime = OfficeJS.getMimeOfExt (array[i].fileExt); mime = OfficeJS.getMimeOfExt (array[i].ext);
if (!mime) { if (!mime) {
array[i].icon = '?'; array[i].icon = '?';
array[i].app = 'textEditor'; array[i].app = 'text_editor';
} else { } else {
array[i].icon = mime.icon; array[i].icon = mime.icon;
array[i].app = mime.pref || mime.app; array[i].app = mime.pref || mime.app;
...@@ -81,51 +81,51 @@ ...@@ -81,51 +81,51 @@
// dates // dates
// FIXME : we can have 2012/1/1 12:5 // FIXME : we can have 2012/1/1 12:5
// we should have 2012/01/01 12:05 // we should have 2012/01/01 12:05
lm = (new Date(array[i].lastModified)); lm = (new Date(array[i].last_modified));
cd = (new Date(array[i].creationDate)); cd = (new Date(array[i].creation_date));
array[i].lastModified = lm.getFullYear()+'/'+ array[i].last_modified = lm.getFullYear()+'/'+
(lm.getMonth()+1)+'/'+lm.getDate()+' '+ (lm.getMonth()+1)+'/'+lm.getDate()+' '+
lm.getHours()+':'+lm.getMinutes(); lm.getHours()+':'+lm.getMinutes();
array[i].creationDate = cd.getFullYear()+'/'+ array[i].creation_date = cd.getFullYear()+'/'+
(cd.getMonth()+1)+'/'+cd.getDate()+' '+ (cd.getMonth()+1)+'/'+cd.getDate()+' '+
cd.getHours()+':'+cd.getMinutes(); cd.getHours()+':'+cd.getMinutes();
} }
}(documentlist)); }(document_list));
$(function () { $(function () {
checkboxselector = new Slick.CheckboxSelectColumn({ check_box_selector = new Slick.CheckboxSelectColumn({
cssClass: "slick-cell-checkboxsel" cssClass: "slick-cell-checkboxsel"
}); });
columns.push(checkboxselector.getColumnDefinition()); columns.push(check_box_selector.getColumnDefinition());
columns.push({id:"icon",name:"",field:"icon", columns.push({id:"icon",name:"",field:"icon",
sortable:true,resizable:false,width:24, sortable:true,resizable:false,width:24,
formatter:showIconFormatter}); formatter:showIconFormatter});
columns.push({id:"fileName",name:"Document", columns.push({id:"file_name",name:"Document",
field:"fileBaseName",sortable:true}); field:"base_name",sortable:true});
columns.push({id:"lastModified",name:"Modified", columns.push({id:"last_modified",name:"Modified",
field:"lastModified",sortable:true}); field:"last_modified",sortable:true});
columns.push({id:"creationDate",name:"Created", columns.push({id:"creation_date",name:"Created",
field:"creationDate",sortable:true}); field:"creation_date",sortable:true});
grid = new Slick.Grid("#myDocumentList", grid = new Slick.Grid("#myDocumentList",
documentlist, document_list,
columns, columns,
options); options);
grid.setSelectionModel(new Slick.RowSelectionModel( grid.setSelectionModel(new Slick.RowSelectionModel(
{selectActiveRow: false})); {selectActiveRow: false}));
grid.registerPlugin(checkboxselector); grid.registerPlugin(check_box_selector);
onSortFunction = function (e, args) { onSortFunction = function (e, args) {
var cols = args.sortCols; var cols = args.sortCols;
documentlist.sort(function (dataRow1, dataRow2) { document_list.sort(function (data_row1, data_row2) {
var i, l, field, sign, value1, value2, result; var i, l, field, sign, value1, value2, result;
for (i = 0, l = cols.length; i < l; i++) { for (i = 0, l = cols.length; i < l; i++) {
field = cols[i].sortCol.field; field = cols[i].sortCol.field;
sign = cols[i].sortAsc ? 1 : -1; sign = cols[i].sortAsc ? 1 : -1;
value1 = dataRow1[field]; value1 = data_row1[field];
value2 = dataRow2[field]; value2 = data_row2[field];
result = (value1==value2?0:(value1>value2?1:-1))*sign; result = (value1==value2?0:(value1>value2?1:-1))*sign;
if (result != 0) { if (result != 0) {
return result; return result;
...@@ -138,18 +138,18 @@ ...@@ -138,18 +138,18 @@
}; };
onClickFunction = function (e) { onClickFunction = function (e) {
var cell = grid.getCellFromEvent(e); var cell = grid.getCellFromEvent(e);
if (cell.cell === grid.getColumnIndex('fileName')) { if (cell.cell === grid.getColumnIndex('file_name')) {
OfficeJS.open({app:documentlist[cell.row].app, OfficeJS.open({app:document_list[cell.row].app,
fileName:documentlist[cell.row].fileName}); file_name:document_list[cell.row].name});
} }
}; };
onRemoveSeveral = function () { onRemoveSeveral = function () {
var documentnamesarray = [], selected, i, l; var document_name_array = [], selected, i, l;
selected = grid.getSelectedRows(); selected = grid.getSelectedRows();
for (i = 0, l = selected.length; i < l; i+= 1) { for (i = 0, l = selected.length; i < l; i+= 1) {
documentnamesarray.push(documentlist[selected[i]].fileName); document_name_array.push(document_list[selected[i]].name);
} }
OfficeJS.removeSeveralFromArray (documentnamesarray); OfficeJS.removeSeveralFromArray (document_name_array);
}; };
document.querySelector ('#slickgrid_document_lister_remove_selected'). document.querySelector ('#slickgrid_document_lister_remove_selected').
onclick = onRemoveSeveral; onclick = onRemoveSeveral;
......
<div> <div>
<input type="text" <input type="text"
name="fileName" name="fileName"
id="input_fileName" id="input_file_name"
value="" value=""
placeholder="File name here" />&nbsp; placeholder="File name here" />&nbsp;
<button type="submit" <button type="submit"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<script type="text/javascript" src="src/localorcookiestorage.js"></script> <script type="text/javascript" src="src/localorcookiestorage.js"></script>
<script type="text/javascript" src="src/jio.js"></script> <script type="text/javascript" src="src/jio.js"></script>
<script type="text/javascript" src="lib/base64/base64.js"></script> <script type="text/javascript" src="lib/base64/base64.js"></script>
<script type="text/javascript" src="lib/sjcl/sjcl.js"></script>
<script type="text/javascript" src="src/jio.storage.js"></script> <script type="text/javascript" src="src/jio.storage.js"></script>
</head> </head>
<body> <body>
......
(function () { (function () {
// Tools // Tools
var extend = function (o1,o2) { var baseName = function (file_name) {
var key; for (key in o2) { o1[key] = o2[key]; } return o1; var split = file_name.split('.');
},
baseName = function (filename) {
var split = filename.split('.');
if (split.length > 1) { if (split.length > 1) {
split.length -= 1; split.length -= 1;
return split.join('.'); return split.join('.');
} else { } else {
return filename; return file_name;
} }
}; };
...@@ -20,22 +17,22 @@ ...@@ -20,22 +17,22 @@
var that = {}, priv = {}; var that = {}, priv = {};
// Attributes // // Attributes //
priv.preference_object = { priv.preference_object = {
documentLister:'slickgrid', document_lister:'slickgrid',
editpreferences:'simplepreferenceeditor', edit_preferences:'simplepreferenceeditor',
textEditor:'elrte', text_editor:'elrte',
imgEditor:'svg-edit', img_editor:'svg-edit',
speadsheet:'jquery-sheet' spreadsheet:'jquery-sheet'
}; };
priv.app_object = { priv.app_object = {
topnavbar: { topnavbar: {
type:'nav', type:'nav',
path:'component/top_nav_bar.html', path:'component/top_nav_bar.html',
gadgetid:'page-top_nav_bar' gadget_id:'page-top_nav_bar'
}, },
leftnavbar: { leftnavbar: {
type:'nav', type:'nav',
path:'component/left_nav_bar.html', path:'component/left_nav_bar.html',
gadgetid:'page-left_nav_bar', gadget_id:'page-left_nav_bar',
bar_tools: false, bar_tools: false,
update: function () { update: function () {
var elmt; var elmt;
...@@ -51,10 +48,10 @@ ...@@ -51,10 +48,10 @@
login: { login: {
type:'loader', type:'loader',
path:'component/login.html', path:'component/login.html',
gadgetid:'page-content', gadget_id:'page-content',
getContent: function () { getContent: function () {
var tmp = { var tmp = {
userName: 'NoName', user_name: 'NoName',
password: 'NoPwd' password: 'NoPwd'
}; };
// NOTE : stringify or not ? // NOTE : stringify or not ?
...@@ -64,12 +61,12 @@ ...@@ -64,12 +61,12 @@
about: { about: {
type:'viewer', type:'viewer',
path:'component/about.html', path:'component/about.html',
gadgetid:'page-content' gadget_id:'page-content'
}, },
contact: { contact: {
type:'viewer', type:'viewer',
path:'component/contact.html', path:'component/contact.html',
gadgetid:'page-content' gadget_id:'page-content'
}, },
simplepreferenceeditor: { simplepreferenceeditor: {
// NOTE // NOTE
...@@ -80,7 +77,7 @@ ...@@ -80,7 +77,7 @@
elrte: { elrte: {
type:'editor', // means it can edit a content type:'editor', // means it can edit a content
path:'component/elrte.html', path:'component/elrte.html',
gadgetid:'page-content', gadget_id:'page-content',
ext:'html', ext:'html',
element:'#elrte_editor', element:'#elrte_editor',
getContent: function () { getContent: function () {
...@@ -93,12 +90,12 @@ ...@@ -93,12 +90,12 @@
onload: function (param) { onload: function (param) {
// FIXME : wait for initialization end // FIXME : wait for initialization end
setTimeout(function () { setTimeout(function () {
if (typeof param.fileName !== 'undefined') { if (typeof param.file_name !== 'undefined') {
$('#input_fileName').attr('value', $('#input_file_name').attr('value',
baseName(param.fileName)); baseName(param.file_name));
that.load(baseName(param.fileName)); that.load(baseName(param.file_name));
} else { } else {
$('#input_fileName').attr( $('#input_file_name').attr(
'value','untitled'); 'value','untitled');
} }
},1000); },1000);
...@@ -108,7 +105,7 @@ ...@@ -108,7 +105,7 @@
'jquery-sheet': { 'jquery-sheet': {
type:'editor', type:'editor',
path:'component/jquery-sheet.html', path:'component/jquery-sheet.html',
gadgetid:'page-content', gadget_id:'page-content',
ext:'jqs', ext:'jqs',
getContent: function () { getContent: function () {
return JSON.stringify ( return JSON.stringify (
...@@ -128,12 +125,12 @@ ...@@ -128,12 +125,12 @@
onload: function (param) { onload: function (param) {
// FIXME : wait for initialization end // FIXME : wait for initialization end
setTimeout(function () { setTimeout(function () {
if (typeof param.fileName !== 'undefined') { if (typeof param.file_name !== 'undefined') {
$('#input_fileName').attr('value', $('#input_file_name').attr('value',
baseName(param.fileName)); baseName(param.file_name));
that.load(baseName(param.fileName)); that.load(baseName(param.file_name));
} else { } else {
$('#input_fileName').attr( $('#input_file_name').attr(
'value','untitled'); 'value','untitled');
} }
},1000); },1000);
...@@ -142,7 +139,7 @@ ...@@ -142,7 +139,7 @@
'svg-edit': { 'svg-edit': {
type:'editor', type:'editor',
path:'component/svg-edit.html', path:'component/svg-edit.html',
gadgetid:'page-content', gadget_id:'page-content',
ext:'svg', ext:'svg',
frameid:'svg_edit_frame', frameid:'svg_edit_frame',
getContent: function () { getContent: function () {
...@@ -159,12 +156,12 @@ ...@@ -159,12 +156,12 @@
setTimeout(fun,1000); setTimeout(fun,1000);
} }
waitForInit(function () { waitForInit(function () {
if (typeof param.fileName !== 'undefined') { if (typeof param.file_name !== 'undefined') {
$('#input_fileName').attr('value', $('#input_file_name').attr('value',
baseName(param.fileName)); baseName(param.file_name));
that.load(baseName(param.fileName)); that.load(baseName(param.file_name));
} else { } else {
$('#input_fileName').attr( $('#input_file_name').attr(
'value','untitled'); 'value','untitled');
} }
}); });
...@@ -173,9 +170,9 @@ ...@@ -173,9 +170,9 @@
slickgrid: { slickgrid: {
type:'editor', type:'editor',
path:'component/slickgrid_document_lister.html', path:'component/slickgrid_document_lister.html',
gadgetid:'page-content', gadget_id:'page-content',
update: function () { update: function () {
OfficeJS.open({app:'documentLister',force:true}); OfficeJS.open({app:'document_lister',force:true});
} }
} }
}; };
...@@ -184,9 +181,9 @@ ...@@ -184,9 +181,9 @@
// If pref does not exist it means that the extension is very // If pref does not exist it means that the extension is very
// specific, so <app> is called instead of the default editor. // specific, so <app> is called instead of the default editor.
// NOTE : the icon may be set in the app in app_object. // NOTE : the icon may be set in the app in app_object.
html:{pref:'textEditor',app:'elrte', html:{pref:'text_editor',app:'elrte',
icon:'<i class="icon-font"></i>'}, icon:'<i class="icon-font"></i>'},
svg:{pref:'imgEditor',app:'svg-edit', svg:{pref:'img_editor',app:'svg-edit',
icon:'<i class="icon-pencil"></i>'}, icon:'<i class="icon-pencil"></i>'},
jqs:{app:'jquery-sheet', jqs:{app:'jquery-sheet',
icon:'<i class="icon-signal"></i>'} icon:'<i class="icon-signal"></i>'}
...@@ -282,7 +279,7 @@ ...@@ -282,7 +279,7 @@
console.error ('Unknown application: ' + option.app); console.error ('Unknown application: ' + option.app);
return null; return null;
} }
realgadgetid = realapp.gadgetid; realgadgetid = realapp.gadget_id;
realpath = realapp.path; realpath = realapp.path;
if (option.force || priv.data_object.currentEditor !== realapp) { if (option.force || priv.data_object.currentEditor !== realapp) {
ancientapp = priv.data_object.gadget_object[realgadgetid]; ancientapp = priv.data_object.gadget_object[realgadgetid];
...@@ -387,7 +384,7 @@ ...@@ -387,7 +384,7 @@
return; return;
} }
// if there is not any jio created // if there is not any jio created
priv.jio = JIO.createNew (storage,applicant); priv.jio = JIO.newJio (storage,applicant);
// update left nav bar // update left nav bar
leftnavbar = priv.getRealApplication ('leftnavbar'); leftnavbar = priv.getRealApplication ('leftnavbar');
if (typeof leftnavbar.update !== 'undefined') { if (typeof leftnavbar.update !== 'undefined') {
...@@ -409,10 +406,10 @@ ...@@ -409,10 +406,10 @@
} }
priv.loading_object.getlist(); priv.loading_object.getlist();
priv.jio.getDocumentList({ priv.jio.getDocumentList({
'sort':{'lastModified':'descending', 'sort':{'last_modified':'descending',
'fileName':'ascending'}, 'name':'ascending'},
'limit':{begin:0,end:50}, 'limit':{begin:0,end:50},
// 'search':{fileName:'a'}, // 'search':{name:'a'},
'maxtries':3, 'maxtries':3,
'callback':function (result) { 'callback':function (result) {
if (result.status === 'done') { if (result.status === 'done') {
...@@ -447,8 +444,8 @@ ...@@ -447,8 +444,8 @@
} }
priv.loading_object.save(); priv.loading_object.save();
priv.jio.saveDocument({ priv.jio.saveDocument({
'fileName':basename+'.'+current_editor.ext, 'name':basename+'.'+current_editor.ext,
'fileContent':current_editor.getContent(), 'content':current_editor.getContent(),
'callback':function (result) { 'callback':function (result) {
if (result.status === 'fail') { if (result.status === 'fail') {
console.error (result.message); console.error (result.message);
...@@ -472,14 +469,14 @@ ...@@ -472,14 +469,14 @@
} }
priv.loading_object.load(); priv.loading_object.load();
priv.jio.loadDocument({ priv.jio.loadDocument({
'fileName':basename+'.'+current_editor.ext, 'name':basename+'.'+current_editor.ext,
'maxtries':3, 'maxtries':3,
'callback':function (result) { 'callback':function (result) {
if (result.status === 'fail') { if (result.status === 'fail') {
console.error (result.message); console.error (result.message);
} else { } else {
current_editor.setContent( current_editor.setContent(
result.return_value.fileContent); result.return_value.content);
} }
priv.loading_object.end_load(); priv.loading_object.end_load();
} }
...@@ -498,7 +495,7 @@ ...@@ -498,7 +495,7 @@
} }
priv.loading_object.remove(); priv.loading_object.remove();
priv.jio.removeDocument({ priv.jio.removeDocument({
'fileName':name, 'name':name,
'callback':function (result) { 'callback':function (result) {
if (result.status === 'fail') { if (result.status === 'fail') {
console.error (result.message); console.error (result.message);
...@@ -523,10 +520,9 @@ ...@@ -523,10 +520,9 @@
for (i = 0, l = documentarray.length; i < l; i+= 1) { for (i = 0, l = documentarray.length; i < l; i+= 1) {
priv.loading_object.remove(); priv.loading_object.remove();
priv.jio.removeDocument({ priv.jio.removeDocument({
fileName:documentarray[i], name:documentarray[i],
callback:function (result) { callback:function (result) {
cpt += 1; cpt += 1;
console.log (result);
if (cpt === l) { if (cpt === l) {
if (typeof current_editor.update !== 'undefined') { if (typeof current_editor.update !== 'undefined') {
that.getList(current_editor.update); that.getList(current_editor.update);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// - dummyallfail // - dummyallfail
// - dummyallnotfound // - dummyallnotfound
// - dummyall3tries // - dummyall3tries
(function () { var jio_dummy_storage_loader = function ( Jio ) { (function () { var jioDummyStorageLoader = function ( Jio ) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok // Dummy Storage 1 : all ok
...@@ -33,16 +33,16 @@ ...@@ -33,16 +33,16 @@
// Returns a document object containing all information of the // Returns a document object containing all information of the
// document and its content. // document and its content.
// document object is {'fileName':string,'fileContent':string, // document object is {'name':string,'content':string,
// 'creationDate':date,'lastModified':date} // 'creation_date':date,'last_modified':date}
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
var doc = { var doc = {
'fileContent': 'content', 'content': 'content',
'fileName': 'file', 'name': 'file',
'creationDate': 10000, 'creation_date': 10000,
'lastModified': 15000}; 'last_modified': 15000};
that.done(doc); that.done(doc);
}, 100); }, 100);
}; // end loadDocument }; // end loadDocument
...@@ -51,17 +51,17 @@ ...@@ -51,17 +51,17 @@
// It returns a document array containing all the user documents // It returns a document array containing all the user documents
// informations, but not their content. // informations, but not their content.
// the list is [object,object] -> object = {'fileName':string, // the list is [object,object] -> object = {'name':string,
// 'lastModified':date,'creationDate':date} // 'last_modified':date,'creation_date':date}
setTimeout(function () { setTimeout(function () {
var list = [ var list = [
{'fileName':'file', {'name':'file',
'creationDate':10000, 'creation_date':10000,
'lastModified':15000}, 'last_modified':15000},
{'fileName':'memo', {'name':'memo',
'creationDate':20000, 'creation_date':20000,
'lastModified':25000 'last_modified':25000
}]; }];
that.done(list); that.done(list);
}, 100); }, 100);
...@@ -107,8 +107,8 @@ ...@@ -107,8 +107,8 @@
that.loadDocument = function () { that.loadDocument = function () {
// Returns a document object containing nothing. // Returns a document object containing nothing.
// document object is {'fileName':string,'fileContent':string, // document object is {'name':string,'content':string,
// 'creationDate':date,'lastModified':date} // 'creation_date':date,'last_modified':date}
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
...@@ -120,8 +120,8 @@ ...@@ -120,8 +120,8 @@
that.getDocumentList = function () { that.getDocumentList = function () {
// It returns nothing. // It returns nothing.
// the list is [object,object] -> object = {'fileName':string, // the list is [object,object] -> object = {'name':string,
// 'lastModified':date,'creationDate':date} // 'last_modified':date,'creation_date':date}
setTimeout(function () { setTimeout(function () {
that.fail({status:0,statusText:'Unknown Error', that.fail({status:0,statusText:'Unknown Error',
...@@ -171,8 +171,8 @@ ...@@ -171,8 +171,8 @@
that.loadDocument = function () { that.loadDocument = function () {
// Returns a document object containing nothing. // Returns a document object containing nothing.
// document object is {'fileName':string,'fileContent':string, // document object is {'name':string,'content':string,
// 'creationDate':date,'lastModified':date} // 'creation_date':date,'last_modified':date}
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
...@@ -185,8 +185,8 @@ ...@@ -185,8 +185,8 @@
that.getDocumentList = function () { that.getDocumentList = function () {
// It returns nothing. // It returns nothing.
// the list is [object,object] -> object = {'fileName':string, // the list is [object,object] -> object = {'name':string,
// 'lastModified':date,'creationDate':date} // 'last_modified':date,'creation_date':date}
setTimeout(function () { setTimeout(function () {
that.fail({status:404,statusText:'Not Found', that.fail({status:404,statusText:'Not Found',
...@@ -214,15 +214,15 @@ ...@@ -214,15 +214,15 @@
newDummyStorageAll3Tries = function ( spec, my ) { newDummyStorageAll3Tries = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.doJob = function (ifokreturn) { priv.doJob = function (if_ok_return) {
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
priv.Try3OKElseFail (that.cloneJob().tries,ifokreturn); priv.Try3OKElseFail (that.cloneJob().tries,if_ok_return);
}, 100); }, 100);
}; };
priv.Try3OKElseFail = function (tries,ifokreturn) { priv.Try3OKElseFail = function (tries,if_ok_return) {
if ( tries === 3 ) { if ( tries === 3 ) {
return that.done(ifokreturn); return that.done(if_ok_return);
} }
if ( tries < 3 ) { if ( tries < 3 ) {
return that.fail({message:'' + (3 - tries) + ' tries left.'}); return that.fail({message:'' + (3 - tries) + ' tries left.'});
...@@ -242,20 +242,20 @@ ...@@ -242,20 +242,20 @@
that.loadDocument = function () { that.loadDocument = function () {
priv.doJob ({ priv.doJob ({
'fileContent': 'content2', 'content': 'content2',
'fileName': 'file', 'name': 'file',
'creationDate': 11000, 'creation_date': 11000,
'lastModified': 17000 'last_modified': 17000
}); });
}; // end loadDocument }; // end loadDocument
that.getDocumentList = function () { that.getDocumentList = function () {
priv.doJob([{'fileName':'file', priv.doJob([{'name':'file',
'creationDate':10000, 'creation_date':10000,
'lastModified':15000}, 'last_modified':15000},
{'fileName':'memo', {'name':'memo',
'creationDate':20000, 'creation_date':20000,
'lastModified':25000} 'last_modified':25000}
]); ]);
}; // end getDocumentList }; // end getDocumentList
...@@ -269,25 +269,17 @@ ...@@ -269,25 +269,17 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// add key to storageObjectType of global jio // add key to storageObjectType of global jio
Jio.addStorageType('dummyallok', function (options) { Jio.addStorageType('dummyallok', newDummyStorageAllOk);
return newDummyStorageAllOk(options); Jio.addStorageType('dummyallfail', newDummyStorageAllFail);
}); Jio.addStorageType('dummyallnotfound', newDummyStorageAllNotFound);
Jio.addStorageType('dummyallfail', function (options) { Jio.addStorageType('dummyall3tries', newDummyStorageAll3Tries);
return newDummyStorageAllFail(options);
});
Jio.addStorageType('dummyallnotfound', function (options) {
return newDummyStorageAllNotFound(options);
});
Jio.addStorageType('dummyall3tries', function (options) {
return newDummyStorageAll3Tries(options);
});
}; };
if (window.requirejs) { if (window.requirejs) {
define ('JIODummyStorages',['JIO'], jio_dummy_storage_loader); define ('JIODummyStorages',['JIO'], jioDummyStorageLoader);
} else { } else {
jio_dummy_storage_loader ( JIO ); jioDummyStorageLoader ( JIO );
} }
}()); }());
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @module JIO * @module JIO
*/ */
var JIO = var JIO =
(function () { var jio_loader_function = function ( localOrCookieStorage, $ ) { (function () { var jioLoaderFunction = function ( localOrCookieStorage, $ ) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// constants // constants
...@@ -27,8 +27,8 @@ var JIO = ...@@ -27,8 +27,8 @@ var JIO =
- s: storage - s: storage
- a: applicant - a: applicant
- m: method - m: method
- n: fileName - n: name
- c: fileContent - c: content
- o: options - o: options
- =: are equal - =: are equal
- !: are not equal - !: are not equal
...@@ -96,7 +96,7 @@ var JIO = ...@@ -96,7 +96,7 @@ var JIO =
JSON.stringify (job2.storage) && JSON.stringify (job2.storage) &&
JSON.stringify (job1.applicant) === JSON.stringify (job1.applicant) ===
JSON.stringify (job2.applicant) && JSON.stringify (job2.applicant) &&
job1.fileName === job2.fileName) { job1.name === job2.name) {
return true; return true;
} }
return false; return false;
...@@ -109,7 +109,7 @@ var JIO = ...@@ -109,7 +109,7 @@ var JIO =
return false; return false;
}, },
canEliminate:function (job1,job2) { canEliminate:function (job1,job2) {
if (job1.status !== 'ongoing' && if (job1.status !== 'on_going' &&
(job1.method === 'removeDocument' && (job1.method === 'removeDocument' &&
job2.method === 'saveDocument' || job2.method === 'saveDocument' ||
job1.method === 'saveDocument' && job1.method === 'saveDocument' &&
...@@ -119,7 +119,7 @@ var JIO = ...@@ -119,7 +119,7 @@ var JIO =
return false; return false;
}, },
canReplace:function (job1,job2) { canReplace:function (job1,job2) {
if (job1.status !== 'ongoing' && if (job1.status !== 'on_going' &&
job1.method === job2.method && job1.method === job2.method &&
job1.date < job2.date) { job1.date < job2.date) {
return true; return true;
...@@ -127,7 +127,7 @@ var JIO = ...@@ -127,7 +127,7 @@ var JIO =
return false; return false;
}, },
cannotAccept:function (job1,job2) { cannotAccept:function (job1,job2) {
if (job1.status !== 'ongoing' ) { if (job1.status !== 'on_going' ) {
if (job1.method === 'removeDocument' && if (job1.method === 'removeDocument' &&
job2.method === 'loadDocument') { job2.method === 'loadDocument') {
return true; return true;
...@@ -140,7 +140,7 @@ var JIO = ...@@ -140,7 +140,7 @@ var JIO =
job2.method === 'removeDocument')) { job2.method === 'removeDocument')) {
return true; return true;
} else if (job1.method === job2.method === 'saveDocument' && } else if (job1.method === job2.method === 'saveDocument' &&
job1.fileContent === job2.fileContent) { job1.content === job2.content) {
return true; return true;
} else if (job1.method === job2.method === } else if (job1.method === job2.method ===
'getDocumentList' || 'getDocumentList' ||
...@@ -200,18 +200,18 @@ var JIO = ...@@ -200,18 +200,18 @@ var JIO =
} }
return topic; return topic;
}; };
that.publish = function (eventname,obj) { that.publish = function (event_name,obj) {
// publish an event // publish an event
priv.eventAction(eventname).publish(obj); priv.eventAction(event_name).publish(obj);
}; };
that.subscribe = function (eventname,callback) { that.subscribe = function (event_name,callback) {
// subscribe and return the callback function // subscribe and return the callback function
priv.eventAction(eventname).subscribe(callback); priv.eventAction(event_name).subscribe(callback);
return callback; return callback;
}; };
that.unsubscribe = function (eventname,callback) { that.unsubscribe = function (event_name,callback) {
// unsubscribe the callback from eventname // unsubscribe the callback from eventname
priv.eventAction(eventname).unsubscribe(callback); priv.eventAction(event_name).unsubscribe(callback);
}; };
return that; return that;
}; };
...@@ -237,14 +237,14 @@ var JIO = ...@@ -237,14 +237,14 @@ var JIO =
// spec.options.useLocalStorage: if true, save jobs into localStorage, // spec.options.useLocalStorage: if true, save jobs into localStorage,
// else only save on memory. // else only save on memory.
var that = {}, priv = {}, jio_id_array_name = 'jio/idarray'; var that = {}, priv = {}, jio_id_array_name = 'jio/id_array';
that.init = function ( options ) { that.init = function ( options ) {
// initialize the JobQueue // initialize the JobQueue
// options.publisher : is the publisher to use to send events // options.publisher : is the publisher to use to send events
// options.jio_id : the jio ID // options.jio_id : the jio ID
var k, emptyfun = function (){}, jio_id_array; var k, emptyFun = function (){}, jio_id_array;
if (priv.use_local_storage) { if (priv.use_local_storage) {
jio_id_array = localOrCookieStorage. jio_id_array = localOrCookieStorage.
getItem (jio_id_array_name)||[]; getItem (jio_id_array_name)||[];
...@@ -252,14 +252,14 @@ var JIO = ...@@ -252,14 +252,14 @@ var JIO =
priv.publisher = spec.publisher; priv.publisher = spec.publisher;
} }
priv.jio_id = options.jio_id; priv.jio_id = options.jio_id;
priv.job_object_name = 'jio/jobobject/' + priv.jio_id; priv.job_object_name = 'jio/job_object/' + priv.jio_id;
jio_id_array.push (priv.jio_id); jio_id_array.push (priv.jio_id);
localOrCookieStorage.setItem (jio_id_array_name,jio_id_array); localOrCookieStorage.setItem (jio_id_array_name,jio_id_array);
} }
priv.job_object = {}; priv.job_object = {};
that.copyJobQueueToLocalStorage(); that.copyJobQueueToLocalStorage();
for (k in priv.recovered_job_object) { for (k in priv.recovered_job_object) {
priv.recovered_job_object[k].callback = emptyfun; priv.recovered_job_object[k].callback = emptyFun;
that.addJob (priv.recovered_job_object[k]); that.addJob (priv.recovered_job_object[k]);
} }
}; };
...@@ -304,10 +304,10 @@ var JIO = ...@@ -304,10 +304,10 @@ var JIO =
jio_id_array[k]); jio_id_array[k]);
// job recovery // job recovery
priv.recovered_job_object = localOrCookieStorage. priv.recovered_job_object = localOrCookieStorage.
getItem('jio/jobobject/'+ jio_id_array[k]); getItem('jio/job_object/'+ jio_id_array[k]);
// remove ex job object // remove ex job object
localOrCookieStorage.deleteItem( localOrCookieStorage.deleteItem(
'jio/jobobject/'+ jio_id_array[k]); 'jio/job_object/'+ jio_id_array[k]);
jio_id_array_changed = true; jio_id_array_changed = true;
} else { } else {
new_jio_id_array.push (jio_id_array[k]); new_jio_id_array.push (jio_id_array[k]);
...@@ -353,8 +353,8 @@ var JIO = ...@@ -353,8 +353,8 @@ var JIO =
// It also clean fail or done jobs. // It also clean fail or done jobs.
// job = the job object // job = the job object
var newone = true, elim_array = [], wait_array = [], var new_one = true, elim_array = [], wait_array = [],
remove_array = [], basestorage = null, id = 'id'; remove_array = [], base_storage = null, id = 'id';
//// browsing current jobs //// browsing current jobs
for (id in priv.job_object) { for (id in priv.job_object) {
...@@ -372,10 +372,10 @@ var JIO = ...@@ -372,10 +372,10 @@ var JIO =
} }
if (jio_global_obj.job_managing_method.canReplace( if (jio_global_obj.job_managing_method.canReplace(
priv.job_object[id],job)) { priv.job_object[id],job)) {
basestorage = newBaseStorage( base_storage = newBaseStorage(
{'queue':that,'job':priv.job_object[id]}); {'queue':that,'job':priv.job_object[id]});
basestorage.replace(job); base_storage.replace(job);
newone = false; new_one = false;
break; break;
} }
if (jio_global_obj.job_managing_method.cannotAccept( if (jio_global_obj.job_managing_method.cannotAccept(
...@@ -394,21 +394,21 @@ var JIO = ...@@ -394,21 +394,21 @@ var JIO =
} }
//// end browsing current jobs //// end browsing current jobs
if (newone) { if (new_one) {
// if it is a new job, we can eliminate deprecated jobs and // if it is a new job, we can eliminate deprecated jobs and
// set this job dependencies. // set this job dependencies.
for (id = 0; id < elim_array.length; id += 1) { for (id = 0; id < elim_array.length; id += 1) {
basestorage = newBaseStorage( base_storage = newBaseStorage(
{'queue':that, {'queue':that,
'job':priv.job_object[elim_array[id]]}); 'job':priv.job_object[elim_array[id]]});
basestorage.eliminate(); base_storage.eliminate();
} }
if (wait_array.length > 0) { if (wait_array.length > 0) {
job.status = 'wait'; job.status = 'wait';
job.waitingFor = {'jobIdArray':wait_array}; job.waiting_for = {'job_id_array':wait_array};
for (id = 0; id < wait_array.length; id += 1) { for (id = 0; id < wait_array.length; id += 1) {
if (priv.job_object[wait_array[id]]) { if (priv.job_object[wait_array[id]]) {
priv.job_object[wait_array[id]].maxtries = 1; priv.job_object[wait_array[id]].max_tries = 1;
} }
} }
} }
...@@ -485,24 +485,24 @@ var JIO = ...@@ -485,24 +485,24 @@ var JIO =
} else if (priv.job_object[i].status === 'wait') { } else if (priv.job_object[i].status === 'wait') {
ok = true; ok = true;
// if status wait // if status wait
if (priv.job_object[i].waitingFor.jobIdArray) { if (priv.job_object[i].waiting_for.job_id_array) {
// wait job // wait job
// browsing job id array // browsing job id array
for (j = 0; for (j = 0;
j < priv.job_object[i]. j < priv.job_object[i].
waitingFor.jobIdArray.length; waiting_for.job_id_array.length;
j += 1) { j += 1) {
if (priv.job_object[priv.job_object[i]. if (priv.job_object[priv.job_object[i].
waitingFor.jobIdArray[j]]) { waiting_for.job_id_array[j]]) {
// if a job is still exist, don't invoke // if a job is still exist, don't invoke
ok = false; ok = false;
break; break;
} }
} }
} }
if (priv.job_object[i].waitingFor.time) { if (priv.job_object[i].waiting_for.time) {
// wait time // wait time
if (priv.job_object[i].waitingFor.time > Date.now()) { if (priv.job_object[i].waiting_for.time > Date.now()) {
// it is not time to restore the job! // it is not time to restore the job!
ok = false; ok = false;
} }
...@@ -521,7 +521,7 @@ var JIO = ...@@ -521,7 +521,7 @@ var JIO =
that.invoke = function (job) { that.invoke = function (job) {
// Do a job invoking the good method in the good storage. // Do a job invoking the good method in the good storage.
var basestorage; var base_storage;
//// analysing job method //// analysing job method
// if the method does not exist, do nothing // if the method does not exist, do nothing
...@@ -534,15 +534,15 @@ var JIO = ...@@ -534,15 +534,15 @@ var JIO =
return (testjob.method === job.method && return (testjob.method === job.method &&
testjob.method === 'initial'); testjob.method === 'initial');
})) { })) {
job.status = 'ongoing'; job.status = 'on_going';
priv.publisher.publish(jio_const_obj.job_method_object[ priv.publisher.publish(jio_const_obj.job_method_object[
job.method]['start_'+job.method]); job.method]['start_'+job.method]);
} else { } else {
job.status = 'ongoing'; job.status = 'on_going';
} }
// Create a storage object and use it to save,load,...! // Create a storage object and use it to save,load,...!
basestorage = newBaseStorage({'queue':this,'job':job}); base_storage = newBaseStorage({'queue':this,'job':job});
basestorage.execute(); base_storage.execute();
//// end method analyse //// end method analyse
}; };
...@@ -563,7 +563,7 @@ var JIO = ...@@ -563,7 +563,7 @@ var JIO =
if (!that.isThereJobsWhere(function(testjob){ if (!that.isThereJobsWhere(function(testjob){
return (testjob.method === job.method && return (testjob.method === job.method &&
// testjob.status === 'wait' || // TODO ? // testjob.status === 'wait' || // TODO ?
testjob.status === 'ongoing' || testjob.status === 'on_going' ||
testjob.status === 'initial'); testjob.status === 'initial');
})) { })) {
priv.publisher.publish( priv.publisher.publish(
...@@ -711,7 +711,7 @@ var JIO = ...@@ -711,7 +711,7 @@ var JIO =
priv.res.message = 'Unable to check name availability.'; priv.res.message = 'Unable to check name availability.';
}; };
priv.done_checkNameAvailability = function ( isavailable ) { priv.done_checkNameAvailability = function ( isavailable ) {
priv.res.message = priv.job.userName + ' is ' + priv.res.message = priv.job.user_name + ' is ' +
(isavailable?'':'not ') + 'available.'; (isavailable?'':'not ') + 'available.';
priv.res.return_value = isavailable; priv.res.return_value = isavailable;
}; };
...@@ -722,10 +722,10 @@ var JIO = ...@@ -722,10 +722,10 @@ var JIO =
priv.res.message = 'Document loaded.'; priv.res.message = 'Document loaded.';
priv.res.return_value = returneddocument; priv.res.return_value = returneddocument;
// transform date into ms // transform date into ms
priv.res.return_value.lastModified = priv.res.return_value.last_modified =
new Date(priv.res.return_value.lastModified).getTime(); new Date(priv.res.return_value.last_modified).getTime();
priv.res.return_value.creationDate = priv.res.return_value.creation_date =
new Date(priv.res.return_value.creationDate).getTime(); new Date(priv.res.return_value.creation_date).getTime();
}; };
priv.fail_saveDocument = function () { priv.fail_saveDocument = function () {
priv.res.message = 'Unable to save document.'; priv.res.message = 'Unable to save document.';
...@@ -743,14 +743,14 @@ var JIO = ...@@ -743,14 +743,14 @@ var JIO =
for (i = 0; i < priv.res.return_value.length; i += 1) { for (i = 0; i < priv.res.return_value.length; i += 1) {
// transform current date format into ms since 1/1/1970 // transform current date format into ms since 1/1/1970
// useful for easy comparison // useful for easy comparison
if (typeof priv.res.return_value[i].lastModified !== 'number') { if (typeof priv.res.return_value[i].last_modified !== 'number') {
priv.res.return_value[i].lastModified = priv.res.return_value[i].last_modified =
new Date(priv.res.return_value[i].lastModified). new Date(priv.res.return_value[i].last_modified).
getTime(); getTime();
} }
if (typeof priv.res.return_value[i].creationDate !== 'number') { if (typeof priv.res.return_value[i].creation_date !== 'number') {
priv.res.return_value[i].creationDate = priv.res.return_value[i].creation_date =
new Date(priv.res.return_value[i].creationDate). new Date(priv.res.return_value[i].creation_date).
getTime(); getTime();
} }
} }
...@@ -788,7 +788,7 @@ var JIO = ...@@ -788,7 +788,7 @@ var JIO =
time = jio_global_obj.max_wait_time; time = jio_global_obj.max_wait_time;
} }
priv.job.status = 'wait'; priv.job.status = 'wait';
priv.job.waitingFor = {'time':Date.now() + time}; priv.job.waiting_for = {'time':Date.now() + time};
}; };
//// end Private Methods //// end Private Methods
...@@ -797,43 +797,43 @@ var JIO = ...@@ -797,43 +797,43 @@ var JIO =
return $.extend(true,{},priv.job); return $.extend(true,{},priv.job);
}; };
that.getUserName = function () { that.getUserName = function () {
return priv.job.userName || ''; return priv.job.user_name || '';
}; };
that.getApplicantID = function () { that.getApplicantID = function () {
return priv.job.applicant.ID || ''; return priv.job.applicant.ID || '';
}; };
that.getStorageUserName = function () { that.getStorageUserName = function () {
return priv.job.storage.userName || ''; return priv.job.storage.user_name || '';
}; };
that.getStoragePassword = function () { that.getStoragePassword = function () {
return priv.job.storage.password || ''; return priv.job.storage.password || '';
}; };
that.getStorageLocation = function () { that.getStorageURL = function () {
return priv.job.storage.location || ''; return priv.job.storage.url || '';
}; };
that.getSecondStorage = function () { that.getSecondStorage = function () {
return priv.job.storage.storage || {}; return priv.job.storage.storage || {};
}; };
that.getStorageArray = function () { that.getStorageArray = function () {
return priv.job.storage.storageArray || []; return priv.job.storage.storage_array || [];
}; };
that.getFileName = function () { that.getFileName = function () {
return priv.job.fileName || ''; return priv.job.name || '';
}; };
that.getFileContent = function () { that.getFileContent = function () {
return priv.job.fileContent || ''; return priv.job.content || '';
}; };
that.cloneOptionObject = function () { that.cloneOptionObject = function () {
return $.extend(true,{},priv.job.options); return $.extend(true,{},priv.job.options);
}; };
that.getMaxTries = function () { that.getMaxTries = function () {
return priv.job.maxtries; return priv.job.max_tries;
}; };
that.getTries = function () { that.getTries = function () {
return priv.job.tries || 0; return priv.job.tries || 0;
}; };
that.setMaxTries = function (maxtries) { that.setMaxTries = function (max_tries) {
priv.job.maxtries = maxtries; priv.job.max_tries = max_tries;
}; };
//// end Getters Setters //// end Getters Setters
...@@ -844,7 +844,7 @@ var JIO = ...@@ -844,7 +844,7 @@ var JIO =
that.eliminate = function () { that.eliminate = function () {
// Stop and remove a job ! // Stop and remove a job !
priv.job.maxtries = 1; priv.job.max_tries = 1;
priv.job.tries = 1; priv.job.tries = 1;
that.fail('Job Stopped!',0); that.fail('Job Stopped!',0);
}; };
...@@ -879,8 +879,8 @@ var JIO = ...@@ -879,8 +879,8 @@ var JIO =
priv.res.error.array = priv.res.error.array || []; priv.res.error.array = priv.res.error.array || [];
priv.res.error.message = priv.res.error.message || ''; priv.res.error.message = priv.res.error.message || '';
// retry ? // retry ?
if (!priv.job.maxtries || if (!priv.job.max_tries ||
priv.job.tries < priv.job.maxtries) { priv.job.tries < priv.job.max_tries) {
priv.retryLater(); priv.retryLater();
} else { } else {
priv.job.status = 'fail'; priv.job.status = 'fail';
...@@ -1135,7 +1135,7 @@ var JIO = ...@@ -1135,7 +1135,7 @@ var JIO =
// - true if the job was added or replaced // - true if the job was added or replaced
// example : // example :
// jio.checkNameAvailability({'userName':'myName','callback': // jio.checkNameAvailability({'user_name':'myName','callback':
// function (result) { // function (result) {
// if (result.status === 'done') { // if (result.status === 'done') {
// if (result.return_value === true) { // available // if (result.return_value === true) { // available
...@@ -1144,14 +1144,14 @@ var JIO = ...@@ -1144,14 +1144,14 @@ var JIO =
// }}); // }});
var settings = $.extend (true,{ var settings = $.extend (true,{
'userName': priv.storage.userName, 'user_name': priv.storage.user_name,
'storage': priv.storage, 'storage': priv.storage,
'applicant': priv.applicant, 'applicant': priv.applicant,
'method': 'checkNameAvailability', 'method': 'checkNameAvailability',
'callback': function () {} 'callback': function () {}
},options); },options);
// check dependencies // check dependencies
if (that.isReady() && settings.userName && if (that.isReady() && settings.user_name &&
settings.storage && settings.applicant) { settings.storage && settings.applicant) {
return priv.queue.createJob ( settings ); return priv.queue.createJob ( settings );
} }
...@@ -1170,7 +1170,7 @@ var JIO = ...@@ -1170,7 +1170,7 @@ var JIO =
// - false if the job was not added // - false if the job was not added
// - true if the job was added or replaced // - true if the job was added or replaced
// jio.saveDocument({'fileName':'file','fileContent':'content', // jio.saveDocument({'name':'file','content':'content',
// 'callback': function (result) { // 'callback': function (result) {
// if (result.status === 'done') { // Saved // if (result.status === 'done') { // Saved
// } else { } // Error // } else { } // Error
...@@ -1179,12 +1179,12 @@ var JIO = ...@@ -1179,12 +1179,12 @@ var JIO =
var settings = $.extend(true,{ var settings = $.extend(true,{
'storage': priv.storage, 'storage': priv.storage,
'applicant': priv.applicant, 'applicant': priv.applicant,
'fileContent': '', 'content': '',
'method':'saveDocument', 'method':'saveDocument',
'callback': function () {} 'callback': function () {}
},options); },options);
// check dependencies // check dependencies
if (that.isReady() && settings.fileName && if (that.isReady() && settings.name &&
settings.storage && settings.applicant) { settings.storage && settings.applicant) {
return priv.queue.createJob ( settings ); return priv.queue.createJob ( settings );
} }
...@@ -1194,7 +1194,7 @@ var JIO = ...@@ -1194,7 +1194,7 @@ var JIO =
that.loadDocument = function ( options ) { that.loadDocument = function ( options ) {
// Load a document in the storage set in [options] // Load a document in the storage set in [options]
// or in the storage set at init. At the end of the job, // or in the storage set at init. At the end of the job,
// 'job_done' will be sent with this job and its 'fileContent' // 'job_done' will be sent with this job and its 'content'
// return value. // return value.
// options.storage : the storage where to load (optional) // options.storage : the storage where to load (optional)
// options.applicant : the applicant (optional) // options.applicant : the applicant (optional)
...@@ -1204,15 +1204,15 @@ var JIO = ...@@ -1204,15 +1204,15 @@ var JIO =
// - false if the job was not added // - false if the job was not added
// - true if the job was added or replaced // - true if the job was added or replaced
// jio.loadDocument({'fileName':'file','callback': // jio.loadDocument({'name':'file','callback':
// function (result) { // function (result) {
// if (result.status === 'done') { // Loaded // if (result.status === 'done') { // Loaded
// } else { } // Error // } else { } // Error
// }}); // }});
// result.return_value is a document object that looks like { // result.return_value is a document object that looks like {
// fileName:'string',fileContent:'string', // name:'string',content:'string',
// creationDate:123,lastModified:456 } // creation_date:123,last_modified:456 }
var settings = $.extend (true,{ var settings = $.extend (true,{
'storage': priv.storage, 'storage': priv.storage,
...@@ -1221,7 +1221,7 @@ var JIO = ...@@ -1221,7 +1221,7 @@ var JIO =
'callback': function(){} 'callback': function(){}
},options); },options);
// check dependencies // check dependencies
if (that.isReady() && settings.fileName && if (that.isReady() && settings.name &&
settings.storage && settings.applicant) { settings.storage && settings.applicant) {
return priv.queue.createJob ( settings ); return priv.queue.createJob ( settings );
} }
...@@ -1272,7 +1272,7 @@ var JIO = ...@@ -1272,7 +1272,7 @@ var JIO =
// - false if the job was not added // - false if the job was not added
// - true if the job was added or replaced // - true if the job was added or replaced
// jio.removeDocument({'fileName':'file','callback': // jio.removeDocument({'name':'file','callback':
// function (result) { // function (result) {
// if(result.status === 'done') { // Removed // if(result.status === 'done') { // Removed
// } else { } // Not Removed // } else { } // Not Removed
...@@ -1284,7 +1284,7 @@ var JIO = ...@@ -1284,7 +1284,7 @@ var JIO =
'method':'removeDocument', 'method':'removeDocument',
'callback':function (){} 'callback':function (){}
},options); },options);
if (that.isReady() && settings.fileName && if (that.isReady() && settings.name &&
settings.storage && settings.applicant ) { settings.storage && settings.applicant ) {
return priv.queue.createJob ( settings ); return priv.queue.createJob ( settings );
} }
...@@ -1340,7 +1340,7 @@ var JIO = ...@@ -1340,7 +1340,7 @@ var JIO =
var that = {}; var that = {};
// Jio creator object // Jio creator object
// this object permit to create jio object // this object permit to create jio object
that.createNew = function ( storage, applicant, options ) { that.newJio = function ( storage, applicant, options ) {
// Return a new instance of JIO // Return a new instance of JIO
// storage: the storage object or json string // storage: the storage object or json string
// applicant: the applicant object or json string // applicant: the applicant object or json string
...@@ -1387,10 +1387,10 @@ var JIO = ...@@ -1387,10 +1387,10 @@ var JIO =
}; };
if (window.requirejs) { if (window.requirejs) {
define ('JIO',['LocalOrCookieStorage','jQuery'],jio_loader_function); define ('JIO',['LocalOrCookieStorage','jQuery'],jioLoaderFunction);
return undefined; return undefined;
} else { } else {
return jio_loader_function ( LocalOrCookieStorage, jQuery ); return jioLoaderFunction ( LocalOrCookieStorage, jQuery );
} }
}()); }());
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* @module JIOStorages * @module JIOStorages
*/ */
(function () { (function () {
var jio_storage_loader = var jioStorageLoader =
function ( LocalOrCookieStorage, $, Base64, sjcl, Jio) { function ( LocalOrCookieStorage, $, Base64, sjcl, Jio) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
var that = Jio.newBaseStorage( spec, my ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storage_user_array_name = 'jio/localuserarray'; priv.storage_user_array_name = 'jio/local_user_array';
priv.storage_file_array_name = 'jio/localfilenamearray/' + priv.storage_file_array_name = 'jio/local_file_name_array/' +
that.getStorageUserName() + '/' + that.getApplicantID(); that.getStorageUserName() + '/' + that.getApplicantID();
/** /**
...@@ -52,25 +52,25 @@ ...@@ -52,25 +52,25 @@
/** /**
* Adds a user to the user list. * Adds a user to the user list.
* @method addUser * @method addUser
* @param {string} username The user name. * @param {string} user_name The user name.
*/ */
priv.addUser = function (username) { priv.addUser = function (user_name) {
var userarray = priv.getUserArray(); var user_array = priv.getUserArray();
userarray.push(username); user_array.push(user_name);
LocalOrCookieStorage.setItem(priv.storage_user_array_name, LocalOrCookieStorage.setItem(priv.storage_user_array_name,
userarray); user_array);
}; };
/** /**
* checks if a user exists in the user array. * checks if a user exists in the user array.
* @method userExists * @method userExists
* @param {string} username The user name * @param {string} user_name The user name
* @return {boolean} true if exist, else false * @return {boolean} true if exist, else false
*/ */
priv.userExists = function (username) { priv.userExists = function (user_name) {
var userarray = priv.getUserArray(), i, l; var user_array = priv.getUserArray(), i, l;
for (i = 0, l = userarray.length; i < l; i += 1) { for (i = 0, l = user_array.length; i < l; i += 1) {
if (userarray[i] === username) { if (user_array[i] === user_name) {
return true; return true;
} }
} }
...@@ -90,29 +90,29 @@ ...@@ -90,29 +90,29 @@
/** /**
* Adds a file name to the local file name array. * Adds a file name to the local file name array.
* @method addFileName * @method addFileName
* @param {string} filename The new file name. * @param {string} file_name The new file name.
*/ */
priv.addFileName = function (filename) { priv.addFileName = function (file_name) {
var filenamearray = priv.getFileNameArray(); var file_name_array = priv.getFileNameArray();
filenamearray.push(filename); file_name_array.push(file_name);
LocalOrCookieStorage.setItem(priv.storage_file_array_name, LocalOrCookieStorage.setItem(priv.storage_file_array_name,
filenamearray); file_name_array);
}; };
/** /**
* Removes a file name from the local file name array. * Removes a file name from the local file name array.
* @method removeFileName * @method removeFileName
* @param {string} filename The file name to remove. * @param {string} file_name The file name to remove.
*/ */
priv.removeFileName = function (filename) { priv.removeFileName = function (file_name) {
var i, l, array = priv.getFileNameArray(), newarray = []; var i, l, array = priv.getFileNameArray(), new_array = [];
for (i = 0, l = array.length; i < l; i+= 1) { for (i = 0, l = array.length; i < l; i+= 1) {
if (array[i] !== filename) { if (array[i] !== file_name) {
newarray.push(array[i]); new_array.push(array[i]);
} }
} }
LocalOrCookieStorage.setItem(priv.storage_file_array_name, LocalOrCookieStorage.setItem(priv.storage_file_array_name,
newarray); new_array);
}; };
/** /**
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
/** /**
* Saves a document in the local storage. * Saves a document in the local storage.
* It will store the file in 'jio/local/USR/APP/FILENAME'. * It will store the file in 'jio/local/USR/APP/FILE_NAME'.
* @method saveDocument * @method saveDocument
*/ */
that.saveDocument = function () { that.saveDocument = function () {
...@@ -144,10 +144,10 @@ ...@@ -144,10 +144,10 @@
if (!doc) { if (!doc) {
// create document // create document
doc = { doc = {
'fileName': that.getFileName(), 'name': that.getFileName(),
'fileContent': that.getFileContent(), 'content': that.getFileContent(),
'creationDate': Date.now(), 'creation_date': Date.now(),
'lastModified': Date.now() 'last_modified': Date.now()
}; };
if (!priv.userExists()){ if (!priv.userExists()){
priv.addUser (that.getStorageUserName()); priv.addUser (that.getStorageUserName());
...@@ -155,8 +155,8 @@ ...@@ -155,8 +155,8 @@
priv.addFileName(that.getFileName()); priv.addFileName(that.getFileName());
} else { } else {
// overwriting // overwriting
doc.lastModified = Date.now(); doc.last_modified = Date.now();
doc.fileContent = that.getFileContent(); doc.content = that.getFileContent();
} }
LocalOrCookieStorage.setItem(path, doc); LocalOrCookieStorage.setItem(path, doc);
return that.done(); return that.done();
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
/** /**
* Loads a document from the local storage. * Loads a document from the local storage.
* It will load file in 'jio/local/USR/APP/FILENAME'. * It will load file in 'jio/local/USR/APP/FILE_NAME'.
* You can add an 'options' object to the job, it can contain: * You can add an 'options' object to the job, it can contain:
* - metadata_only {boolean} default false, retrieve the file metadata * - metadata_only {boolean} default false, retrieve the file metadata
* only if true. * only if true.
...@@ -174,8 +174,8 @@ ...@@ -174,8 +174,8 @@
* @method loadDocument * @method loadDocument
*/ */
that.loadDocument = function () { that.loadDocument = function () {
// document object is {'fileName':string,'fileContent':string, // document object is {'name':string,'content':string,
// 'creationDate':date,'lastModified':date} // 'creation_date':date,'last_modified':date}
setTimeout(function () { setTimeout(function () {
var doc = null, settings = that.cloneOptionObject(); var doc = null, settings = that.cloneOptionObject();
...@@ -189,10 +189,10 @@ ...@@ -189,10 +189,10 @@
'" not found in localStorage.'}); '" not found in localStorage.'});
} else { } else {
if (settings.metadata_only) { if (settings.metadata_only) {
delete doc.fileContent; delete doc.content;
} else if (settings.content_only) { } else if (settings.content_only) {
delete doc.lastModified; delete doc.last_modified;
delete doc.creationDate; delete doc.creation_date;
} }
that.done(doc); that.done(doc);
} }
...@@ -206,24 +206,24 @@ ...@@ -206,24 +206,24 @@
* @method getDocumentList * @method getDocumentList
*/ */
that.getDocumentList = function () { that.getDocumentList = function () {
// the list is [object,object] -> object = {'fileName':string, // the list is [object,object] -> object = {'name':string,
// 'lastModified':date,'creationDate':date} // 'last_modified':date,'creation_date':date}
setTimeout(function () { setTimeout(function () {
var newarray = [], array = [], i, l, k = 'key', var new_array = [], array = [], i, l, k = 'key',
path = 'jio/local/'+that.getStorageUserName()+'/'+ path = 'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID(), fileObject = {}; that.getApplicantID(), file_object = {};
array = priv.getFileNameArray(); array = priv.getFileNameArray();
for (i = 0, l = array.length; i < l; i += 1) { for (i = 0, l = array.length; i < l; i += 1) {
fileObject = file_object =
LocalOrCookieStorage.getItem(path+'/'+array[i]); LocalOrCookieStorage.getItem(path+'/'+array[i]);
newarray.push ({ new_array.push ({
'fileName':fileObject.fileName, 'name':file_object.name,
'creationDate':fileObject.creationDate, 'creation_date':file_object.creation_date,
'lastModified':fileObject.lastModified}); 'last_modified':file_object.last_modified});
} }
that.done(newarray); that.done(new_array);
}, 100); }, 100);
}; // end getDocumentList }; // end getDocumentList
...@@ -257,17 +257,17 @@ ...@@ -257,17 +257,17 @@
that.mkcol = function ( options ) { that.mkcol = function ( options ) {
// create folders in dav storage, synchronously // create folders in dav storage, synchronously
// options : contains mkcol list // options : contains mkcol list
// options.location : the davstorage locations // options.url : the davstorage url
// options.path: if path=/foo/bar then creates location/dav/foo/bar // options.path: if path=/foo/bar then creates url/dav/foo/bar
// options.success: the function called if success // options.success: the function called if success
// options.userName: the username // options.user_name: the user name
// options.password: the password // options.password: the password
// TODO this method is not working !!! // TODO this method is not working !!!
var settings = $.extend ({ var settings = $.extend ({
'success':function(){},'error':function(){}},options), 'success':function(){},'error':function(){}},options),
splitpath = ['splitedpath'], tmppath = 'temp/path'; split_path = ['split_path'], tmp_path = 'temp/path';
// if pathstep is not defined, then split the settings.path // if pathstep is not defined, then split the settings.path
// and do mkcol recursively // and do mkcol recursively
...@@ -275,25 +275,25 @@ ...@@ -275,25 +275,25 @@
settings.pathsteps = 1; settings.pathsteps = 1;
that.mkcol(settings); that.mkcol(settings);
} else { } else {
splitpath = settings.path.split('/'); split_path = settings.path.split('/');
// // check if the path is terminated by '/' // // check if the path is terminated by '/'
// if (splitpath[splitpath.length-1] == '') { // if (split_path[split_path.length-1] == '') {
// splitpath.length --; // split_path.length --;
// } // }
// check if the pathstep is lower than the longer // check if the pathstep is lower than the longer
if (settings.pathsteps >= splitpath.length-1) { if (settings.pathsteps >= split_path.length-1) {
return settings.success(); return settings.success();
} }
splitpath.length = settings.pathsteps + 1; split_path.length = settings.pathsteps + 1;
settings.pathsteps++; settings.pathsteps++;
tmppath = splitpath.join('/'); tmp_path = split_path.join('/');
// alert(settings.location + tmppath); // alert(settings.url + tmp_path);
$.ajax ( { $.ajax ( {
url: settings.location + tmppath, url: settings.url + tmp_path,
type: 'MKCOL', type: 'MKCOL',
async: true, async: true,
headers: {'Authorization': 'Basic '+Base64.encode( headers: {'Authorization': 'Basic '+Base64.encode(
settings.userName + ':' + settings.user_name + ':' +
settings.password ), Depth: '1'}, settings.password ), Depth: '1'},
// xhrFields: {withCredentials: 'true'}, // cross domain // xhrFields: {withCredentials: 'true'}, // cross domain
success: function () { success: function () {
...@@ -317,16 +317,16 @@ ...@@ -317,16 +317,16 @@
}; };
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// checks the availability of the [job.userName]. // checks the availability of the [job.user_name].
// if the name already exists, it is not available. // if the name already exists, it is not available.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.url: the dav storage url.
// this.job.userName: the name we want to check. // this.job.user_name: the name we want to check.
// this.job.storage.userName: the user name. // this.job.storage.user_name: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
$.ajax ( { $.ajax ( {
url: that.getStorageLocation() + '/dav/' + url: that.getStorageURL() + '/dav/' +
that.getStorageUserName() + '/', that.getStorageUserName() + '/',
async: true, async: true,
type: 'PROPFIND', type: 'PROPFIND',
...@@ -352,16 +352,16 @@ ...@@ -352,16 +352,16 @@
that.saveDocument = function () { that.saveDocument = function () {
// Save a document in a DAVStorage // Save a document in a DAVStorage
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.userName: the user name. // this.job.storage.user_name: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant ID. // this.job.applicant.ID: the applicant ID.
// this.job.fileName: the document name. // this.job.name: the document name.
// this.job.fileContent: the document content. // this.job.content: the document content.
// TODO if path of /dav/user/applic does not exists, it won't work! // TODO if path of /dav/user/applic does not exists, it won't work!
//// save on dav //// save on dav
$.ajax ( { $.ajax ( {
url: that.getStorageLocation() + '/dav/' + url: that.getStorageURL() + '/dav/' +
that.getStorageUserName() + '/' + that.getStorageUserName() + '/' +
that.getApplicantID() + '/' + that.getApplicantID() + '/' +
that.getFileName(), that.getFileName(),
...@@ -387,21 +387,21 @@ ...@@ -387,21 +387,21 @@
that.loadDocument = function () { that.loadDocument = function () {
// Load a document from a DAVStorage. It returns a document object // Load a document from a DAVStorage. It returns a document object
// containing all information of the document and its content. // containing all information of the document and its content.
// this.job.fileName: the document name we want to load. // this.job.name: the document name we want to load.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.url: the dav storage url.
// this.job.storage.userName: the user name. // this.job.storage.userName: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.options.getContent: if true, also get the file content. // this.job.options.getContent: if true, also get the file content.
// document object is {'fileName':string,'fileContent':string, // document object is {'name':string,'content':string,
// 'creationDate':date,'lastModified':date} // 'creation_date':date,'last_modified':date}
var doc = {}, var doc = {},
settings = that.cloneOptionObject(), settings = that.cloneOptionObject(),
getContent = function () { getContent = function () {
$.ajax ( { $.ajax ( {
url: that.getStorageLocation() + '/dav/' + url: that.getStorageURL() + '/dav/' +
that.getStorageUserName() + '/' + that.getStorageUserName() + '/' +
that.getApplicantID() + '/' + that.getApplicantID() + '/' +
that.getFileName(), that.getFileName(),
...@@ -413,7 +413,7 @@ ...@@ -413,7 +413,7 @@
that.getStoragePassword() )}, that.getStoragePassword() )},
// xhrFields: {withCredentials: 'true'}, // cross domain // xhrFields: {withCredentials: 'true'}, // cross domain
success: function (content) { success: function (content) {
doc.fileContent = content; doc.content = content;
that.done(doc); that.done(doc);
}, },
error: function (type) { error: function (type) {
...@@ -430,14 +430,14 @@ ...@@ -430,14 +430,14 @@
} }
} ); } );
}; };
doc.fileName = that.getFileName(); doc.name = that.getFileName();
if (settings.content_only) { if (settings.content_only) {
getContent(); getContent();
return; return;
} }
// Get properties // Get properties
$.ajax ( { $.ajax ( {
url: that.getStorageLocation() + '/dav/' + url: that.getStorageURL() + '/dav/' +
that.getStorageUserName() + '/' + that.getStorageUserName() + '/' +
that.getApplicantID() + '/' + that.getApplicantID() + '/' +
that.getFileName(), that.getFileName(),
...@@ -448,16 +448,16 @@ ...@@ -448,16 +448,16 @@
that.getStorageUserName() + ':' + that.getStorageUserName() + ':' +
that.getStoragePassword() )}, that.getStoragePassword() )},
success: function (xmlData) { success: function (xmlData) {
// doc.lastModified = // doc.last_modified =
$(xmlData).find( $(xmlData).find(
'lp1\\:getlastmodified, getlastmodified' 'lp1\\:getlastmodified, getlastmodified'
).each( function () { ).each( function () {
doc.lastModified = $(this).text(); doc.last_modified = $(this).text();
}); });
$(xmlData).find( $(xmlData).find(
'lp1\\:creationdate, creationdate' 'lp1\\:creationdate, creationdate'
).each( function () { ).each( function () {
doc.creationDate = $(this).text(); doc.creation_date = $(this).text();
}); });
if (!settings.metadata_only) { if (!settings.metadata_only) {
getContent(); getContent();
...@@ -477,18 +477,18 @@ ...@@ -477,18 +477,18 @@
// Get a document list from a DAVStorage. It returns a document // Get a document list from a DAVStorage. It returns a document
// array containing all the user documents informations. // array containing all the user documents informations.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.url: the dav storage url.
// this.job.storage.userName: the user name. // this.job.storage.user_name: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
// the list is [object,object] -> object = {'fileName':string, // the list is [object,object] -> object = {'name':string,
// 'lastModified':date,'creationDate':date} // 'last_modified':date,'creation_date':date}
var documentArrayList = [], file = {}, pathArray = []; var document_array = [], file = {}, path_array = [];
$.ajax ( { $.ajax ( {
url: that.getStorageLocation() + '/dav/' + url: that.getStorageURL() + '/dav/' +
that.getStorageUserName() + '/' + that.getStorageUserName() + '/' +
that.getApplicantID() + '/', that.getApplicantID() + '/',
async: true, async: true,
...@@ -504,28 +504,28 @@ ...@@ -504,28 +504,28 @@
if(i>0) { // exclude parent folder if(i>0) { // exclude parent folder
file = {}; file = {};
$(data).find('D\\:href, href').each(function(){ $(data).find('D\\:href, href').each(function(){
pathArray = $(this).text().split('/'); path_array = $(this).text().split('/');
file.fileName = file.name =
(pathArray[pathArray.length-1] ? (path_array[path_array.length-1] ?
pathArray[pathArray.length-1] : path_array[path_array.length-1] :
pathArray[pathArray.length-2]+'/'); path_array[path_array.length-2]+'/');
}); });
if (file.fileName === '.htaccess' || if (file.name === '.htaccess' ||
file.fileName === '.htpasswd') { return; } file.name === '.htpasswd') { return; }
$(data).find( $(data).find(
'lp1\\:getlastmodified, getlastmodified' 'lp1\\:getlastmodified, getlastmodified'
).each(function () { ).each(function () {
file.lastModified = $(this).text(); file.last_modified = $(this).text();
}); });
$(data).find( $(data).find(
'lp1\\:creationdate, creationdate' 'lp1\\:creationdate, creationdate'
).each(function () { ).each(function () {
file.creationDate = $(this).text(); file.creation_date = $(this).text();
}); });
documentArrayList.push (file); document_array.push (file);
} }
}); });
that.done(documentArrayList); that.done(document_array);
}, },
error: function (type) { error: function (type) {
type.message = type.message =
...@@ -537,15 +537,15 @@ ...@@ -537,15 +537,15 @@
that.removeDocument = function () { that.removeDocument = function () {
// Remove a document from a DAVStorage. // Remove a document from a DAVStorage.
// this.job.fileName: the document name we want to remove. // this.job.name: the document name we want to remove.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.url: the dav storage url.
// this.job.storage.userName: the user name. // this.job.storage.user_name: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
$.ajax ( { $.ajax ( {
url: that.getStorageLocation() + '/dav/' + url: that.getStorageURL() + '/dav/' +
that.getStorageUserName() + '/' + that.getStorageUserName() + '/' +
that.getApplicantID() + '/' + that.getApplicantID() + '/' +
that.getFileName(), that.getFileName(),
...@@ -582,8 +582,8 @@ ...@@ -582,8 +582,8 @@
priv.storageArray = that.getStorageArray(); priv.storageArray = that.getStorageArray();
// TODO Add a tests that check if there is no duplicate storages. // TODO Add a tests that check if there is no duplicate storages.
priv.length = priv.storageArray.length; priv.length = priv.storageArray.length;
priv.returnsValuesArray = []; priv.return_value_array = [];
priv.maxtries = that.getMaxTries(); priv.max_tries = that.getMaxTries();
that.setMaxTries (1); that.setMaxTries (1);
...@@ -591,7 +591,7 @@ ...@@ -591,7 +591,7 @@
var newjob = {}, i; var newjob = {}, i;
for (i = 0; i < priv.storageArray.length; i += 1) { for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob(); newjob = that.cloneJob();
newjob.maxtries = priv.maxtries; newjob.max_tries = priv.max_tries;
newjob.storage = priv.storageArray[i]; newjob.storage = priv.storageArray[i];
newjob.callback = callback; newjob.callback = callback;
that.addJob ( newjob ) ; that.addJob ( newjob ) ;
...@@ -599,18 +599,18 @@ ...@@ -599,18 +599,18 @@
}; };
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// Checks the availability of the [job.userName]. // Checks the availability of the [job.user_name].
// if the name already exists in a storage, it is not available. // if the name already exists in a storage, it is not available.
// this.job.userName: the name we want to check. // this.job.user_name: the name we want to check.
// this.job.storage.storageArray: An Array of storages. // this.job.storage.storageArray: An Array of storages.
var i = 'id', done = false, errorArray = [], var i = 'id', done = false, error_array = [],
res = {'status':'done'}, callback = function (result) { res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result); priv.return_value_array.push(result);
if (!done) { if (!done) {
if (result.status === 'fail') { if (result.status === 'fail') {
res.status = 'fail'; res.status = 'fail';
errorArray.push(result.error); error_array.push(result.error);
} else { } else {
if (result.return_value === false) { if (result.return_value === false) {
that.done (false); that.done (false);
...@@ -618,7 +618,7 @@ ...@@ -618,7 +618,7 @@
return; return;
} }
} }
if (priv.returnsValuesArray.length === if (priv.return_value_array.length ===
priv.length) { priv.length) {
if (res.status === 'fail') { if (res.status === 'fail') {
that.fail ( that.fail (
...@@ -626,7 +626,7 @@ ...@@ -626,7 +626,7 @@
statusText:'Multi-Status', statusText:'Multi-Status',
message:'Some check availability of "' + message:'Some check availability of "' +
that.getUserName() + '" requests have failed.', that.getUserName() + '" requests have failed.',
array:errorArray}); array:error_array});
} else { } else {
that.done (true); that.done (true);
} }
...@@ -641,30 +641,30 @@ ...@@ -641,30 +641,30 @@
// Save a single document in several storages. // Save a single document in several storages.
// If a storage failed to save the document. // If a storage failed to save the document.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.userName: the user name. // this.job.storage.user_name: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant ID. // this.job.applicant.ID: the applicant ID.
// this.job.fileName: the document name. // this.job.name: the document name.
// this.job.fileContent: the document content. // this.job.content: the document content.
var res = {'status':'done'}, i = 'id', var res = {'status':'done'}, i = 'id',
done = false, errorArray = [], done = false, error_array = [],
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.return_value_array.push(result);
if (!done) { if (!done) {
if (result.status !== 'fail') { if (result.status !== 'fail') {
that.done (); that.done ();
done = true; done = true;
} else { } else {
errorArray.push(result.error); error_array.push(result.error);
if (priv.returnsValuesArray.length === if (priv.return_value_array.length ===
priv.length) { priv.length) {
that.fail ( that.fail (
{status:207, {status:207,
statusText:'Multi-Status', statusText:'Multi-Status',
message:'All save "' + that.getFileName() + message:'All save "' + that.getFileName() +
'" requests have failed.', '" requests have failed.',
array:errorArray}); array:error_array});
} }
} }
} }
...@@ -677,31 +677,30 @@ ...@@ -677,31 +677,30 @@
// object containing all information of the document and its // object containing all information of the document and its
// content. TODO will popup a window which will help us to choose // content. TODO will popup a window which will help us to choose
// the good file if the files are different. // the good file if the files are different.
// this.job.fileName: the document name we want to load. // this.job.name: the document name we want to load.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.user_name: the user name.
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.options.getContent: if true, also get the file content. // this.job.options.getContent: if true, also get the file content.
var doc = {}, i = 'id', var doc = {}, i = 'id',
done = false, errorArray = [], done = false, error_array = [],
res = {'status':'done'}, callback = function (result) { res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result); priv.return_value_array.push(result);
if (!done) { if (!done) {
if (result.status !== 'fail') { if (result.status !== 'fail') {
that.done (result.return_value); that.done (result.return_value);
done = true; done = true;
} else { } else {
errorArray.push(result.error); error_array.push(result.error);
if (priv.returnsValuesArray.length === if (priv.return_value_array.length ===
priv.length) { priv.length) {
that.fail ( that.fail (
{status:207, {status:207,
statusText:'Multi-Status', statusText:'Multi-Status',
message:'All load "' + that.getFileName() + message:'All load "' + that.getFileName() +
'" requests have failed.', '" requests have failed.',
array:errorArray}); array:error_array});
} }
} }
} }
...@@ -713,29 +712,28 @@ ...@@ -713,29 +712,28 @@
// Get a document list from several storages. It returns a document // Get a document list from several storages. It returns a document
// array containing all the user documents informations. // array containing all the user documents informations.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.user_name: the user name.
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
var res = {'status':'done'}, i = 'id', var res = {'status':'done'}, i = 'id',
done = false, errorArray = [], done = false, error_array = [],
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.return_value_array.push(result);
if (!done) { if (!done) {
if (result.status !== 'fail') { if (result.status !== 'fail') {
that.done (result.return_value); that.done (result.return_value);
done = true; done = true;
} else { } else {
errorArray.push(result.error); error_array.push(result.error);
if (priv.returnsValuesArray.length === if (priv.return_value_array.length ===
priv.length) { priv.length) {
that.fail ( that.fail (
{status:207, {status:207,
statusText:'Multi-Status', statusText:'Multi-Status',
message:'All get document list requests'+ message:'All get document list requests'+
' have failed', ' have failed',
array:errorArray}); array:error_array});
} }
} }
} }
...@@ -745,31 +743,30 @@ ...@@ -745,31 +743,30 @@
that.removeDocument = function () { that.removeDocument = function () {
// Remove a document from several storages. // Remove a document from several storages.
// this.job.fileName: the document name we want to remove. // this.job.name: the document name we want to remove.
// this.job.storage: the storage informations. // this.job.storage: the storage informations.
// this.job.storage.location: the dav storage location. // this.job.storage.user_name: the user name.
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
var res = {'status':'done'}, i = 'key', var res = {'status':'done'}, i = 'key',
done = false, errorArray = [], done = false, error_array = [],
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.return_value_array.push(result);
if (!done) { if (!done) {
if (result.status !== 'fail') { if (result.status !== 'fail') {
that.done (); that.done ();
done = true; done = true;
} else { } else {
errorArray.push(result.error); error_array.push(result.error);
if (priv.returnsValuesArray.length === if (priv.return_value_array.length ===
priv.length) { priv.length) {
that.fail ( that.fail (
{status:207, {status:207,
statusText:'Multi-Status', statusText:'Multi-Status',
message:'All remove "' + that.getFileName() + message:'All remove "' + that.getFileName() +
'" requests have failed.', '" requests have failed.',
array:errorArray}); array:error_array});
} }
} }
} }
...@@ -793,8 +790,8 @@ ...@@ -793,8 +790,8 @@
var that = Jio.newBaseStorage( spec, my ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storage_array_name = 'jio/indexedstoragearray'; priv.storage_array_name = 'jio/indexed_storage_array';
priv.storage_file_array_name = 'jio/indexedfilearray/'+ priv.storage_file_array_name = 'jio/indexed_file_array/'+
JSON.stringify (that.getSecondStorage()) + '/' + JSON.stringify (that.getSecondStorage()) + '/' +
that.getApplicantID(); that.getApplicantID();
...@@ -825,10 +822,10 @@ ...@@ -825,10 +822,10 @@
* @param {object} storage The new indexed storage. * @param {object} storage The new indexed storage.
*/ */
priv.addIndexedStorage = function (storage) { priv.addIndexedStorage = function (storage) {
var indexedstoragearray = priv.getIndexedStorageArray(); var indexed_storage_array = priv.getIndexedStorageArray();
indexedstoragearray.push(JSON.stringify (storage)); indexed_storage_array.push(JSON.stringify (storage));
LocalOrCookieStorage.setItem(priv.storage_array_name, LocalOrCookieStorage.setItem(priv.storage_array_name,
indexedstoragearray); indexed_storage_array);
}; };
/** /**
...@@ -838,10 +835,10 @@ ...@@ -838,10 +835,10 @@
* @return {boolean} true if found, else false * @return {boolean} true if found, else false
*/ */
priv.isAnIndexedStorage = function (storage) { priv.isAnIndexedStorage = function (storage) {
var jsonstorage = JSON.stringify (storage),i,l, var json_storae = JSON.stringify (storage),i,l,
array = priv.getIndexedStorageArray(); array = priv.getIndexedStorageArray();
for (i = 0, l = array.length; i < l; i+= 1) { for (i = 0, l = array.length; i < l; i+= 1) {
if (JSON.stringify(array[i]) === jsonstorage) { if (JSON.stringify(array[i]) === json_storae) {
return true; return true;
} }
} }
...@@ -871,24 +868,24 @@ ...@@ -871,24 +868,24 @@
/** /**
* Sets the file array list. * Sets the file array list.
* @method setFileArray * @method setFileArray
* @param {array} filearray The array containing files. * @param {array} file_array The array containing files.
*/ */
priv.setFileArray = function (filearray) { priv.setFileArray = function (file_array) {
return LocalOrCookieStorage.setItem( return LocalOrCookieStorage.setItem(
priv.storage_file_array_name, priv.storage_file_array_name,
filearray); file_array);
}; };
/** /**
* Checks if the file already exists in the array. * Checks if the file already exists in the array.
* @method isFileIndexed * @method isFileIndexed
* @param {string} filename The file we want to find. * @param {string} file_name The file we want to find.
* @return {boolean} true if found, else false * @return {boolean} true if found, else false
*/ */
priv.isFileIndexed = function (filename) { priv.isFileIndexed = function (file_name) {
var i, l, array = priv.getFileArray(); var i, l, array = priv.getFileArray();
for (i = 0, l = array.length; i < l; i+= 1) { for (i = 0, l = array.length; i < l; i+= 1) {
if (array[i].fileName === filename){ if (array[i].name === file_name){
return true; return true;
} }
} }
...@@ -901,26 +898,26 @@ ...@@ -901,26 +898,26 @@
* @param {object} file The new file. * @param {object} file The new file.
*/ */
priv.addFile = function (file) { priv.addFile = function (file) {
var filearray = priv.getFileArray(); var file_array = priv.getFileArray();
filearray.push(file); file_array.push(file);
LocalOrCookieStorage.setItem(priv.storage_file_array_name, LocalOrCookieStorage.setItem(priv.storage_file_array_name,
filearray); file_array);
}; };
/** /**
* Removes a file from the local file array. * Removes a file from the local file array.
* @method removeFile * @method removeFile
* @param {string} filename The file to remove. * @param {string} file_name The file to remove.
*/ */
priv.removeFile = function (filename) { priv.removeFile = function (file_name) {
var i, l, array = priv.getFileArray(), newarray = []; var i, l, array = priv.getFileArray(), new_array = [];
for (i = 0, l = array.length; i < l; i+= 1) { for (i = 0, l = array.length; i < l; i+= 1) {
if (array[i].fileName !== filename) { if (array[i].name !== file_name) {
newarray.push(array[i]); new_array.push(array[i]);
} }
} }
LocalOrCookieStorage.setItem(priv.storage_file_array_name, LocalOrCookieStorage.setItem(priv.storage_file_array_name,
newarray); new_array);
}; };
/** /**
...@@ -944,7 +941,7 @@ ...@@ -944,7 +941,7 @@
storage: that.getSecondStorage(), storage: that.getSecondStorage(),
applicant: {ID:that.getApplicantID()}, applicant: {ID:that.getApplicantID()},
method: 'getDocumentList', method: 'getDocumentList',
maxtries: 3, max_tries: 3,
callback: getlist_callback callback: getlist_callback
}; };
that.addJob ( newjob ); that.addJob ( newjob );
...@@ -955,17 +952,17 @@ ...@@ -955,17 +952,17 @@
* @method checkNameAvailability * @method checkNameAvailability
*/ */
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
var newjob = that.cloneJob(); var new_job = that.cloneJob();
priv.update(); priv.update();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = function (result) { new_job.callback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
that.done(result.return_value); that.done(result.return_value);
} else { } else {
that.fail(result.error); that.fail(result.error);
} }
}; };
that.addJob( newjob ); that.addJob( new_job );
}; // end checkNameAvailability }; // end checkNameAvailability
/** /**
...@@ -973,14 +970,14 @@ ...@@ -973,14 +970,14 @@
* @method saveDocument * @method saveDocument
*/ */
that.saveDocument = function () { that.saveDocument = function () {
var newjob = that.cloneJob(); var new_job = that.cloneJob();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = function (result) { new_job.callback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
if (!priv.isFileIndexed(that.getFileName())) { if (!priv.isFileIndexed(that.getFileName())) {
priv.addFile({fileName:that.getFileName(), priv.addFile({name:that.getFileName(),
lastModified:0, last_modified:0,
creationDate:0}); creation_date:0});
} }
priv.update(); priv.update();
that.done(); that.done();
...@@ -988,7 +985,7 @@ ...@@ -988,7 +985,7 @@
that.fail(result.error); that.fail(result.error);
} }
}; };
that.addJob ( newjob ); that.addJob ( new_job );
}; // end saveDocument }; // end saveDocument
/** /**
...@@ -998,13 +995,13 @@ ...@@ -998,13 +995,13 @@
* @method loadDocument * @method loadDocument
*/ */
that.loadDocument = function () { that.loadDocument = function () {
var filearray, i, l, newjob, var file_array, i, l, new_job,
loadcallback = function (result) { loadCallback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
// if (filearray[i].lastModified !== // if (file_array[i].last_modified !==
// result.return_value.lastModified || // result.return_value.last_modified ||
// filearray[i].creationDate !== // file_array[i].creation_date !==
// result.return_value.creationDate) { // result.return_value.creation_date) {
// // the file in the index storage is different than // // the file in the index storage is different than
// // the one in the second storage. priv.update will // // the one in the second storage. priv.update will
// // take care of refresh the indexed storage // // take care of refresh the indexed storage
...@@ -1015,20 +1012,20 @@ ...@@ -1015,20 +1012,20 @@
} }
}, },
secondLoadDocument = function () { secondLoadDocument = function () {
newjob = that.cloneJob(); new_job = that.cloneJob();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = loadcallback; new_job.callback = loadCallback;
that.addJob ( newjob ); that.addJob ( new_job );
}, },
settings = that.cloneOptionObject(); settings = that.cloneOptionObject();
priv.update(); priv.update();
if (settings.metadata_only) { if (settings.metadata_only) {
setTimeout(function () { setTimeout(function () {
if (priv.fileArrayExists()) { if (priv.fileArrayExists()) {
filearray = priv.getFileArray(); file_array = priv.getFileArray();
for (i = 0, l = filearray.length; i < l; i+= 1) { for (i = 0, l = file_array.length; i < l; i+= 1) {
if (filearray[i].fileName === that.getFileName()) { if (file_array[i].name === that.getFileName()) {
return that.done(filearray[i]); return that.done(file_array[i]);
} }
} }
} else { } else {
...@@ -1060,9 +1057,9 @@ ...@@ -1060,9 +1057,9 @@
* @method removeDocument * @method removeDocument
*/ */
that.removeDocument = function () { that.removeDocument = function () {
var newjob = that.cloneJob(); var new_job = that.cloneJob();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = function (result) { new_job.callback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
priv.removeFile(that.getFileName()); priv.removeFile(that.getFileName());
priv.update(); priv.update();
...@@ -1071,7 +1068,7 @@ ...@@ -1071,7 +1068,7 @@
that.fail(result.error); that.fail(result.error);
} }
}; };
that.addJob(newjob); that.addJob(new_job);
}; };
return that; return that;
}; };
...@@ -1108,16 +1105,16 @@ ...@@ -1108,16 +1105,16 @@
* @method checkNameAvailability * @method checkNameAvailability
*/ */
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
var newjob = that.cloneJob(); var new_job = that.cloneJob();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = function (result) { new_job.callback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
that.done(result.return_value); that.done(result.return_value);
} else { } else {
that.fail(result.error); that.fail(result.error);
} }
}; };
that.addJob( newjob ); that.addJob( new_job );
}; // end checkNameAvailability }; // end checkNameAvailability
/** /**
...@@ -1125,18 +1122,18 @@ ...@@ -1125,18 +1122,18 @@
* @method saveDocument * @method saveDocument
*/ */
that.saveDocument = function () { that.saveDocument = function () {
var newjob, newfilename, newfilecontent, var new_job, new_file_name, newfilecontent,
_1 = function () { _1 = function () {
priv.encrypt(that.getFileName(),function(res) { priv.encrypt(that.getFileName(),function(res) {
newfilename = res; new_file_name = res;
_2(); _2();
}); });
}, },
_2 = function () { _2 = function () {
priv.encrypt( priv.encrypt(
JSON.stringify({ JSON.stringify({
fileName: that.getFileName(), name: that.getFileName(),
fileContent:that.getFileContent() content:that.getFileContent()
}), }),
function(res) { function(res) {
newfilecontent = res; newfilecontent = res;
...@@ -1144,18 +1141,18 @@ ...@@ -1144,18 +1141,18 @@
}); });
}, },
_3 = function () { _3 = function () {
newjob = that.cloneJob(); new_job = that.cloneJob();
newjob.fileName = newfilename; new_job.name = new_file_name;
newjob.fileContent = newfilecontent; new_job.content = newfilecontent;
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = function (result) { new_job.callback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
that.done(); that.done();
} else { } else {
that.fail(result.error); that.fail(result.error);
} }
}; };
that.addJob ( newjob ); that.addJob ( new_job );
}; };
_1(); _1();
}; // end saveDocument }; // end saveDocument
...@@ -1167,24 +1164,24 @@ ...@@ -1167,24 +1164,24 @@
* @method loadDocument * @method loadDocument
*/ */
that.loadDocument = function () { that.loadDocument = function () {
var newjob, newfilename, var new_job, new_file_name,
_1 = function () { _1 = function () {
priv.encrypt(that.getFileName(),function(res) { priv.encrypt(that.getFileName(),function(res) {
newfilename = res; new_file_name = res;
_2(); _2();
}); });
}, },
_2 = function () { _2 = function () {
newjob = that.cloneJob(); new_job = that.cloneJob();
newjob.fileName = newfilename; new_job.name = new_file_name;
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = loadcallback; new_job.callback = loadCallback;
console.log (newjob); console.log (new_job);
that.addJob ( newjob ); that.addJob ( new_job );
}, },
loadcallback = function (result) { loadCallback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
priv.decrypt (result.return_value.fileContent,function(res){ priv.decrypt (result.return_value.content,function(res){
that.done(JSON.parse(res)); that.done(JSON.parse(res));
}); });
} else { } else {
...@@ -1199,12 +1196,12 @@ ...@@ -1199,12 +1196,12 @@
* @method getDocumentList * @method getDocumentList
*/ */
that.getDocumentList = function () { that.getDocumentList = function () {
var newjob, i, l, cpt = 0, array, var new_job, i, l, cpt = 0, array,
_1 = function () { _1 = function () {
newjob = that.cloneJob(); new_job = that.cloneJob();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = getListCallback; new_job.callback = getListCallback;
that.addJob ( newjob ); that.addJob ( new_job );
}, },
getListCallback = function (result) { getListCallback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
...@@ -1221,8 +1218,8 @@ ...@@ -1221,8 +1218,8 @@
var tmp; var tmp;
cpt++; cpt++;
tmp = JSON.parse(res); tmp = JSON.parse(res);
array[index] = res.fileName; array[index] = res.name;
array[index] = res.fileContent; array[index] = res.content;
if (cpt === l) { if (cpt === l) {
// this is the last callback // this is the last callback
that.done(array); that.done(array);
...@@ -1236,16 +1233,16 @@ ...@@ -1236,16 +1233,16 @@
* @method removeDocument * @method removeDocument
*/ */
that.removeDocument = function () { that.removeDocument = function () {
var newjob = that.cloneJob(); var new_job = that.cloneJob();
newjob.storage = that.getSecondStorage(); new_job.storage = that.getSecondStorage();
newjob.callback = function (result) { new_job.callback = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
that.done(); that.done();
} else { } else {
that.fail(result.error); that.fail(result.error);
} }
}; };
that.addJob(newjob); that.addJob(new_job);
}; };
return that; return that;
}; };
...@@ -1263,9 +1260,9 @@ ...@@ -1263,9 +1260,9 @@
if (window.requirejs) { if (window.requirejs) {
define ('JIOStorages', define ('JIOStorages',
['LocalOrCookieStorage','jQuery','Base64','SJCL','JIO'], ['LocalOrCookieStorage','jQuery','Base64','SJCL','JIO'],
jio_storage_loader); jioStorageLoader);
} else { } else {
jio_storage_loader ( LocalOrCookieStorage, jQuery, Base64, sjcl, JIO); jioStorageLoader ( LocalOrCookieStorage, jQuery, Base64, sjcl, JIO);
} }
}()); }());
...@@ -26,45 +26,45 @@ var getXML = function (url) { ...@@ -26,45 +26,45 @@ var getXML = function (url) {
}, },
addFile = function (user,appid,file) { addFile = function (user,appid,file) {
var i, l, found = false, filenamearray, var i, l, found = false, filenamearray,
userarray = LocalOrCookieStorage.getItem('jio/localuserarray') || []; userarray = LocalOrCookieStorage.getItem('jio/local_user_array') || [];
for (i = 0, l = userarray.length; i < l; i+= 1) { for (i = 0, l = userarray.length; i < l; i+= 1) {
if (userarray[i] === user) { found = true; } if (userarray[i] === user) { found = true; }
} }
if (!found) { if (!found) {
userarray.push(user); userarray.push(user);
LocalOrCookieStorage.setItem('jio/localuserarray',userarray); LocalOrCookieStorage.setItem('jio/local_user_array',userarray);
LocalOrCookieStorage.setItem('jio/localfilenamearray/'+user+'/'+appid, LocalOrCookieStorage.setItem(
[file.fileName]); 'jio/local_file_name_array/'+user+'/'+appid,[file.name]);
} else { } else {
filenamearray = filenamearray =
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/localfilenamearray/'+user+'/'+appid) || []; 'jio/local_file_name_array/'+user+'/'+appid) || [];
filenamearray.push(file.fileName); filenamearray.push(file.name);
LocalOrCookieStorage.setItem( LocalOrCookieStorage.setItem(
'jio/localfilenamearray/'+user+'/'+appid, 'jio/local_file_name_array/'+user+'/'+appid,
filenamearray); filenamearray);
LocalOrCookieStorage.setItem( LocalOrCookieStorage.setItem(
'jio/local/'+user+'/'+appid+'/'+file.fileName, 'jio/local/'+user+'/'+appid+'/'+file.name,
file); file);
} }
LocalOrCookieStorage.setItem( LocalOrCookieStorage.setItem(
'jio/local/'+user+'/'+appid+'/'+file.fileName, 'jio/local/'+user+'/'+appid+'/'+file.name,
file); file);
}, },
removeFile = function (user,appid,file) { removeFile = function (user,appid,file) {
var i, l, newarray = [], var i, l, newarray = [],
filenamearray = filenamearray =
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/localfilenamearray/'+user+'/'+appid) || []; 'jio/local_file_name_array/'+user+'/'+appid) || [];
for (i = 0, l = filenamearray.length; i < l; i+= 1) { for (i = 0, l = filenamearray.length; i < l; i+= 1) {
if (filenamearray[i] !== file.fileName) { if (filenamearray[i] !== file.name) {
newarray.push(filenamearray[i]); newarray.push(filenamearray[i]);
} }
} }
LocalOrCookieStorage.setItem('jio/localfilenamearray/'+user+'/'+appid, LocalOrCookieStorage.setItem('jio/local_file_name_array/'+user+'/'+appid,
newarray); newarray);
LocalOrCookieStorage.deleteItem( LocalOrCookieStorage.deleteItem(
'jio/local/'+user+'/'+appid+'/'+file.fileName); 'jio/local/'+user+'/'+appid+'/'+file.name);
}; };
//// end tools //// end tools
...@@ -80,10 +80,10 @@ test ( "Jio simple methods", function () { ...@@ -80,10 +80,10 @@ test ( "Jio simple methods", function () {
// have to be ready. // have to be ready.
var o = {}; var o = {};
o.jio = JIO.createNew(); o.jio = JIO.newJio();
ok ( o.jio, 'a new jio -> 1'); ok ( o.jio, 'a new jio -> 1');
o.jio2 = JIO.createNew(); o.jio2 = JIO.newJio();
ok ( o.jio2, 'another new jio -> 2'); ok ( o.jio2, 'another new jio -> 2');
ok ( JIO.addStorageType('qunit', function(){}) , ok ( JIO.addStorageType('qunit', function(){}) ,
...@@ -109,7 +109,7 @@ test ( 'Jio Publish/Sububscribe/Unsubscribe methods', function () { ...@@ -109,7 +109,7 @@ test ( 'Jio Publish/Sububscribe/Unsubscribe methods', function () {
// the unsubscribe method is not working correctly. // the unsubscribe method is not working correctly.
var o = {}; var o = {};
o.jio = JIO.createNew(); o.jio = JIO.newJio();
var spy1 = this.spy(); var spy1 = this.spy();
...@@ -138,31 +138,31 @@ test ('All tests', function () { ...@@ -138,31 +138,31 @@ test ('All tests', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result[retmethod],value,message);}; deepEqual (result[retmethod],value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio[method]({'userName':'Dummy','fileName':'file', o.jio[method]({'user_name':'Dummy','name':'file',
'fileContent':'content','callback':o.f, 'content':'content','callback':o.f,
'maxtries':1}); 'max_tries':1});
clock.tick(510); clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
// All Ok Dummy Storage // All Ok Dummy Storage
o.jio = JIO.createNew({'type':'dummyallok','userName':'Dummy'}, o.jio = JIO.newJio({'type':'dummyallok','user_name':'Dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('check name availability OK','checkNameAvailability', mytest('check name availability OK','checkNameAvailability',
'return_value',true); 'return_value',true);
mytest('save document OK','saveDocument','status','done'); mytest('save document OK','saveDocument','status','done');
mytest('load document OK','loadDocument','return_value', mytest('load document OK','loadDocument','return_value',
{'fileName':'file','fileContent':'content', {'name':'file','content':'content',
'lastModified':15000,'creationDate':10000}); 'last_modified':15000,'creation_date':10000});
mytest('get document list OK','getDocumentList','return_value', mytest('get document list OK','getDocumentList','return_value',
[{'fileName':'file','creationDate':10000,'lastModified':15000}, [{'name':'file','creation_date':10000,'last_modified':15000},
{'fileName':'memo','creationDate':20000,'lastModified':25000}]); {'name':'memo','creation_date':20000,'last_modified':25000}]);
mytest('remove document OK','removeDocument','status','done'); mytest('remove document OK','removeDocument','status','done');
o.jio.stop(); o.jio.stop();
// All Fail Dummy Storage // All Fail Dummy Storage
o.jio = JIO.createNew({'type':'dummyallfail','userName':'Dummy'}, o.jio = JIO.newJio({'type':'dummyallfail','user_name':'Dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('check name availability FAIL','checkNameAvailability', mytest('check name availability FAIL','checkNameAvailability',
'status','fail'); 'status','fail');
...@@ -173,7 +173,7 @@ test ('All tests', function () { ...@@ -173,7 +173,7 @@ test ('All tests', function () {
o.jio.stop(); o.jio.stop();
// All Not Found Dummy Storage // All Not Found Dummy Storage
o.jio = JIO.createNew({'type':'dummyallnotfound','userName':'Dummy'}, o.jio = JIO.newJio({'type':'dummyallnotfound','user_name':'Dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('check name availability NOT FOUND','checkNameAvailability', mytest('check name availability NOT FOUND','checkNameAvailability',
'return_value',true); 'return_value',true);
...@@ -190,17 +190,17 @@ test ('Simple Job Elimination', function () { ...@@ -190,17 +190,17 @@ test ('Simple Job Elimination', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0; var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f1 = this.spy(); o.f2 = this.spy(); o.f1 = this.spy(); o.f2 = this.spy();
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.newJio({'type':'dummyallok','user_name':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.getID(); id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f1,'maxtries':1}); 'callback':o.f1,'max_tries':1});
ok(LocalOrCookieStorage.getItem('jio/jobobject/'+id)['1'], ok(LocalOrCookieStorage.getItem('jio/job_object/'+id)['1'],
'job creation'); 'job creation');
clock.tick(10); clock.tick(10);
o.jio.removeDocument({'fileName':'file','fileContent':'content', o.jio.removeDocument({'name':'file','content':'content',
'callback':o.f2,'maxtries':1}); 'callback':o.f2,'max_tries':1});
o.tmp = LocalOrCookieStorage.getItem('jio/jobobject/'+id)['1']; o.tmp = LocalOrCookieStorage.getItem('jio/job_object/'+id)['1'];
ok(!o.tmp || o.tmp.status === 'fail','job elimination'); ok(!o.tmp || o.tmp.status === 'fail','job elimination');
}); });
...@@ -214,16 +214,16 @@ test ('Simple Job Replacement', function () { ...@@ -214,16 +214,16 @@ test ('Simple Job Replacement', function () {
this.spy(o,'f1'); this.spy(o,'f1');
o.f2 = this.spy(); o.f2 = this.spy();
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.newJio({'type':'dummyallok','user_name':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.getID(); id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f1,'maxtries':1}); 'callback':o.f1,'max_tries':1});
clock.tick(10); clock.tick(10);
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f2,'maxtries':1}); 'callback':o.f2,'max_tries':1});
deepEqual(LocalOrCookieStorage.getItem( deepEqual(LocalOrCookieStorage.getItem(
'jio/jobobject/'+id)['1'].date,10, 'jio/job_object/'+id)['1'].date,10,
'The first job date have to be equal to the second job date.'); 'The first job date have to be equal to the second job date.');
clock.tick(500); clock.tick(500);
deepEqual([o.f1.calledOnce,o.status],[true,'fail'], deepEqual([o.f1.calledOnce,o.status],[true,'fail'],
...@@ -234,30 +234,30 @@ test ('Simple Job Replacement', function () { ...@@ -234,30 +234,30 @@ test ('Simple Job Replacement', function () {
}); });
test ('Simple Job Waiting', function () { test ('Simple Job Waiting', function () {
// Test if the second job doesn't erase the first ongoing one // Test if the second job doesn't erase the first on going one
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0; var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f3 = this.spy(); o.f4 = this.spy(); o.f3 = this.spy(); o.f4 = this.spy();
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.newJio({'type':'dummyallok','user_name':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.getID(); id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f3,'maxtries':1}); 'callback':o.f3,'max_tries':1});
clock.tick(200); clock.tick(200);
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f4,'maxtries':1}); 'callback':o.f4,'max_tries':1});
ok(LocalOrCookieStorage.getItem( ok(LocalOrCookieStorage.getItem(
'jio/jobobject/'+id)['2'] && 'jio/job_object/'+id)['2'] &&
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/jobobject/'+id)['1'].status === 'ongoing', 'jio/job_object/'+id)['1'].status === 'on_going',
'The second job must not overwrite the first ongoing one.'); 'The second job must not overwrite the first on going one.');
ok(LocalOrCookieStorage.getItem( ok(LocalOrCookieStorage.getItem(
'jio/jobobject/'+id)['2'].status === 'wait' && 'jio/job_object/'+id)['2'].status === 'wait' &&
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/jobobject/'+id)['2'].waitingFor && 'jio/job_object/'+id)['2'].waiting_for &&
JSON.stringify (LocalOrCookieStorage.getItem( JSON.stringify (LocalOrCookieStorage.getItem(
'jio/jobobject/'+id)['2'].waitingFor.jobIdArray) === '["1"]', 'jio/job_object/'+id)['2'].waiting_for.job_id_array) === '["1"]',
'The second job must be waiting for the first to end'); 'The second job must be waiting for the first to end');
clock.tick(500); clock.tick(500);
ok(o.f3.calledOnce,'first request passed'); ok(o.f3.calledOnce,'first request passed');
...@@ -274,10 +274,10 @@ test ('Simple Time Waiting' , function () { ...@@ -274,10 +274,10 @@ test ('Simple Time Waiting' , function () {
o.res = (result.status === 'done'); o.res = (result.status === 'done');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio = JIO.createNew({'type':'dummyall3tries','userName':'dummy'}, o.jio = JIO.newJio({'type':'dummyall3tries','user_name':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f,'maxtries':3}); 'callback':o.f,'max_tries':3});
clock.tick(100000); clock.tick(100000);
ok(o.f.calledOnce,'callback called once.'); ok(o.f.calledOnce,'callback called once.');
ok(o.res,'job done.'); ok(o.res,'job done.');
...@@ -297,7 +297,7 @@ test ('Check name availability', function () { ...@@ -297,7 +297,7 @@ test ('Check name availability', function () {
deepEqual(result.return_value,value,'checking name availabality');}; deepEqual(result.return_value,value,'checking name availabality');};
t.spy(o,'f'); t.spy(o,'f');
o.jio.checkNameAvailability( o.jio.checkNameAvailability(
{'userName':'MrCheckName','callback': o.f,'maxtries':1}); {'user_name':'MrCheckName','callback': o.f,'max_tries':1});
clock.tick(510); clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
...@@ -305,15 +305,15 @@ test ('Check name availability', function () { ...@@ -305,15 +305,15 @@ test ('Check name availability', function () {
}; };
// new jio // new jio
o.jio = JIO.createNew({'type':'local','userName':'noname'}, o.jio = JIO.newJio({'type':'local','user_name':'noname'},
{"ID":'noid'}); {"ID":'noid'});
// name must be available // name must be available
removeFile ('MrCheckName','jiotests',{fileName:'file'}); removeFile ('MrCheckName','jiotests',{name:'file'});
mytest(true); mytest(true);
// name must be unavailable // name must be unavailable
addFile ('MrCheckName','jiotests',{fileName:'file'}); addFile ('MrCheckName','jiotests',{name:'file'});
mytest(false); mytest(false);
o.jio.stop(); o.jio.stop();
...@@ -330,8 +330,8 @@ test ('Document save', function () { ...@@ -330,8 +330,8 @@ test ('Document save', function () {
deepEqual(result.status,value,message);}; deepEqual(result.status,value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.saveDocument( o.jio.saveDocument(
{'fileName':'file','fileContent':'content','callback': o.f, {'name':'file','content':'content','callback': o.f,
'maxtries':1}); 'max_tries':1});
clock.tick(510); clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
...@@ -339,15 +339,15 @@ test ('Document save', function () { ...@@ -339,15 +339,15 @@ test ('Document save', function () {
// check content // check content
o.tmp = LocalOrCookieStorage.getItem ( o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrSaveName/jiotests/file'); 'jio/local/MrSaveName/jiotests/file');
o.tmp.lmcd = lmcd(o.tmp.creationDate,o.tmp.lastModified); o.tmp.lmcd = lmcd(o.tmp.creation_date,o.tmp.last_modified);
delete o.tmp.lastModified; delete o.tmp.last_modified;
delete o.tmp.creationDate; delete o.tmp.creation_date;
deepEqual (o.tmp,{'fileName':'file','fileContent':'content', deepEqual (o.tmp,{'name':'file','content':'content',
'lmcd':true},'check content'); 'lmcd':true},'check content');
} }
}; };
o.jio = JIO.createNew({'type':'local','userName':'MrSaveName'}, o.jio = JIO.newJio({'type':'local','user_name':'MrSaveName'},
{"ID":'jiotests'}); {"ID":'jiotests'});
LocalOrCookieStorage.deleteItem ('jio/local/MrSaveName/jiotests/file'); LocalOrCookieStorage.deleteItem ('jio/local/MrSaveName/jiotests/file');
// save and check document existence // save and check document existence
...@@ -377,23 +377,23 @@ test ('Document load', function () { ...@@ -377,23 +377,23 @@ test ('Document load', function () {
deepEqual(result[res],value,'loading document');}; deepEqual(result[res],value,'loading document');};
t.spy(o,'f'); t.spy(o,'f');
o.jio.loadDocument( o.jio.loadDocument(
{'fileName':'file','callback': o.f,'maxtries':1}); {'name':'file','callback': o.f,'max_tries':1});
clock.tick(510); clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.createNew({'type':'local','userName':'MrLoadName'}, o.jio = JIO.newJio({'type':'local','user_name':'MrLoadName'},
{"ID":'jiotests'}); {"ID":'jiotests'});
// load a non existing file // load a non existing file
LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file'); LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file');
mytest ('status','fail'); mytest ('status','fail');
// re-load file after saving it manually // re-load file after saving it manually
doc = {'fileName':'file','fileContent':'content', doc = {'name':'file','content':'content',
'lastModified':1234,'creationDate':1000}; 'last_modified':1234,'creation_date':1000};
LocalOrCookieStorage.setItem ('jio/localfilenamearray/MrLoadName/jiotests', LocalOrCookieStorage.setItem (
['file']); 'jio/local_file_name_array/MrLoadName/jiotests',['file']);
LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc); LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc);
mytest ('return_value',doc); mytest ('return_value',doc);
...@@ -411,7 +411,7 @@ test ('Get document list', function () { ...@@ -411,7 +411,7 @@ test ('Get document list', function () {
var objectifyDocumentArray = function (array) { var objectifyDocumentArray = function (array) {
var obj = {}, k; var obj = {}, k;
for (k = 0; k < array.length; k+=1) { for (k = 0; k < array.length; k+=1) {
obj[array[k].fileName] = array[k]; obj[array[k].name] = array[k];
} }
return obj; return obj;
}; };
...@@ -419,22 +419,22 @@ test ('Get document list', function () { ...@@ -419,22 +419,22 @@ test ('Get document list', function () {
objectifyDocumentArray(value),'getting list'); objectifyDocumentArray(value),'getting list');
}; };
t.spy(o,'f'); t.spy(o,'f');
o.jio.getDocumentList({'callback': o.f,'maxtries':1}); o.jio.getDocumentList({'callback': o.f,'max_tries':1});
clock.tick(510); clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.createNew({'type':'local','userName':'MrListName'}, o.jio = JIO.newJio({'type':'local','user_name':'MrListName'},
{"ID":'jiotests'}); {"ID":'jiotests'});
doc1 = {'fileName':'file','fileContent':'content', doc1 = {'name':'file','content':'content',
'lastModified':1,'creationDate':0}; 'last_modified':1,'creation_date':0};
doc2 = {'fileName':'memo','fileContent':'test', doc2 = {'name':'memo','content':'test',
'lastModified':5,'creationDate':2}; 'last_modified':5,'creation_date':2};
addFile ('MrListName','jiotests',doc1); addFile ('MrListName','jiotests',doc1);
addFile ('MrListName','jiotests',doc2); addFile ('MrListName','jiotests',doc2);
delete doc1.fileContent; delete doc1.content;
delete doc2.fileContent; delete doc2.content;
mytest ([doc1,doc2]); mytest ([doc1,doc2]);
o.jio.stop(); o.jio.stop();
...@@ -451,7 +451,7 @@ test ('Document remove', function () { ...@@ -451,7 +451,7 @@ test ('Document remove', function () {
deepEqual(result.status,'done','removing document');}; deepEqual(result.status,'done','removing document');};
t.spy(o,'f'); t.spy(o,'f');
o.jio.removeDocument( o.jio.removeDocument(
{'fileName':'file','callback': o.f,'maxtries':1}); {'name':'file','callback': o.f,'max_tries':1});
clock.tick(510); clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
...@@ -462,7 +462,7 @@ test ('Document remove', function () { ...@@ -462,7 +462,7 @@ test ('Document remove', function () {
ok (!o.tmp, 'check no content'); ok (!o.tmp, 'check no content');
} }
}; };
o.jio = JIO.createNew({'type':'local','userName':'MrRemoveName'}, o.jio = JIO.newJio({'type':'local','user_name':'MrRemoveName'},
{"ID":'jiotests'}); {"ID":'jiotests'});
// test removing a file // test removing a file
LocalOrCookieStorage.setItem ('jio/local/MrRemoveName/jiotests/file',{}); LocalOrCookieStorage.setItem ('jio/local/MrRemoveName/jiotests/file',{});
...@@ -486,8 +486,8 @@ test ('Check name availability', function () { ...@@ -486,8 +486,8 @@ test ('Check name availability', function () {
o.f = function (result) { o.f = function (result) {
deepEqual(result[method],value,'checking name availability');}; deepEqual(result[method],value,'checking name availability');};
t.spy(o,'f'); t.spy(o,'f');
o.jio.checkNameAvailability({'userName':'davcheck','callback':o.f, o.jio.checkNameAvailability({'user_name':'davcheck','callback':o.f,
'maxtries':1}); 'max_tries':1});
clock.tick(500); clock.tick(500);
server.respond(); server.respond();
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
...@@ -495,9 +495,9 @@ test ('Check name availability', function () { ...@@ -495,9 +495,9 @@ test ('Check name availability', function () {
} }
}; };
o.jio = JIO.createNew({'type':'dav','userName':'davcheck', o.jio = JIO.newJio({'type':'dav','user_name':'davcheck',
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
// 404 error, the name does not exist, name is available. // 404 error, the name does not exist, name is available.
mytest ('return_value',true,404); mytest ('return_value',true,404);
...@@ -526,16 +526,16 @@ test ('Document load', function () { ...@@ -526,16 +526,16 @@ test ('Document load', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.return_value,doc,message);}; deepEqual (result.return_value,doc,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.loadDocument({'fileName':'file','callback':o.f,'maxtries':1}); o.jio.loadDocument({'name':'file','callback':o.f,'max_tries':1});
clock.tick(500); clock.tick(500);
server.respond(); server.respond();
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.createNew({'type':'dav','userName':'davload', o.jio = JIO.newJio({'type':'dav','user_name':'davload',
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
// note: http errno: // note: http errno:
// 200 OK // 200 OK
...@@ -547,9 +547,9 @@ test ('Document load', function () { ...@@ -547,9 +547,9 @@ test ('Document load', function () {
// load an inexistant document. // load an inexistant document.
mytest ('load inexistant document',undefined,404,404); mytest ('load inexistant document',undefined,404,404);
// load a document. // load a document.
mytest ('load document',{'fileName':'file','fileContent':'content', mytest ('load document',{'name':'file','content':'content',
'lastModified':1335953199000, 'last_modified':1335953199000,
'creationDate':1335953202000},207,200); 'creation_date':1335953202000},207,200);
o.jio.stop(); o.jio.stop();
}); });
...@@ -583,17 +583,17 @@ test ('Document save', function () { ...@@ -583,17 +583,17 @@ test ('Document save', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,value,message);}; deepEqual (result.status,value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f,'maxtries':1}); 'callback':o.f,'max_tries':1});
clock.tick(500); clock.tick(500);
server.respond(); server.respond();
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.createNew({'type':'dav','userName':'davsave', o.jio = JIO.newJio({'type':'dav','user_name':'davsave',
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
// note: http errno: // note: http errno:
// 200 OK // 200 OK
...@@ -628,7 +628,7 @@ test ('Get Document List', function () { ...@@ -628,7 +628,7 @@ test ('Get Document List', function () {
var objectifyDocumentArray = function (array) { var objectifyDocumentArray = function (array) {
var obj = {}, k; var obj = {}, k;
for (k = 0; k < array.length; k += 1) { for (k = 0; k < array.length; k += 1) {
obj[array[k].fileName] = array[k]; obj[array[k].name] = array[k];
} }
return obj; return obj;
}; };
...@@ -640,22 +640,22 @@ test ('Get Document List', function () { ...@@ -640,22 +640,22 @@ test ('Get Document List', function () {
} }
}; };
t.spy(o,'f'); t.spy(o,'f');
o.jio.getDocumentList({'callback':o.f,'maxtries':1}); o.jio.getDocumentList({'callback':o.f,'max_tries':1});
clock.tick(500); clock.tick(500);
server.respond(); server.respond();
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.createNew({'type':'dav','userName':'davlist', o.jio = JIO.newJio({'type':'dav','user_name':'davlist',
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('fail to get list',undefined,404); mytest('fail to get list',undefined,404);
mytest('getting list',[{'fileName':'file','creationDate':1335962911000, mytest('getting list',[{'name':'file','creation_date':1335962911000,
'lastModified':1335962907000}, 'last_modified':1335962907000},
{'fileName':'memo','creationDate':1335894073000, {'name':'memo','creation_date':1335894073000,
'lastModified':1335955713000}],207); 'last_modified':1335955713000}],207);
o.jio.stop(); o.jio.stop();
}); });
...@@ -671,16 +671,16 @@ test ('Remove document', function () { ...@@ -671,16 +671,16 @@ test ('Remove document', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,value,message);}; deepEqual (result.status,value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.removeDocument({'fileName':'file','callback':o.f,'maxtries':1}); o.jio.removeDocument({'name':'file','callback':o.f,'max_tries':1});
clock.tick(500); clock.tick(500);
server.respond(); server.respond();
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.createNew({'type':'dav','userName':'davremove', o.jio = JIO.newJio({'type':'dav','user_name':'davremove',
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('remove document','done',204); mytest('remove document','done',204);
...@@ -702,58 +702,58 @@ test ('Check name availability', function () { ...@@ -702,58 +702,58 @@ test ('Check name availability', function () {
deepEqual (result.return_value,value,message); deepEqual (result.return_value,value,message);
}; };
t.spy(o,'f'); t.spy(o,'f');
o.jio.checkNameAvailability({'userName':'Dummy','callback':o.f, o.jio.checkNameAvailability({'user_name':'Dummy','callback':o.f,
'maxtries':o.maxtries}); 'max_tries':o.max_tries});
clock.tick(300000); clock.tick(300000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false,'no respose / too much results'); ok(false,'no respose / too much results');
} }
}; };
o.maxtries = 1; o.max_tries = 1;
// DummyStorageAllOK,OK // DummyStorageAllOK,OK
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyallok','userName':'2'}]}, {'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllOK,OK : name available',true); mytest('DummyStoragesAllOK,OK : name available',true);
o.jio.stop(); o.jio.stop();
// DummyStorageAllOK,Fail // DummyStorageAllOK,Fail
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyallfail','userName':'2'}]}, {'type':'dummyallfail','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllOK,Fail : name not available',undefined); mytest('DummyStoragesAllOK,Fail : name not available',undefined);
o.jio.stop(); o.jio.stop();
// DummyStorageAllFail,OK // DummyStorageAllFail,OK
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallfail','userName':'1'}, {'type':'dummyallfail','user_name':'1'},
{'type':'dummyallok','userName':'2'}]}, {'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllFail,OK : name not available',undefined); mytest('DummyStoragesAllFail,OK : name not available',undefined);
o.jio.stop(); o.jio.stop();
// DummyStorageAllFail,Fail // DummyStorageAllFail,Fail
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallfail','userName':'1'}, {'type':'dummyallfail','user_name':'1'},
{'type':'dummyallfail','userName':'2'}]}, {'type':'dummyallfail','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllFail,Fail : fail to check name',undefined); mytest('DummyStoragesAllFail,Fail : fail to check name',undefined);
o.jio.stop(); o.jio.stop();
// DummyStorageAllOK,3Tries // DummyStorageAllOK,3Tries
o.maxtries = 3 ; o.max_tries = 3 ;
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','userName':'2'}]}, {'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllOK,3Tries : name available',true); mytest('DummyStoragesAllOK,3Tries : name available',true);
o.jio.stop(); o.jio.stop();
// DummyStorageAll{3tries,{3tries,3tries},3tries} // DummyStorageAll{3tries,{3tries,3tries},3tries}
o.maxtries = 3 ; o.max_tries = 3 ;
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyall3tries','userName':'1'}, {'type':'dummyall3tries','user_name':'1'},
{'type':'replicate','storageArray':[ {'type':'replicate','storage_array':[
{'type':'dummyall3tries','userName':'2'}, {'type':'dummyall3tries','user_name':'2'},
{'type':'dummyall3tries','userName':'3'}]}, {'type':'dummyall3tries','user_name':'3'}]},
{'type':'dummyall3tries','userName':'4'}]}, {'type':'dummyall3tries','user_name':'4'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available', mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available',
true); true);
...@@ -768,29 +768,29 @@ test ('Document load', function () { ...@@ -768,29 +768,29 @@ test ('Document load', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.return_value,doc,message);}; deepEqual (result.return_value,doc,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.loadDocument({'fileName':'file','callback':o.f}); o.jio.loadDocument({'name':'file','callback':o.f});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio=JIO.createNew({'type':'replicate','userName':'Dummy','storageArray':[ o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyallok','userName':'2'}]}, {'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStorageAllOK,OK: load same file',{ mytest('DummyStorageAllOK,OK: load same file',{
'fileName':'file','fileContent':'content', 'name':'file','content':'content',
'lastModified':15000, 'last_modified':15000,
'creationDate':10000}); 'creation_date':10000});
o.jio.stop(); o.jio.stop();
o.jio=JIO.createNew({'type':'replicate','userName':'Dummy','storageArray':[ o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','userName':'2'}]}, {'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: load 2 different files',{ mytest('DummyStorageAllOK,3tries: load 2 different files',{
'fileName':'file','fileContent':'content', 'name':'file','content':'content',
'lastModified':15000, 'last_modified':15000,
'creationDate':10000}); 'creation_date':10000});
o.jio.stop(); o.jio.stop();
}); });
...@@ -803,16 +803,16 @@ test ('Document save', function () { ...@@ -803,16 +803,16 @@ test ('Document save', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,value,message);}; deepEqual (result.status,value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'name':'file','content':'content',
'callback':o.f,'maxtries':3}); 'callback':o.f,'max_tries':3});
clock.tick(500); clock.tick(500);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio=JIO.createNew({'type':'replicate','userName':'Dummy','storageArray':[ o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyallok','userName':'2'}]}, {'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStorageAllOK,OK: save a file.','done'); mytest('DummyStorageAllOK,OK: save a file.','done');
o.jio.stop(); o.jio.stop();
...@@ -827,7 +827,7 @@ test ('Get Document List', function () { ...@@ -827,7 +827,7 @@ test ('Get Document List', function () {
var objectifyDocumentArray = function (array) { var objectifyDocumentArray = function (array) {
var obj = {}, k; var obj = {}, k;
for (k = 0; k < array.length; k += 1) { for (k = 0; k < array.length; k += 1) {
obj[array[k].fileName] = array[k]; obj[array[k].name] = array[k];
} }
return obj; return obj;
}; };
...@@ -835,20 +835,20 @@ test ('Get Document List', function () { ...@@ -835,20 +835,20 @@ test ('Get Document List', function () {
objectifyDocumentArray(value),'getting list'); objectifyDocumentArray(value),'getting list');
}; };
t.spy(o,'f'); t.spy(o,'f');
o.jio.getDocumentList({'callback':o.f,'maxtries':3}); o.jio.getDocumentList({'callback':o.f,'max_tries':3});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio=JIO.createNew({'type':'replicate','userName':'Dummy','storageArray':[ o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','userName':'2'}]}, {'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
o.doc1 = {'fileName':'file', o.doc1 = {'name':'file',
'lastModified':15000,'creationDate':10000}; 'last_modified':15000,'creation_date':10000};
o.doc2 = {'fileName':'memo', o.doc2 = {'name':'memo',
'lastModified':25000,'creationDate':20000}; 'last_modified':25000,'creation_date':20000};
mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]); mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]);
o.jio.stop(); o.jio.stop();
}); });
...@@ -861,15 +861,15 @@ test ('Remove document', function () { ...@@ -861,15 +861,15 @@ test ('Remove document', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,value,message);}; deepEqual (result.status,value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.removeDocument({'fileName':'file','callback':o.f,'maxtries':3}); o.jio.removeDocument({'name':'file','callback':o.f,'max_tries':3});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio=JIO.createNew({'type':'replicate','userName':'Dummy','storageArray':[ o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','userName':'2'}]}, {'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: remove document.','done'); mytest('DummyStorageAllOK,3tries: remove document.','done');
o.jio.stop(); o.jio.stop();
...@@ -883,16 +883,16 @@ test ('Check name availability', function () { ...@@ -883,16 +883,16 @@ test ('Check name availability', function () {
o.f = function (result) { o.f = function (result) {
deepEqual (result.return_value,value,message);}; deepEqual (result.return_value,value,message);};
t.spy(o,'f'); t.spy(o,'f');
o.jio.checkNameAvailability({userName:'MrIndexedCheck', o.jio.checkNameAvailability({user_name:'MrIndexedCheck',
callback:o.f,maxtries:3}); callback:o.f,max_tries:3});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; };
o.jio=JIO.createNew({type:'indexed', o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
userName:'indexedcheck'}}, user_name:'indexedcheck'}},
{ID:'jiotests'}); {ID:'jiotests'});
mytest('dummy ok : name must be available', true); mytest('dummy ok : name must be available', true);
o.jio.stop(); o.jio.stop();
...@@ -900,39 +900,39 @@ test ('Check name availability', function () { ...@@ -900,39 +900,39 @@ test ('Check name availability', function () {
test ('Document load', function () { test ('Document load', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed', o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
userName:'indexedload'}}, user_name:'indexedload'}},
{ID:'jiotests'}); {ID:'jiotests'});
// loading must take long time with dummyall3tries // loading must take long time with dummyall3tries
o.f = function () {}; o.f = function () {};
this.spy(o,'f'); this.spy(o,'f');
o.jio.loadDocument({fileName:'memo',maxtries:3,callback:o.f, o.jio.loadDocument({name:'memo',max_tries:3,callback:o.f,
options:{metadata_only:true}}); options:{metadata_only:true}});
clock.tick(500); clock.tick(500);
ok(!o.f.calledOnce,'Callback must not be called'); ok(!o.f.calledOnce,'Callback must not be called');
// wait long time too retreive list // wait long time too retreive list
clock.tick(100000); clock.tick(100000);
// now we can test if the document metadata are loaded faster. // now we can test if the document metadata are loaded faster.
o.doc = {fileName:'memo',lastModified:25000,creationDate:20000}; o.doc = {name:'memo',last_modified:25000,creation_date:20000};
o.f2 = function (result) { o.f2 = function (result) {
deepEqual (result.return_value,o.doc,'Document metadata retrieved'); deepEqual (result.return_value,o.doc,'Document metadata retrieved');
}; };
this.spy(o,'f2'); this.spy(o,'f2');
o.jio.loadDocument({fileName:'memo',maxtries:3,callback:o.f2, o.jio.loadDocument({name:'memo',max_tries:3,callback:o.f2,
options:{metadata_only:true}}); options:{metadata_only:true}});
clock.tick(500); clock.tick(500);
if (!o.f2.calledOnce) { if (!o.f2.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
} }
// test a simple document loading // test a simple document loading
o.doc2 = {fileName:'file',lastModified:17000, o.doc2 = {name:'file',last_modified:17000,
creationDate:11000,fileContent:'content2'}; creation_date:11000,content:'content2'};
o.f3 = function (result) { o.f3 = function (result) {
deepEqual (result.return_value,o.doc2,'Simple document loading'); deepEqual (result.return_value,o.doc2,'Simple document loading');
}; };
this.spy(o,'f3'); this.spy(o,'f3');
o.jio.loadDocument({fileName:'file',maxtries:3,callback:o.f3}); o.jio.loadDocument({name:'file',max_tries:3,callback:o.f3});
clock.tick(100000); clock.tick(100000);
if (!o.f3.calledOnce) { if (!o.f3.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -942,15 +942,15 @@ test ('Document load', function () { ...@@ -942,15 +942,15 @@ test ('Document load', function () {
test ('Document save', function () { test ('Document save', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed', o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
userName:'indexedsave'}}, user_name:'indexedsave'}},
{ID:'jiotests'}); {ID:'jiotests'});
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,'done','document save'); deepEqual (result.status,'done','document save');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.saveDocument({fileName:'file',maxtries:3,callback:o.f}); o.jio.saveDocument({name:'file',max_tries:3,callback:o.f});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce){ if (!o.f.calledOnce){
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -960,16 +960,16 @@ test ('Document save', function () { ...@@ -960,16 +960,16 @@ test ('Document save', function () {
test ('Get document list', function () { test ('Get document list', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed', o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
userName:'indexedgetlist'}}, user_name:'indexedgetlist'}},
{ID:'jiotests'}); {ID:'jiotests'});
o.doc1 = {fileName:'file',lastModified:15000,creationDate:10000}; o.doc1 = {name:'file',last_modified:15000,creation_date:10000};
o.doc2 = {fileName:'memo',lastModified:25000,creationDate:20000}; o.doc2 = {name:'memo',last_modified:25000,creation_date:20000};
// getting list must take long time with dummyall3tries // getting list must take long time with dummyall3tries
o.f = function () {}; o.f = function () {};
this.spy(o,'f'); this.spy(o,'f');
o.jio.getDocumentList({maxtries:3,callback:o.f}); o.jio.getDocumentList({max_tries:3,callback:o.f});
clock.tick(500); clock.tick(500);
ok(!o.f.calledOnce,'Callback must not be called'); ok(!o.f.calledOnce,'Callback must not be called');
// wail long time too retreive list // wail long time too retreive list
...@@ -979,7 +979,7 @@ test ('Get document list', function () { ...@@ -979,7 +979,7 @@ test ('Get document list', function () {
deepEqual (result.return_value,[o.doc1,o.doc2],'get document list'); deepEqual (result.return_value,[o.doc1,o.doc2],'get document list');
}; };
this.spy(o,'f2'); this.spy(o,'f2');
o.jio.getDocumentList({maxtries:3,callback:o.f2}); o.jio.getDocumentList({max_tries:3,callback:o.f2});
clock.tick(500); clock.tick(500);
if (!o.f2.calledOnce) { if (!o.f2.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -988,15 +988,15 @@ test ('Get document list', function () { ...@@ -988,15 +988,15 @@ test ('Get document list', function () {
test ('Remove document', function () { test ('Remove document', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'indexed', o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
userName:'indexedsave'}}, user_name:'indexedsave'}},
{ID:'jiotests'}); {ID:'jiotests'});
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,'done','document remove'); deepEqual (result.status,'done','document remove');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.removeDocument({fileName:'file',maxtries:3,callback:o.f}); o.jio.removeDocument({name:'file',max_tries:3,callback:o.f});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce){ if (!o.f.calledOnce){
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -1008,16 +1008,16 @@ module ('Jio CryptedStorage'); ...@@ -1008,16 +1008,16 @@ module ('Jio CryptedStorage');
test ('Check name availability' , function () { test ('Check name availability' , function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'crypted', o.jio=JIO.newJio({type:'crypted',
storage:{type:'local', storage:{type:'local',
userName:'cryptcheck'}}, user_name:'cryptcheck'}},
{ID:'jiotests'}); {ID:'jiotests'});
o.f = function (result) { o.f = function (result) {
deepEqual (result.return_value,true,'name must be available'); deepEqual (result.return_value,true,'name must be available');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.checkNameAvailability({userName:'cryptcheck', o.jio.checkNameAvailability({user_name:'cryptcheck',
maxtries:1,callback:o.f}); max_tries:1,callback:o.f});
clock.tick(1000); clock.tick(1000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -1027,17 +1027,17 @@ test ('Check name availability' , function () { ...@@ -1027,17 +1027,17 @@ test ('Check name availability' , function () {
test ('Document save' , function () { test ('Document save' , function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'crypted', o.jio=JIO.newJio({type:'crypted',
password:'mypwd', password:'mypwd',
storage:{type:'local', storage:{type:'local',
userName:'cryptsave'}}, user_name:'cryptsave'}},
{ID:'jiotests'}); {ID:'jiotests'});
o.f = function (result) { o.f = function (result) {
deepEqual (result.status,'done','save ok'); deepEqual (result.status,'done','save ok');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.saveDocument({fileName:'testsave',fileContent:'contentoftest', o.jio.saveDocument({name:'testsave',content:'contentoftest',
maxtries:1,callback:o.f}); max_tries:1,callback:o.f});
clock.tick(1000); clock.tick(1000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -1047,25 +1047,25 @@ test ('Document save' , function () { ...@@ -1047,25 +1047,25 @@ test ('Document save' , function () {
test ('Document Load' , function () { test ('Document Load' , function () {
var o = {}, clock = this.sandbox.useFakeTimers(); var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.createNew({type:'crypted', o.jio=JIO.newJio({type:'crypted',
password:'mypwd', password:'mypwd',
storage:{type:'local', storage:{type:'local',
userName:'cryptload'}}, user_name:'cryptload'}},
{ID:'jiotests'}); {ID:'jiotests'});
o.f = function (result) { o.f = function (result) {
if (result.status === 'done') { if (result.status === 'done') {
deepEqual (result.return_value,{fileName:'testload', deepEqual (result.return_value,{name:'testload',
fileContent:'contentoftest', content:'contentoftest',
lastModified:500, last_modified:500,
creationDate:500} creation_date:500}
,'load ok'); ,'load ok');
} else { } else {
ok (false ,'cannot load'); ok (false ,'cannot load');
} }
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.loadDocument({fileName:'testload', o.jio.loadDocument({name:'testload',
maxtries:1,callback:o.f}); max_tries:1,callback:o.f});
clock.tick(1000); clock.tick(1000);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
......
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