Commit 7680c9e0 authored by Tomáš Peterka's avatar Tomáš Peterka

[renderjs_ui+hal_json] Add information about previous view (using form_id) to...

[renderjs_ui+hal_json] Add information about previous view (using form_id) to actions/workflow links
parent b5fca5ba
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>form_id, dialog_id, **kw</string> </value>
<value> <string>dialog_id, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -298,6 +298,9 @@ class TestERP5Document_getHateoas_mode_root(ERP5HALJSONStyleSkinsMixin):
document = self._makeDocument()
parent = document.getParentValue()
fake_request = do_fake_request("GET")
# XXX Kato: Can someone please put comments why getHateoas is called on a Document?
# From test point of view it does not make much sense since this should never happen in reality
# ERP5Document_getHateoas should be always called on portal, Web Site, or Web Section.
result = document.ERP5Document_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
......@@ -359,17 +362,20 @@ class TestERP5Document_getHateoas_mode_root(ERP5HALJSONStyleSkinsMixin):
document = self.portal.web_site_module.hateoas
parent = document.getParentValue()
fake_request = do_fake_request("GET")
result = document.ERP5Document_getHateoas(REQUEST=fake_request)
# Note empty relative_url to force `is_portal_root` == True and to obtain "raw_search" in the links
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
# This means that no object is actually rendered because no relative_url is given thus getHateoas is not in "web_mode"
# XXX Kato: I think it is just more unecessary complexity because in real life - getHateoas is always called on a Web Section
self.assertEqual(result_dict['_links']['self'], {"href": "http://example.org/bar"})
self.assertEqual(result_dict['_links']['parent'],
{"href": "urn:jio:get:%s" % parent.getRelativeUrl(), "name": parent.getTitle()})
# form_id must be empty in this case because we have no relative_url to display view for
self.assertEqual(result_dict['_links']['view'][0]['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=view" % (
self.portal.absolute_url(),
......@@ -455,7 +461,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_links']['parent'],
{"href": "urn:jio:get:%s" % parent.getRelativeUrl(), "name": parent.getTitle()})
# view links do not have form_id in their URL
self.assertEqual(result_dict['_links']['view'][0]['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=view" % (
self.portal.absolute_url(),
......@@ -560,7 +566,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_links']['action_object_view'][0]['name'], "view")
self.assertEqual(result_dict['_links']['action_workflow'][0]['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog" % (
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog&form_id=Foo_view" % (
self.portal.absolute_url(),
urllib.quote_plus(document.getRelativeUrl())))
self.assertEqual(result_dict['_links']['action_workflow'][0]['title'], "Custom Action No Dialog")
......@@ -579,7 +585,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_links']['site_root']['name'], self.portal.web_site_module.hateoas.getTitle())
self.assertEqual(result_dict['_links']['action_object_new_content_action']['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document" % (
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document&form_id=Foo_view" % (
self.portal.absolute_url(),
urllib.quote_plus(document.getRelativeUrl())))
self.assertEqual(result_dict['_links']['action_object_new_content_action']['title'], "Create a Document")
......@@ -710,7 +716,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_links']['parent'],
{"href": "urn:jio:get:%s" % parent.getRelativeUrl(), "name": parent.getTitle()})
# view links do not have form_id in the URL
self.assertEqual(result_dict['_links']['view'][0]['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=view" % (
self.portal.absolute_url(),
......@@ -1353,7 +1359,7 @@ class TestERP5Document_getHateoas_mode_bulk(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['result_list'][0]['_links']['action_object_view'][0]['name'], "view")
self.assertEqual(result_dict['result_list'][0]['_links']['action_workflow'][0]['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog" % (
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog&form_id=Foo_view" % (
self.portal.absolute_url(),
urllib.quote_plus(document.getRelativeUrl())))
self.assertEqual(result_dict['result_list'][0]['_links']['action_workflow'][0]['title'], "Custom Action No Dialog")
......@@ -1366,7 +1372,7 @@ class TestERP5Document_getHateoas_mode_bulk(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['result_list'][0]['_links']['site_root']['name'], self.portal.web_site_module.hateoas.getTitle())
self.assertEqual(result_dict['result_list'][0]['_links']['action_object_new_content_action']['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document" % (
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document&form_id=Foo_view" % (
self.portal.absolute_url(),
urllib.quote_plus(document.getRelativeUrl())))
self.assertEqual(result_dict['result_list'][0]['_links']['action_object_new_content_action']['title'], "Create a Document")
......
"""Stay there with a "Nothing" portal status message"""
kw.update(context.REQUEST.form)
return context.ERP5Site_redirect(context.absolute_url(), keep_items={'portal_status_message': '"Nothing" action is done.'}, **kw)
return context.Base_redirect(kw['form_id'], keep_items={'portal_status_message': '"Nothing" action is done.'})
......@@ -79,7 +79,9 @@
clone_list,
delete_list;
return gadget.jio_getAttachment(options.jio_key, "links")
// Get the whole view as attachment because actions can change based on
// what view we are at. If no view available than fallback to "links".
return gadget.jio_getAttachment(options.jio_key, options.view || "links")
.push(function (result) {
erp5_document = result;
transition_list = asArray(erp5_document._links.action_workflow);
......
......@@ -74,16 +74,20 @@
.declareMethod("render", function (options) {
var gadget = this,
erp5_document,
report_list;
report_list,
print_list;
return gadget.jio_getAttachment(options.jio_key, "links")
// Get the whole view as attachment because actions can change based on
// what view we are at. If no view available than fallback to "links".
return gadget.jio_getAttachment(options.jio_key, options.view || "links")
.push(function (result) {
erp5_document = result;
report_list = asArray(erp5_document._links.action_object_report_jio)
.concat(asArray(erp5_document._links.action_object_jio_report));
report_list = asArray(erp5_document._links.action_object_jio_report),
print_list = asArray(erp5_document._links.action_object_jio_print);
return RSVP.all([
renderLinkList(gadget, "Reports", "bar-chart-o", report_list)
renderLinkList(gadget, "Reports", "bar-chart-o", report_list),
renderLinkList(gadget, "Print", "print", print_list)
]);
})
.push(function (translated_html_link_list) {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.3162.7999.42854</string> </value>
<value> <string>965.24790.41231.802</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1509097420.01</float>
<float>1518172272.43</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, RSVP, URI, calculatePageTitle, Blob, URL, document, jIO, Handlebars */
(function (window, rJS, RSVP, URI, calculatePageTitle, Blob, URL, document, jIO, Handlebars) {
/*global window, rJS, RSVP, URI, calculatePageTitle, Blob, URL, document, jIO, Handlebars, ensureArray */
(function (window, rJS, RSVP, URI, calculatePageTitle, Blob, URL, document, jIO, Handlebars, ensureArray) {
"use strict";
/* Make sure that returned object is an Array instance. */
function ensureArray(obj) {
if (!obj) {return []; }
if (Array.isArray(obj)) {return obj; }
return [obj];
}
function submitDialog(gadget, submit_action_id, is_update_method) {
var form_gadget = gadget,
action = form_gadget.state.erp5_document._embedded._view._actions.put,
form_id = form_gadget.state.erp5_document._embedded._view.form_id,
dialog_id = form_gadget.state.erp5_document._embedded._view.dialog_id,
redirect_to_parent;
return form_gadget.notifySubmitting()
......@@ -27,9 +21,12 @@
var data = {},
key;
data[form_id.key] = form_id['default'];
// XXX Hardcoded
data.dialog_id = form_id['default'];
// In dialog form, dialog_id is mandatory and form_id is optional
data.dialog_id = dialog_id['default'];
if (form_id !== undefined) {
data.form_id = form_id['default'];
}
data.dialog_method = form_gadget.state.form_definition[submit_action_id];
if (is_update_method) {
data.update_method = data.dialog_method;
......@@ -179,7 +176,7 @@
});
})
.push(undefined, function (error) {
if (error.target !== undefined) {
if (error !== undefined && error.target !== undefined) {
var error_text = 'Encountered an unknown error. Try to resubmit',
promise_queue = new RSVP.Queue();
// if we know what the error was, try to precise it for the user
......@@ -235,6 +232,7 @@
});
}
var gadget_klass = rJS(window),
dialog_button_source = gadget_klass.__template_element
.getElementById("dialog-button-template")
......@@ -295,11 +293,11 @@
.onStateChange(function (modification_dict) {
var form_gadget = this,
icon,
selector = form_gadget.element.querySelector("h3"),
view_list = ensureArray(this.state.erp5_document._links.action_workflow),
icon,
title,
i,
view_list = ensureArray(this.state.erp5_document._links.action_workflow);
i;
title = this.state.form_definition.title;
......@@ -322,8 +320,9 @@
break;
}
// By default we display dialog form title
for (i = 0; i < view_list.length; i += 1) {
if (view_list[i].href === this.state.view) {
if (this.state.view === view_list[i].href) {
title = view_list[i].title;
}
}
......@@ -435,4 +434,4 @@
}
}, false, false);
}(window, rJS, RSVP, URI, calculatePageTitle, Blob, URL, document, jIO, Handlebars));
\ No newline at end of file
}(window, rJS, RSVP, URI, calculatePageTitle, Blob, URL, document, jIO, Handlebars, ensureArray));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.13214.39160.9318</string> </value>
<value> <string>965.30841.12858.15274</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1517480919.98</float>
<float>1518535283.31</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -7,7 +7,7 @@
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Default Module View</td></tr>
<tr><th rowspan="1" colspan="3">Test Default Module View (expected failure)</th></tr>
</thead><tbody>
<tal:block metal:use-macro="here/PTZuite_CommonTemplate/macros/init" />
......
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