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
...@@ -27,13 +27,23 @@ ...@@ -27,13 +27,23 @@
.declareMethod('getDocumentUrl', function (raw_url) { .declareMethod('getDocumentUrl', function (raw_url) {
var gadget = this; var gadget = this;
return gadget.jio_getAttachment(raw_url, "links") return gadget.jio_getAttachment(raw_url, "links")
.push(function (links) { .push(function (links) {
var page = "preview", // try to find a preview action
has_preview = links._links.view.filter(function (i) { var page, i, view_actions = links._links.view;
return i.name === "preview"; for (i = 0; i < view_actions.length; i += 1) {
}).length > 0; if (view_actions[i].name.indexOf('preview') !== -1 || view_actions[i].title === 'Preview') {
if (!has_preview) { page = view_actions[i].name;
page = "html_view"; 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({ return gadget.getUrlFor({
command: 'display_erp5_action_with_history', command: 'display_erp5_action_with_history',
......
...@@ -256,8 +256,8 @@ ...@@ -256,8 +256,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1610600799.71</float> <float>1625719287.68</float>
<string>GMT+1</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -133,7 +133,9 @@ ...@@ -133,7 +133,9 @@
'test_support_request_spreadsheet.xlsx', 'test_support_request_spreadsheet.xlsx',
'test_support_request_docx.docx', 'test_support_request_docx.docx',
'test_support_request_txt.txt', 'test_support_request_txt.txt',
'test_support_request_png.png']"> 'test_support_request_png.png',
'test_support_request_bin.bin',
]">
<tr> <tr>
<td>setFile</td> <td>setFile</td>
<td>attachment</td> <td>attachment</td>
...@@ -203,7 +205,9 @@ ...@@ -203,7 +205,9 @@
'test_support_request_spreadsheet.xlsx', 'test_support_request_spreadsheet.xlsx',
'test_support_request_docx.docx', 'test_support_request_docx.docx',
'test_support_request_txt.txt', 'test_support_request_txt.txt',
'test_support_request_png.png']"> 'test_support_request_png.png',
'test_support_request_bin.bin',
]">
<tr> <tr>
<td>waitForElementPresent</td> <td>waitForElementPresent</td>
<td tal:content="string: //a[contains(text(), '${filename}')]"></td> <td tal:content="string: //a[contains(text(), '${filename}')]"></td>
...@@ -225,6 +229,11 @@ ...@@ -225,6 +229,11 @@
<td>undefined</td> <td>undefined</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertTextNotPresent</td>
<td>Error</td>
<td></td>
</tr>
<tr tal:define="title python: filename.split('.')[0]"> <tr tal:define="title python: filename.split('.')[0]">
<td>click</td> <td>click</td>
<td tal:content="python: '//div[@class=\'ui-header\']/h1/a[contains(text(), \'{}\')]'.format(title)"></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