mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
N°3980 - Manage dictionary entries for JS script in AjaxPage
This commit is contained in:
@@ -19,6 +19,9 @@ 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';
|
||||
|
||||
/**
|
||||
@@ -154,6 +157,24 @@ class AjaxPage extends WebPage implements iTabbedPage
|
||||
header($s_header);
|
||||
}
|
||||
|
||||
// - 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleBlockRenderer::AddCssJsToPage($this, $this->oContentLayout);
|
||||
|
||||
// Render the blocks
|
||||
@@ -185,6 +206,7 @@ EOF
|
||||
'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'),
|
||||
|
||||
@@ -26,6 +26,16 @@
|
||||
{% block iboPageJsFiles %}
|
||||
<script type="text/javascript">
|
||||
var aFilesToLoad{{ sId }} = [];
|
||||
{# manage Dictionary file if exist #}
|
||||
var sUrlDictFile = '';
|
||||
{% if aPage.sDictScript is not empty %}
|
||||
if ($.inArray('{{ aPage.sDictScript|raw }}', aListJsFiles) == -1)
|
||||
{
|
||||
sUrlDictFile = "{{ aPage.sDictScript|raw }}";
|
||||
aListJsFiles.push(sUrlDictFile);
|
||||
}
|
||||
{% endif %}
|
||||
{# manage the other Js File #}
|
||||
{% for sJsFile in aPage.aJsFiles %}
|
||||
if ($.inArray('{{ sJsFile|raw }}', aListJsFiles) == -1)
|
||||
{
|
||||
@@ -33,48 +43,100 @@
|
||||
aListJsFiles.push("{{ sJsFile|raw }}");
|
||||
}
|
||||
{% endfor %}
|
||||
var iCurrentIdx{{ sId }} = 0;
|
||||
var iFilesToLoadCount{{ sId }} = aFilesToLoad{{ sId }}.length;
|
||||
if(iFilesToLoadCount{{ sId }}>0)
|
||||
{
|
||||
var fLoadScript{{ sId }} = function () {
|
||||
$.when(
|
||||
$.ajax({
|
||||
url: aFilesToLoad{{ sId }}[iCurrentIdx{{ sId }}],
|
||||
dataType: 'script',
|
||||
cache: true
|
||||
})
|
||||
)
|
||||
.then(function () {
|
||||
iCurrentIdx{{ sId }}++;
|
||||
if (iCurrentIdx{{ sId }} !== iFilesToLoadCount{{ sId }})
|
||||
{
|
||||
fLoadScript{{ sId }}();
|
||||
}
|
||||
else
|
||||
{
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
{% endfor %}
|
||||
}
|
||||
});
|
||||
};
|
||||
var iCurrentIdx{{ sId }} = 0;
|
||||
var iFilesToLoadCount{{ sId }} = aFilesToLoad{{ sId }}.length;
|
||||
if (iFilesToLoadCount{{ sId }}> 0)
|
||||
{
|
||||
var fLoadScript{{ sId }} = function () {
|
||||
$.when(
|
||||
$.ajax({
|
||||
url: aFilesToLoad{{ sId }}[iCurrentIdx{{ sId }}],
|
||||
dataType: 'script',
|
||||
cache: true
|
||||
})
|
||||
)
|
||||
.then(function () {
|
||||
iCurrentIdx{{ sId }}++;
|
||||
if (iCurrentIdx{{ sId }} !== iFilesToLoadCount{{ sId }})
|
||||
{
|
||||
fLoadScript{{ sId }}();
|
||||
}
|
||||
else
|
||||
{
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
{% endfor %}
|
||||
}
|
||||
});
|
||||
};
|
||||
{# first load Dictionary if exist #}
|
||||
if (sUrlDictFile != '')
|
||||
{
|
||||
$.ajax({
|
||||
url: '{{ aPage.sDictScript|raw }}',
|
||||
dataType: 'script',
|
||||
cache: true
|
||||
}).done(function (data) {
|
||||
if (Dict != undefined && data.startsWith("var aDictEntries = {\""))
|
||||
{
|
||||
eval(data);
|
||||
$.extend(Dict._entries, aDictEntries);
|
||||
}
|
||||
}).then(function () {
|
||||
fLoadScript{{ sId }}();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
fLoadScript{{ sId }}();
|
||||
} else
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
{% endfor %}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% else %}
|
||||
{% block iboPageJsInlineOnDomReady %}
|
||||
{# first load Dictionnary if exist #}
|
||||
{% if aPage.sDictScript is not empty %}
|
||||
<script type="text/javascript">
|
||||
if ($.inArray('{{ aPage.sDictScript|raw }}', aListJsFiles) == -1)
|
||||
{
|
||||
aListJsFiles.push("{{ aPage.sDictScript|raw }}");
|
||||
$.ajax({
|
||||
url: '{{ aPage.sDictScript|raw }}',
|
||||
dataType: 'script',
|
||||
cache: true
|
||||
}).done(function (data) {
|
||||
if (Dict != undefined && data.startsWith("var aDictEntries = {\""))
|
||||
{
|
||||
eval(data);
|
||||
$.extend(Dict._entries, aDictEntries);
|
||||
}
|
||||
}).then(function () {
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
{% endfor %}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
{% endfor %}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% else %}
|
||||
{% block iboPageJsInlineOnDomReady %}
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
<script type="text/javascript">
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
</script>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
|
||||
<script type="text/javascript">
|
||||
{{ sJsInlineOnDomReady|raw }}
|
||||
</script>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user