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
Ivan Tyagov
jio
Commits
62c918ae
Commit
62c918ae
authored
Dec 24, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localstorage.js remove method improved
parent
b5f2b208
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
+33
-3
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+33
-3
No files found.
src/jio.storage/localstorage.js
View file @
62c918ae
...
...
@@ -57,6 +57,20 @@ var newLocalStorage = function (spec, my) {
}
};
/**
* Checks if an object has no enumerable keys
* @method objectIsEmpty
* @param {object} obj The object
* @return {boolean} true if empty, else false
*/
priv
.
objectIsEmpty
=
function
(
obj
)
{
var
k
;
for
(
k
in
obj
)
{
return
false
;
}
return
true
;
};
// ===================== overrides ======================
that
.
serialized
=
function
()
{
return
{
...
...
@@ -225,16 +239,19 @@ var newLocalStorage = function (spec, my) {
that
.
remove
=
function
(
command
)
{
setTimeout
(
function
()
{
var
doc
;
doc
=
localstorage
.
getItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
());
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
// seeking for an attachment
doc
=
localstorage
.
getItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
());
localstorage
.
deleteItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
());
// remove attachment from document
if
(
typeof
doc
[
"
_attachments
"
]
!==
"
undefined
"
)
{
if
(
typeof
doc
[
"
_attachments
"
]
===
"
object
"
)
{
delete
doc
[
"
_attachments
"
][
command
.
getAttachmentId
()];
if
(
priv
.
objectIsEmpty
(
doc
[
"
_attachments
"
]))
{
delete
doc
[
"
_attachments
"
];
}
localstorage
.
setItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
(),
doc
);
...
...
@@ -245,8 +262,21 @@ var newLocalStorage = function (spec, my) {
});
}
else
{
// seeking for a document
var
attachment_list
=
[],
i
;
if
(
typeof
doc
[
"
_attachments
"
]
===
"
object
"
)
{
// prepare list of attachments
for
(
i
in
doc
[
"
_attachments
"
])
{
attachment_list
.
push
(
i
);
}
}
localstorage
.
deleteItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
());
// delete all attachments
for
(
i
=
0
;
i
<
attachment_list
.
length
;
i
+=
1
)
{
localstorage
.
deleteItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
()
+
"
/
"
+
attachment_list
[
i
]);
}
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
...
...
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