Commit cc7fb525 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

erp5_api_style: Add view API call as cURL in API view gadget

parent 659b166e
......@@ -68,6 +68,52 @@
}
function renderCurlCall(gadget, data, element) {
var curl_call;
curl_call = "curl -X 'POST' \\\n" +
" " + gadget.state.api_url + " \\\n" +
" -H 'accept: application/json' \\\n" +
" -H 'Content-Type: application/json' \\\n" +
" -d '" + data + "' \\\n" +
" -u your_username:your_password";
domsugar(
element,
[
domsugar("section", {"class": "ui-content-header-plain"},
[domsugar("br"), domsugar("h3", ["Curl Call"]),
domsugar("br")]),
domsugar("p", [domsugar("code", [domsugar("pre", [curl_call])])])
]
);
}
function displayCurlContent(gadget) {
var form_gadget;
return gadget.getDeclaredGadget("form_schema")
.push(function (result) {
form_gadget = result;
return form_gadget.checkValidity()
.push(function (is_valid) {
if (!is_valid) {
return gadget.notifySubmitted({
"message": "Data is not Valid, please make sure no error is left.",
"status": "failed"
});
}
return form_gadget.getContent()
.push(function (content_dict) {
var json_data = content_dict.my_key;
return renderCurlCall(
gadget,
json_data,
gadget.element.querySelector('.data-response')
);
});
});
});
}
function sendContent(gadget, data) {
var url = gadget.state.api_url,
http_method;
......@@ -128,7 +174,6 @@
var json_data = content_dict.my_key,
status,
message;
console.log(json_data);
return sendContent(gadget, json_data)
.push(function (response) {
enableButton();
......@@ -289,15 +334,26 @@
domsugar(
gadget.element
.querySelector('.dialog_button_container'),
[domsugar(
'input',
{
name: 'action_confirm',
'class': 'dialogconfirm',
type: 'submit',
value: "Send"
}
)]
[
domsugar(
'input',
{
name: 'action_confirm',
'class': 'dialogconfirm',
type: 'submit',
value: "Send"
}
),
domsugar(
'input',
{
name: 'get_curl',
'class': 'dialogconfirm',
type: 'submit',
value: "Generate Curl"
}
)
]
);
displayAPIInformation(gadget);
return gadget.getUrlFor({command: 'display', options: {
......@@ -319,6 +375,10 @@
evt.preventDefault();
return submitDialog(this);
}
if (evt.target.name === "get_curl") {
evt.preventDefault();
return displayCurlContent(this);
}
}, false, false)
.onEvent('submit', function submit() {
return submitDialog(this);
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1000.376.45673.9557</string> </value>
<value> <string>1000.3573.16294.22084</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1651654628.56</float>
<float>1651846416.67</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment