Commit e8e7f5d1 authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: more flexible way of making preview link for attachments

Instead of expecting exactly actions with "preview" or "view" name, take any
action which name contains "preview" (or title is "Preview") or name is "view".

This makes it easier to include support request applications in different
applications, where the default actions might have a different name. This also
fixes the preview link for File portal type, because there was no "preview" or
"view" actions for File.
parent 81a6500d
Pipeline #16676 failed with stage
......@@ -27,13 +27,23 @@
.declareMethod('getDocumentUrl', function (raw_url) {
var gadget = this;
return gadget.jio_getAttachment(raw_url, "links")
.push(function (links) {
var page = "preview",
has_preview = links._links.view.filter(function (i) {
return i.name === "preview";
}).length > 0;
if (!has_preview) {
page = "html_view";
.push(function (links) {
// try to find a preview action
var page, i, view_actions = links._links.view;
for (i = 0; i < view_actions.length; i += 1) {
if (view_actions[i].name.indexOf('preview') !== -1 || view_actions[i].title === 'Preview') {
page = view_actions[i].name;
break;
}
}
// if not found, fallback to the first view action
if (page === undefined) {
for (i = 0; i < view_actions.length; i += 1) {
if (view_actions[i].name.indexOf('view') !== -1) {
page = view_actions[i].name;
break;
}
}
}
return gadget.getUrlFor({
command: 'display_erp5_action_with_history',
......
......@@ -256,8 +256,8 @@
</tuple>
<state>
<tuple>
<float>1610600799.71</float>
<string>GMT+1</string>
<float>1625719287.68</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -133,7 +133,9 @@
'test_support_request_spreadsheet.xlsx',
'test_support_request_docx.docx',
'test_support_request_txt.txt',
'test_support_request_png.png']">
'test_support_request_png.png',
'test_support_request_bin.bin',
]">
<tr>
<td>setFile</td>
<td>attachment</td>
......@@ -203,7 +205,9 @@
'test_support_request_spreadsheet.xlsx',
'test_support_request_docx.docx',
'test_support_request_txt.txt',
'test_support_request_png.png']">
'test_support_request_png.png',
'test_support_request_bin.bin',
]">
<tr>
<td>waitForElementPresent</td>
<td tal:content="string: //a[contains(text(), '${filename}')]"></td>
......@@ -225,6 +229,11 @@
<td>undefined</td>
<td></td>
</tr>
<tr>
<td>assertTextNotPresent</td>
<td>Error</td>
<td></td>
</tr>
<tr tal:define="title python: filename.split('.')[0]">
<td>click</td>
<td tal:content="python: '//div[@class=\'ui-header\']/h1/a[contains(text(), \'{}\')]'.format(title)"></td>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>test_support_request_bin.bin</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/octet-stream</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>random binary file</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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