Commit 33f61f4a authored by Tomáš Peterka's avatar Tomáš Peterka

[renderjs_ui] Allow "print_action" to showup in "Export" page

-  implement 'dialog_id' for dialog forms (to replace form_id)
-  introduce "prev_view" containing previous view of an object, mandatory for printing that view
-  overwrite form_id for print_action with "prev_view" - the only thing we can get from javascript
parent 43a37bab
...@@ -23,5 +23,6 @@ return context.ERP5Document_getHateoas( ...@@ -23,5 +23,6 @@ return context.ERP5Document_getHateoas(
bulk_list=bulk_list, bulk_list=bulk_list,
sort_on=sort_on, sort_on=sort_on,
local_roles=local_roles, local_roles=local_roles,
restricted=1 restricted=1,
prev_view=prev_view
) )
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, prev_view=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -835,6 +835,9 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti ...@@ -835,6 +835,9 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
# Do not crash if field configuration is wrong. # Do not crash if field configuration is wrong.
pass pass
# Edit uses form_id to recover the submitted form.
# Dialog uses 'dialog_id' instead and 'form_id' only as a parameter to the dialog form
# Beware that print_action rewrites value of form_id in callee!
response_dict["form_id"] = { response_dict["form_id"] = {
"type": "StringField", "type": "StringField",
"key": "form_id", "key": "form_id",
...@@ -847,6 +850,20 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti ...@@ -847,6 +850,20 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
"required": 1, "required": 1,
} }
# Form dialog (subsequent callDialogMethod) selects its form based on dialog_id, not form_id
if (form.pt == 'form_dialog'):
response_dict["dialog_id"] = {
"type": "StringField",
"key": "dialog_id",
"default": form.id,
"editable": 0,
"css_class": "",
"hidden": 1,
"description": "",
"title": "dialog_id",
"required": 1,
}
if (form.pt == 'report_view'): if (form.pt == 'report_view'):
report_item_list = [] report_item_list = []
report_result_list = [] report_result_list = []
...@@ -1058,8 +1075,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1058,8 +1075,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# XXX Loop on form rendering # XXX Loop on form rendering
erp5_action_dict = portal.Base_filterDuplicateActions( erp5_action_dict = portal.Base_filterDuplicateActions(
portal.portal_actions.listFilteredActionsFor(traversed_document)) portal.portal_actions.listFilteredActionsFor(traversed_document))
embedded_url = None embedded_url = None
prev_embedded_url = None
# XXX See ERP5Type.getDefaultViewFor # XXX See ERP5Type.getDefaultViewFor
for erp5_action_key in erp5_action_dict.keys(): for erp5_action_key in erp5_action_dict.keys():
erp5_action_list = [] erp5_action_list = []
...@@ -1075,8 +1094,12 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1075,8 +1094,12 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if (view == view_action['id']): if (view == view_action['id']):
embedded_url = '%s' % view_action['url'] embedded_url = '%s' % view_action['url']
global_action_type = ("view", "workflow", "object_new_content_action", # Print action requires Form ID of the previous view - thus if we receive prev_view, resolve it
"object_clone_action", "object_delete_action") if prev_view == view_action['id']:
prev_embedded_url = '%s' % view_action['url']
global_action_type = ("view", "workflow", "object_new_content_action",
"object_clone_action", "object_delete_action", "object_print")
if (erp5_action_key == view_action_type or if (erp5_action_key == view_action_type or
erp5_action_key in global_action_type or erp5_action_key in global_action_type or
"_jio" in erp5_action_key): "_jio" in erp5_action_key):
...@@ -1168,6 +1191,12 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1168,6 +1191,12 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
REQUEST.set(query_key, query_value) REQUEST.set(query_key, query_value)
renderForm(traversed_document, renderer_form, embedded_dict) renderForm(traversed_document, renderer_form, embedded_dict)
if (prev_embedded_url is not None):
# Resolve Form ID of previous view and make it accessible inside embedded form as form_id
# because old UI does that by passing the form_id in query string and hidden fields
embedded_dict["form_id"]["default"] = prev_embedded_url.split('?', 1)[0].split("/")[-1]
result_dict['_embedded'] = { result_dict['_embedded'] = {
'_view': embedded_dict '_view': embedded_dict
# embedded_action_key: embedded_dict # embedded_action_key: embedded_dict
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, prev_view=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
/*global window, rJS, RSVP, Handlebars, calculatePageTitle */ /*global window, rJS, RSVP, Handlebars, calculatePageTitle, URL */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, calculatePageTitle) { (function (window, rJS, RSVP, Handlebars, calculatePageTitle, URL) {
"use strict"; "use strict";
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -67,24 +67,46 @@ ...@@ -67,24 +67,46 @@
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
erp5_document, erp5_document;
report_list;
return gadget.jio_getAttachment(options.jio_key, "links") return gadget.jio_getAttachment(options.jio_key, "links")
.push(function (result) { .push(function (jio_document) {
erp5_document = result; var report_list = asArray(jio_document._links.action_object_report_jio)
report_list = asArray(erp5_document._links.action_object_report_jio) .concat(asArray(jio_document._links.action_object_jio_report)),
.concat(asArray(erp5_document._links.action_object_jio_report)); print_list = asArray(jio_document._links.action_object_print);
erp5_document = jio_document;
return RSVP.all([ return new RSVP.Queue()
renderLinkList(gadget, "Reports", "bar-chart-o", report_list) .push(function () {
]); return gadget.getUrlParameter("view");
})
.push(function (prev_view) {
// prev_view can have two forms
// 1/ action name like "view", "detail"...
// 2/ absolute script URL like "https://erp5.com/erp5/web_site_module/renderjs_runner/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=account_module%2Fbank&view=transaction_list"
if (prev_view.startsWith('http')) {
prev_view = new URL(prev_view).searchParams.get("view");
}
print_list.forEach(function (link) {
if (link.href.search(/\?/) > 0) {
link.href += "&";
} else {
link.href += "?";
}
link.href += "prev_view=" + prev_view;
});
return RSVP.all([
renderLinkList(gadget, "Reports", "bar-chart-o", report_list),
renderLinkList(gadget, "Print", "print", print_list)
]);
});
}) })
.push(function (translated_html_link_list) { .push(function (translated_html_link_list) {
gadget.element.innerHTML = translated_html_link_list.join("\n"); gadget.element.innerHTML = translated_html_link_list.join("\n");
...@@ -101,4 +123,4 @@ ...@@ -101,4 +123,4 @@
}); });
}); });
}(window, rJS, RSVP, Handlebars, calculatePageTitle)); }(window, rJS, RSVP, Handlebars, calculatePageTitle, URL));
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.3162.7999.42854</string> </value> <value> <string>964.54289.22007.9642</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509097420.01</float> <float>1516023151.41</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -177,6 +177,7 @@ ...@@ -177,6 +177,7 @@
var form_gadget = this, var form_gadget = this,
action = this.state.erp5_document._embedded._view._actions.put, action = this.state.erp5_document._embedded._view._actions.put,
form_id = this.state.erp5_document._embedded._view.form_id, form_id = this.state.erp5_document._embedded._view.form_id,
dialog_id = this.state.erp5_document._embedded._view.dialog_id,
redirect_to_parent; redirect_to_parent;
return form_gadget.notifySubmitting() return form_gadget.notifySubmitting()
...@@ -191,8 +192,7 @@ ...@@ -191,8 +192,7 @@
key; key;
data[form_id.key] = form_id['default']; data[form_id.key] = form_id['default'];
// XXX Hardcoded data.dialog_id = dialog_id['default'];
data.dialog_id = form_id['default'];
data.dialog_method = action.action; data.dialog_method = action.action;
//XXX hack for redirect, difined in form //XXX hack for redirect, difined in form
redirect_to_parent = content_dict.field_your_redirect_to_parent; redirect_to_parent = content_dict.field_your_redirect_to_parent;
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.65326.20561.44834</string> </value> <value> <string>964.55768.7414.13687</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1512740130.49</float> <float>1516098887.02</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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