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
Guillaume Royer
jio
Commits
fc2b0295
Commit
fc2b0295
authored
Dec 24, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localstorage.js private methods added, modified or removed
parent
7c518e1e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
182 deletions
+21
-182
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+21
-182
No files found.
src/jio.storage/localstorage.js
View file @
fc2b0295
...
@@ -5,8 +5,9 @@
...
@@ -5,8 +5,9 @@
var
newLocalStorage
=
function
(
spec
,
my
)
{
var
newLocalStorage
=
function
(
spec
,
my
)
{
spec
=
spec
||
{};
spec
=
spec
||
{};
var
that
=
my
.
basicStorage
(
spec
,
my
),
var
that
,
priv
,
localstorage
;
priv
=
{},
that
=
my
.
basicStorage
(
spec
,
my
);
priv
=
{};
/*
/*
* Wrapper for the localStorage used to simplify instion of any kind of
* Wrapper for the localStorage used to simplify instion of any kind of
...
@@ -22,110 +23,16 @@ var newLocalStorage = function (spec, my) {
...
@@ -22,110 +23,16 @@ var newLocalStorage = function (spec, my) {
deleteItem
:
function
(
item
)
{
deleteItem
:
function
(
item
)
{
delete
localStorage
[
item
];
delete
localStorage
[
item
];
}
}
},
};
storage_user_array_name
,
storage_file_array_name
;
// attributes
// attributes
priv
.
username
=
spec
.
username
||
''
;
priv
.
username
=
spec
.
username
||
''
;
priv
.
applicationname
=
spec
.
applicationname
||
'
untitled
'
;
priv
.
applicationname
=
spec
.
applicationname
||
'
untitled
'
;
storage_user_array_name
=
'
jio/local_user_array
'
;
priv
.
localpath
=
'
jio/localstorage/
'
+
storage_file_array_name
=
'
jio/local_file_name_array/
'
+
priv
.
username
+
'
/
'
+
priv
.
applicationname
;
priv
.
username
+
'
/
'
+
priv
.
applicationname
;
/**
// ==================== Tools ====================
* Returns a list of users.
* @method getUserArray
* @return {array} The list of users.
*/
priv
.
getUserArray
=
function
()
{
return
localstorage
.
getItem
(
storage_user_array_name
)
||
[];
};
/**
* Adds a user to the user list.
* @method addUser
* @param {string} user_name The user name.
*/
priv
.
addUser
=
function
(
user_name
)
{
var
user_array
=
priv
.
getUserArray
();
user_array
.
push
(
user_name
);
localstorage
.
setItem
(
storage_user_array_name
,
user_array
);
};
/**
* checks if a user exists in the user array.
* @method doesUserExist
* @param {string} user_name The user name
* @return {boolean} true if exist, else false
*/
priv
.
doesUserExist
=
function
(
user_name
)
{
var
user_array
=
priv
.
getUserArray
(),
i
,
l
;
for
(
i
=
0
,
l
=
user_array
.
length
;
i
<
l
;
i
+=
1
)
{
if
(
user_array
[
i
]
===
user_name
)
{
return
true
;
}
}
return
false
;
};
/**
* Returns the file names of all existing files owned by the user.
* @method getFileNameArray
* @return {array} All the existing file paths.
*/
priv
.
getFileNameArray
=
function
()
{
return
localstorage
.
getItem
(
storage_file_array_name
)
||
[];
};
/**
* Adds a file name to the local file name array.
* @method addFileName
* @param {string} file_name The new file name.
*/
priv
.
addFileName
=
function
(
file_name
)
{
var
file_name_array
=
priv
.
getFileNameArray
();
file_name_array
.
push
(
file_name
);
localstorage
.
setItem
(
storage_file_array_name
,
file_name_array
);
};
/**
* Removes a file name from the local file name array.
* @method removeFileName
* @param {string} file_name The file name to remove.
*/
priv
.
removeFileName
=
function
(
file_name
)
{
var
i
,
l
,
array
=
priv
.
getFileNameArray
(),
new_array
=
[];
for
(
i
=
0
,
l
=
array
.
length
;
i
<
l
;
i
+=
1
)
{
if
(
array
[
i
]
!==
file_name
)
{
new_array
.
push
(
array
[
i
]);
}
}
localstorage
.
setItem
(
storage_file_array_name
,
new_array
);
};
/**
* Extends [obj] adding 0 to 3 values according to [command] options.
* @method manageOptions
* @param {object} obj The obj to extend
* @param {object} command The JIO command
* @param {object} doc The document object
*/
priv
.
manageOptions
=
function
(
obj
,
command
,
doc
)
{
obj
=
obj
||
{};
if
(
command
.
getOption
(
'
revs
'
))
{
obj
.
revisions
=
doc
.
_revisions
;
}
if
(
command
.
getOption
(
'
revs_info
'
))
{
obj
.
revs_info
=
doc
.
_revs_info
;
}
if
(
command
.
getOption
(
'
conflicts
'
))
{
obj
.
conflicts
=
{
total_rows
:
0
,
rows
:[]};
}
return
obj
;
};
/**
/**
* Update [doc] the document object and remove [doc] keys
* Update [doc] the document object and remove [doc] keys
* which are not in [new_doc]. It only changes [doc] keys not starting
* which are not in [new_doc]. It only changes [doc] keys not starting
...
@@ -150,75 +57,6 @@ var newLocalStorage = function (spec, my) {
...
@@ -150,75 +57,6 @@ var newLocalStorage = function (spec, my) {
}
}
};
};
/**
* Create a new document
* @method setDocument
* @param {object} command Command object
* @param {string} trigger Put/Post
*/
priv
.
setDocument
=
function
(
command
,
trigger
)
{
var
doc
=
command
.
getDoc
(),
document_id
=
doc
.
_id
,
document_rev
=
doc
.
_rev
,
document_path
=
'
jio/local/
'
+
priv
.
username
+
'
/
'
+
priv
.
applicationname
+
'
/
'
+
document_id
+
'
/
'
+
document_rev
;
if
(
trigger
===
'
put
'
){
priv
.
documentObjectUpdate
(
doc
,
command
.
cloneDoc
());
}
localstorage
.
setItem
(
document_path
,
doc
);
if
(
trigger
===
'
post
'
){
if
(
!
priv
.
doesUserExist
(
priv
.
username
))
{
priv
.
addUser
(
priv
.
username
);
}
priv
.
addFileName
(
document_id
);
}
return
priv
.
manageOptions
(
{
ok
:
true
,
id
:
document_id
,
rev
:
document_rev
},
command
,
doc
);
};
/**
* get a document or attachment
* @method getDocument
* @param {object} command Command object
*/
priv
.
getDocument
=
function
(
command
)
{
var
doc
=
command
.
getDoc
();
document_id
=
doc
.
_id
;
document_rev
=
doc
.
_rev
;
document_path
=
'
jio/local/
'
+
priv
.
username
+
'
/
'
+
priv
.
applicationname
+
'
/
'
+
document_id
+
'
/
'
+
document_rev
;
localStorage
.
getItem
(
document_path
);
return
priv
.
manageOptions
(
{
ok
:
true
,
id
:
document_id
,
rev
:
document_rev
},
command
,
doc
);
};
/**
* delete a document or attachment
* @method getDocument
* @param {object} command Command object
*/
priv
.
deleteDocument
=
function
(
command
)
{
var
doc
=
command
.
getDoc
();
document_id
=
doc
.
_id
;
document_rev
=
doc
.
_rev
;
document_path
=
'
jio/local/
'
+
priv
.
username
+
'
/
'
+
priv
.
applicationname
+
'
/
'
+
document_id
+
'
/
'
+
document_rev
;
localStorage
.
deleteItem
(
document_path
);
return
priv
.
manageOptions
(
{
ok
:
true
,
id
:
document_id
,
rev
:
document_rev
},
command
,
doc
);
};
// ===================== overrides ======================
// ===================== overrides ======================
that
.
serialized
=
function
()
{
that
.
serialized
=
function
()
{
return
{
return
{
...
@@ -228,7 +66,8 @@ var newLocalStorage = function (spec, my) {
...
@@ -228,7 +66,8 @@ var newLocalStorage = function (spec, my) {
};
};
that
.
validateState
=
function
()
{
that
.
validateState
=
function
()
{
if
(
priv
.
username
)
{
if
(
typeof
priv
.
username
===
"
string
"
&&
priv
.
username
!==
''
)
{
return
''
;
return
''
;
}
}
return
'
Need at least one parameter: "username".
'
;
return
'
Need at least one parameter: "username".
'
;
...
...
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