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
Sven Franck
jio
Commits
11de6e45
Commit
11de6e45
authored
Nov 08, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5storage.js upgraded to JIO v2
parent
6021fe13
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
370 additions
and
383 deletions
+370
-383
src/jio.storage/erp5storage.js
src/jio.storage/erp5storage.js
+370
-383
No files found.
src/jio.storage/erp5storage.js
View file @
11de6e45
...
@@ -3,9 +3,6 @@
...
@@ -3,9 +3,6 @@
* Released under the LGPL license.
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
* http://www.gnu.org/licenses/lgpl.html
*/
*/
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global jIO: true, $: true, complex_queries: true */
// JIO Erp5 Storage Description :
// JIO Erp5 Storage Description :
// {
// {
// type: "erp5"
// type: "erp5"
...
@@ -32,9 +29,21 @@
...
@@ -32,9 +29,21 @@
//
//
// secured_login: {string} (not implemented)
// secured_login: {string} (not implemented)
// }
// }
jIO
.
addStorageType
(
"
erp5
"
,
function
(
spec
,
my
)
{
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, jIO, jQuery, complex_queries */
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
module
(
jIO
,
jQuery
);
}([
'
jio
'
,
'
jquery
'
],
function
(
jIO
,
$
)
{
"
use strict
"
;
"
use strict
"
;
var
priv
=
{},
that
=
my
.
basicStorage
(
spec
,
my
),
erp5
=
{};
function
ERP5Storage
(
spec
)
{
var
priv
=
{},
that
=
this
,
erp5
=
{};
// ATTRIBUTES //
// ATTRIBUTES //
priv
.
url
=
null
;
priv
.
url
=
null
;
...
@@ -69,29 +78,6 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -69,29 +78,6 @@ jIO.addStorageType("erp5", function (spec, my) {
}
}
};
};
// OVERRIDES //
that
.
specToStore
=
function
()
{
// TODO: secured password
// The encoded_login can be seen by anyone, we must find a way to secure it!
// secured_login = encrypt(encoded_login)
// encoded_login = decrypt(secured_login)
return
{
"
url
"
:
priv
.
url
,
"
mode
"
:
priv
.
mode
,
"
encoded_login
"
:
priv
.
encoded_login
};
};
that
.
validateState
=
function
()
{
if
(
typeof
priv
.
url
!==
"
string
"
||
priv
.
url
===
""
)
{
return
"
The erp5 server URL is not provided
"
;
}
if
(
priv
.
encoded_login
===
null
)
{
return
"
Impossible to create the authorization
"
;
}
return
""
;
};
// TOOLS //
// TOOLS //
/**
/**
* Replace substrings to another strings
* Replace substrings to another strings
...
@@ -157,7 +143,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -157,7 +143,8 @@ jIO.addStorageType("erp5", function (spec, my) {
ajax_object
.
url
=
priv
.
url
+
"
/JIO_
"
+
method
+
ajax_object
.
url
=
priv
.
url
+
"
/JIO_
"
+
method
+
"
?
"
+
priv
.
encoded_login
+
"
_=
"
+
Date
.
now
();
"
?
"
+
priv
.
encoded_login
+
"
_=
"
+
Date
.
now
();
ajax_object
.
async
=
ajax_object
.
async
===
false
?
false
:
true
;
ajax_object
.
async
=
ajax_object
.
async
===
false
?
false
:
true
;
ajax_object
.
crossdomain
=
ajax_object
.
crossdomain
===
false
?
false
:
true
;
ajax_object
.
crossdomain
=
ajax_object
.
crossdomain
===
false
?
false
:
true
;
ajax_object
.
headers
=
ajax_object
.
headers
||
{};
ajax_object
.
headers
=
ajax_object
.
headers
||
{};
return
ajax_object
;
return
ajax_object
;
};
};
...
@@ -171,7 +158,9 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -171,7 +158,9 @@ jIO.addStorageType("erp5", function (spec, my) {
* @param {object} ajax_object The request parameters (optional)
* @param {object} ajax_object The request parameters (optional)
*/
*/
priv
.
ajax
=
function
(
json
,
option
,
method
,
ajax_object
)
{
priv
.
ajax
=
function
(
json
,
option
,
method
,
ajax_object
)
{
return
$
.
ajax
(
priv
.
makeAjaxObject
(
json
,
option
,
method
,
ajax_object
||
{}));
return
$
.
ajax
(
priv
.
makeAjaxObject
(
json
,
option
,
method
,
ajax_object
||
{})
);
//.always(then || function () {});
//.always(then || function () {});
};
};
...
@@ -182,27 +171,11 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -182,27 +171,11 @@ jIO.addStorageType("erp5", function (spec, my) {
* @return {object} error The error object
* @return {object} error The error object
*/
*/
priv
.
createError
=
function
(
status
,
message
,
reason
)
{
priv
.
createError
=
function
(
status
,
message
,
reason
)
{
var
error
=
{
return
{
"
status
"
:
status
,
"
status
"
:
status
,
"
message
"
:
message
,
"
message
"
:
message
,
"
reason
"
:
reason
"
reason
"
:
reason
};
};
switch
(
status
)
{
case
404
:
error
.
statusText
=
"
Not found
"
;
break
;
case
405
:
error
.
statusText
=
"
Method Not Allowed
"
;
break
;
case
409
:
error
.
statusText
=
"
Conflicts
"
;
break
;
case
24
:
error
.
statusText
=
"
Corrupted Document
"
;
break
;
}
error
.
error
=
error
.
statusText
.
toLowerCase
().
split
(
"
"
).
join
(
"
_
"
);
return
error
;
};
};
/**
/**
...
@@ -230,7 +203,9 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -230,7 +203,9 @@ jIO.addStorageType("erp5", function (spec, my) {
* @return {object} jQuery like callback methods
* @return {object} jQuery like callback methods
*/
*/
priv
.
makeJQLikeCallback
=
function
()
{
priv
.
makeJQLikeCallback
=
function
()
{
var
result
=
null
,
emptyFun
=
function
()
{},
jql
=
{
var
result
=
null
,
emptyFun
=
function
()
{
return
;
},
jql
=
{
"
respond
"
:
function
()
{
"
respond
"
:
function
()
{
result
=
arguments
;
result
=
arguments
;
},
},
...
@@ -298,9 +273,9 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -298,9 +273,9 @@ jIO.addStorageType("erp5", function (spec, my) {
* @param {object} option The option object
* @param {object} option The option object
* @param {string} method The ERP5 request method
* @param {string} method The ERP5 request method
*/
*/
erp5
.
genericRequest
=
function
(
json
,
option
,
method
)
{
erp5
.
genericRequest
=
function
(
method
,
json
,
option
)
{
var
jql
=
priv
.
makeJQLikeCallback
(),
error
=
null
;
var
jql
=
priv
.
makeJQLikeCallback
(),
error
=
null
;
priv
.
ajax
(
json
,
option
,
method
).
always
(
function
(
one
,
state
,
thre
e
)
{
priv
.
ajax
(
json
,
option
,
method
).
always
(
function
(
one
,
stat
e
)
{
if
(
state
===
"
parsererror
"
)
{
if
(
state
===
"
parsererror
"
)
{
return
jql
.
respond
(
priv
.
createError
(
return
jql
.
respond
(
priv
.
createError
(
24
,
24
,
...
@@ -341,22 +316,24 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -341,22 +316,24 @@ jIO.addStorageType("erp5", function (spec, my) {
* @param {object} command The JIO command object
* @param {object} command The JIO command object
* @param {string} method The ERP5 request method
* @param {string} method The ERP5 request method
*/
*/
priv
.
genericCommand
=
function
(
command
,
method
)
{
priv
.
genericCommand
=
function
(
method
,
command
,
param
,
option
)
{
var
option
=
command
.
cloneOption
();
if
(
complex_queries
!==
undefined
&&
if
(
complex_queries
!==
undefined
&&
method
===
'
allDocs
'
&&
method
===
'
allDocs
'
&&
option
.
query
)
{
option
.
query
)
{
priv
.
convertToErp5Query
(
option
);
priv
.
convertToErp5Query
(
option
);
}
}
erp5
.
genericRequest
(
erp5
.
genericRequest
(
command
.
cloneDoc
()
,
method
,
option
,
param
,
method
option
).
always
(
function
(
err
,
response
)
{
).
always
(
function
(
err
,
response
)
{
if
(
err
)
{
if
(
err
)
{
return
that
.
error
(
err
);
return
command
.
error
(
err
);
}
}
return
that
.
success
(
response
);
if
([
'
get
'
,
'
getAttachment
'
,
'
allDocs
'
].
indexOf
(
method
)
===
-
1
)
{
return
command
.
success
(
response
);
}
return
command
.
success
({
"
data
"
:
response
});
});
});
};
};
...
@@ -365,8 +342,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -365,8 +342,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method post
* @method post
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
,
metadata
,
options
)
{
priv
.
genericCommand
(
command
,
"
post
"
);
priv
.
genericCommand
(
"
post
"
,
command
,
metadata
,
options
);
};
};
/**
/**
...
@@ -374,8 +351,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -374,8 +351,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method put
* @method put
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
put
=
function
(
command
)
{
that
.
put
=
function
(
command
,
metadata
,
options
)
{
priv
.
genericCommand
(
command
,
"
put
"
);
priv
.
genericCommand
(
"
put
"
,
command
,
metadata
,
options
);
};
};
/**
/**
...
@@ -383,8 +360,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -383,8 +360,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method putAttachment
* @method putAttachment
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
putAttachment
=
function
(
command
)
{
that
.
putAttachment
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
putAttachment
"
);
priv
.
genericCommand
(
"
putAttachment
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -392,8 +369,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -392,8 +369,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method get
* @method get
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
get
"
);
priv
.
genericCommand
(
"
get
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -401,8 +378,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -401,8 +378,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method getAttachment
* @method getAttachment
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
getAttachment
=
function
(
command
)
{
that
.
getAttachment
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
getAttachment
"
);
priv
.
genericCommand
(
"
getAttachment
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -410,8 +387,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -410,8 +387,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method remove
* @method remove
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
remove
"
);
priv
.
genericCommand
(
"
remove
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -419,8 +396,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -419,8 +396,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method removeAttachment
* @method removeAttachment
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
removeAttachment
=
function
(
command
)
{
that
.
removeAttachment
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
removeAttachment
"
);
priv
.
genericCommand
(
"
removeAttachment
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -430,8 +407,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -430,8 +407,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method allDocs
* @method allDocs
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
allDocs
"
);
priv
.
genericCommand
(
"
allDocs
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -439,8 +416,8 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -439,8 +416,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method check
* @method check
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
check
=
function
(
command
)
{
that
.
check
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
check
"
);
priv
.
genericCommand
(
"
check
"
,
command
,
param
,
options
);
};
};
/**
/**
...
@@ -448,10 +425,20 @@ jIO.addStorageType("erp5", function (spec, my) {
...
@@ -448,10 +425,20 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method repair
* @method repair
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
repair
=
function
(
command
)
{
that
.
repair
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
command
,
"
repair
"
);
priv
.
genericCommand
(
"
repair
"
,
command
,
param
,
options
);
};
};
priv
.
__init__
(
spec
);
priv
.
__init__
(
spec
);
return
that
;
});
if
(
typeof
priv
.
url
!==
"
string
"
||
priv
.
url
===
""
)
{
throw
new
TypeError
(
"
The erp5 server URL is not provided
"
);
}
if
(
priv
.
encoded_login
===
null
)
{
throw
new
TypeError
(
"
Impossible to create the authorization
"
);
}
}
jIO
.
addStorage
(
"
erp5
"
,
ERP5Storage
);
}));
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