Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
df16f201
Commit
df16f201
authored
Jun 04, 2012
by
Tristan Cavelier
Committed by
Sebastien Robin
Jun 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename vars.
parent
4a4b4a5b
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
646 additions
and
660 deletions
+646
-660
OfficeJS/component/elrte.html
OfficeJS/component/elrte.html
+1
-1
OfficeJS/component/jquery-sheet.html
OfficeJS/component/jquery-sheet.html
+1
-1
OfficeJS/component/left_nav_bar.html
OfficeJS/component/left_nav_bar.html
+6
-6
OfficeJS/component/slickgrid_document_lister.html
OfficeJS/component/slickgrid_document_lister.html
+32
-32
OfficeJS/component/svg-edit.html
OfficeJS/component/svg-edit.html
+1
-1
OfficeJS/index.html
OfficeJS/index.html
+1
-0
OfficeJS/js/officejs.js
OfficeJS/js/officejs.js
+47
-51
OfficeJS/src/jio.dummystorages.js
OfficeJS/src/jio.dummystorages.js
+43
-51
OfficeJS/src/jio.js
OfficeJS/src/jio.js
+82
-82
OfficeJS/src/jio.storage.js
OfficeJS/src/jio.storage.js
+228
-231
OfficeJS/test/jiotests.js
OfficeJS/test/jiotests.js
+204
-204
No files found.
OfficeJS/component/elrte.html
View file @
df16f201
...
...
@@ -49,7 +49,7 @@ $().ready(function() {
<div>
<input
type=
"text"
name=
"fileName"
id=
"input_file
N
ame"
id=
"input_file
_n
ame"
value=
""
placeholder=
"File name here"
/>
<button
type=
"submit"
...
...
OfficeJS/component/jquery-sheet.html
View file @
df16f201
...
...
@@ -208,7 +208,7 @@ function goToObj(s){
<div>
<input
type=
"text"
name=
"fileName"
id=
"input_file
N
ame"
id=
"input_file
_n
ame"
value=
""
placeholder=
"File name here"
/>
<button
type=
"submit"
...
...
OfficeJS/component/left_nav_bar.html
View file @
df16f201
...
...
@@ -20,7 +20,7 @@
<
li
class
=
"
texteditor left-nav-tools
"
>
<
a
href
=
"
#/texteditor
"
onclick
=
"
javascript:
OfficeJS.open({app:'text
E
ditor'});
OfficeJS.open({app:'text
_e
ditor'});
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:'img
E
ditor'});
OfficeJS.open({app:'img
_e
ditor'});
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:'sp
r
eadsheet'});
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:'document
L
ister'});
OfficeJS.open({app:'document
_l
ister'});
return false;
"
>
<
i
class
=
"
icon-list
"
><
/i
>
Document
List
...
...
OfficeJS/component/slickgrid_document_lister.html
View file @
df16f201
...
...
@@ -43,9 +43,9 @@
<script
type=
"text/javascript"
>
<!--
(
function
()
{
var
grid
,
onSortFunction
,
onClickFunction
,
check
box
selector
,
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
].
fileN
ame
.
split
(
'
.
'
);
array
[
i
].
fileE
xt
=
''
;
split
=
array
[
i
].
n
ame
.
split
(
'
.
'
);
array
[
i
].
e
xt
=
''
;
if
(
split
.
length
>
1
)
{
array
[
i
].
fileE
xt
=
split
[
split
.
length
-
1
];
array
[
i
].
e
xt
=
split
[
split
.
length
-
1
];
split
.
length
-=
1
;
}
array
[
i
].
fileBaseN
ame
=
split
.
join
(
'
.
'
);
array
[
i
].
base_n
ame
=
split
.
join
(
'
.
'
);
// app & icon
mime
=
OfficeJS
.
getMimeOfExt
(
array
[
i
].
fileE
xt
);
mime
=
OfficeJS
.
getMimeOfExt
(
array
[
i
].
e
xt
);
if
(
!
mime
)
{
array
[
i
].
icon
=
'
?
'
;
array
[
i
].
app
=
'
text
E
ditor
'
;
array
[
i
].
app
=
'
text
_e
ditor
'
;
}
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
].
last
M
odified
));
cd
=
(
new
Date
(
array
[
i
].
creation
D
ate
));
array
[
i
].
last
M
odified
=
lm
.
getFullYear
()
+
'
/
'
+
lm
=
(
new
Date
(
array
[
i
].
last
_m
odified
));
cd
=
(
new
Date
(
array
[
i
].
creation
_d
ate
));
array
[
i
].
last
_m
odified
=
lm
.
getFullYear
()
+
'
/
'
+
(
lm
.
getMonth
()
+
1
)
+
'
/
'
+
lm
.
getDate
()
+
'
'
+
lm
.
getHours
()
+
'
:
'
+
lm
.
getMinutes
();
array
[
i
].
creation
D
ate
=
cd
.
getFullYear
()
+
'
/
'
+
array
[
i
].
creation
_d
ate
=
cd
.
getFullYear
()
+
'
/
'
+
(
cd
.
getMonth
()
+
1
)
+
'
/
'
+
cd
.
getDate
()
+
'
'
+
cd
.
getHours
()
+
'
:
'
+
cd
.
getMinutes
();
}
}(
documentlist
));
}(
document
_
list
));
$
(
function
()
{
check
box
selector
=
new
Slick
.
CheckboxSelectColumn
({
check
_box_
selector
=
new
Slick
.
CheckboxSelectColumn
({
cssClass
:
"
slick-cell-checkboxsel
"
});
columns
.
push
(
check
box
selector
.
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
:
"
file
N
ame
"
,
name
:
"
Document
"
,
field
:
"
fileBaseN
ame
"
,
sortable
:
true
});
columns
.
push
({
id
:
"
last
M
odified
"
,
name
:
"
Modified
"
,
field
:
"
last
M
odified
"
,
sortable
:
true
});
columns
.
push
({
id
:
"
creation
D
ate
"
,
name
:
"
Created
"
,
field
:
"
creation
D
ate
"
,
sortable
:
true
});
columns
.
push
({
id
:
"
file
_n
ame
"
,
name
:
"
Document
"
,
field
:
"
base_n
ame
"
,
sortable
:
true
});
columns
.
push
({
id
:
"
last
_m
odified
"
,
name
:
"
Modified
"
,
field
:
"
last
_m
odified
"
,
sortable
:
true
});
columns
.
push
({
id
:
"
creation
_d
ate
"
,
name
:
"
Created
"
,
field
:
"
creation
_d
ate
"
,
sortable
:
true
});
grid
=
new
Slick
.
Grid
(
"
#myDocumentList
"
,
documentlist
,
document
_
list
,
columns
,
options
);
grid
.
setSelectionModel
(
new
Slick
.
RowSelectionModel
(
{
selectActiveRow
:
false
}));
grid
.
registerPlugin
(
check
box
selector
);
grid
.
registerPlugin
(
check
_box_
selector
);
onSortFunction
=
function
(
e
,
args
)
{
var
cols
=
args
.
sortCols
;
document
list
.
sort
(
function
(
dataRow1
,
dataR
ow2
)
{
document
_list
.
sort
(
function
(
data_row1
,
data_r
ow2
)
{
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
=
data
R
ow1
[
field
];
value2
=
data
R
ow2
[
field
];
value1
=
data
_r
ow1
[
field
];
value2
=
data
_r
ow2
[
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
(
'
file
N
ame
'
))
{
OfficeJS
.
open
({
app
:
documentlist
[
cell
.
row
].
app
,
file
Name
:
documentlist
[
cell
.
row
].
fileN
ame
});
if
(
cell
.
cell
===
grid
.
getColumnIndex
(
'
file
_n
ame
'
))
{
OfficeJS
.
open
({
app
:
document
_
list
[
cell
.
row
].
app
,
file
_name
:
document_list
[
cell
.
row
].
n
ame
});
}
};
onRemoveSeveral
=
function
()
{
var
document
names
array
=
[],
selected
,
i
,
l
;
var
document
_name_
array
=
[],
selected
,
i
,
l
;
selected
=
grid
.
getSelectedRows
();
for
(
i
=
0
,
l
=
selected
.
length
;
i
<
l
;
i
+=
1
)
{
document
namesarray
.
push
(
documentlist
[
selected
[
i
]].
fileN
ame
);
document
_name_array
.
push
(
document_list
[
selected
[
i
]].
n
ame
);
}
OfficeJS
.
removeSeveralFromArray
(
document
names
array
);
OfficeJS
.
removeSeveralFromArray
(
document
_name_
array
);
};
document
.
querySelector
(
'
#slickgrid_document_lister_remove_selected
'
).
onclick
=
onRemoveSeveral
;
...
...
OfficeJS/component/svg-edit.html
View file @
df16f201
<div>
<input
type=
"text"
name=
"fileName"
id=
"input_file
N
ame"
id=
"input_file
_n
ame"
value=
""
placeholder=
"File name here"
/>
<button
type=
"submit"
...
...
OfficeJS/index.html
View file @
df16f201
...
...
@@ -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>
...
...
OfficeJS/js/officejs.js
View file @
df16f201
(
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
=
{
document
L
ister
:
'
slickgrid
'
,
editpreferences
:
'
simplepreferenceeditor
'
,
text
E
ditor
:
'
elrte
'
,
img
E
ditor
:
'
svg-edit
'
,
speadsheet
:
'
jquery-sheet
'
document
_l
ister
:
'
slickgrid
'
,
edit
_
preferences
:
'
simplepreferenceeditor
'
,
text
_e
ditor
:
'
elrte
'
,
img
_e
ditor
:
'
svg-edit
'
,
sp
r
eadsheet
:
'
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
=
{
user
N
ame
:
'
NoName
'
,
user
_n
ame
:
'
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
.
file
N
ame
!==
'
undefined
'
)
{
$
(
'
#input_file
N
ame
'
).
attr
(
'
value
'
,
baseName
(
param
.
fileN
ame
));
that
.
load
(
baseName
(
param
.
file
N
ame
));
if
(
typeof
param
.
file
_n
ame
!==
'
undefined
'
)
{
$
(
'
#input_file
_n
ame
'
).
attr
(
'
value
'
,
baseName
(
param
.
file_n
ame
));
that
.
load
(
baseName
(
param
.
file
_n
ame
));
}
else
{
$
(
'
#input_file
N
ame
'
).
attr
(
$
(
'
#input_file
_n
ame
'
).
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
.
file
N
ame
!==
'
undefined
'
)
{
$
(
'
#input_file
N
ame
'
).
attr
(
'
value
'
,
baseName
(
param
.
fileN
ame
));
that
.
load
(
baseName
(
param
.
file
N
ame
));
if
(
typeof
param
.
file
_n
ame
!==
'
undefined
'
)
{
$
(
'
#input_file
_n
ame
'
).
attr
(
'
value
'
,
baseName
(
param
.
file_n
ame
));
that
.
load
(
baseName
(
param
.
file
_n
ame
));
}
else
{
$
(
'
#input_file
N
ame
'
).
attr
(
$
(
'
#input_file
_n
ame
'
).
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
.
file
N
ame
!==
'
undefined
'
)
{
$
(
'
#input_file
N
ame
'
).
attr
(
'
value
'
,
baseName
(
param
.
fileN
ame
));
that
.
load
(
baseName
(
param
.
file
N
ame
));
if
(
typeof
param
.
file
_n
ame
!==
'
undefined
'
)
{
$
(
'
#input_file
_n
ame
'
).
attr
(
'
value
'
,
baseName
(
param
.
file_n
ame
));
that
.
load
(
baseName
(
param
.
file
_n
ame
));
}
else
{
$
(
'
#input_file
N
ame
'
).
attr
(
$
(
'
#input_file
_n
ame
'
).
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
:
'
document
L
ister
'
,
force
:
true
});
OfficeJS
.
open
({
app
:
'
document
_l
ister
'
,
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
:
'
text
E
ditor
'
,
app
:
'
elrte
'
,
html
:{
pref
:
'
text
_e
ditor
'
,
app
:
'
elrte
'
,
icon
:
'
<i class="icon-font"></i>
'
},
svg
:{
pref
:
'
img
E
ditor
'
,
app
:
'
svg-edit
'
,
svg
:{
pref
:
'
img
_e
ditor
'
,
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
'
:{
'
last
M
odified
'
:
'
descending
'
,
'
fileN
ame
'
:
'
ascending
'
},
'
sort
'
:{
'
last
_m
odified
'
:
'
descending
'
,
'
n
ame
'
:
'
ascending
'
},
'
limit
'
:{
begin
:
0
,
end
:
50
},
// 'search':{
fileN
ame:'a'},
// 'search':{
n
ame:'a'},
'
maxtries
'
:
3
,
'
callback
'
:
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
...
...
@@ -447,8 +444,8 @@
}
priv
.
loading_object
.
save
();
priv
.
jio
.
saveDocument
({
'
fileN
ame
'
:
basename
+
'
.
'
+
current_editor
.
ext
,
'
fileC
ontent
'
:
current_editor
.
getContent
(),
'
n
ame
'
:
basename
+
'
.
'
+
current_editor
.
ext
,
'
c
ontent
'
:
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
({
'
fileN
ame
'
:
basename
+
'
.
'
+
current_editor
.
ext
,
'
n
ame
'
:
basename
+
'
.
'
+
current_editor
.
ext
,
'
maxtries
'
:
3
,
'
callback
'
:
function
(
result
)
{
if
(
result
.
status
===
'
fail
'
)
{
console
.
error
(
result
.
message
);
}
else
{
current_editor
.
setContent
(
result
.
return_value
.
fileC
ontent
);
result
.
return_value
.
c
ontent
);
}
priv
.
loading_object
.
end_load
();
}
...
...
@@ -498,7 +495,7 @@
}
priv
.
loading_object
.
remove
();
priv
.
jio
.
removeDocument
({
'
fileN
ame
'
:
name
,
'
n
ame
'
:
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
({
fileN
ame
:
documentarray
[
i
],
n
ame
:
documentarray
[
i
],
callback
:
function
(
result
)
{
cpt
+=
1
;
console
.
log
(
result
);
if
(
cpt
===
l
)
{
if
(
typeof
current_editor
.
update
!==
'
undefined
'
)
{
that
.
getList
(
current_editor
.
update
);
...
...
OfficeJS/src/jio.dummystorages.js
View file @
df16f201
...
...
@@ -5,7 +5,7 @@
// - dummyallfail
// - dummyallnotfound
// - dummyall3tries
(
function
()
{
var
jio
_dummy_storage_l
oader
=
function
(
Jio
)
{
(
function
()
{
var
jio
DummyStorageL
oader
=
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,'fileC
ontent':string,
// 'creation
Date':date,'lastM
odified':date}
// document object is {'
name':string,'c
ontent':string,
// 'creation
_date':date,'last_m
odified':date}
// wait a little in order to simulate asynchronous operation
setTimeout
(
function
()
{
var
doc
=
{
'
fileC
ontent
'
:
'
content
'
,
'
fileN
ame
'
:
'
file
'
,
'
creation
D
ate
'
:
10000
,
'
last
M
odified
'
:
15000
};
'
c
ontent
'
:
'
content
'
,
'
n
ame
'
:
'
file
'
,
'
creation
_d
ate
'
:
10000
,
'
last
_m
odified
'
:
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 = {'
fileN
ame':string,
// 'last
Modified':date,'creationD
ate':date}
// the list is [object,object] -> object = {'
n
ame':string,
// 'last
_modified':date,'creation_d
ate':date}
setTimeout
(
function
()
{
var
list
=
[
{
'
fileN
ame
'
:
'
file
'
,
'
creation
D
ate
'
:
10000
,
'
last
M
odified
'
:
15000
},
{
'
fileN
ame
'
:
'
memo
'
,
'
creation
D
ate
'
:
20000
,
'
last
M
odified
'
:
25000
{
'
n
ame
'
:
'
file
'
,
'
creation
_d
ate
'
:
10000
,
'
last
_m
odified
'
:
15000
},
{
'
n
ame
'
:
'
memo
'
,
'
creation
_d
ate
'
:
20000
,
'
last
_m
odified
'
:
25000
}];
that
.
done
(
list
);
},
100
);
...
...
@@ -107,8 +107,8 @@
that
.
loadDocument
=
function
()
{
// Returns a document object containing nothing.
// document object is {'
fileName':string,'fileC
ontent':string,
// 'creation
Date':date,'lastM
odified':date}
// document object is {'
name':string,'c
ontent':string,
// 'creation
_date':date,'last_m
odified':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 = {'
fileN
ame':string,
// 'last
Modified':date,'creationD
ate':date}
// the list is [object,object] -> object = {'
n
ame':string,
// 'last
_modified':date,'creation_d
ate':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,'fileC
ontent':string,
// 'creation
Date':date,'lastM
odified':date}
// document object is {'
name':string,'c
ontent':string,
// 'creation
_date':date,'last_m
odified':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 = {'
fileN
ame':string,
// 'last
Modified':date,'creationD
ate':date}
// the list is [object,object] -> object = {'
n
ame':string,
// 'last
_modified':date,'creation_d
ate':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
(
if
ok
return
)
{
priv
.
doJob
=
function
(
if
_ok_
return
)
{
// wait a little in order to simulate asynchronous operation
setTimeout
(
function
()
{
priv
.
Try3OKElseFail
(
that
.
cloneJob
().
tries
,
if
ok
return
);
priv
.
Try3OKElseFail
(
that
.
cloneJob
().
tries
,
if
_ok_
return
);
},
100
);
};
priv
.
Try3OKElseFail
=
function
(
tries
,
if
ok
return
)
{
priv
.
Try3OKElseFail
=
function
(
tries
,
if
_ok_
return
)
{
if
(
tries
===
3
)
{
return
that
.
done
(
if
ok
return
);
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
({
'
fileC
ontent
'
:
'
content2
'
,
'
fileN
ame
'
:
'
file
'
,
'
creation
D
ate
'
:
11000
,
'
last
M
odified
'
:
17000
'
c
ontent
'
:
'
content2
'
,
'
n
ame
'
:
'
file
'
,
'
creation
_d
ate
'
:
11000
,
'
last
_m
odified
'
:
17000
});
};
// end loadDocument
that
.
getDocumentList
=
function
()
{
priv
.
doJob
([{
'
fileN
ame
'
:
'
file
'
,
'
creation
D
ate
'
:
10000
,
'
last
M
odified
'
:
15000
},
{
'
fileN
ame
'
:
'
memo
'
,
'
creation
D
ate
'
:
20000
,
'
last
M
odified
'
:
25000
}
priv
.
doJob
([{
'
n
ame
'
:
'
file
'
,
'
creation
_d
ate
'
:
10000
,
'
last
_m
odified
'
:
15000
},
{
'
n
ame
'
:
'
memo
'
,
'
creation
_d
ate
'
:
20000
,
'
last
_m
odified
'
:
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_l
oader
);
define
(
'
JIODummyStorages
'
,[
'
JIO
'
],
jio
DummyStorageL
oader
);
}
else
{
jio
_dummy_storage_l
oader
(
JIO
);
jio
DummyStorageL
oader
(
JIO
);
}
}());
OfficeJS/src/jio.js
View file @
df16f201
...
...
@@ -4,7 +4,7 @@
* @module JIO
*/
var
JIO
=
(
function
()
{
var
jio
_loader_f
unction
=
function
(
localOrCookieStorage
,
$
)
{
(
function
()
{
var
jio
LoaderF
unction
=
function
(
localOrCookieStorage
,
$
)
{
////////////////////////////////////////////////////////////////////////////
// constants
...
...
@@ -27,8 +27,8 @@ var JIO =
- s: storage
- a: applicant
- m: method
- n:
fileN
ame
- c:
fileC
ontent
- n:
n
ame
- c:
c
ontent
- 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
.
fileN
ame
)
{
job1
.
name
===
job2
.
n
ame
)
{
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
.
fileC
ontent
)
{
job1
.
content
===
job2
.
c
ontent
)
{
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
,
empty
f
un
=
function
(){},
jio_id_array
;
var
k
,
empty
F
un
=
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
=
empty
f
un
;
priv
.
recovered_job_object
[
k
].
callback
=
empty
F
un
;
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
.
waiting
For
=
{
'
jobIdA
rray
'
:
wait_array
};
job
.
waiting
_for
=
{
'
job_id_a
rray
'
:
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
].
waiting
For
.
jobIdA
rray
)
{
if
(
priv
.
job_object
[
i
].
waiting
_for
.
job_id_a
rray
)
{
// wait job
// browsing job id array
for
(
j
=
0
;
j
<
priv
.
job_object
[
i
].
waiting
For
.
jobIdA
rray
.
length
;
waiting
_for
.
job_id_a
rray
.
length
;
j
+=
1
)
{
if
(
priv
.
job_object
[
priv
.
job_object
[
i
].
waiting
For
.
jobIdA
rray
[
j
]])
{
waiting
_for
.
job_id_a
rray
[
j
]])
{
// if a job is still exist, don't invoke
ok
=
false
;
break
;
}
}
}
if
(
priv
.
job_object
[
i
].
waiting
F
or
.
time
)
{
if
(
priv
.
job_object
[
i
].
waiting
_f
or
.
time
)
{
// wait time
if
(
priv
.
job_object
[
i
].
waiting
F
or
.
time
>
Date
.
now
())
{
if
(
priv
.
job_object
[
i
].
waiting
_f
or
.
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
.
user
N
ame
+
'
is
'
+
priv
.
res
.
message
=
priv
.
job
.
user
_n
ame
+
'
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
.
last
M
odified
=
new
Date
(
priv
.
res
.
return_value
.
last
M
odified
).
getTime
();
priv
.
res
.
return_value
.
creation
D
ate
=
new
Date
(
priv
.
res
.
return_value
.
creation
D
ate
).
getTime
();
priv
.
res
.
return_value
.
last
_m
odified
=
new
Date
(
priv
.
res
.
return_value
.
last
_m
odified
).
getTime
();
priv
.
res
.
return_value
.
creation
_d
ate
=
new
Date
(
priv
.
res
.
return_value
.
creation
_d
ate
).
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
].
last
M
odified
!==
'
number
'
)
{
priv
.
res
.
return_value
[
i
].
last
M
odified
=
new
Date
(
priv
.
res
.
return_value
[
i
].
last
M
odified
).
if
(
typeof
priv
.
res
.
return_value
[
i
].
last
_m
odified
!==
'
number
'
)
{
priv
.
res
.
return_value
[
i
].
last
_m
odified
=
new
Date
(
priv
.
res
.
return_value
[
i
].
last
_m
odified
).
getTime
();
}
if
(
typeof
priv
.
res
.
return_value
[
i
].
creation
D
ate
!==
'
number
'
)
{
priv
.
res
.
return_value
[
i
].
creation
D
ate
=
new
Date
(
priv
.
res
.
return_value
[
i
].
creation
D
ate
).
if
(
typeof
priv
.
res
.
return_value
[
i
].
creation
_d
ate
!==
'
number
'
)
{
priv
.
res
.
return_value
[
i
].
creation
_d
ate
=
new
Date
(
priv
.
res
.
return_value
[
i
].
creation
_d
ate
).
getTime
();
}
}
...
...
@@ -788,7 +788,7 @@ var JIO =
time
=
jio_global_obj
.
max_wait_time
;
}
priv
.
job
.
status
=
'
wait
'
;
priv
.
job
.
waiting
F
or
=
{
'
time
'
:
Date
.
now
()
+
time
};
priv
.
job
.
waiting
_f
or
=
{
'
time
'
:
Date
.
now
()
+
time
};
};
//// end Private Methods
...
...
@@ -797,43 +797,43 @@ var JIO =
return
$
.
extend
(
true
,{},
priv
.
job
);
};
that
.
getUserName
=
function
()
{
return
priv
.
job
.
user
N
ame
||
''
;
return
priv
.
job
.
user
_n
ame
||
''
;
};
that
.
getApplicantID
=
function
()
{
return
priv
.
job
.
applicant
.
ID
||
''
;
};
that
.
getStorageUserName
=
function
()
{
return
priv
.
job
.
storage
.
user
N
ame
||
''
;
return
priv
.
job
.
storage
.
user
_n
ame
||
''
;
};
that
.
getStoragePassword
=
function
()
{
return
priv
.
job
.
storage
.
password
||
''
;
};
that
.
getStorage
Location
=
function
()
{
return
priv
.
job
.
storage
.
location
||
''
;
that
.
getStorage
URL
=
function
()
{
return
priv
.
job
.
storage
.
url
||
''
;
};
that
.
getSecondStorage
=
function
()
{
return
priv
.
job
.
storage
.
storage
||
{};
};
that
.
getStorageArray
=
function
()
{
return
priv
.
job
.
storage
.
storage
A
rray
||
[];
return
priv
.
job
.
storage
.
storage
_a
rray
||
[];
};
that
.
getFileName
=
function
()
{
return
priv
.
job
.
fileN
ame
||
''
;
return
priv
.
job
.
n
ame
||
''
;
};
that
.
getFileContent
=
function
()
{
return
priv
.
job
.
fileC
ontent
||
''
;
return
priv
.
job
.
c
ontent
||
''
;
};
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
.
max
tries
=
max
tries
;
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({'user
N
ame':'myName','callback':
// jio.checkNameAvailability({'user
_n
ame':'myName','callback':
// function (result) {
// if (result.status === 'done') {
// if (result.return_value === true) { // available
...
...
@@ -1144,14 +1144,14 @@ var JIO =
// }});
var
settings
=
$
.
extend
(
true
,{
'
user
Name
'
:
priv
.
storage
.
userN
ame
,
'
user
_name
'
:
priv
.
storage
.
user_n
ame
,
'
storage
'
:
priv
.
storage
,
'
applicant
'
:
priv
.
applicant
,
'
method
'
:
'
checkNameAvailability
'
,
'
callback
'
:
function
()
{}
},
options
);
// check dependencies
if
(
that
.
isReady
()
&&
settings
.
user
N
ame
&&
if
(
that
.
isReady
()
&&
settings
.
user
_n
ame
&&
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','fileC
ontent':'content',
// jio.saveDocument({'
name':'file','c
ontent':'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
,
'
fileC
ontent
'
:
''
,
'
c
ontent
'
:
''
,
'
method
'
:
'
saveDocument
'
,
'
callback
'
:
function
()
{}
},
options
);
// check dependencies
if
(
that
.
isReady
()
&&
settings
.
fileN
ame
&&
if
(
that
.
isReady
()
&&
settings
.
n
ame
&&
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 '
fileC
ontent'
// 'job_done' will be sent with this job and its '
c
ontent'
// 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({'
fileN
ame':'file','callback':
// jio.loadDocument({'
n
ame':'file','callback':
// function (result) {
// if (result.status === 'done') { // Loaded
// } else { } // Error
// }});
// result.return_value is a document object that looks like {
//
fileName:'string',fileC
ontent:'string',
// creation
Date:123,lastM
odified:456 }
//
name:'string',c
ontent:'string',
// creation
_date:123,last_m
odified:456 }
var
settings
=
$
.
extend
(
true
,{
'
storage
'
:
priv
.
storage
,
...
...
@@ -1221,7 +1221,7 @@ var JIO =
'
callback
'
:
function
(){}
},
options
);
// check dependencies
if
(
that
.
isReady
()
&&
settings
.
fileN
ame
&&
if
(
that
.
isReady
()
&&
settings
.
n
ame
&&
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({'
fileN
ame':'file','callback':
// jio.removeDocument({'
n
ame':'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
.
fileN
ame
&&
if
(
that
.
isReady
()
&&
settings
.
n
ame
&&
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_f
unction
);
define
(
'
JIO
'
,[
'
LocalOrCookieStorage
'
,
'
jQuery
'
],
jio
LoaderF
unction
);
return
undefined
;
}
else
{
return
jio
_loader_f
unction
(
LocalOrCookieStorage
,
jQuery
);
return
jio
LoaderF
unction
(
LocalOrCookieStorage
,
jQuery
);
}
}());
OfficeJS/src/jio.storage.js
View file @
df16f201
...
...
@@ -9,7 +9,7 @@
* @module JIOStorages
*/
(
function
()
{
var
jio
_storage_l
oader
=
var
jio
StorageL
oader
=
function
(
LocalOrCookieStorage
,
$
,
Base64
,
sjcl
,
Jio
)
{
////////////////////////////////////////////////////////////////////////////
...
...
@@ -35,8 +35,8 @@
var
that
=
Jio
.
newBaseStorage
(
spec
,
my
),
priv
=
{};
priv
.
storage_user_array_name
=
'
jio/local
user
array
'
;
priv
.
storage_file_array_name
=
'
jio/local
filename
array/
'
+
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
();
user
array
.
push
(
user
name
);
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
(
user
array
[
i
]
===
user
name
)
{
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
file
name
array
=
priv
.
getFileNameArray
();
file
namearray
.
push
(
file
name
);
priv
.
addFileName
=
function
(
file
_
name
)
{
var
file
_name_
array
=
priv
.
getFileNameArray
();
file
_name_array
.
push
(
file_
name
);
LocalOrCookieStorage
.
setItem
(
priv
.
storage_file_array_name
,
file
name
array
);
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
=
{
'
fileN
ame
'
:
that
.
getFileName
(),
'
fileC
ontent
'
:
that
.
getFileContent
(),
'
creation
D
ate
'
:
Date
.
now
(),
'
last
M
odified
'
:
Date
.
now
()
'
n
ame
'
:
that
.
getFileName
(),
'
c
ontent
'
:
that
.
getFileContent
(),
'
creation
_d
ate
'
:
Date
.
now
(),
'
last
_m
odified
'
:
Date
.
now
()
};
if
(
!
priv
.
userExists
()){
priv
.
addUser
(
that
.
getStorageUserName
());
...
...
@@ -155,8 +155,8 @@
priv
.
addFileName
(
that
.
getFileName
());
}
else
{
// overwriting
doc
.
last
M
odified
=
Date
.
now
();
doc
.
fileC
ontent
=
that
.
getFileContent
();
doc
.
last
_m
odified
=
Date
.
now
();
doc
.
c
ontent
=
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,'fileC
ontent':string,
// 'creation
Date':date,'lastM
odified':date}
// document object is {'
name':string,'c
ontent':string,
// 'creation
_date':date,'last_m
odified':date}
setTimeout
(
function
()
{
var
doc
=
null
,
settings
=
that
.
cloneOptionObject
();
...
...
@@ -189,10 +189,10 @@
'
" not found in localStorage.
'
});
}
else
{
if
(
settings
.
metadata_only
)
{
delete
doc
.
fileC
ontent
;
delete
doc
.
c
ontent
;
}
else
if
(
settings
.
content_only
)
{
delete
doc
.
last
M
odified
;
delete
doc
.
creation
D
ate
;
delete
doc
.
last
_m
odified
;
delete
doc
.
creation
_d
ate
;
}
that
.
done
(
doc
);
}
...
...
@@ -206,24 +206,24 @@
* @method getDocumentList
*/
that
.
getDocumentList
=
function
()
{
// the list is [object,object] -> object = {'
fileN
ame':string,
// 'last
Modified':date,'creationD
ate':date}
// the list is [object,object] -> object = {'
n
ame':string,
// 'last
_modified':date,'creation_d
ate':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
(),
file
O
bject
=
{};
that
.
getApplicantID
(),
file
_o
bject
=
{};
array
=
priv
.
getFileNameArray
();
for
(
i
=
0
,
l
=
array
.
length
;
i
<
l
;
i
+=
1
)
{
file
O
bject
=
file
_o
bject
=
LocalOrCookieStorage
.
getItem
(
path
+
'
/
'
+
array
[
i
]);
newarray
.
push
({
'
fileName
'
:
fileObject
.
fileN
ame
,
'
creation
Date
'
:
fileObject
.
creationD
ate
,
'
last
Modified
'
:
fileObject
.
lastM
odified
});
new
_
array
.
push
({
'
name
'
:
file_object
.
n
ame
,
'
creation
_date
'
:
file_object
.
creation_d
ate
,
'
last
_modified
'
:
file_object
.
last_m
odified
});
}
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.user
Name: the user
name
// options.user
_name: the user
name
// options.password: the password
// TODO this method is not working !!!
var
settings
=
$
.
extend
({
'
success
'
:
function
(){},
'
error
'
:
function
(){}},
options
),
split
path
=
[
'
splitedpath
'
],
tmp
path
=
'
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 (split
path[split
path.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
++
;
tmp
path
=
split
path
.
join
(
'
/
'
);
// alert(settings.
location + tmp
path);
tmp
_path
=
split_
path
.
join
(
'
/
'
);
// alert(settings.
url + tmp_
path);
$
.
ajax
(
{
url
:
settings
.
location
+
tmp
path
,
url
:
settings
.
url
+
tmp_
path
,
type
:
'
MKCOL
'
,
async
:
true
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
settings
.
user
N
ame
+
'
:
'
+
settings
.
user
_n
ame
+
'
:
'
+
settings
.
password
),
Depth
:
'
1
'
},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
()
{
...
...
@@ -317,16 +317,16 @@
};
that
.
checkNameAvailability
=
function
()
{
// checks the availability of the [job.user
N
ame].
// checks the availability of the [job.user
_n
ame].
// 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.user
N
ame: the name we want to check.
// this.job.storage.user
N
ame: the user name.
// this.job.storage.
url: the dav storage url
.
// this.job.user
_n
ame: the name we want to check.
// this.job.storage.user
_n
ame: the user name.
// this.job.storage.password: the user password.
$
.
ajax
(
{
url
:
that
.
getStorage
Location
()
+
'
/dav/
'
+
url
:
that
.
getStorage
URL
()
+
'
/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.user
N
ame: the user name.
// this.job.storage.user
_n
ame: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant ID.
// this.job.
fileN
ame: the document name.
// this.job.
fileC
ontent: the document content.
// this.job.
n
ame: the document name.
// this.job.
c
ontent: the document content.
// TODO if path of /dav/user/applic does not exists, it won't work!
//// save on dav
$
.
ajax
(
{
url
:
that
.
getStorage
Location
()
+
'
/dav/
'
+
url
:
that
.
getStorage
URL
()
+
'
/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.
fileN
ame: the document name we want to load.
// this.job.
n
ame: 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,'fileC
ontent':string,
// 'creation
Date':date,'lastM
odified':date}
// document object is {'
name':string,'c
ontent':string,
// 'creation
_date':date,'last_m
odified':date}
var
doc
=
{},
settings
=
that
.
cloneOptionObject
(),
getContent
=
function
()
{
$
.
ajax
(
{
url
:
that
.
getStorage
Location
()
+
'
/dav/
'
+
url
:
that
.
getStorage
URL
()
+
'
/dav/
'
+
that
.
getStorageUserName
()
+
'
/
'
+
that
.
getApplicantID
()
+
'
/
'
+
that
.
getFileName
(),
...
...
@@ -413,7 +413,7 @@
that
.
getStoragePassword
()
)},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
(
content
)
{
doc
.
fileC
ontent
=
content
;
doc
.
c
ontent
=
content
;
that
.
done
(
doc
);
},
error
:
function
(
type
)
{
...
...
@@ -430,14 +430,14 @@
}
}
);
};
doc
.
fileN
ame
=
that
.
getFileName
();
doc
.
n
ame
=
that
.
getFileName
();
if
(
settings
.
content_only
)
{
getContent
();
return
;
}
// Get properties
$
.
ajax
(
{
url
:
that
.
getStorage
Location
()
+
'
/dav/
'
+
url
:
that
.
getStorage
URL
()
+
'
/dav/
'
+
that
.
getStorageUserName
()
+
'
/
'
+
that
.
getApplicantID
()
+
'
/
'
+
that
.
getFileName
(),
...
...
@@ -448,16 +448,16 @@
that
.
getStorageUserName
()
+
'
:
'
+
that
.
getStoragePassword
()
)},
success
:
function
(
xmlData
)
{
// doc.last
M
odified =
// doc.last
_m
odified =
$
(
xmlData
).
find
(
'
lp1
\\
:getlastmodified, getlastmodified
'
).
each
(
function
()
{
doc
.
last
M
odified
=
$
(
this
).
text
();
doc
.
last
_m
odified
=
$
(
this
).
text
();
});
$
(
xmlData
).
find
(
'
lp1
\\
:creationdate, creationdate
'
).
each
(
function
()
{
doc
.
creation
D
ate
=
$
(
this
).
text
();
doc
.
creation
_d
ate
=
$
(
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.user
N
ame: the user name.
// this.job.storage.
url: the dav storage url
.
// this.job.storage.user
_n
ame: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// the list is [object,object] -> object = {'
fileN
ame':string,
// 'last
Modified':date,'creationD
ate':date}
// the list is [object,object] -> object = {'
n
ame':string,
// 'last
_modified':date,'creation_d
ate':date}
var
document
ArrayList
=
[],
file
=
{},
pathA
rray
=
[];
var
document
_array
=
[],
file
=
{},
path_a
rray
=
[];
$
.
ajax
(
{
url
:
that
.
getStorage
Location
()
+
'
/dav/
'
+
url
:
that
.
getStorage
URL
()
+
'
/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
(){
path
A
rray
=
$
(
this
).
text
().
split
(
'
/
'
);
file
.
fileN
ame
=
(
path
Array
[
pathA
rray
.
length
-
1
]
?
path
Array
[
pathA
rray
.
length
-
1
]
:
path
Array
[
pathA
rray
.
length
-
2
]
+
'
/
'
);
path
_a
rray
=
$
(
this
).
text
().
split
(
'
/
'
);
file
.
n
ame
=
(
path
_array
[
path_a
rray
.
length
-
1
]
?
path
_array
[
path_a
rray
.
length
-
1
]
:
path
_array
[
path_a
rray
.
length
-
2
]
+
'
/
'
);
});
if
(
file
.
fileN
ame
===
'
.htaccess
'
||
file
.
fileN
ame
===
'
.htpasswd
'
)
{
return
;
}
if
(
file
.
n
ame
===
'
.htaccess
'
||
file
.
n
ame
===
'
.htpasswd
'
)
{
return
;
}
$
(
data
).
find
(
'
lp1
\\
:getlastmodified, getlastmodified
'
).
each
(
function
()
{
file
.
last
M
odified
=
$
(
this
).
text
();
file
.
last
_m
odified
=
$
(
this
).
text
();
});
$
(
data
).
find
(
'
lp1
\\
:creationdate, creationdate
'
).
each
(
function
()
{
file
.
creation
D
ate
=
$
(
this
).
text
();
file
.
creation
_d
ate
=
$
(
this
).
text
();
});
document
ArrayList
.
push
(
file
);
document
_array
.
push
(
file
);
}
});
that
.
done
(
document
ArrayList
);
that
.
done
(
document
_array
);
},
error
:
function
(
type
)
{
type
.
message
=
...
...
@@ -537,15 +537,15 @@
that
.
removeDocument
=
function
()
{
// Remove a document from a DAVStorage.
// this.job.
fileN
ame: the document name we want to remove.
// this.job.
n
ame: the document name we want to remove.
// this.job.storage: the storage informations.
// this.job.storage.
location: the dav storage location
.
// this.job.storage.user
N
ame: the user name.
// this.job.storage.
url: the dav storage url
.
// this.job.storage.user
_n
ame: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
$
.
ajax
(
{
url
:
that
.
getStorage
Location
()
+
'
/dav/
'
+
url
:
that
.
getStorage
URL
()
+
'
/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
.
return
sValuesA
rray
=
[];
priv
.
maxtries
=
that
.
getMaxTries
();
priv
.
return
_value_a
rray
=
[];
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
.
max
tries
=
priv
.
max
tries
;
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.user
N
ame].
// Checks the availability of the [job.user
_n
ame].
// if the name already exists in a storage, it is not available.
// this.job.user
N
ame: the name we want to check.
// this.job.user
_n
ame: the name we want to check.
// this.job.storage.storageArray: An Array of storages.
var
i
=
'
id
'
,
done
=
false
,
error
A
rray
=
[],
var
i
=
'
id
'
,
done
=
false
,
error
_a
rray
=
[],
res
=
{
'
status
'
:
'
done
'
},
callback
=
function
(
result
)
{
priv
.
return
sValuesA
rray
.
push
(
result
);
priv
.
return
_value_a
rray
.
push
(
result
);
if
(
!
done
)
{
if
(
result
.
status
===
'
fail
'
)
{
res
.
status
=
'
fail
'
;
error
A
rray
.
push
(
result
.
error
);
error
_a
rray
.
push
(
result
.
error
);
}
else
{
if
(
result
.
return_value
===
false
)
{
that
.
done
(
false
);
...
...
@@ -618,7 +618,7 @@
return
;
}
}
if
(
priv
.
return
sValuesA
rray
.
length
===
if
(
priv
.
return
_value_a
rray
.
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
:
error
A
rray
});
array
:
error
_a
rray
});
}
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.user
N
ame: the user name.
// this.job.storage.user
_n
ame: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant ID.
// this.job.
fileN
ame: the document name.
// this.job.
fileC
ontent: the document content.
// this.job.
n
ame: the document name.
// this.job.
c
ontent: the document content.
var
res
=
{
'
status
'
:
'
done
'
},
i
=
'
id
'
,
done
=
false
,
error
A
rray
=
[],
done
=
false
,
error
_a
rray
=
[],
callback
=
function
(
result
)
{
priv
.
return
sValuesA
rray
.
push
(
result
);
priv
.
return
_value_a
rray
.
push
(
result
);
if
(
!
done
)
{
if
(
result
.
status
!==
'
fail
'
)
{
that
.
done
();
done
=
true
;
}
else
{
error
A
rray
.
push
(
result
.
error
);
if
(
priv
.
return
sValuesA
rray
.
length
===
error
_a
rray
.
push
(
result
.
error
);
if
(
priv
.
return
_value_a
rray
.
length
===
priv
.
length
)
{
that
.
fail
(
{
status
:
207
,
statusText
:
'
Multi-Status
'
,
message
:
'
All save "
'
+
that
.
getFileName
()
+
'
" requests have failed.
'
,
array
:
error
A
rray
});
array
:
error
_a
rray
});
}
}
}
...
...
@@ -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.
fileN
ame: the document name we want to load.
// this.job.
n
ame: 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
,
error
A
rray
=
[],
done
=
false
,
error
_a
rray
=
[],
res
=
{
'
status
'
:
'
done
'
},
callback
=
function
(
result
)
{
priv
.
return
sValuesA
rray
.
push
(
result
);
priv
.
return
_value_a
rray
.
push
(
result
);
if
(
!
done
)
{
if
(
result
.
status
!==
'
fail
'
)
{
that
.
done
(
result
.
return_value
);
done
=
true
;
}
else
{
error
A
rray
.
push
(
result
.
error
);
if
(
priv
.
return
sValuesA
rray
.
length
===
error
_a
rray
.
push
(
result
.
error
);
if
(
priv
.
return
_value_a
rray
.
length
===
priv
.
length
)
{
that
.
fail
(
{
status
:
207
,
statusText
:
'
Multi-Status
'
,
message
:
'
All load "
'
+
that
.
getFileName
()
+
'
" requests have failed.
'
,
array
:
error
A
rray
});
array
:
error
_a
rray
});
}
}
}
...
...
@@ -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
,
error
A
rray
=
[],
done
=
false
,
error
_a
rray
=
[],
callback
=
function
(
result
)
{
priv
.
return
sValuesA
rray
.
push
(
result
);
priv
.
return
_value_a
rray
.
push
(
result
);
if
(
!
done
)
{
if
(
result
.
status
!==
'
fail
'
)
{
that
.
done
(
result
.
return_value
);
done
=
true
;
}
else
{
error
A
rray
.
push
(
result
.
error
);
if
(
priv
.
return
sValuesA
rray
.
length
===
error
_a
rray
.
push
(
result
.
error
);
if
(
priv
.
return
_value_a
rray
.
length
===
priv
.
length
)
{
that
.
fail
(
{
status
:
207
,
statusText
:
'
Multi-Status
'
,
message
:
'
All get document list requests
'
+
'
have failed
'
,
array
:
error
A
rray
});
array
:
error
_a
rray
});
}
}
}
...
...
@@ -745,31 +743,30 @@
that
.
removeDocument
=
function
()
{
// Remove a document from several storages.
// this.job.
fileN
ame: the document name we want to remove.
// this.job.
n
ame: 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
,
error
A
rray
=
[],
done
=
false
,
error
_a
rray
=
[],
callback
=
function
(
result
)
{
priv
.
return
sValuesA
rray
.
push
(
result
);
priv
.
return
_value_a
rray
.
push
(
result
);
if
(
!
done
)
{
if
(
result
.
status
!==
'
fail
'
)
{
that
.
done
();
done
=
true
;
}
else
{
error
A
rray
.
push
(
result
.
error
);
if
(
priv
.
return
sValuesA
rray
.
length
===
error
_a
rray
.
push
(
result
.
error
);
if
(
priv
.
return
_value_a
rray
.
length
===
priv
.
length
)
{
that
.
fail
(
{
status
:
207
,
statusText
:
'
Multi-Status
'
,
message
:
'
All remove "
'
+
that
.
getFileName
()
+
'
" requests have failed.
'
,
array
:
error
A
rray
});
array
:
error
_a
rray
});
}
}
}
...
...
@@ -793,8 +790,8 @@
var
that
=
Jio
.
newBaseStorage
(
spec
,
my
),
priv
=
{};
priv
.
storage_array_name
=
'
jio/indexed
storage
array
'
;
priv
.
storage_file_array_name
=
'
jio/indexed
file
array/
'
+
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
indexed
storage
array
=
priv
.
getIndexedStorageArray
();
indexed
storage
array
.
push
(
JSON
.
stringify
(
storage
));
var
indexed
_storage_
array
=
priv
.
getIndexedStorageArray
();
indexed
_storage_
array
.
push
(
JSON
.
stringify
(
storage
));
LocalOrCookieStorage
.
setItem
(
priv
.
storage_array_name
,
indexed
storage
array
);
indexed
_storage_
array
);
};
/**
...
...
@@ -838,10 +835,10 @@
* @return {boolean} true if found, else false
*/
priv
.
isAnIndexedStorage
=
function
(
storage
)
{
var
json
storag
e
=
JSON
.
stringify
(
storage
),
i
,
l
,
var
json
_stora
e
=
JSON
.
stringify
(
storage
),
i
,
l
,
array
=
priv
.
getIndexedStorageArray
();
for
(
i
=
0
,
l
=
array
.
length
;
i
<
l
;
i
+=
1
)
{
if
(
JSON
.
stringify
(
array
[
i
])
===
json
storag
e
)
{
if
(
JSON
.
stringify
(
array
[
i
])
===
json
_stora
e
)
{
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
===
file
name
){
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
!==
file
name
)
{
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
({
fileN
ame
:
that
.
getFileName
(),
last
M
odified
:
0
,
creation
D
ate
:
0
});
priv
.
addFile
({
n
ame
:
that
.
getFileName
(),
last
_m
odified
:
0
,
creation
_d
ate
:
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
file
array
,
i
,
l
,
new
job
,
load
c
allback
=
function
(
result
)
{
var
file
_array
,
i
,
l
,
new_
job
,
load
C
allback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
// if (file
array[i].lastM
odified !==
// result.return_value.last
M
odified ||
// file
array[i].creationD
ate !==
// result.return_value.creation
D
ate) {
// if (file
_array[i].last_m
odified !==
// result.return_value.last
_m
odified ||
// file
_array[i].creation_d
ate !==
// result.return_value.creation
_d
ate) {
// // 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
();
new
job
.
callback
=
loadc
allback
;
that
.
addJob
(
newjob
);
new
_
job
=
that
.
cloneJob
();
new
_
job
.
storage
=
that
.
getSecondStorage
();
new
_job
.
callback
=
loadC
allback
;
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
(
file
array
[
i
].
fileN
ame
===
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
].
n
ame
===
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
new
job
,
newfile
name
,
newfilecontent
,
var
new
_job
,
new_file_
name
,
newfilecontent
,
_1
=
function
()
{
priv
.
encrypt
(
that
.
getFileName
(),
function
(
res
)
{
new
file
name
=
res
;
new
_file_
name
=
res
;
_2
();
});
},
_2
=
function
()
{
priv
.
encrypt
(
JSON
.
stringify
({
fileN
ame
:
that
.
getFileName
(),
fileC
ontent
:
that
.
getFileContent
()
n
ame
:
that
.
getFileName
(),
c
ontent
:
that
.
getFileContent
()
}),
function
(
res
)
{
newfilecontent
=
res
;
...
...
@@ -1144,18 +1141,18 @@
});
},
_3
=
function
()
{
newjob
=
that
.
cloneJob
();
new
job
.
fileName
=
newfile
name
;
new
job
.
fileC
ontent
=
newfilecontent
;
newjob
.
storage
=
that
.
getSecondStorage
();
newjob
.
callback
=
function
(
result
)
{
new
_
job
=
that
.
cloneJob
();
new
_job
.
name
=
new_file_
name
;
new
_job
.
c
ontent
=
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
new
job
,
newfile
name
,
var
new
_job
,
new_file_
name
,
_1
=
function
()
{
priv
.
encrypt
(
that
.
getFileName
(),
function
(
res
)
{
new
file
name
=
res
;
new
_file_
name
=
res
;
_2
();
});
},
_2
=
function
()
{
newjob
=
that
.
cloneJob
();
new
job
.
fileName
=
newfile
name
;
newjob
.
storage
=
that
.
getSecondStorage
();
new
job
.
callback
=
loadc
allback
;
console
.
log
(
newjob
);
that
.
addJob
(
newjob
);
new
_
job
=
that
.
cloneJob
();
new
_job
.
name
=
new_file_
name
;
new
_
job
.
storage
=
that
.
getSecondStorage
();
new
_job
.
callback
=
loadC
allback
;
console
.
log
(
new
_
job
);
that
.
addJob
(
new
_
job
);
},
load
c
allback
=
function
(
result
)
{
load
C
allback
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
priv
.
decrypt
(
result
.
return_value
.
fileC
ontent
,
function
(
res
){
priv
.
decrypt
(
result
.
return_value
.
c
ontent
,
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
.
fileN
ame
;
array
[
index
]
=
res
.
fileC
ontent
;
array
[
index
]
=
res
.
n
ame
;
array
[
index
]
=
res
.
c
ontent
;
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_l
oader
);
jio
StorageL
oader
);
}
else
{
jio
_storage_l
oader
(
LocalOrCookieStorage
,
jQuery
,
Base64
,
sjcl
,
JIO
);
jio
StorageL
oader
(
LocalOrCookieStorage
,
jQuery
,
Base64
,
sjcl
,
JIO
);
}
}());
OfficeJS/test/jiotests.js
View file @
df16f201
...
...
@@ -26,45 +26,45 @@ var getXML = function (url) {
},
addFile
=
function
(
user
,
appid
,
file
)
{
var
i
,
l
,
found
=
false
,
filenamearray
,
userarray
=
LocalOrCookieStorage
.
getItem
(
'
jio/local
user
array
'
)
||
[];
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/local
user
array
'
,
userarray
);
LocalOrCookieStorage
.
setItem
(
'
jio/localfilenamearray/
'
+
user
+
'
/
'
+
appid
,
[
file
.
fileN
ame
]);
LocalOrCookieStorage
.
setItem
(
'
jio/local
_user_
array
'
,
userarray
);
LocalOrCookieStorage
.
setItem
(
'
jio/local_file_name_array/
'
+
user
+
'
/
'
+
appid
,[
file
.
n
ame
]);
}
else
{
filenamearray
=
LocalOrCookieStorage
.
getItem
(
'
jio/local
filename
array/
'
+
user
+
'
/
'
+
appid
)
||
[];
filenamearray
.
push
(
file
.
fileN
ame
);
'
jio/local
_file_name_
array/
'
+
user
+
'
/
'
+
appid
)
||
[];
filenamearray
.
push
(
file
.
n
ame
);
LocalOrCookieStorage
.
setItem
(
'
jio/local
filename
array/
'
+
user
+
'
/
'
+
appid
,
'
jio/local
_file_name_
array/
'
+
user
+
'
/
'
+
appid
,
filenamearray
);
LocalOrCookieStorage
.
setItem
(
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
fileN
ame
,
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
n
ame
,
file
);
}
LocalOrCookieStorage
.
setItem
(
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
fileN
ame
,
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
n
ame
,
file
);
},
removeFile
=
function
(
user
,
appid
,
file
)
{
var
i
,
l
,
newarray
=
[],
filenamearray
=
LocalOrCookieStorage
.
getItem
(
'
jio/local
filename
array/
'
+
user
+
'
/
'
+
appid
)
||
[];
'
jio/local
_file_name_
array/
'
+
user
+
'
/
'
+
appid
)
||
[];
for
(
i
=
0
,
l
=
filenamearray
.
length
;
i
<
l
;
i
+=
1
)
{
if
(
filenamearray
[
i
]
!==
file
.
fileN
ame
)
{
if
(
filenamearray
[
i
]
!==
file
.
n
ame
)
{
newarray
.
push
(
filenamearray
[
i
]);
}
}
LocalOrCookieStorage
.
setItem
(
'
jio/local
filename
array/
'
+
user
+
'
/
'
+
appid
,
LocalOrCookieStorage
.
setItem
(
'
jio/local
_file_name_
array/
'
+
user
+
'
/
'
+
appid
,
newarray
);
LocalOrCookieStorage
.
deleteItem
(
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
fileN
ame
);
'
jio/local/
'
+
user
+
'
/
'
+
appid
+
'
/
'
+
file
.
n
ame
);
};
//// 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
]({
'
user
Name
'
:
'
Dummy
'
,
'
fileN
ame
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f
,
'
maxtries
'
:
1
});
o
.
jio
[
method
]({
'
user
_name
'
:
'
Dummy
'
,
'
n
ame
'
:
'
file
'
,
'
c
ontent
'
:
'
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
'
,
'
userN
ame
'
:
'
Dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallok
'
,
'
user_n
ame
'
:
'
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
last
Modified
'
:
15000
,
'
creationD
ate
'
:
10000
});
{
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
last
_modified
'
:
15000
,
'
creation_d
ate
'
:
10000
});
mytest
(
'
get document list OK
'
,
'
getDocumentList
'
,
'
return_value
'
,
[{
'
fileName
'
:
'
file
'
,
'
creationDate
'
:
10000
,
'
lastM
odified
'
:
15000
},
{
'
fileName
'
:
'
memo
'
,
'
creationDate
'
:
20000
,
'
lastM
odified
'
:
25000
}]);
[{
'
name
'
:
'
file
'
,
'
creation_date
'
:
10000
,
'
last_m
odified
'
:
15000
},
{
'
name
'
:
'
memo
'
,
'
creation_date
'
:
20000
,
'
last_m
odified
'
:
25000
}]);
mytest
(
'
remove document OK
'
,
'
removeDocument
'
,
'
status
'
,
'
done
'
);
o
.
jio
.
stop
();
// All Fail Dummy Storage
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
dummyallfail
'
,
'
userN
ame
'
:
'
Dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallfail
'
,
'
user_n
ame
'
:
'
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
'
,
'
userN
ame
'
:
'
Dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallnotfound
'
,
'
user_n
ame
'
:
'
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
'
,
'
userN
ame
'
:
'
dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallok
'
,
'
user_n
ame
'
:
'
dummy
'
},
{
'
ID
'
:
'
jiotests
'
});
id
=
o
.
jio
.
getID
();
o
.
jio
.
saveDocument
({
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f1
,
'
maxtries
'
:
1
});
ok
(
LocalOrCookieStorage
.
getItem
(
'
jio/jobobject/
'
+
id
)[
'
1
'
],
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f2
,
'
maxtries
'
:
1
});
o
.
tmp
=
LocalOrCookieStorage
.
getItem
(
'
jio/jobobject/
'
+
id
)[
'
1
'
];
o
.
jio
.
removeDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
'
,
'
userN
ame
'
:
'
dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallok
'
,
'
user_n
ame
'
:
'
dummy
'
},
{
'
ID
'
:
'
jiotests
'
});
id
=
o
.
jio
.
getID
();
o
.
jio
.
saveDocument
({
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f1
,
'
maxtries
'
:
1
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f1
,
'
max
_
tries
'
:
1
});
clock
.
tick
(
10
);
o
.
jio
.
saveDocument
({
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f2
,
'
maxtries
'
:
1
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
'
,
'
userN
ame
'
:
'
dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyallok
'
,
'
user_n
ame
'
:
'
dummy
'
},
{
'
ID
'
:
'
jiotests
'
});
id
=
o
.
jio
.
getID
();
o
.
jio
.
saveDocument
({
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f3
,
'
maxtries
'
:
1
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f3
,
'
max
_
tries
'
:
1
});
clock
.
tick
(
200
);
o
.
jio
.
saveDocument
({
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f4
,
'
maxtries
'
:
1
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f4
,
'
max
_
tries
'
:
1
});
ok
(
LocalOrCookieStorage
.
getItem
(
'
jio/jobobject/
'
+
id
)[
'
2
'
]
&&
'
jio/job
_
object/
'
+
id
)[
'
2
'
]
&&
LocalOrCookieStorage
.
getItem
(
'
jio/job
object/
'
+
id
)[
'
1
'
].
status
===
'
on
going
'
,
'
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/job
object/
'
+
id
)[
'
2
'
].
waitingF
or
&&
'
jio/job
_object/
'
+
id
)[
'
2
'
].
waiting_f
or
&&
JSON
.
stringify
(
LocalOrCookieStorage
.
getItem
(
'
jio/job
object/
'
+
id
)[
'
2
'
].
waitingFor
.
jobIdA
rray
)
===
'
["1"]
'
,
'
jio/job
_object/
'
+
id
)[
'
2
'
].
waiting_for
.
job_id_a
rray
)
===
'
["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
'
,
'
userN
ame
'
:
'
dummy
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dummyall3tries
'
,
'
user_n
ame
'
:
'
dummy
'
},
{
'
ID
'
:
'
jiotests
'
});
o
.
jio
.
saveDocument
({
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f
,
'
maxtries
'
:
3
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
(
{
'
user
Name
'
:
'
MrCheckName
'
,
'
callback
'
:
o
.
f
,
'
max
tries
'
:
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
'
,
'
userN
ame
'
:
'
noname
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
local
'
,
'
user_n
ame
'
:
'
noname
'
},
{
"
ID
"
:
'
noid
'
});
// name must be available
removeFile
(
'
MrCheckName
'
,
'
jiotests
'
,{
fileN
ame
:
'
file
'
});
removeFile
(
'
MrCheckName
'
,
'
jiotests
'
,{
n
ame
:
'
file
'
});
mytest
(
true
);
// name must be unavailable
addFile
(
'
MrCheckName
'
,
'
jiotests
'
,{
fileN
ame
:
'
file
'
});
addFile
(
'
MrCheckName
'
,
'
jiotests
'
,{
n
ame
:
'
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f
,
'
maxtries
'
:
1
});
{
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
.
creation
Date
,
o
.
tmp
.
lastM
odified
);
delete
o
.
tmp
.
last
M
odified
;
delete
o
.
tmp
.
creation
D
ate
;
deepEqual
(
o
.
tmp
,{
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
o
.
tmp
.
lmcd
=
lmcd
(
o
.
tmp
.
creation
_date
,
o
.
tmp
.
last_m
odified
);
delete
o
.
tmp
.
last
_m
odified
;
delete
o
.
tmp
.
creation
_d
ate
;
deepEqual
(
o
.
tmp
,{
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
lmcd
'
:
true
},
'
check content
'
);
}
};
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
local
'
,
'
userN
ame
'
:
'
MrSaveName
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
local
'
,
'
user_n
ame
'
:
'
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
,
'
max
tries
'
:
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
'
,
'
userN
ame
'
:
'
MrLoadName
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
local
'
,
'
user_n
ame
'
:
'
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
last
Modified
'
:
1234
,
'
creationD
ate
'
:
1000
};
LocalOrCookieStorage
.
setItem
(
'
jio/localfilenamearray/MrLoadName/jiotests
'
,
[
'
file
'
]);
doc
=
{
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
last
_modified
'
:
1234
,
'
creation_d
ate
'
:
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
].
fileN
ame
]
=
array
[
k
];
obj
[
array
[
k
].
n
ame
]
=
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
'
,
'
userN
ame
'
:
'
MrListName
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
local
'
,
'
user_n
ame
'
:
'
MrListName
'
},
{
"
ID
"
:
'
jiotests
'
});
doc1
=
{
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
last
Modified
'
:
1
,
'
creationD
ate
'
:
0
};
doc2
=
{
'
fileName
'
:
'
memo
'
,
'
fileC
ontent
'
:
'
test
'
,
'
last
Modified
'
:
5
,
'
creationD
ate
'
:
2
};
doc1
=
{
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
last
_modified
'
:
1
,
'
creation_d
ate
'
:
0
};
doc2
=
{
'
name
'
:
'
memo
'
,
'
c
ontent
'
:
'
test
'
,
'
last
_modified
'
:
5
,
'
creation_d
ate
'
:
2
};
addFile
(
'
MrListName
'
,
'
jiotests
'
,
doc1
);
addFile
(
'
MrListName
'
,
'
jiotests
'
,
doc2
);
delete
doc1
.
fileC
ontent
;
delete
doc2
.
fileC
ontent
;
delete
doc1
.
c
ontent
;
delete
doc2
.
c
ontent
;
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
,
'
max
tries
'
:
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
'
,
'
userN
ame
'
:
'
MrRemoveName
'
},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
local
'
,
'
user_n
ame
'
:
'
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
({
'
user
N
ame
'
:
'
davcheck
'
,
'
callback
'
:
o
.
f
,
'
maxtries
'
:
1
});
o
.
jio
.
checkNameAvailability
({
'
user
_n
ame
'
:
'
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
'
,
'
userN
ame
'
:
'
davcheck
'
,
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dav
'
,
'
user_n
ame
'
:
'
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
,
'
max
tries
'
:
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
'
,
'
userN
ame
'
:
'
davload
'
,
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dav
'
,
'
user_n
ame
'
:
'
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
last
M
odified
'
:
1335953199000
,
'
creation
D
ate
'
:
1335953202000
},
207
,
200
);
mytest
(
'
load document
'
,{
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
last
_m
odified
'
:
1335953199000
,
'
creation
_d
ate
'
:
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f
,
'
maxtries
'
:
1
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
'
,
'
userN
ame
'
:
'
davsave
'
,
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dav
'
,
'
user_n
ame
'
:
'
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
].
fileN
ame
]
=
array
[
k
];
obj
[
array
[
k
].
n
ame
]
=
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
'
,
'
userN
ame
'
:
'
davlist
'
,
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dav
'
,
'
user_n
ame
'
:
'
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
'
,
'
creationD
ate
'
:
1335962911000
,
'
last
M
odified
'
:
1335962907000
},
{
'
fileName
'
:
'
memo
'
,
'
creationD
ate
'
:
1335894073000
,
'
last
M
odified
'
:
1335955713000
}],
207
);
mytest
(
'
getting list
'
,[{
'
name
'
:
'
file
'
,
'
creation_d
ate
'
:
1335962911000
,
'
last
_m
odified
'
:
1335962907000
},
{
'
name
'
:
'
memo
'
,
'
creation_d
ate
'
:
1335894073000
,
'
last
_m
odified
'
:
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
,
'
max
tries
'
:
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
'
,
'
userN
ame
'
:
'
davremove
'
,
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
dav
'
,
'
user_n
ame
'
:
'
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
({
'
user
N
ame
'
:
'
Dummy
'
,
'
callback
'
:
o
.
f
,
'
max
tries
'
:
o
.
max
tries
});
o
.
jio
.
checkNameAvailability
({
'
user
_n
ame
'
:
'
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
2
'
}]},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
DummyStoragesAllOK,OK : name available
'
,
true
);
o
.
jio
.
stop
();
// DummyStorageAllOK,Fail
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
replicate
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallfail
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallfail
'
,
'
user
_n
ame
'
:
'
2
'
}]},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
DummyStoragesAllOK,Fail : name not available
'
,
undefined
);
o
.
jio
.
stop
();
// DummyStorageAllFail,OK
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
replicate
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallfail
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallfail
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
2
'
}]},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
DummyStoragesAllFail,OK : name not available
'
,
undefined
);
o
.
jio
.
stop
();
// DummyStorageAllFail,Fail
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
replicate
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallfail
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallfail
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallfail
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallfail
'
,
'
user
_n
ame
'
:
'
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
max
_
tries
=
3
;
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
replicate
'
,
'
storage
A
rray
'
:[
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
2
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
3
'
}]},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
4
'
}]},
o
.
max
_
tries
=
3
;
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
replicate
'
,
'
storage
_a
rray
'
:[
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
2
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
3
'
}]},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
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
({
'
fileN
ame
'
:
'
file
'
,
'
callback
'
:
o
.
f
});
o
.
jio
.
loadDocument
({
'
n
ame
'
:
'
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
user_name
'
:
'
Dummy
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
2
'
}]},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
DummyStorageAllOK,OK: load same file
'
,{
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
last
M
odified
'
:
15000
,
'
creation
D
ate
'
:
10000
});
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
last
_m
odified
'
:
15000
,
'
creation
_d
ate
'
:
10000
});
o
.
jio
.
stop
();
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
replicate
'
,
'
userName
'
:
'
Dummy
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
user_name
'
:
'
Dummy
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
2
'
}]},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
DummyStorageAllOK,3tries: load 2 different files
'
,{
'
fileName
'
:
'
file
'
,
'
fileC
ontent
'
:
'
content
'
,
'
last
M
odified
'
:
15000
,
'
creation
D
ate
'
:
10000
});
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
content
'
,
'
last
_m
odified
'
:
15000
,
'
creation
_d
ate
'
:
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
'
,
'
fileC
ontent
'
:
'
content
'
,
'
callback
'
:
o
.
f
,
'
maxtries
'
:
3
});
o
.
jio
.
saveDocument
({
'
name
'
:
'
file
'
,
'
c
ontent
'
:
'
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
user_name
'
:
'
Dummy
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
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
].
fileN
ame
]
=
array
[
k
];
obj
[
array
[
k
].
n
ame
]
=
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
user_name
'
:
'
Dummy
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
2
'
}]},
{
'
ID
'
:
'
jiotests
'
});
o
.
doc1
=
{
'
fileN
ame
'
:
'
file
'
,
'
last
Modified
'
:
15000
,
'
creationD
ate
'
:
10000
};
o
.
doc2
=
{
'
fileN
ame
'
:
'
memo
'
,
'
last
Modified
'
:
25000
,
'
creationD
ate
'
:
20000
};
o
.
doc1
=
{
'
n
ame
'
:
'
file
'
,
'
last
_modified
'
:
15000
,
'
creation_d
ate
'
:
10000
};
o
.
doc2
=
{
'
n
ame
'
:
'
memo
'
,
'
last
_modified
'
:
25000
,
'
creation_d
ate
'
:
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
,
'
max
tries
'
:
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
'
,
'
storageA
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
N
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
N
ame
'
:
'
2
'
}]},
o
.
jio
=
JIO
.
newJio
({
'
type
'
:
'
replicate
'
,
'
user_name
'
:
'
Dummy
'
,
'
storage_a
rray
'
:[
{
'
type
'
:
'
dummyallok
'
,
'
user
_n
ame
'
:
'
1
'
},
{
'
type
'
:
'
dummyall3tries
'
,
'
user
_n
ame
'
:
'
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
({
user
N
ame
:
'
MrIndexedCheck
'
,
callback
:
o
.
f
,
maxtries
:
3
});
o
.
jio
.
checkNameAvailability
({
user
_n
ame
:
'
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
'
,
user
N
ame
:
'
indexedcheck
'
}},
user
_n
ame
:
'
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
'
,
user
N
ame
:
'
indexedload
'
}},
user
_n
ame
:
'
indexedload
'
}},
{
ID
:
'
jiotests
'
});
// loading must take long time with dummyall3tries
o
.
f
=
function
()
{};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
memo
'
,
max
tries
:
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
,
creationD
ate
:
20000
};
o
.
doc
=
{
name
:
'
memo
'
,
last_modified
:
25000
,
creation_d
ate
:
20000
};
o
.
f2
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
o
.
doc
,
'
Document metadata retrieved
'
);
};
this
.
spy
(
o
,
'
f2
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
memo
'
,
max
tries
:
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
'
,
lastM
odified
:
17000
,
creation
Date
:
11000
,
fileC
ontent
:
'
content2
'
};
o
.
doc2
=
{
name
:
'
file
'
,
last_m
odified
:
17000
,
creation
_date
:
11000
,
c
ontent
:
'
content2
'
};
o
.
f3
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
o
.
doc2
,
'
Simple document loading
'
);
};
this
.
spy
(
o
,
'
f3
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
file
'
,
max
tries
:
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
'
,
user
N
ame
:
'
indexedsave
'
}},
user
_n
ame
:
'
indexedsave
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
status
,
'
done
'
,
'
document save
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
saveDocument
({
fileName
:
'
file
'
,
max
tries
:
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
'
,
user
N
ame
:
'
indexedgetlist
'
}},
user
_n
ame
:
'
indexedgetlist
'
}},
{
ID
:
'
jiotests
'
});
o
.
doc1
=
{
fileName
:
'
file
'
,
lastModified
:
15000
,
creationD
ate
:
10000
};
o
.
doc2
=
{
fileName
:
'
memo
'
,
lastModified
:
25000
,
creationD
ate
:
20000
};
o
.
doc1
=
{
name
:
'
file
'
,
last_modified
:
15000
,
creation_d
ate
:
10000
};
o
.
doc2
=
{
name
:
'
memo
'
,
last_modified
:
25000
,
creation_d
ate
:
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
'
,
user
N
ame
:
'
indexedsave
'
}},
user
_n
ame
:
'
indexedsave
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
status
,
'
done
'
,
'
document remove
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
removeDocument
({
fileName
:
'
file
'
,
max
tries
:
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
'
,
user
N
ame
:
'
cryptcheck
'
}},
user
_n
ame
:
'
cryptcheck
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
true
,
'
name must be available
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
checkNameAvailability
({
user
N
ame
:
'
cryptcheck
'
,
maxtries
:
1
,
callback
:
o
.
f
});
o
.
jio
.
checkNameAvailability
({
user
_n
ame
:
'
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
'
,
user
N
ame
:
'
cryptsave
'
}},
user
_n
ame
:
'
cryptsave
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
status
,
'
done
'
,
'
save ok
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
saveDocument
({
fileName
:
'
testsave
'
,
fileC
ontent
:
'
contentoftest
'
,
maxtries
:
1
,
callback
:
o
.
f
});
o
.
jio
.
saveDocument
({
name
:
'
testsave
'
,
c
ontent
:
'
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
'
,
user
N
ame
:
'
cryptload
'
}},
user
_n
ame
:
'
cryptload
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
if
(
result
.
status
===
'
done
'
)
{
deepEqual
(
result
.
return_value
,{
fileN
ame
:
'
testload
'
,
fileC
ontent
:
'
contentoftest
'
,
last
M
odified
:
500
,
creation
D
ate
:
500
}
deepEqual
(
result
.
return_value
,{
n
ame
:
'
testload
'
,
c
ontent
:
'
contentoftest
'
,
last
_m
odified
:
500
,
creation
_d
ate
:
500
}
,
'
load ok
'
);
}
else
{
ok
(
false
,
'
cannot load
'
);
}
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
loadDocument
({
fileN
ame
:
'
testload
'
,
maxtries
:
1
,
callback
:
o
.
f
});
o
.
jio
.
loadDocument
({
n
ame
:
'
testload
'
,
max
_
tries
:
1
,
callback
:
o
.
f
});
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment