Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Roque
jio
Commits
cf955906
Commit
cf955906
authored
Jan 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass indexstorage.js
parent
6e6d67b7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
220 additions
and
201 deletions
+220
-201
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+220
-201
No files found.
src/jio.storage/indexstorage.js
View file @
cf955906
jIO
.
addStorageType
(
'
indexed
'
,
function
(
spec
,
my
)
{
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global jIO: true, localStorage: true, setTimeout: true */
jIO
.
addStorageType
(
'
indexed
'
,
function
(
spec
,
my
)
{
spec
=
spec
||
{};
spec
=
spec
||
{};
var
that
=
my
.
basicStorage
(
spec
,
my
),
priv
=
{};
var
that
=
my
.
basicStorage
(
spec
,
my
),
priv
=
{},
validatestate_sub_storage
=
spec
.
storage
||
false
,
storage_object_name
=
'
jio/indexed_storage_object
'
,
storage_file_object_name
,
super_serialized
=
that
.
serialized
;
var
validatestate_sub_storage
=
spec
.
storage
||
false
;
priv
.
sub_storage_spec
=
spec
.
storage
||
{
priv
.
sub_storage_spec
=
spec
.
storage
||
{
type
:
'
base
'
};
type
:
'
base
'
priv
.
sub_storage_string
=
JSON
.
stringify
(
priv
.
sub_storage_spec
);
};
priv
.
sub_storage_string
=
JSON
.
stringify
(
priv
.
sub_storage_spec
);
var
storage_object_name
=
'
jio/indexed_storage_object
'
;
storage_file_object_name
=
'
jio/indexed_file_object/
'
+
var
storage_file_object_name
=
'
jio/indexed_file_object/
'
+
priv
.
sub_storage_string
;
priv
.
sub_storage_string
;
var
super_serialized
=
that
.
serialized
;
that
.
serialized
=
function
()
{
that
.
serialized
=
function
()
{
var
o
=
super_serialized
();
var
o
=
super_serialized
();
o
.
storage
=
priv
.
sub_storage_spec
;
o
.
storage
=
priv
.
sub_storage_spec
;
...
@@ -19,45 +25,56 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -19,45 +25,56 @@ jIO.addStorageType ('indexed', function (spec, my) {
that
.
validateState
=
function
()
{
that
.
validateState
=
function
()
{
if
(
!
validatestate_sub_storage
)
{
if
(
!
validatestate_sub_storage
)
{
return
'
Need at least one parameter: "storage"
'
+
return
'
Need at least one parameter: "storage"
'
+
'
containing storage specifications.
'
;
'
containing storage specifications.
'
;
}
}
return
''
;
return
''
;
};
};
priv
.
secureDocId
=
function
(
string
)
{
priv
.
secureDocId
=
function
(
string
)
{
var
split
=
string
.
split
(
'
/
'
),
i
;
var
split
=
string
.
split
(
'
/
'
),
i
;
if
(
split
[
0
]
===
''
)
{
if
(
split
[
0
]
===
''
)
{
split
=
split
.
slice
(
1
);
split
=
split
.
slice
(
1
);
}
}
for
(
i
=
0
;
i
<
split
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
split
.
length
;
i
+=
1
)
{
if
(
split
[
i
]
===
''
)
{
return
''
;
}
if
(
split
[
i
]
===
''
)
{
return
''
;
}
}
}
return
split
.
join
(
'
%2F
'
);
return
split
.
join
(
'
%2F
'
);
};
};
priv
.
indexStorage
=
function
()
{
priv
.
indexStorage
=
function
()
{
var
obj
=
localStorage
.
getItem
(
storage_object_name
)
||
{};
var
obj
=
localStorage
.
getItem
(
storage_object_name
)
||
{};
obj
[
priv
.
sub_storage_spec
]
=
new
Date
().
getTime
();
obj
[
priv
.
sub_storage_spec
]
=
new
Date
().
getTime
();
localStorage
.
setItem
(
storage_object_name
,
obj
);
localStorage
.
setItem
(
storage_object_name
,
obj
);
};
};
priv
.
formatToFileObject
=
function
(
row
)
{
priv
.
formatToFileObject
=
function
(
row
)
{
var
k
,
obj
=
{
_id
:
row
.
id
};
var
k
,
obj
=
{
_id
:
row
.
id
};
for
(
k
in
row
.
value
)
{
for
(
k
in
row
.
value
)
{
if
(
row
.
value
.
hasOwnProperty
(
k
))
{
obj
[
k
]
=
row
.
value
[
k
];
obj
[
k
]
=
row
.
value
[
k
];
}
}
}
return
obj
;
return
obj
;
};
};
priv
.
allDocs
=
function
(
files_object
)
{
priv
.
allDocs
=
function
(
files_object
)
{
var
k
,
obj
=
{
rows
:[]},
i
=
0
;
var
k
,
obj
=
{
rows
:
[]
},
i
=
0
;
for
(
k
in
files_object
)
{
for
(
k
in
files_object
)
{
if
(
files_object
.
hasOwnProperty
(
k
))
{
obj
.
rows
[
i
]
=
{};
obj
.
rows
[
i
]
=
{};
obj
.
rows
[
i
].
value
=
files_object
[
k
];
obj
.
rows
[
i
].
value
=
files_object
[
k
];
obj
.
rows
[
i
].
id
=
obj
.
rows
[
i
].
key
=
obj
.
rows
[
i
].
value
.
_id
;
obj
.
rows
[
i
].
id
=
obj
.
rows
[
i
].
key
=
obj
.
rows
[
i
].
value
.
_id
;
delete
obj
.
rows
[
i
].
value
.
_id
;
delete
obj
.
rows
[
i
].
value
.
_id
;
i
++
;
i
+=
1
;
}
}
}
obj
.
total_rows
=
obj
.
rows
.
length
;
obj
.
total_rows
=
obj
.
rows
.
length
;
return
obj
;
return
obj
;
...
@@ -65,27 +82,27 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -65,27 +82,27 @@ jIO.addStorageType ('indexed', function (spec, my) {
priv
.
setFileArray
=
function
(
file_array
)
{
priv
.
setFileArray
=
function
(
file_array
)
{
var
i
,
obj
=
{};
var
i
,
obj
=
{};
for
(
i
=
0
;
i
<
file_array
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
file_array
.
length
;
i
+=
1
)
{
obj
[
file_array
[
i
].
id
]
=
priv
.
formatToFileObject
(
file_array
[
i
]);
obj
[
file_array
[
i
].
id
]
=
priv
.
formatToFileObject
(
file_array
[
i
]);
}
}
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
};
};
priv
.
getFileObject
=
function
(
docid
)
{
priv
.
getFileObject
=
function
(
docid
)
{
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
return
obj
[
docid
];
return
obj
[
docid
];
};
};
priv
.
addFile
=
function
(
file_obj
)
{
priv
.
addFile
=
function
(
file_obj
)
{
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
obj
[
file_obj
.
_id
]
=
file_obj
;
obj
[
file_obj
.
_id
]
=
file_obj
;
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
};
};
priv
.
removeFile
=
function
(
docid
)
{
priv
.
removeFile
=
function
(
docid
)
{
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
delete
obj
[
docid
];
delete
obj
[
docid
];
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
};
};
/**
/**
...
@@ -99,8 +116,9 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -99,8 +116,9 @@ jIO.addStorageType ('indexed', function (spec, my) {
var
success
=
function
(
val
)
{
var
success
=
function
(
val
)
{
priv
.
setFileArray
(
val
.
rows
);
priv
.
setFileArray
(
val
.
rows
);
};
};
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
{
{
max_retry
:
3
},
success
,
function
(){});
max_retry
:
3
},
success
,
function
()
{});
};
};
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
...
@@ -122,8 +140,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -122,8 +140,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
that
.
error
(
err
);
that
.
error
(
err
);
};
};
priv
.
indexStorage
();
priv
.
indexStorage
();
that
.
addJob
(
'
put
'
,
priv
.
sub_storage_spec
,
cloned_doc
,
that
.
addJob
(
'
put
'
,
priv
.
sub_storage_spec
,
cloned_doc
,
cloned_option
,
success
,
error
);
cloned_option
,
success
,
error
);
};
// end put
};
// end put
/**
/**
...
@@ -131,8 +149,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -131,8 +149,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
* @method get
* @method get
*/
*/
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
var
file_array
,
// jslint unused var file_array
success
=
function
(
val
)
{
var
success
=
function
(
val
)
{
that
.
success
(
val
);
that
.
success
(
val
);
},
},
error
=
function
(
err
)
{
error
=
function
(
err
)
{
...
@@ -140,8 +158,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -140,8 +158,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
},
},
get
=
function
()
{
get
=
function
()
{
var
cloned_option
=
command
.
cloneOption
();
var
cloned_option
=
command
.
cloneOption
();
that
.
addJob
(
'
get
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
that
.
addJob
(
'
get
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
cloned_option
,
success
,
error
);
cloned_option
,
success
,
error
);
that
.
end
();
that
.
end
();
};
};
priv
.
indexStorage
();
priv
.
indexStorage
();
...
@@ -149,10 +167,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -149,10 +167,8 @@ jIO.addStorageType ('indexed', function (spec, my) {
if
(
command
.
getOption
(
'
metadata_only
'
))
{
if
(
command
.
getOption
(
'
metadata_only
'
))
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
file_obj
=
priv
.
getFileObject
(
command
.
getDocId
());
var
file_obj
=
priv
.
getFileObject
(
command
.
getDocId
());
if
(
file_obj
&&
if
(
file_obj
&&
(
file_obj
.
_last_modified
||
file_obj
.
_creation_date
))
{
(
file_obj
.
_last_modified
||
that
.
success
(
file_obj
);
file_obj
.
_creation_date
))
{
that
.
success
(
file_obj
);
}
else
{
}
else
{
get
();
get
();
}
}
...
@@ -167,22 +183,25 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -167,22 +183,25 @@ jIO.addStorageType ('indexed', function (spec, my) {
* @method allDocs
* @method allDocs
*/
*/
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
);
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
),
success
,
error
;
if
(
obj
)
{
if
(
obj
)
{
priv
.
update
();
priv
.
update
();
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
(
priv
.
allDocs
(
obj
));
that
.
success
(
priv
.
allDocs
(
obj
));
});
});
}
else
{
}
else
{
var
success
=
function
(
val
)
{
success
=
function
(
val
)
{
priv
.
setFileArray
(
val
.
rows
);
priv
.
setFileArray
(
val
.
rows
);
that
.
success
(
val
);
that
.
success
(
val
);
},
};
error
=
function
(
err
)
{
error
=
function
(
err
)
{
that
.
error
(
err
);
that
.
error
(
err
);
};
};
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
command
.
cloneOption
(),
success
,
error
);
command
.
cloneOption
(),
success
,
error
);
}
}
};
// end allDocs
};
// end allDocs
...
@@ -199,9 +218,9 @@ jIO.addStorageType ('indexed', function (spec, my) {
...
@@ -199,9 +218,9 @@ jIO.addStorageType ('indexed', function (spec, my) {
error
=
function
(
err
)
{
error
=
function
(
err
)
{
that
.
error
(
err
);
that
.
error
(
err
);
};
};
that
.
addJob
(
'
remove
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
that
.
addJob
(
'
remove
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
command
.
cloneOption
(),
success
,
error
);
command
.
cloneOption
(),
success
,
error
);
};
// end remove
};
// end remove
return
that
;
return
that
;
};
}
)
;
\ No newline at end of file
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