Browse Source

MC mods to handle response codes

Vijayakrishnan 4 years ago
parent
commit
f99879b59a
1 changed files with 43 additions and 31 deletions
  1. 43 31
      public/js/mc.js

+ 43 - 31
public/js/mc.js

@@ -150,36 +150,48 @@ function initFastLoad(_parent = false) {
 
 function onFastLoaded(_data, _href, _history) {
     var targetParent = $('.stag-content');
-    _data = '<div>' + _data + '</div>';
-    var content = $(_data).find('.stag-content');
-    if (content && content.length) {
-
-        targetParent.html(content.html());
-        hideMask();
-        hideMoeFormMask();
-        targetParent.append('<script src="/js/yemi.js?_=7"></script>');
-        window.setTimeout(function() {
-            initCreateNote();
-            initQuillEdit();
-            initFastLoad(targetParent);
-            initPrimaryForm();
-            initPatientPresenceIndicator();
-            runMCInitializers();
-            if(window.top.currentMcUrl !== window.top.location.href) {
-                $(window).scrollTop(0);
-            }
-            window.top.currentMcUrl = window.top.location.href;
-        }, 50);
-        // if(typeof initializeCalendar !== 'undefined') {
-        //     initializeCalendar();
-        // }
-        // if(typeof initIntakeEvents !== 'undefined') {
-        //     initIntakeEvents();
-        // }
+    if (!Number.isInteger(_data)) {
+        _data = '<div>' + _data + '</div>';
+        var content = $(_data).find('.stag-content');
+        if (content && content.length) {
+            targetParent.html(content.html());
+            hideMask();
+            hideMoeFormMask();
+            targetParent.append('<script src="/js/yemi.js?_=7"></script>');
+            window.setTimeout(function () {
+                initCreateNote();
+                initQuillEdit();
+                initFastLoad(targetParent);
+                initPrimaryForm();
+                initPatientPresenceIndicator();
+                runMCInitializers();
+                if (window.top.currentMcUrl !== window.top.location.href) {
+                    $(window).scrollTop(0);
+                }
+                window.top.currentMcUrl = window.top.location.href;
+            }, 50);
+        }
+        else {
+            targetParent.html('<p class="text-danger p-3 small">Error on page: <b>' + _href + '</b></p>');
+            hideMask();
+            hideMoeFormMask();
+        }
     } else {
         // fallback
+        let msg = 'Unable to open page: ';
+        switch (_data) {
+            case 403:
+                msg = 'You do not have access to this page: ';
+                break;
+            case 404:
+                msg = 'Page not found: ';
+                break;
+            case 500:
+                msg = 'Error on page: ';
+                break;
+        }
         console.warn('MC: Target page failed: ' + _href);
-        targetParent.html('<p class="text-danger p-3 small">Target page not found or returned error: <b>' + _href + '</b></p>');
+        targetParent.html('<p class="text-danger p-3 small"><b>' + _data + '</b> - ' + msg + '<b>' + _href + '</b></p>');
         hideMask();
         hideMoeFormMask();
     }
@@ -225,10 +237,10 @@ function fastLoad(_href, _history = true, _useCache = true, _replaceState = fals
         $.get(_href, function (_data) {
             onFastLoaded(_data, _href, _history);
         }).fail(function (_jqXhr) {
-            if(_jqXhr.status === 403) {
-                alert('You do not have access to this patient.');
-            }
-            onFastLoaded('error', _href, _history);
+            // if(_jqXhr.status === 403) {
+            //     alert('You do not have access to this patient.');
+            // }
+            onFastLoaded(_jqXhr.status, _href, _history);
         });
     }
 }