Можно ли добавить в проект на платформе CUBA HTML страницу (со стилями и скриптами) со ссылками по которым открываются экраны CUBA?
Добрый день!
Компонент BrowserFrame предназначен для включения веб-страницы на страницу приложения. Это аналог HTML-элемента iframe.
Документация | Demo
В простом случае просто указываем путь до html файла.
<browserFrame height="100%"
width="100%">
<classpath path="com/company/demo/web/screens/html/sample-layout.html"/>
</browserFrame>
Открыть экран CUBA приложения по ссылке можно двумя способами:
-
Используя механиз навигации, т.е. если экран имеет аннотацию
@Route(например,@Route("task-info")), то его можно открыть по ссылке:http://localhost:8080/app/#main/task-info - Используя старый механизм ссылок на экраны, например:
http://localhost:8080/app/open?screen=sec$User.browse
Ниже пример JavaScript, который формирует подобные ссылки в HTML документе:
<script type="text/javascript">
// Wait for the page to load first
window.onload = function () {
//Get a reference to the link on the page
// with an id of "cubaScreenLink"
let cubaScreenLinkRoute = document.getElementById("cubaScreenLinkRoute");
//Set code to run when the link is clicked
// by assigning a function to "onclick"
cubaScreenLinkRoute.onclick = function () {
// Your code here...
// Since BrowserFrame displays its content in an iframe,
// we need to obtain parent's location and open a link
// in the parent's window
let url = window.parent.location.origin + window.parent.location.pathname + "#main/users";
window.open(url, "_parent");
//If you don't want the link to actually
// redirect the browser to another page,
// then return false at the end of this block.
// Note that this also prevents event bubbling,
// which is probably what we want here, but won't
// always be the case.
return false;
};
let cubaScreenLinkId = document.getElementById("cubaScreenLinkId");
cubaScreenLinkId.onclick = function () {
let url = window.parent.location.origin + window.parent.location.pathname + "open?screen=sec$Role.browse";
window.open(url, "_parent");
return false;
};
}
</script>
Полный код экрана и HTML файла можно найти в демо приложении: html-demo.zip (78.7 КБ)
Глеб
1 симпатия