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
Hamza
jio
Commits
9dbf26eb
Commit
9dbf26eb
authored
Apr 30, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5.get: returns properties based on document default form calculation.
parent
4e0e4b7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
11 deletions
+173
-11
src/jio.storage/erp5storage.js
src/jio.storage/erp5storage.js
+58
-9
test/jio.storage/erp5storage.tests.js
test/jio.storage/erp5storage.tests.js
+115
-2
No files found.
src/jio.storage/erp5storage.js
View file @
9dbf26eb
...
...
@@ -62,6 +62,59 @@
});
}
var
allowed_field_dict
=
{
"
StringField
"
:
null
,
"
IntegerField
"
:
null
,
"
FloatField
"
:
null
,
"
TextAreaField
"
:
null
};
function
extractPropertyFromForm
(
context
,
id
)
{
return
context
.
getAttachment
(
id
,
"
view
"
)
.
push
(
function
(
blob
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
push
(
function
(
evt
)
{
return
JSON
.
parse
(
evt
.
target
.
result
);
})
.
push
(
function
(
json
)
{
var
form
=
json
.
_embedded
.
_view
,
converted_json
=
{
portal_type
:
json
.
portal_type
},
form_data_json
=
{},
field
,
key
;
form_data_json
.
form_id
=
{
"
key
"
:
[
form
.
form_id
.
key
],
"
default
"
:
form
.
form_id
[
"
default
"
]
};
// XXX How to store datetime
for
(
key
in
form
)
{
if
(
form
.
hasOwnProperty
(
key
))
{
field
=
form
[
key
];
if
((
key
.
indexOf
(
'
my_
'
)
===
0
)
&&
(
field
.
editable
)
&&
(
allowed_field_dict
.
hasOwnProperty
(
field
.
type
)))
{
form_data_json
[
key
.
substring
(
3
)]
=
{
"
default
"
:
field
[
"
default
"
],
"
key
"
:
field
.
key
};
converted_json
[
key
.
substring
(
3
)]
=
field
[
"
default
"
];
}
}
}
return
{
action_href
:
form
.
_actions
.
put
.
href
,
data
:
converted_json
,
form_data
:
form_data_json
};
});
}
// XXX docstring
function
ERP5Storage
(
spec
)
{
if
(
typeof
spec
.
url
!==
"
string
"
||
!
spec
.
url
)
{
...
...
@@ -73,22 +126,18 @@
}
ERP5Storage
.
prototype
.
get
=
function
(
id
)
{
return
getDocumentAndHateoas
(
this
,
id
)
.
push
(
function
(
response
)
{
var
result
=
JSON
.
parse
(
response
.
target
.
responseText
),
key
;
// action_type;
result
.
portal_type
=
result
.
_links
.
type
.
name
;
return
extractPropertyFromForm
(
this
,
id
)
.
push
(
function
(
result
)
{
var
key
;
result
=
result
.
data
;
// Remove all ERP5 hateoas links / convert them into jIO ID
for
(
key
in
result
)
{
if
(
result
.
hasOwnProperty
(
key
))
{
if
(
key
.
indexOf
(
"
_
"
)
===
0
)
{
if
(
!
result
[
key
]
)
{
delete
result
[
key
];
}
}
}
return
result
;
});
};
...
...
test/jio.storage/erp5storage.tests.js
View file @
9dbf26eb
...
...
@@ -55,7 +55,8 @@
this
.
jio
=
jIO
.
createJIO
({
type
:
"
erp5
"
,
url
:
domain
url
:
domain
,
default_view_reference
:
"
bar_view
"
});
},
teardown
:
function
()
{
...
...
@@ -93,10 +94,73 @@
});
});
test
(
"
get ERP5 document with empty form
"
,
function
()
{
var
id
=
"
person_module/20150119_azerty
"
,
traverse_url
=
domain
+
"
?mode=traverse&relative_url=
"
+
encodeURIComponent
(
id
)
+
"
&view=bar_view
"
,
document_hateoas
=
JSON
.
stringify
({
// Kept property
"
title
"
:
"
foo
"
,
// Remove all _ properties
"
_bar
"
:
"
john doo
"
,
"
_links
"
:
{
type
:
{
name
:
"
Person
"
}
},
"
_embedded
"
:
{
"
_view
"
:
{
form_id
:
{
key
:
"
form_id
"
,
"
default
"
:
"
Base_view
"
},
"
_actions
"
:
{
put
:
{
href
:
"
one erp5 url
"
}
}
}
}
}),
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
domain
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
root_hateoas
]);
this
.
server
.
respondWith
(
"
GET
"
,
traverse_url
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
document_hateoas
]);
stop
();
expect
(
10
);
this
.
jio
.
get
(
id
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
portal_type
:
"
Person
"
},
"
Check document
"
);
equal
(
server
.
requests
.
length
,
2
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
domain
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
equal
(
server
.
requests
[
1
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
1
].
url
,
traverse_url
);
equal
(
server
.
requests
[
1
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
1
].
withCredentials
,
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get ERP5 document
"
,
function
()
{
var
id
=
"
person_module/20150119_azerty
"
,
traverse_url
=
domain
+
"
?mode=traverse&relative_url=
"
+
encodeURIComponent
(
id
),
encodeURIComponent
(
id
)
+
"
&view=bar_view
"
,
document_hateoas
=
JSON
.
stringify
({
// Kept property
"
title
"
:
"
foo
"
,
...
...
@@ -106,6 +170,55 @@
type
:
{
name
:
"
Person
"
}
},
"
_embedded
"
:
{
"
_view
"
:
{
form_id
:
{
key
:
"
form_id
"
,
"
default
"
:
"
Base_view
"
},
my_title
:
{
key
:
"
field_my_title
"
,
"
default
"
:
"
foo
"
,
editable
:
true
,
type
:
"
StringField
"
},
my_id
:
{
key
:
"
field_my_id
"
,
"
default
"
:
""
,
editable
:
true
,
type
:
"
StringField
"
},
my_title_non_editable
:
{
key
:
"
field_my_title_non_editable
"
,
"
default
"
:
"
foo
"
,
editable
:
false
,
type
:
"
StringField
"
},
my_start_date
:
{
key
:
"
field_my_start_date
"
,
"
default
"
:
"
foo
"
,
editable
:
true
,
type
:
"
DateTimeField
"
},
your_reference
:
{
key
:
"
field_your_title
"
,
"
default
"
:
"
bar
"
,
editable
:
true
,
type
:
"
StringField
"
},
sort_index
:
{
key
:
"
field_sort_index
"
,
"
default
"
:
"
foobar
"
,
editable
:
true
,
type
:
"
StringField
"
},
"
_actions
"
:
{
put
:
{
href
:
"
one erp5 url
"
}
}
}
}
}),
server
=
this
.
server
;
...
...
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