Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
preetwinder
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
Hide 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 */
spec
=
spec
||
{};
/*global jIO: true, localStorage: true, setTimeout: true */
var
that
=
my
.
basicStorage
(
spec
,
my
),
priv
=
{};
jIO
.
addStorageType
(
'
indexed
'
,
function
(
spec
,
my
)
{
spec
=
spec
||
{};
var
validatestate_sub_storage
=
spec
.
storage
||
false
;
var
that
=
my
.
basicStorage
(
spec
,
my
),
priv
.
sub_storage_spec
=
spec
.
storage
||
{
type
:
'
base
'
};
priv
=
{},
priv
.
sub_storage_string
=
JSON
.
stringify
(
priv
.
sub_storage_spec
);
validatestate_sub_storage
=
spec
.
storage
||
false
,
storage_object_name
=
'
jio/indexed_storage_object
'
,
var
storage_object_name
=
'
jio/indexed_storage_object
'
;
storage_file_object_name
,
var
storage_file_object_name
=
'
jio/indexed_file_object/
'
+
super_serialized
=
that
.
serialized
;
priv
.
sub_storage_string
;
priv
.
sub_storage_spec
=
spec
.
storage
||
{
var
super_serialized
=
that
.
serialized
;
type
:
'
base
'
that
.
serialized
=
function
()
{
};
var
o
=
super_serialized
();
priv
.
sub_storage_string
=
JSON
.
stringify
(
priv
.
sub_storage_spec
);
o
.
storage
=
priv
.
sub_storage_spec
;
return
o
;
storage_file_object_name
=
'
jio/indexed_file_object/
'
+
};
priv
.
sub_storage_string
;
that
.
validateState
=
function
()
{
that
.
serialized
=
function
()
{
if
(
!
validatestate_sub_storage
)
{
var
o
=
super_serialized
();
return
'
Need at least one parameter: "storage"
'
+
o
.
storage
=
priv
.
sub_storage_spec
;
'
containing storage specifications.
'
;
return
o
;
}
};
that
.
validateState
=
function
()
{
if
(
!
validatestate_sub_storage
)
{
return
'
Need at least one parameter: "storage"
'
+
'
containing storage specifications.
'
;
}
return
''
;
};
priv
.
secureDocId
=
function
(
string
)
{
var
split
=
string
.
split
(
'
/
'
),
i
;
if
(
split
[
0
]
===
''
)
{
split
=
split
.
slice
(
1
);
}
for
(
i
=
0
;
i
<
split
.
length
;
i
+=
1
)
{
if
(
split
[
i
]
===
''
)
{
return
''
;
return
''
;
}
}
return
split
.
join
(
'
%2F
'
);
};
priv
.
indexStorage
=
function
()
{
var
obj
=
localStorage
.
getItem
(
storage_object_name
)
||
{};
obj
[
priv
.
sub_storage_spec
]
=
new
Date
().
getTime
();
localStorage
.
setItem
(
storage_object_name
,
obj
);
};
priv
.
formatToFileObject
=
function
(
row
)
{
var
k
,
obj
=
{
_id
:
row
.
id
};
};
for
(
k
in
row
.
value
)
{
priv
.
secureDocId
=
function
(
string
)
{
if
(
row
.
value
.
hasOwnProperty
(
k
))
{
var
split
=
string
.
split
(
'
/
'
),
i
;
obj
[
k
]
=
row
.
value
[
k
];
if
(
split
[
0
]
===
''
)
{
}
split
=
split
.
slice
(
1
);
}
}
return
obj
;
for
(
i
=
0
;
i
<
split
.
length
;
i
+=
1
)
{
};
if
(
split
[
i
]
===
''
)
{
return
''
;
}
}
priv
.
allDocs
=
function
(
files_object
)
{
return
split
.
join
(
'
%2F
'
);
var
k
,
obj
=
{
};
rows
:
[]
},
i
=
0
;
priv
.
indexStorage
=
function
()
{
for
(
k
in
files_object
)
{
var
obj
=
localStorage
.
getItem
(
storage_object_name
)
||
{};
if
(
files_object
.
hasOwnProperty
(
k
))
{
obj
[
priv
.
sub_storage_spec
]
=
new
Date
().
getTime
();
obj
.
rows
[
i
]
=
{};
localStorage
.
setItem
(
storage_object_name
,
obj
);
obj
.
rows
[
i
].
value
=
files_object
[
k
];
};
obj
.
rows
[
i
].
id
=
obj
.
rows
[
i
].
key
=
obj
.
rows
[
i
].
value
.
_id
;
delete
obj
.
rows
[
i
].
value
.
_id
;
priv
.
formatToFileObject
=
function
(
row
)
{
i
+=
1
;
var
k
,
obj
=
{
_id
:
row
.
id
};
}
for
(
k
in
row
.
value
)
{
}
obj
[
k
]
=
row
.
value
[
k
];
obj
.
total_rows
=
obj
.
rows
.
length
;
}
return
obj
;
return
obj
;
};
};
priv
.
setFileArray
=
function
(
file_array
)
{
priv
.
allDocs
=
function
(
files_object
)
{
var
i
,
obj
=
{};
var
k
,
obj
=
{
rows
:[]},
i
=
0
;
for
(
i
=
0
;
i
<
file_array
.
length
;
i
+=
1
)
{
for
(
k
in
files_object
)
{
obj
[
file_array
[
i
].
id
]
=
priv
.
formatToFileObject
(
file_array
[
i
]);
obj
.
rows
[
i
]
=
{};
}
obj
.
rows
[
i
].
value
=
files_object
[
k
];
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
obj
.
rows
[
i
].
id
=
obj
.
rows
[
i
].
key
=
obj
.
rows
[
i
].
value
.
_id
;
};
delete
obj
.
rows
[
i
].
value
.
_id
;
i
++
;
priv
.
getFileObject
=
function
(
docid
)
{
}
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
obj
.
total_rows
=
obj
.
rows
.
length
;
return
obj
[
docid
];
return
obj
;
};
};
priv
.
addFile
=
function
(
file_obj
)
{
priv
.
setFileArray
=
function
(
file_array
)
{
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
var
i
,
obj
=
{};
obj
[
file_obj
.
_id
]
=
file_obj
;
for
(
i
=
0
;
i
<
file_array
.
length
;
i
+=
1
)
{
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
obj
[
file_array
[
i
].
id
]
=
priv
.
formatToFileObject
(
file_array
[
i
]);
};
}
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
priv
.
removeFile
=
function
(
docid
)
{
};
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
delete
obj
[
docid
];
priv
.
getFileObject
=
function
(
docid
)
{
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
};
return
obj
[
docid
];
};
/**
* updates the storage.
priv
.
addFile
=
function
(
file_obj
)
{
* It will retreive all files from a storage. It is an asynchronous task
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
* so the update can be on going even if IndexedStorage has already
obj
[
file_obj
.
_id
]
=
file_obj
;
* returned the result.
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
* @method update
};
*/
priv
.
update
=
function
()
{
priv
.
removeFile
=
function
(
docid
)
{
var
success
=
function
(
val
)
{
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
)
||
{};
priv
.
setFileArray
(
val
.
rows
);
delete
obj
[
docid
];
localStorage
.
setItem
(
storage_file_object_name
,
obj
);
};
};
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
{
/**
max_retry
:
3
* updates the storage.
},
success
,
function
()
{});
* It will retreive all files from a storage. It is an asynchronous task
};
* so the update can be on going even if IndexedStorage has already
* returned the result.
that
.
post
=
function
(
command
)
{
* @method update
that
.
put
(
command
);
*/
};
priv
.
update
=
function
()
{
var
success
=
function
(
val
)
{
/**
priv
.
setFileArray
(
val
.
rows
);
* Saves a document.
};
* @method put
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
*/
{
max_retry
:
3
},
success
,
function
(){});
that
.
put
=
function
(
command
)
{
};
var
cloned_doc
=
command
.
cloneDoc
(),
cloned_option
=
command
.
cloneOption
(),
that
.
post
=
function
(
command
)
{
success
=
function
(
val
)
{
that
.
put
(
command
);
};
/**
* Saves a document.
* @method put
*/
that
.
put
=
function
(
command
)
{
var
cloned_doc
=
command
.
cloneDoc
(),
cloned_option
=
command
.
cloneOption
(),
success
=
function
(
val
)
{
priv
.
update
();
that
.
success
(
val
);
},
error
=
function
(
err
)
{
that
.
error
(
err
);
};
priv
.
indexStorage
();
that
.
addJob
(
'
put
'
,
priv
.
sub_storage_spec
,
cloned_doc
,
cloned_option
,
success
,
error
);
};
// end put
/**
* Loads a document.
* @method get
*/
that
.
get
=
function
(
command
)
{
var
file_array
,
success
=
function
(
val
)
{
that
.
success
(
val
);
},
error
=
function
(
err
)
{
that
.
error
(
err
);
},
get
=
function
()
{
var
cloned_option
=
command
.
cloneOption
();
that
.
addJob
(
'
get
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
cloned_option
,
success
,
error
);
that
.
end
();
};
priv
.
indexStorage
();
priv
.
update
();
priv
.
update
();
if
(
command
.
getOption
(
'
metadata_only
'
))
{
that
.
success
(
val
);
setTimeout
(
function
()
{
},
var
file_obj
=
priv
.
getFileObject
(
command
.
getDocId
());
error
=
function
(
err
)
{
if
(
file_obj
&&
that
.
error
(
err
);
(
file_obj
.
_last_modified
||
};
file_obj
.
_creation_date
))
{
priv
.
indexStorage
();
that
.
success
(
file_obj
);
that
.
addJob
(
'
put
'
,
priv
.
sub_storage_spec
,
cloned_doc
,
}
else
{
cloned_option
,
success
,
error
);
get
();
};
// end put
}
});
/**
}
else
{
* Loads a document.
get
();
* @method get
}
*/
};
// end get
that
.
get
=
function
(
command
)
{
// jslint unused var file_array
/**
var
success
=
function
(
val
)
{
* Gets a document list.
that
.
success
(
val
);
* @method allDocs
},
*/
error
=
function
(
err
)
{
that
.
allDocs
=
function
(
command
)
{
that
.
error
(
err
);
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
);
},
if
(
obj
)
{
get
=
function
()
{
priv
.
update
();
var
cloned_option
=
command
.
cloneOption
();
setTimeout
(
function
(){
that
.
addJob
(
'
get
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
that
.
success
(
priv
.
allDocs
(
obj
));
cloned_option
,
success
,
error
);
});
that
.
end
();
};
priv
.
indexStorage
();
priv
.
update
();
if
(
command
.
getOption
(
'
metadata_only
'
))
{
setTimeout
(
function
()
{
var
file_obj
=
priv
.
getFileObject
(
command
.
getDocId
());
if
(
file_obj
&&
(
file_obj
.
_last_modified
||
file_obj
.
_creation_date
))
{
that
.
success
(
file_obj
);
}
else
{
}
else
{
var
success
=
function
(
val
)
{
get
();
priv
.
setFileArray
(
val
.
rows
);
that
.
success
(
val
);
},
error
=
function
(
err
)
{
that
.
error
(
err
);
};
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
command
.
cloneOption
(),
success
,
error
);
}
}
};
// end allDocs
});
}
else
{
/**
get
();
* Removes a document.
}
* @method remove
};
// end get
*/
that
.
remove
=
function
(
command
)
{
/**
var
success
=
function
(
val
)
{
* Gets a document list.
priv
.
removeFile
(
command
.
getDocId
());
* @method allDocs
priv
.
update
();
*/
that
.
success
(
val
);
that
.
allDocs
=
function
(
command
)
{
},
var
obj
=
localStorage
.
getItem
(
storage_file_object_name
),
error
=
function
(
err
)
{
success
,
that
.
error
(
err
);
error
;
};
that
.
addJob
(
'
remove
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
if
(
obj
)
{
command
.
cloneOption
(),
success
,
error
);
priv
.
update
();
};
// end remove
setTimeout
(
function
()
{
that
.
success
(
priv
.
allDocs
(
obj
));
return
that
;
});
};
}
else
{
success
=
function
(
val
)
{
priv
.
setFileArray
(
val
.
rows
);
that
.
success
(
val
);
};
error
=
function
(
err
)
{
that
.
error
(
err
);
};
that
.
addJob
(
'
allDocs
'
,
priv
.
sub_storage_spec
,
null
,
command
.
cloneOption
(),
success
,
error
);
}
};
// end allDocs
/**
* Removes a document.
* @method remove
*/
that
.
remove
=
function
(
command
)
{
var
success
=
function
(
val
)
{
priv
.
removeFile
(
command
.
getDocId
());
priv
.
update
();
that
.
success
(
val
);
},
error
=
function
(
err
)
{
that
.
error
(
err
);
};
that
.
addJob
(
'
remove
'
,
priv
.
sub_storage_spec
,
command
.
cloneDoc
(),
command
.
cloneOption
(),
success
,
error
);
};
// end remove
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