From e46743af2a850084b8459a0418128d012fcbf9f7 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 1 Jul 2021 09:48:00 +0200 Subject: [PATCH] Fix and simplify dynamic dictionaries load in ajax pages --- sources/application/WebPage/AjaxPage.php | 19 +--- sources/application/WebPage/WebPage.php | 24 +++-- .../backoffice/ajaxpage/layout.html.twig | 91 +++---------------- 3 files changed, 33 insertions(+), 101 deletions(-) diff --git a/sources/application/WebPage/AjaxPage.php b/sources/application/WebPage/AjaxPage.php index 6f24b6b47..0d4ed1ca7 100644 --- a/sources/application/WebPage/AjaxPage.php +++ b/sources/application/WebPage/AjaxPage.php @@ -20,8 +20,6 @@ class AjaxPage extends WebPage implements iTabbedPage */ protected $m_oTabs; private $m_sMenu; // If set, then the menu will be updated - /** @var string Scripts to load entries of dictionary */ - protected $s_dict_scripts; const DEFAULT_PAGE_TEMPLATE_REL_PATH = 'pages/backoffice/ajaxpage/layout'; /** @var string */ @@ -161,22 +159,10 @@ class AjaxPage extends WebPage implements iTabbedPage header($s_header); } + // Prepare internal parts (js files, css files, js snippets, css snippets, ...) // - Generate necessary dict. files - // Dict entries for JS if ($this->bAddJSDict) { - if ((count($this->a_dict_entries) > 0) || (count($this->a_dict_entries_prefixes) > 0)) { - if (class_exists('Dict')) { - // The dictionary may not be available for example during the setup... - // Create a specific dictionary file and load it as a JS script - $sSignature = $this->get_dict_signature(); - $sJSFileName = utils::GetCachePath().$sSignature.'.js'; - if (!file_exists($sJSFileName) && is_writable(utils::GetCachePath())) { - file_put_contents($sJSFileName, $this->get_dict_file_content()); - } - // Load the dictionary as the first javascript file, so that other JS file benefit from the translations - $this->s_dict_scripts = utils::GetAbsoluteUrlAppRoot().'pages/ajax.document.php?operation=dict&s='.$sSignature; - } - } + $this->output_dict_entries(); } ConsoleBlockRenderer::AddCssJsToPage($this, $this->oContentLayout); @@ -200,7 +186,6 @@ class AjaxPage extends WebPage implements iTabbedPage 'aCssInline' => $this->a_styles, 'aJsFiles' => $this->a_linked_scripts, 'aJsInlineLive' => $this->a_scripts, - 'sDictScript' => $this->s_dict_scripts, 'aJsInlineOnDomReady' => $this->GetReadyScripts(), 'aJsInlineOnInit' => $this->a_init_scripts, 'bEscapeContent' => ($this->sContentType == 'text/html') && ($this->sContentDisposition == 'inline'), diff --git a/sources/application/WebPage/WebPage.php b/sources/application/WebPage/WebPage.php index 52861eefe..817596ea9 100644 --- a/sources/application/WebPage/WebPage.php +++ b/sources/application/WebPage/WebPage.php @@ -702,7 +702,18 @@ class WebPage implements Page { $aEntries = array_merge($aEntries, Dict::ExportEntries($sPrefix)); } - $sJSFile = 'var aDictEntries = '.json_encode($aEntries); + + $sEntriesAsJson = json_encode($aEntries); + $sJSFile = <<bAddJSDict) { - $this->output_dict_entries(); - } - $s_captured_output = $this->ob_get_clean_safe(); $aData = []; + // Prepare internal parts (js files, css files, js snippets, css snippets, ...) + // - Generate necessary dict. files + if ($this->bAddJSDict) { + $this->output_dict_entries(); + } + $aData['oLayout'] = $this->oContentLayout; $aData['aDeferredBlocks'] = $this->GetDeferredBlocks($this->oContentLayout); diff --git a/templates/pages/backoffice/ajaxpage/layout.html.twig b/templates/pages/backoffice/ajaxpage/layout.html.twig index f01b4f11a..d5cd16163 100644 --- a/templates/pages/backoffice/ajaxpage/layout.html.twig +++ b/templates/pages/backoffice/ajaxpage/layout.html.twig @@ -28,23 +28,14 @@ - {% else %} - {% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %} - - {% endfor %} - {% endif %} + {% endfor %} {% endblock %} {% endif %}