Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ecommerce-ui
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
ecommerce-ui
Commits
a1e93301
Commit
a1e93301
authored
Apr 08, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libs: update JIO and localStorage to latest to fix bugs
parent
ac0a7350
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2166 additions
and
93 deletions
+2166
-93
ext/libs/jio/jio.js
ext/libs/jio/jio.js
+2103
-41
ext/libs/jio/localstorage.js
ext/libs/jio/localstorage.js
+63
-52
No files found.
ext/libs/jio/jio.js
View file @
a1e93301
This diff is collapsed.
Click to expand it.
ext/libs/jio/localstorage.js
View file @
a1e93301
...
...
@@ -5,7 +5,7 @@
*/
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*global jIO, localStorage, setTimeout,
complex_queries, window, define
,
/*global jIO, localStorage, setTimeout,
window, define, Blob, Uint8Array
,
exports, require */
/**
...
...
@@ -54,15 +54,14 @@
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
exports
,
require
(
'
jio
'
)
,
require
(
'
complex_queries
'
)
);
return
module
(
exports
,
require
(
'
jio
'
));
}
window
.
local_storage
=
{};
module
(
window
.
local_storage
,
jIO
,
complex_queries
);
module
(
window
.
local_storage
,
jIO
);
}([
'
exports
'
,
'
jio
'
,
'
complex_queries
'
],
function
(
exports
,
jIO
,
complex_queries
)
{
'
jio
'
],
function
(
exports
,
jIO
)
{
"
use strict
"
;
/**
...
...
@@ -124,9 +123,8 @@
* @constructor
*/
function
LocalStorage
(
spec
)
{
if
(
typeof
spec
.
username
!==
'
string
'
&&
!
spec
.
username
)
{
throw
new
TypeError
(
"
LocalStorage 'username' must be a string
"
+
"
which contains more than one character.
"
);
if
(
typeof
spec
.
username
!==
'
string
'
||
spec
.
username
===
''
)
{
throw
new
TypeError
(
"
LocalStorage 'username' must be a non-empty string
"
);
}
this
.
_localpath
=
'
jio/localstorage/
'
+
spec
.
username
+
'
/
'
+
(
spec
.
application_name
===
null
||
spec
.
application_name
===
...
...
@@ -142,6 +140,7 @@
this
.
_database
=
localStorage
;
this
.
_storage
=
localstorage
;
this
.
_mode
=
"
localStorage
"
;
this
.
_key_schema
=
spec
.
key_schema
;
break
;
}
}
...
...
@@ -215,7 +214,7 @@
* @param {Object} options The command options
*/
LocalStorage
.
prototype
.
putAttachment
=
function
(
command
,
param
)
{
var
that
=
this
,
doc
,
status
=
"
ok
"
;
var
that
=
this
,
doc
,
status
=
"
created
"
;
doc
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
);
if
(
doc
===
null
)
{
// the document does not exist
...
...
@@ -231,7 +230,7 @@
jIO
.
util
.
readBlobAsBinaryString
(
param
.
_blob
).
then
(
function
(
e
)
{
doc
.
_attachments
=
doc
.
_attachments
||
{};
if
(
doc
.
_attachments
[
param
.
_attachment
])
{
status
=
"
created
"
;
status
=
"
no_content
"
;
}
doc
.
_attachments
[
param
.
_attachment
]
=
{
"
content_type
"
:
param
.
_blob
.
type
,
...
...
@@ -287,7 +286,7 @@
* @param {Object} options The command options
*/
LocalStorage
.
prototype
.
getAttachment
=
function
(
command
,
param
)
{
var
doc
;
var
doc
,
i
,
uint8array
,
binarystring
;
doc
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
);
if
(
doc
===
null
)
{
return
command
.
error
(
...
...
@@ -306,12 +305,22 @@
);
}
// Storing data twice in binarystring and in uint8array (in memory)
// is not a problem here because localStorage <= 5MB
binarystring
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
+
"
/
"
+
param
.
_attachment
)
||
""
;
uint8array
=
new
Uint8Array
(
binarystring
.
length
);
for
(
i
=
0
;
i
<
binarystring
.
length
;
i
+=
1
)
{
uint8array
[
i
]
=
binarystring
.
charCodeAt
(
i
);
// mask `& 0xFF` not necessary
}
uint8array
=
new
Blob
([
uint8array
],
{
"
type
"
:
doc
.
_attachments
[
param
.
_attachment
].
content_type
||
""
});
command
.
success
({
"
data
"
:
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
+
"
/
"
+
param
.
_attachment
)
||
""
,
"
content_type
"
:
doc
.
_attachments
[
param
.
_attachment
].
content_type
||
""
"
data
"
:
uint8array
,
"
digest
"
:
doc
.
_attachments
[
param
.
_attachment
].
digest
});
};
...
...
@@ -362,7 +371,7 @@
*/
LocalStorage
.
prototype
.
removeAttachment
=
function
(
command
,
param
)
{
var
doc
=
this
.
_storage
.
getItem
(
this
.
_localpath
+
"
/
"
+
param
.
_id
);
if
(
typeof
doc
!==
'
object
'
)
{
if
(
typeof
doc
!==
'
object
'
||
doc
===
null
)
{
return
command
.
error
(
"
not_found
"
,
"
missing document
"
,
...
...
@@ -402,7 +411,7 @@
rows
=
[];
document_list
=
[];
path_re
=
new
RegExp
(
"
^
"
+
complex_queries
.
stringEscapeRegexpCharacters
(
this
.
_localpath
)
+
"
^
"
+
jIO
.
Query
.
stringEscapeRegexpCharacters
(
this
.
_localpath
)
+
"
/[^/]+$
"
);
if
(
options
.
query
===
undefined
&&
options
.
sort_on
===
undefined
&&
...
...
@@ -425,7 +434,7 @@
}
command
.
success
({
"
data
"
:
{
"
rows
"
:
rows
,
"
total_rows
"
:
rows
.
length
}});
}
else
{
// create
complex
query object from returned results
// create
jio
query object from returned results
for
(
i
in
this
.
_database
)
{
if
(
this
.
_database
.
hasOwnProperty
(
i
))
{
if
(
path_re
.
test
(
i
))
{
...
...
@@ -444,27 +453,29 @@
document_object
[
meta
.
_id
]
=
meta
;
});
}
complex_queries
.
QueryFactory
.
create
(
options
.
query
||
""
).
exec
(
document_list
,
options
);
document_list
=
document_list
.
map
(
function
(
value
)
{
var
o
=
{
"
id
"
:
value
.
_id
,
"
key
"
:
value
.
_id
};
if
(
options
.
include_docs
===
true
)
{
o
.
doc
=
document_object
[
value
.
_id
];
delete
document_object
[
value
.
_id
];
}
if
(
delete_id
)
{
delete
value
.
_id
;
}
o
.
value
=
value
;
return
o
;
});
command
.
success
({
"
data
"
:
{
"
total_rows
"
:
document_list
.
length
,
"
rows
"
:
document_list
}});
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
this
.
_key_schema
).
exec
(
document_list
,
options
).
then
(
function
()
{
document_list
=
document_list
.
map
(
function
(
value
)
{
var
o
=
{
"
id
"
:
value
.
_id
,
"
key
"
:
value
.
_id
};
if
(
options
.
include_docs
===
true
)
{
o
.
doc
=
document_object
[
value
.
_id
];
delete
document_object
[
value
.
_id
];
}
if
(
delete_id
)
{
delete
value
.
_id
;
}
o
.
value
=
value
;
return
o
;
});
command
.
success
({
"
data
"
:
{
"
total_rows
"
:
document_list
.
length
,
"
rows
"
:
document_list
}});
});
}
};
...
...
@@ -502,13 +513,13 @@
*/
LocalStorage
.
prototype
.
genericRepair
=
function
(
command
,
param
,
repair
)
{
var
that
=
this
,
result
;
var
that
=
this
,
final_
result
;
function
referenceAttachment
(
param
,
attachment
)
{
if
(
jIO
.
util
.
indexOf
(
param
.
referenced_attachments
,
attachment
)
!==
-
1
)
{
if
(
param
.
referenced_attachments
.
indexOf
(
attachment
)
!==
-
1
)
{
return
;
}
var
i
=
jIO
.
util
.
indexOf
(
param
.
unreferenced_attachments
,
attachment
);
var
i
=
param
.
unreferenced_attachments
.
indexOf
(
attachment
);
if
(
i
!==
-
1
)
{
param
.
unreferenced_attachments
.
splice
(
i
,
1
);
}
...
...
@@ -517,10 +528,10 @@
}
function
attachmentFound
(
param
,
attachment
)
{
if
(
jIO
.
util
.
indexOf
(
param
.
referenced_attachments
,
attachment
)
!==
-
1
)
{
if
(
param
.
referenced_attachments
.
indexOf
(
attachment
)
!==
-
1
)
{
return
;
}
if
(
jIO
.
util
.
indexOf
(
param
.
unreferenced_attachments
,
attachment
)
!==
-
1
)
{
if
(
param
.
unreferenced_attachments
.
indexOf
(
attachment
)
!==
-
1
)
{
return
;
}
param
.
unreferenced_attachments
[
param
.
unreferenced_attachments
.
length
]
=
...
...
@@ -535,7 +546,7 @@
}
// check document type
if
(
typeof
doc
!==
'
object
'
)
{
if
(
typeof
doc
!==
'
object
'
||
doc
===
null
)
{
// wrong document
if
(
!
repair
)
{
return
{
"
error
"
:
true
,
"
answers
"
:
[
...
...
@@ -656,14 +667,14 @@
param
.
referenced_attachments
=
[];
param
.
unreferenced_attachments
=
[];
if
(
typeof
param
.
_id
===
'
string
'
)
{
result
=
repairOne
(
param
,
repair
)
||
{};
final_
result
=
repairOne
(
param
,
repair
)
||
{};
}
else
{
result
=
repairAll
(
param
,
repair
)
||
{};
final_
result
=
repairAll
(
param
,
repair
)
||
{};
}
if
(
result
.
error
)
{
return
command
.
error
.
apply
(
command
,
result
.
answers
||
[]);
if
(
final_
result
.
error
)
{
return
command
.
error
.
apply
(
command
,
final_
result
.
answers
||
[]);
}
command
.
success
.
apply
(
command
,
result
.
answers
||
[]);
command
.
success
.
apply
(
command
,
final_
result
.
answers
||
[]);
};
jIO
.
addStorage
(
'
local
'
,
LocalStorage
);
...
...
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