Browse Source

Moe [target] support for comma separated targets

Vijayakrishnan 3 năm trước cách đây
mục cha
commit
f3c3d9e53e
1 tập tin đã thay đổi với 28 bổ sung18 xóa
  1. 28 18
      public/js/mc.js

+ 28 - 18
public/js/mc.js

@@ -157,20 +157,39 @@ function initFastLoad(_parent = false) {
 }
 
 function onFastLoaded(_data, _href, _history, _target = null) {
-    var targetSelector = _target ? _target : '.stag-content';
-    var targetParent = $(targetSelector);
-    console.log('ALIX load target: ' + targetSelector);
+
     if (!Number.isInteger(_data)) {
         _data = '<div>' + _data + '</div>';
-        var content = $(_data).find(targetSelector);
-        if (content && content.length) {
-            targetParent.html(content.html());
+
+        // do for each element in _target
+        let responseError = false;
+        _target = _target ? _target : '.stag-content';
+        _target = _target.split(',').map(_x => $.trim(_x));
+        for (let i = 0; i < _target.length; i++) {
+            let t = _target[i];
+            let targetElement = $(t).first();
+            if(targetElement.length) {
+                let sourceElement = $(_data).find(t).first();
+                if (sourceElement && sourceElement.length) {
+                    targetElement.html(sourceElement.html());
+                    initFastLoad(targetElement);
+                    console.log('ALIX loaded element: ' + t);
+                }
+                else {
+                    responseError = true;
+                }
+            }
+            else {
+                responseError = true;
+            }
+        }
+
+        if (!responseError) {
             hideMask();
             hideMoeFormMask();
             window.setTimeout(function () {
                 initCreateNote();
                 initQuillEdit();
-                initFastLoad(targetParent);
                 initPrimaryForm();
                 initPatientPresenceIndicator();
                 runMCInitializers();
@@ -180,19 +199,10 @@ function onFastLoaded(_data, _href, _history, _target = null) {
                     $(window).scrollTop(0);
                 }
                 window.top.currentMcUrl = window.top.location.href;
-
-                /*let activeLeftNavLink = $('#sidebarMenu .nav-item>.nav-link.active').first();
-                if(activeLeftNavLink.length) {
-                    activeLeftNavLink[0].scrollIntoView({
-                        behavior: "smooth",
-                        block: "nearest",
-                        inline: "nearest"
-                    });
-                }*/
             }, 0);
         }
         else {
-            targetParent.html('<p class="text-danger p-3 small">Error on page: <b>' + _href + '</b></p>');
+            $('.stag-content').first().html('<p class="text-danger p-3 small">Error on page: <b>' + _href + '</b></p>');
             hideMask();
             hideMoeFormMask();
         }
@@ -214,7 +224,7 @@ function onFastLoaded(_data, _href, _history, _target = null) {
                 break;
         }
         console.warn('MC: Target page failed: ' + _href);
-        targetParent.html('<p class="text-danger p-3 small"><b>' + _data + '</b> - ' + msg + '<b>' + _href + '</b></p>');
+        $('.stag-content').first().html('<p class="text-danger p-3 small"><b>' + _data + '</b> - ' + msg + '<b>' + _href + '</b></p>');
         hideMask();
         hideMoeFormMask();
     }