Commit 5c53e4e6 authored by Xiaowu Zhang's avatar Xiaowu Zhang Committed by Gabriel Monnerat

erp5_web_renderjs_ui: Allow displaying some entries on pages not related to form_view/form_list

erp5_web_renderjs_ui_test: Add page to be used as example of links to extra menu and cover it with test
parent e4273c58
......@@ -18,6 +18,7 @@
data-i18n=Workflows
data-i18n=Actions
data-i18n=Jumps
data-i18n=Global
-->
<!-- renderjs -->
......
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>985.48809.10432.44578</string> </value>
<value> <string>989.49479.12222.40430</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1596701351.5</float>
<float>1612876311.33</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -62,6 +62,7 @@
view = options.view,
jump_view = options.jump_view,
visible = options.visible,
extra_menu_list = options.extra_menu_list,
display_workflow_list,
context = this,
workflow_list,
......@@ -119,6 +120,9 @@
clone_list = JSON.stringify(clone_list);
jump_list = JSON.stringify(jump_list);
}
if (extra_menu_list !== undefined) {
extra_menu_list = JSON.stringify(extra_menu_list);
}
return context.getUrlParameter('editable')
.push(function (editable) {
return context.changeState({
......@@ -133,15 +137,23 @@
jio_key: jio_key,
view: view,
jump_view: jump_view,
editable: asBoolean(options.editable) || asBoolean(editable) || false
editable: asBoolean(options.editable) || asBoolean(editable) || false,
extra_menu_list: extra_menu_list
});
});
})
.onStateChange(function onStateChange(modification_dict) {
var context = this,
var i,
context = this,
gadget = this,
workflow_list,
view_list,
action_list,
clone_list,
jump_list,
dl_fragment,
dl_element,
queue = new RSVP.Queue();
if (modification_dict.hasOwnProperty("visible")) {
......@@ -198,7 +210,6 @@
})
.push(function (result_list) {
var editable_value = [],
i,
ul_fragment = document.createDocumentFragment(),
a_element,
li_element,
......@@ -256,17 +267,17 @@
modification_dict.hasOwnProperty("clone_list") ||
modification_dict.hasOwnProperty("jump_list") ||
modification_dict.hasOwnProperty("jio_key") ||
modification_dict.hasOwnProperty("view_list"))) {
if (this.state.view_list === undefined) {
modification_dict.hasOwnProperty("view_list") ||
modification_dict.hasOwnProperty("extra_menu_list"))) {
dl_fragment = document.createDocumentFragment();
gadget.element.querySelector("dl").textContent = '';
} else {
if (this.state.view_list !== undefined) {
queue
.push(function () {
var i = 0,
parameter_list = [],
view_list = JSON.parse(gadget.state.view_list),
action_list = JSON.parse(gadget.state.action_list),
clone_list = JSON.parse(gadget.state.clone_list),
var parameter_list = [];
view_list = JSON.parse(gadget.state.view_list);
action_list = JSON.parse(gadget.state.action_list);
clone_list = JSON.parse(gadget.state.clone_list);
jump_list = JSON.parse(gadget.state.jump_list);
workflow_list = JSON.parse(gadget.state.workflow_list);
......@@ -323,13 +334,6 @@
]);
})
.push(function (result_list) {
var dl_element,
dl_fragment = document.createDocumentFragment(),
view_list = JSON.parse(gadget.state.view_list),
action_list = JSON.parse(gadget.state.action_list),
clone_list = JSON.parse(gadget.state.clone_list),
jump_list = JSON.parse(gadget.state.jump_list);
appendDt(dl_fragment, result_list[1][0], 'eye',
view_list, result_list[0], 0);
if (gadget.state.display_workflow_list) {
......@@ -344,16 +348,36 @@
jump_list, result_list[0],
view_list.length + workflow_list.length +
action_list.length + clone_list.length);
});
}
if (gadget.state.hasOwnProperty("extra_menu_list") &&
gadget.state.extra_menu_list) {
queue
.push(function () {
return gadget.getTranslationList(['Global']);
})
.push(function (translation_list) {
var extra_menu_list = JSON.parse(gadget.state.extra_menu_list),
href_list = [];
for (i = 0; i < extra_menu_list.length; i += 1) {
extra_menu_list[i].class_name = extra_menu_list[i].active ? "active" : "";
href_list.push(extra_menu_list[i].href);
}
appendDt(dl_fragment, translation_list[0], 'globe',
extra_menu_list, href_list, 0);
});
}
}
queue
.push(function () {
if (dl_fragment) {
dl_element = gadget.element.querySelector("dl");
while (dl_element.firstChild) {
dl_element.removeChild(dl_element.firstChild);
}
dl_element.appendChild(dl_fragment);
});
}
}
});
return queue;
})
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.65434.35774.5563</string> </value>
<value> <string>989.59257.5605.14267</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1609322633.89</float>
<float>1612884079.54</float>
<string>UTC</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testPanelExtraMenu</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test RenderJS UI</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Initialize -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/foo_module?page=extra_menu_test&#38;view=view</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tr>
<td>assertElementPresent</td>
<td>//dd[@class="document-listview"]/a[@class="active" and contains(text(), "Contribute")]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//dd[@class="document-listview"]/a[@class="active" and contains(text(), "Contribute")]</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr>
<td>assertElementPresent</td>
<td>//h3[@class="ui-content-title ui-body-c ui-icon ui-icon-custom ui-icon-random" and contains(text(), "Contribute File")]</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tr>
<td>assertElementNotPresent</td>
<td>//dd[@class="document-listview"]/a[@class="active" and contains(text(), "Contribute")]</td>
<td></td>
</tr>
<!-- Open a diferent page to force open reload the page with extra_menu_test -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/</td>
<td></td>
</tr>
<!-- Open extra_menu_test page in the web site context instead of foo_module -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/?page=extra_menu_test</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tr>
<td>assertElementPresent</td>
<td>//dd[@class="document-listview"]/a[@class="active" and contains(text(), "Contribute")]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Page Document</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<link rel="http://www.renderjs.org/rel/interface" href="interface_erp5_form_content_provider.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_extra_menu_test.js" type="text/javascript"></script>
</head>
<body>
<p>Test Extra Menu</p>
</body>
</html>
\ No newline at end of file
/*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
/**
Page Form is a top-level gadget (a "Page") taking care of rendering form
and handling data send&receive.
*/
(function (window, rJS) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareMethod("render", function render(options) {
var gadget = this,
new_state = {
options: options
},
parameter_list = [{
command: 'display_erp5_action_with_history',
options: {
jio_key: 'document_module',
page: 'contribute_file',
keep_history: true
}
}];
return gadget.updateHeader({page_title: "Extra Menu"})
.push(function () {
if (options.jio_key) {
return gadget.jio_getAttachment(options.jio_key,
options.view);
}
})
.push(function (result) {
new_state.erp5_document = result;
return gadget.getUrlForList(parameter_list);
})
.push(function (href_list) {
new_state.extra_menu_list = [{
'title' : 'Contribute',
'href': href_list[0],
'active': true
}];
return gadget.changeState(new_state);
});
})
.onStateChange(function onStateChange() {
var gadget = this;
return gadget.updatePanel({
extra_menu_list: gadget.state.extra_menu_list,
jio_key: gadget.state.options.jio_key,
erp5_document: gadget.state.erp5_document,
view_list: []
});
});
}(window, rJS));
\ No newline at end of file
......@@ -52,5 +52,6 @@ portal_tests/renderjs_ui_translate_zuite
portal_tests/renderjs_ui_translate_zuite/**
portal_tests/renderjs_ui_zuite
portal_tests/renderjs_ui_zuite/**
web_page_module/gadget_erp5_page_extra_menu_test_*
web_page_module/gadget_erp5_page_router_test_*
web_page_module/gadget_erp5_page_service_worker_test_*
\ No newline at end of file
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