Commit 3b43c976 authored by Roque's avatar Roque

erp5_web_project_ui: redirector gadget for main page links

parent d4d4c7cd
......@@ -113,6 +113,8 @@ gadget_erp5_page_project_controller.html\n
gadget_erp5_page_project_controller.js\n
gadget_project_info.html\n
gadget_project_info.js\n
gadget_erp5_page_project_redirector.html\n
gadget_erp5_page_project_redirector.js\n
\n
favicon.ico\n
font-awesome/font-awesome-webfont.eot\n
......@@ -401,7 +403,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>979.42032.35189.30737</string> </value>
<value> <string>979.47842.59522.17561</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -419,7 +421,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1573204450.6</float>
<float>1573482418.03</float>
<string>UTC</string>
</tuple>
</state>
......
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Project Redirector</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_project_redirector.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global document, window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 90 */
(function (document, window, rJS) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this, id,
types = '("Text", "File", "PDF", "Drawing", ' +
'"Presentation", "Spreadsheet")',
states = '("shared", "published", "released", ' +
'"shared_alive", "published_alive", "released_alive")',
query = 'portal_type:' + types +
'AND reference:"' + options.reference +
'" AND validation_state:' + states,
redirect_dict = {
'command': 'display',
'options': {
'history': options.history
}
};
return gadget.jio_allDocs({
query: query,
limit: 1
})
.push(function (result_list) {
if (result_list.data.rows[0]) {
redirect_dict.options.jio_key = result_list.data.rows[0].id;
}
//TODO else: redirect to previous and show not found error
return gadget.redirect(redirect_dict);
});
});
}(document, window, rJS));
\ No newline at end of file
......@@ -3,6 +3,21 @@
(function (window, rJS, RSVP, document, ensureArray) {
"use strict";
function parseHTMLLinks(html, url) {
var content = document.createElement('html'),
regex = /href="(.*?)"/g,
link;
while ((link = regex.exec(html)) !== null) {
if (! link[1].startsWith("https") && ! link[1].startsWith("http") &&
! link[1].startsWith("ftp") && ! link[1].includes("/")
) {
// TODO pass current jio_key so redirector can come back if doc not found
html = html.replace(link[1], url + "&n.reference=" + link[1]);
}
}
return html;
}
function enableLink(link_element, url) {
link_element.href = url;
link_element.disabled = false;
......@@ -41,18 +56,20 @@
function getWebPageInfo(gadget, project_reference) {
var query = 'portal_type:="Web Page" AND reference:"' + project_reference +
'-Home.Page" AND validation_state:"published_alive"',
id,
content,
edit_view;
return gadget.jio_allDocs({
query: query,
limit: 1,
select_list: ['text_content']
})
id, content, edit_view, redirector_ulr;
return gadget.getUrlFor({command: 'push_history', options: {page: "project_redirector", editable: false}})
.push(function (url) {
redirector_ulr = url;
return gadget.jio_allDocs({
query: query,
limit: 1,
select_list: ['text_content']
});
})
.push(function (result_list) {
if (result_list.data.rows[0]) {
id = result_list.data.rows[0].id;
content = result_list.data.rows[0].value.text_content;
content = parseHTMLLinks(result_list.data.rows[0].value.text_content, redirector_ulr);
return gadget.jio_getAttachment(id, "links")
.push(function (web_page_document) {
edit_view = getActionListByName(
......@@ -81,6 +98,7 @@
rJS(window)
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("getSetting", "getSetting")
......
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