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
Yaxel Perez
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 @@
* Released under the LGPL license.
* 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 :
// {
// type: "erp5"
...
...
@@ -32,9 +29,21 @@
//
// 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
"
;
var
priv
=
{},
that
=
my
.
basicStorage
(
spec
,
my
),
erp5
=
{};
function
ERP5Storage
(
spec
)
{
var
priv
=
{},
that
=
this
,
erp5
=
{};
// ATTRIBUTES //
priv
.
url
=
null
;
...
...
@@ -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 //
/**
* Replace substrings to another strings
...
...
@@ -157,7 +143,8 @@ jIO.addStorageType("erp5", function (spec, my) {
ajax_object
.
url
=
priv
.
url
+
"
/JIO_
"
+
method
+
"
?
"
+
priv
.
encoded_login
+
"
_=
"
+
Date
.
now
();
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
||
{};
return
ajax_object
;
};
...
...
@@ -171,7 +158,9 @@ jIO.addStorageType("erp5", function (spec, my) {
* @param {object} ajax_object The request parameters (optional)
*/
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 () {});
};
...
...
@@ -182,27 +171,11 @@ jIO.addStorageType("erp5", function (spec, my) {
* @return {object} error The error object
*/
priv
.
createError
=
function
(
status
,
message
,
reason
)
{
var
error
=
{
return
{
"
status
"
:
status
,
"
message
"
:
message
,
"
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) {
* @return {object} jQuery like callback methods
*/
priv
.
makeJQLikeCallback
=
function
()
{
var
result
=
null
,
emptyFun
=
function
()
{},
jql
=
{
var
result
=
null
,
emptyFun
=
function
()
{
return
;
},
jql
=
{
"
respond
"
:
function
()
{
result
=
arguments
;
},
...
...
@@ -298,9 +273,9 @@ jIO.addStorageType("erp5", function (spec, my) {
* @param {object} option The option object
* @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
;
priv
.
ajax
(
json
,
option
,
method
).
always
(
function
(
one
,
state
,
thre
e
)
{
priv
.
ajax
(
json
,
option
,
method
).
always
(
function
(
one
,
stat
e
)
{
if
(
state
===
"
parsererror
"
)
{
return
jql
.
respond
(
priv
.
createError
(
24
,
...
...
@@ -341,22 +316,24 @@ jIO.addStorageType("erp5", function (spec, my) {
* @param {object} command The JIO command object
* @param {string} method The ERP5 request method
*/
priv
.
genericCommand
=
function
(
command
,
method
)
{
var
option
=
command
.
cloneOption
();
priv
.
genericCommand
=
function
(
method
,
command
,
param
,
option
)
{
if
(
complex_queries
!==
undefined
&&
method
===
'
allDocs
'
&&
option
.
query
)
{
priv
.
convertToErp5Query
(
option
);
}
erp5
.
genericRequest
(
command
.
cloneDoc
()
,
option
,
method
method
,
param
,
option
).
always
(
function
(
err
,
response
)
{
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) {
* @method post
* @param {object} command The JIO command
*/
that
.
post
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
post
"
);
that
.
post
=
function
(
command
,
metadata
,
options
)
{
priv
.
genericCommand
(
"
post
"
,
command
,
metadata
,
options
);
};
/**
...
...
@@ -374,8 +351,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method put
* @param {object} command The JIO command
*/
that
.
put
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
put
"
);
that
.
put
=
function
(
command
,
metadata
,
options
)
{
priv
.
genericCommand
(
"
put
"
,
command
,
metadata
,
options
);
};
/**
...
...
@@ -383,8 +360,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method putAttachment
* @param {object} command The JIO command
*/
that
.
putAttachment
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
putAttachment
"
);
that
.
putAttachment
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
putAttachment
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -392,8 +369,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method get
* @param {object} command The JIO command
*/
that
.
get
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
get
"
);
that
.
get
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
get
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -401,8 +378,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method getAttachment
* @param {object} command The JIO command
*/
that
.
getAttachment
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
getAttachment
"
);
that
.
getAttachment
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
getAttachment
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -410,8 +387,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method remove
* @param {object} command The JIO command
*/
that
.
remove
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
remove
"
);
that
.
remove
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
remove
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -419,8 +396,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method removeAttachment
* @param {object} command The JIO command
*/
that
.
removeAttachment
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
removeAttachment
"
);
that
.
removeAttachment
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
removeAttachment
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -430,8 +407,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method allDocs
* @param {object} command The JIO command
*/
that
.
allDocs
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
allDocs
"
);
that
.
allDocs
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
allDocs
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -439,8 +416,8 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method check
* @param {object} command The JIO command
*/
that
.
check
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
check
"
);
that
.
check
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
check
"
,
command
,
param
,
options
);
};
/**
...
...
@@ -448,10 +425,20 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method repair
* @param {object} command The JIO command
*/
that
.
repair
=
function
(
command
)
{
priv
.
genericCommand
(
command
,
"
repair
"
);
that
.
repair
=
function
(
command
,
param
,
options
)
{
priv
.
genericCommand
(
"
repair
"
,
command
,
param
,
options
);
};
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