Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
cc8c320f
Commit
cc8c320f
authored
Nov 23, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating localstorage put method
parent
0536cec8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
23 deletions
+76
-23
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+76
-23
No files found.
src/jio.storage/localstorage.js
View file @
cc8c320f
...
@@ -210,6 +210,30 @@ var newLocalStorage = function ( spec, my ) {
...
@@ -210,6 +210,30 @@ var newLocalStorage = function ( spec, my ) {
return
obj
;
return
obj
;
};
};
/**
* Update [doc] the document object and remove [doc] keys
* which are not in [new_doc]. It only changes [doc] keys not starting
* with an underscore.
* ex: doc: {key:value1,_key:value2} with
* new_doc: {key:value3,_key:value4} updates
* doc: {key:value3,_key:value2}.
* @param {object} doc The original document object.
* @param {object} new_doc The new document object
*/
priv
.
documentObjectUpdate
=
function
(
doc
,
new_doc
)
{
var
k
;
for
(
k
in
doc
)
{
if
(
k
[
0
]
!==
'
_
'
)
{
delete
doc
[
k
];
}
}
for
(
k
in
new_doc
)
{
if
(
k
[
0
]
!==
'
_
'
)
{
doc
[
k
]
=
new_doc
[
k
];
}
}
};
/**
/**
* Create a document in the local storage.
* Create a document in the local storage.
* It will store the file in 'jio/local/USR/APP/FILE_NAME'.
* It will store the file in 'jio/local/USR/APP/FILE_NAME'.
...
@@ -285,37 +309,66 @@ var newLocalStorage = function ( spec, my ) {
...
@@ -285,37 +309,66 @@ var newLocalStorage = function ( spec, my ) {
* @method put
* @method put
*/
*/
that
.
put
=
function
(
command
)
{
that
.
put
=
function
(
command
)
{
var
now
=
Date
.
now
();
// wait a little in order to simulate asynchronous saving
// wait a little in order to simulate asynchronous saving
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
secured_docid
=
priv
.
secureDocId
(
command
.
getDocId
()),
var
docid
,
doc
,
docpath
,
attmtid
,
attmt
,
attmtpath
,
prev_rev
;
doc
=
null
,
path
=
doc
id
=
command
.
getDocId
();
'
jio/local/
'
+
priv
.
secured_username
+
'
/
'
+
prev_rev
=
command
.
getDocInfo
(
'
_rev
'
);
priv
.
secured_application
name
+
'
/
'
+
docpath
=
'
jio/local/
'
+
priv
.
secured_user
name
+
'
/
'
+
secured_
docid
;
priv
.
secured_applicationname
+
'
/
'
+
docid
;
if
(
!
priv
.
checkSecuredDocId
(
secured_docid
,
command
.
getDocId
(),
'
put
'
))
{
return
;}
// reading
// reading
doc
=
LocalOrCookieStorage
.
getItem
(
path
);
doc
=
localstorage
.
getItem
(
doc
path
);
if
(
!
doc
)
{
if
(
!
doc
)
{
// create document
that
.
error
({
doc
=
{
status
:
404
,
statusText
:
'
Not found
'
,
error
:
'
not_found
'
,
_id
:
command
.
getDocId
(),
message
:
'
Document not found.
'
,
content
:
command
.
getDocContent
(),
reason
:
'
document not found
'
_creation_date
:
Date
.
now
(),
});
_last_modified
:
Date
.
now
()
return
;
};
}
if
(
!
priv
.
userExists
(
priv
.
secured_username
))
{
if
(
doc
.
_rev
!==
prev_rev
)
{
priv
.
addUser
(
priv
.
secured_username
);
// want to update an older document
that
.
error
({
status
:
409
,
statusText
:
'
Conflict
'
,
error
:
'
conflict
'
,
message
:
'
Document update conflict.
'
,
reason
:
'
document update conflict.
'
});
return
;
}
// it is the good document
attmtid
=
command
.
getAttachmentId
();
if
(
attmtid
)
{
attmtpath
=
docpath
+
'
/
'
+
attmtid
;
// this is an attachment
attmt
=
localstorage
.
getItem
(
attmtpath
);
if
(
!
attmt
)
{
// there is no attachment to update
that
.
error
({
status
:
404
,
statusText
:
'
Not found
'
,
error
:
'
not_found
'
,
message
:
'
Document is missing attachment.
'
,
reason
:
'
document is missing attachment
'
});
return
;
}
}
priv
.
addFileName
(
secured_docid
);
// updating attachment
doc
.
_attachments
[
attmtid
].
revpos
=
parseInt
(
doc
.
_rev
.
split
(
'
-
'
)[
0
],
10
);
localstorage
.
setItem
(
attmtpath
,
command
.
getContent
());
}
else
{
}
else
{
// overwriting
// update document metadata
doc
.
content
=
command
.
getDocContent
();
priv
.
documentObjectUpdate
(
doc
,
command
.
cloneDoc
());
doc
.
_last_modified
=
Date
.
now
();
}
}
localStorage
.
setItem
(
path
,
doc
);
doc
.
_rev
=
priv
.
generateNextRev
(
prev_rev
,
''
+
doc
+
'
'
+
now
+
''
);
that
.
success
({
ok
:
true
,
id
:
command
.
getDocId
()});
localstorage
.
setItem
(
docpath
,
doc
);
that
.
success
(
priv
.
manageOptions
(
{
ok
:
true
,
id
:
docid
,
rev
:
doc
.
_rev
},
command
,
doc
)
);
});
});
};
// end put
};
// end put
...
...
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