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