Fix multi reload of UI.php and js files

This commit is contained in:
acognet
2021-01-21 15:35:29 +01:00
parent 154156f4a1
commit 63c1a1d2d3
2 changed files with 37 additions and 21 deletions

View File

@@ -27,33 +27,44 @@
<script type="text/javascript"> <script type="text/javascript">
var aFilesToLoad{{ sId }} = []; var aFilesToLoad{{ sId }} = [];
{% for sJsFile in aPage.aJsFiles %} {% for sJsFile in aPage.aJsFiles %}
aFilesToLoad{{ sId }}.push('{{ sJsFile|raw }}'); if (! $.inArray('{{ sJsFile|raw }}',aListJsFiles))
{
aFilesToLoad{{ sId }}.push('{{ sJsFile|add_itop_version }}');
aListJsFiles.push("{{ sJsFile }}");
}
{% endfor %} {% endfor %}
var iCurrentIdx{{ sId }} = 0; var iCurrentIdx{{ sId }} = 0;
var iFilesToLoadCount{{ sId }} = aFilesToLoad{{ sId }}.length; var iFilesToLoadCount{{ sId }} = aFilesToLoad{{ sId }}.length;
var fLoadScript{{ sId }} = function(){ if(iFilesToLoadCount{{ sId }}>0)
$.when( {
$.ajax({ var fLoadScript{{ sId }} = function () {
$.when(
$.ajax({
url: aFilesToLoad{{ sId }}[iCurrentIdx{{ sId }}], url: aFilesToLoad{{ sId }}[iCurrentIdx{{ sId }}],
dataType: 'script', dataType: 'script',
cache: true cache: true
}) })
) )
.then(function(){ .then(function () {
iCurrentIdx{{ sId }}++; iCurrentIdx{{ sId }}++;
if (iCurrentIdx{{ sId }} !== iFilesToLoadCount{{ sId }}) if (iCurrentIdx{{ sId }} !== iFilesToLoadCount{{ sId }})
{ {
fLoadScript{{ sId }}(); fLoadScript{{ sId }}();
} }
else else
{ {
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %} {% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
{{ sJsInlineOnDomReady|raw }} {{ sJsInlineOnDomReady|raw }}
{% endfor %} {% endfor %}
} }
}); });
}; };
fLoadScript{{ sId }}(); fLoadScript{{ sId }}();
} else {
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
{{ sJsInlineOnDomReady|raw }}
{% endfor %}
}
</script> </script>
{% endblock %} {% endblock %}
{% else %} {% else %}

View File

@@ -54,7 +54,12 @@
{{ render_block(oBlock, {aPage: aPage}) }} {{ render_block(oBlock, {aPage: aPage}) }}
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
<script type="text/javascript">
var aListJsFiles = [];
{% for sJsFile in aPage.aJsFiles %}
aListJsFiles.push("{{ sJsFile}}");
{% endfor %}
</script>
{% block iboPageJsFiles %} {% block iboPageJsFiles %}
{% for sJsFile in aPage.aJsFiles %} {% for sJsFile in aPage.aJsFiles %}
<script type="text/javascript" src="{{ sJsFile|add_itop_version }}"></script> <script type="text/javascript" src="{{ sJsFile|add_itop_version }}"></script>