src/Products/NotificationsBundle/Resources/views/dashboard/messages/translations.html.twig line 1

Open in your IDE?
  1. {% extends '@ProductsNotifications/base--full.html.twig' %}
  2. {% block topbar %}
  3.     {% include '@ui2022/topbar--wizard.html.twig' with {
  4.         steps: [
  5.             {
  6.                 text: 'Create message',
  7.                 active: true,
  8.                 button: {
  9.                     button: 'form',
  10.                     type: 'submit',
  11.                     styles: 'wizard',
  12.                     form: {
  13.                         name: '',
  14.                         value: 'save',
  15.                         formaction: path('app.notifications.dashboard.messages.translations', {
  16.                             message: message.id,
  17.                             jump: path('app.notifications.dashboard.messages.update', {
  18.                                 message: message.id,
  19.                             }),
  20.                         }),
  21.                     },
  22.                 },
  23.             },
  24.             {
  25.                 text: 'Review and test',
  26.                     button: {
  27.                     button: 'form',
  28.                     type: 'submit',
  29.                     styles: 'wizard',
  30.                     form: {
  31.                         name: '',
  32.                         value: 'save',
  33.                         formaction: path('app.notifications.dashboard.messages.manage', {
  34.                             message: message.id,
  35.                             jump: path('app.notifications.dashboard.messages.manage', {
  36.                                 message: message.id,
  37.                             }),
  38.                         }),
  39.                     },
  40.                 },
  41.             },
  42.         ],
  43.         subactions: [
  44.         ],
  45.         actions: [
  46.             {
  47.                 button: 'form',
  48.                 type: 'submit',
  49.                 text: 'Next',
  50.                 styles: 'primary wide md',
  51.             },
  52.         ],
  53.     } %}
  54. {% endblock %}
  55. {% block content %}
  56.     <div class="py-5">
  57.         <div class="mx-auto w-50 text-center">
  58.             <img src="/ui2022/images/translation-animation.gif" alt="translating..." style="width: 150px;" />
  59.             <div class="pt-4" id="translation-statuses">
  60.                 {% for locale,status in statuses['statuses'] %}
  61.                     <div class="row justify-content-md-center">
  62.                         <div class="col-4 text-left">{{ humanReadableLocaleNames[locale] }}</div>
  63.                         <div class="col-1" id="translation-statuses-{{ locale }}">
  64.                             {% if status is same as(null) %}
  65.                                 <i class="fas fa-pause"></i>
  66.                             {% elseif status is same as(false) %}
  67.                                 <i class="fas fa-spinner fa-spin"></i>
  68.                             {% elseif status is same as(true) %}
  69.                                 <i class="fas fa-check"></i>
  70.                             {% endif %}
  71.                         </div>
  72.                     </div>
  73.                 {% endfor %}
  74.             </div>
  75.         </div>
  76.     </div>
  77.     <script type="text/javascript">
  78.         (function (window, document, $, undefined) {
  79.             $(function () {
  80.                 let waitingSince = Date.now();
  81.                 const translationsCheckUrl = '{{ path('app.notifications.dashboard.messages.check_translation_progress', {message: message.id}) }}';
  82.                 const redirectUrl = '{{ path('app.notifications.dashboard.messages.manage', {message: message.id}) }}';
  83.                 toastr.options = {
  84.                     positionClass: "toast-top-left mt-5 pt-4",
  85.                     timeOut: 0,
  86.                     extendedTimeOut: 0,
  87.                     tapToDismiss: false,
  88.                     fadeOut: 0,
  89.                 };
  90.                 const translationWarning =
  91.                     '<div class="mb-3">There is a problem with the translation services.</div>' +
  92.                     '<div><a href="{{ path('app.notifications.dashboard.messages.update', {message: message.id}) }}" class="alert-link">Exit</a> and try again later.</div>' +
  93.                     '<div>Or <a href="https://www.schoolnow.com/support" target="_blank" class="alert-link">report</a> to the support team.</div>';
  94.                 let translationWarningElement = null;
  95.                 let lastResponseJson = '{}';
  96.                 setInterval(() => {
  97.                     $.ajax({
  98.                         method: 'GET',
  99.                         url: translationsCheckUrl
  100.                     }).done(function (response) {
  101.                         if (JSON.stringify(response) !== lastResponseJson) {
  102.                             lastResponseJson = JSON.stringify(response);
  103.                             waitingSince = Date.now();
  104.                             toastr.clear();
  105.                             translationWarningElement = null;
  106.                         }
  107.                         for (var [locale, status] of Object.entries(response.statuses)) {
  108.                             switch (status) {
  109.                                 case null:
  110.                                     status = 'fas fa-pause';
  111.                                     break;
  112.                                 case false:
  113.                                     status = 'fas fa-spinner fa-spin';
  114.                                     break;
  115.                                 case true:
  116.                                     status = 'fas fa-check';
  117.                                     break;
  118.                             }
  119.                             $('#translation-statuses-' + locale + ' i').attr('class', status);
  120.                         }
  121.                         let waitSeconds = Math.floor(((Date.now() - waitingSince) / 1000));
  122.                         if (45 < waitSeconds && !translationWarningElement) {
  123.                             translationWarningElement = toastr.warning(translationWarning);
  124.                         }
  125.                         if ( (response.ready === true)) {
  126.                             window.location.replace(redirectUrl);
  127.                         }
  128.                     });
  129.                 }, 2000);
  130.             });
  131.         })(window, document, jQuery);
  132.     </script>
  133. {% endblock %}