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

Rename vars.

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