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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Junming
jio
Commits
1581dc4a
Commit
1581dc4a
authored
Apr 02, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix line length to 80 characters
parent
5c005528
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
78 deletions
+45
-78
src/jio.js
src/jio.js
+45
-78
No files found.
src/jio.js
View file @
1581dc4a
/*jslint maxlen: 200*/
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, FileReader */
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, FileReader */
(
function
(
window
,
RSVP
,
Blob
,
QueryFactory
,
Query
,
FileReader
)
{
(
function
(
window
,
RSVP
,
Blob
,
QueryFactory
,
Query
,
FileReader
)
{
"
use strict
"
;
"
use strict
"
;
var
util
=
{},
var
util
=
{},
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
/**
/**
* Send request with XHR and return a promise. xhr.onload: The promise is
* Send request with XHR and return a promise. xhr.onload: The promise is
* resolved when the status code is lower than 400 with the xhr object as
first
* resolved when the status code is lower than 400 with the xhr object as
* parameter. xhr.onerror: reject with xhr object as first
*
first
parameter. xhr.onerror: reject with xhr object as first
* parameter. xhr.onprogress: notifies the xhr object.
* parameter. xhr.onprogress: notifies the xhr object.
*
*
* @param {Object} param The parameters
* @param {Object} param The parameters
...
@@ -28,8 +28,8 @@
...
@@ -28,8 +28,8 @@
* @param {String} [param.dataType=""] The data type to retrieve
* @param {String} [param.dataType=""] The data type to retrieve
* @param {String} param.url The url
* @param {String} param.url The url
* @param {Any} [param.data] The data to send
* @param {Any} [param.data] The data to send
* @param {Function} [param.beforeSend] A function called just before the
send
* @param {Function} [param.beforeSend] A function called just before the
* request. The first parameter of this function is the XHR object.
*
send
request. The first parameter of this function is the XHR object.
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
function
ajax
(
param
)
{
function
ajax
(
param
)
{
...
@@ -77,8 +77,8 @@
...
@@ -77,8 +77,8 @@
* It can also clone object which are serializable, like Date.
* It can also clone object which are serializable, like Date.
*
*
* To make a class serializable, you need to implement the `toJSON` function
* To make a class serializable, you need to implement the `toJSON` function
* which returns a JSON representation of the object. The returned value is
used
* which returns a JSON representation of the object. The returned value is
* as first parameter of the object constructor.
*
used
as first parameter of the object constructor.
*
*
* @param {A} object The object to clone
* @param {A} object The object to clone
* @return {A} The cloned object
* @return {A} The cloned object
...
@@ -109,10 +109,11 @@
...
@@ -109,10 +109,11 @@
// XXX this block is to enable phantomjs and browsers compatibility with
// XXX this block is to enable phantomjs and browsers compatibility with
// Date.prototype.toJSON when it is an invalid date. In phantomjs, it
// Date.prototype.toJSON when it is an invalid date. In phantomjs, it
// returns `"Invalid Date"` but in browsers it returns `null`. In
// returns `"Invalid Date"` but in browsers it returns `null`. In
// browsers, giving `null` as parameter to `new Date()` doesn't return
an
// browsers, giving `null` as parameter to `new Date()` doesn't return
// invalid date.
//
an
invalid date.
// Cloning a date with `return new Date(object)` has problems on Firefox.
// Cloning a date with `return new Date(object)` has problems on
// Firefox.
// I don't know why... (Tested on Firefox 23)
// I don't know why... (Tested on Firefox 23)
if
(
isFinite
(
object
.
getTime
()))
{
if
(
isFinite
(
object
.
getTime
()))
{
...
@@ -172,67 +173,22 @@
...
@@ -172,67 +173,22 @@
}
}
util
.
readBlobAsDataURL
=
readBlobAsDataURL
;
util
.
readBlobAsDataURL
=
readBlobAsDataURL
;
//
// // // XXX What is "jio"?
// // var rest_method_names = [
// // "remove",
// // "allDocs",
// // "removeAttachment",
// // "check",
// // "repair"
// // ],
// // i,
// // len = rest_method_names.length;
// //
// // for (i = 0; i < len; i += 1) {
// // declareMethod(rest_method_names[i]);
// // }
// // ["removeAttachment"].forEach(function (method) {
// // shared.on(method, function (param) {
// // if (!checkId(param)) {
// // checkAttachmentId(param);
// // }
// // });
// // });
// //
// //
// // ["check", "repair"].forEach(function (method) {
// // shared.on(method, function (param) {
// // if (param.kwargs._id !== undefined) {
// // if (!checkId(param)) {
// // return;
// // }
// // }
// // });
// // });
// tools
// tools
function
checkId
(
param
,
storage
,
method_name
)
{
function
checkId
(
param
,
storage
,
method_name
)
{
if
(
typeof
param
.
_id
!==
'
string
'
||
param
.
_id
===
''
)
{
if
(
typeof
param
.
_id
!==
'
string
'
||
param
.
_id
===
''
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Document id must be a non empty string on '
"
+
storage
.
__type
+
"
.
"
+
method_name
+
"
'.
"
,
throw
new
jIO
.
util
.
jIOError
(
400
);
"
Document id must be a non empty string on '
"
+
storage
.
__type
+
"
.
"
+
method_name
+
"
'.
"
,
400
);
}
}
}
}
function
checkAttachmentId
(
param
,
storage
,
method_name
)
{
function
checkAttachmentId
(
param
,
storage
,
method_name
)
{
if
(
typeof
param
.
_attachment
!==
'
string
'
||
param
.
_attachment
===
''
)
{
if
(
typeof
param
.
_attachment
!==
'
string
'
||
param
.
_attachment
===
''
)
{
throw
new
jIO
.
util
.
jIOError
(
throw
new
jIO
.
util
.
jIOError
(
"
Attachment id must be a non empty string on '
"
+
storage
.
__type
+
"
.
"
+
method_name
+
"
'.
"
,
"
Attachment id must be a non empty string on '
"
+
storage
.
__type
+
"
.
"
+
method_name
+
"
'.
"
,
400
400
);
);
}
}
...
@@ -256,7 +212,8 @@
...
@@ -256,7 +212,8 @@
var
storage_method
=
context
.
__storage
[
name
];
var
storage_method
=
context
.
__storage
[
name
];
if
(
storage_method
===
undefined
)
{
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
throw
new
jIO
.
util
.
jIOError
(
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
501
);
);
}
}
...
@@ -297,12 +254,13 @@
...
@@ -297,12 +254,13 @@
declareMethod
(
JioProxyStorage
,
"
put
"
,
checkId
,
function
(
argument_list
)
{
declareMethod
(
JioProxyStorage
,
"
put
"
,
checkId
,
function
(
argument_list
)
{
return
argument_list
[
0
].
_id
;
return
argument_list
[
0
].
_id
;
});
});
declareMethod
(
JioProxyStorage
,
"
get
"
,
checkId
,
function
(
argument_list
,
result
)
{
declareMethod
(
JioProxyStorage
,
"
get
"
,
checkId
,
// XXX Drop all _ properties
function
(
argument_list
,
result
)
{
// Put _id properties to the result
// XXX Drop all _ properties
result
.
_id
=
argument_list
[
0
].
_id
;
// Put _id properties to the result
return
result
;
result
.
_id
=
argument_list
[
0
].
_id
;
});
return
result
;
});
declareMethod
(
JioProxyStorage
,
"
remove
"
,
checkId
,
function
(
argument_list
)
{
declareMethod
(
JioProxyStorage
,
"
remove
"
,
checkId
,
function
(
argument_list
)
{
return
argument_list
[
0
].
_id
;
return
argument_list
[
0
].
_id
;
});
});
...
@@ -325,14 +283,16 @@
...
@@ -325,14 +283,16 @@
});
});
};
};
declareMethod
(
JioProxyStorage
,
'
putAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
declareMethod
(
JioProxyStorage
,
'
putAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
checkId
(
param
,
storage
,
method_name
);
checkId
(
param
,
storage
,
method_name
);
checkAttachmentId
(
param
,
storage
,
method_name
);
checkAttachmentId
(
param
,
storage
,
method_name
);
if
(
!
(
param
.
_blob
instanceof
Blob
)
&&
if
(
!
(
param
.
_blob
instanceof
Blob
)
&&
typeof
param
.
_data
===
'
string
'
)
{
typeof
param
.
_data
===
'
string
'
)
{
param
.
_blob
=
new
Blob
([
param
.
_data
],
{
param
.
_blob
=
new
Blob
([
param
.
_data
],
{
"
type
"
:
param
.
_content_type
||
param
.
_mimetype
||
"
text/plain;charset=utf-8
"
"
type
"
:
param
.
_content_type
||
param
.
_mimetype
||
"
text/plain;charset=utf-8
"
});
});
delete
param
.
_data
;
delete
param
.
_data
;
delete
param
.
_mimetype
;
delete
param
.
_mimetype
;
...
@@ -357,12 +317,14 @@
...
@@ -357,12 +317,14 @@
}
}
});
});
declareMethod
(
JioProxyStorage
,
'
removeAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
declareMethod
(
JioProxyStorage
,
'
removeAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
checkId
(
param
,
storage
,
method_name
);
checkId
(
param
,
storage
,
method_name
);
checkAttachmentId
(
param
,
storage
,
method_name
);
checkAttachmentId
(
param
,
storage
,
method_name
);
});
});
declareMethod
(
JioProxyStorage
,
'
getAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
declareMethod
(
JioProxyStorage
,
'
getAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
// if (param.storage_spec.type !== "indexeddb" &&
// if (param.storage_spec.type !== "indexeddb" &&
// param.storage_spec.type !== "dav" &&
// param.storage_spec.type !== "dav" &&
// (param.kwargs._start !== undefined
// (param.kwargs._start !== undefined
...
@@ -379,7 +341,9 @@
...
@@ -379,7 +341,9 @@
},
function
(
argument_list
,
result
)
{
},
function
(
argument_list
,
result
)
{
if
(
!
(
result
.
data
instanceof
Blob
))
{
if
(
!
(
result
.
data
instanceof
Blob
))
{
throw
new
jIO
.
util
.
jIOError
(
throw
new
jIO
.
util
.
jIOError
(
"
'getAttachment' (
"
+
argument_list
[
0
].
_id
+
"
,
"
+
argument_list
[
0
].
_attachment
+
"
) on '
"
+
this
.
__type
+
"
' does not return a Blob.
"
,
"
'getAttachment' (
"
+
argument_list
[
0
].
_id
+
"
,
"
+
argument_list
[
0
].
_attachment
+
"
) on '
"
+
this
.
__type
+
"
' does not return a Blob.
"
,
501
501
);
);
}
}
...
@@ -407,7 +371,8 @@
...
@@ -407,7 +371,8 @@
JioProxyStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
JioProxyStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
storage_method
=
this
.
__storage
.
hasCapacity
;
var
storage_method
=
this
.
__storage
.
hasCapacity
;
if
((
storage_method
===
undefined
)
||
!
storage_method
.
apply
(
this
.
__storage
,
arguments
))
{
if
((
storage_method
===
undefined
)
||
!
storage_method
.
apply
(
this
.
__storage
,
arguments
))
{
throw
new
jIO
.
util
.
jIOError
(
throw
new
jIO
.
util
.
jIOError
(
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
this
.
__type
+
"
'
"
,
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
this
.
__type
+
"
'
"
,
501
501
...
@@ -426,8 +391,10 @@
...
@@ -426,8 +391,10 @@
if
(
context
.
hasCapacity
(
"
list
"
)
&&
if
(
context
.
hasCapacity
(
"
list
"
)
&&
((
options
.
query
===
undefined
)
||
context
.
hasCapacity
(
"
query
"
))
&&
((
options
.
query
===
undefined
)
||
context
.
hasCapacity
(
"
query
"
))
&&
((
options
.
sort_on
===
undefined
)
||
context
.
hasCapacity
(
"
sort
"
))
&&
((
options
.
sort_on
===
undefined
)
||
context
.
hasCapacity
(
"
sort
"
))
&&
((
options
.
select_list
===
undefined
)
||
context
.
hasCapacity
(
"
select
"
))
&&
((
options
.
select_list
===
undefined
)
||
((
options
.
include_docs
===
undefined
)
||
context
.
hasCapacity
(
"
include
"
))
&&
context
.
hasCapacity
(
"
select
"
))
&&
((
options
.
include_docs
===
undefined
)
||
context
.
hasCapacity
(
"
include
"
))
&&
((
options
.
limit
===
undefined
)
||
context
.
hasCapacity
(
"
limit
"
)))
{
((
options
.
limit
===
undefined
)
||
context
.
hasCapacity
(
"
limit
"
)))
{
return
context
.
buildQuery
(
options
);
return
context
.
buildQuery
(
options
);
}
}
...
...
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