Pārlūkot izejas kodu

Post-submit inline ajax-load for Rx

Vijayakrishnan Krishnan 4 gadi atpakaļ
vecāks
revīzija
232a6650c1

+ 1 - 2
app/Http/Controllers/PatientController.php

@@ -172,8 +172,7 @@ class PatientController extends Controller
         ]);
     }
 
-    public function embedSection(Request $request, Client $patient, $section) {
-        $selectable = true;
+    public function embedSection(Request $request, Client $patient, $section, $selectable) {
         return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
     }
 }

+ 32 - 10
public/js/yemi.js

@@ -245,17 +245,13 @@ $(function () {
     });
 });
 
-jQuery(document).ready(function () {
-    var $ = jQuery;
-    $('body').mousedown(function(e){
-        if($(e.target).closest('[moe]').length || $(e.target).closest('#create-shortcut-form').length || $(e.target).is('#create-shortcut-form')){
-            return;
+var initMoes = function() {
+    $('[moe]').each(function () {
+
+        if($(this).is('[initialized]')) { // skip to next moe
+            return true;
         }
-        $('[moe] form:not([show])').hide();
-        hideMoeFormMask();
-    });
 
-    $('[moe]').each(function () {
         var moe = $(this);
         moe.isProcessing = false;
         var info = moe.find('[info]')[0]; // OPTIONAL
@@ -266,6 +262,8 @@ jQuery(document).ready(function () {
         var submit = moe.find('[submit]'); // REQUIRED
         var cancel = moe.find('[cancel]')[0]; // OPTIONAL
 
+        // ajax load - OPTIONAL
+        var moeParent = $(form).closest('[moe-parent][url]');
 
         if ($(this).attr('formOff') != null) {
             $(form).find(':input').attr('disabled', true);
@@ -396,10 +394,18 @@ jQuery(document).ready(function () {
                         window.top.history.back();
                     } else {
                         if (redir.indexOf('[data]') > -1) {
-							redir = redir.replace('[data]', data);
+                            redir = redir.replace('[data]', data);
                         }
                         fastLoad(redir, true, false);
                     }
+                } else if (moeParent.length) {
+                    showMask();
+                    $.get(moeParent.attr('url'), function(_data) {
+                        moeParent.html(_data);
+                        hideMask();
+                        hideMoeFormMask();
+                        initMoes();
+                    });
                 } else {
                     pageReload();
                 }
@@ -407,7 +413,23 @@ jQuery(document).ready(function () {
 
             }, false);
         });
+
+        moe.attr('initialized', 1); // mark as initialized
+
     });
+}
+
+jQuery(document).ready(function () {
+    var $ = jQuery;
+    $('body').mousedown(function(e){
+        if($(e.target).closest('[moe]').length || $(e.target).closest('#create-shortcut-form').length || $(e.target).is('#create-shortcut-form')){
+            return;
+        }
+        $('[moe] form:not([show])').hide();
+        hideMoeFormMask();
+    });
+
+    initMoes();
 
     $('table[info] input').each(function () {
         $(this).prop('readonly', true);

+ 5 - 3
resources/views/app/patient/partials/rx.blade.php

@@ -1,6 +1,9 @@
 <?php $infoLines = json_decode($patient->info_lines);?>
 <?php $infoLines = !$infoLines ? [] : $infoLines; ?>
-<div class="<?= !@$selectable ? 'mt-2' : 'border-bottom' ?> pb-1" rx-section>
+<div moe-parent
+     url="/embed/{{ $patient->uid }}/rx/{{ @$selectable ? 1 : 0 }}"
+     class="<?= !@$selectable ? 'mt-2' : 'border-bottom' ?> pb-1"
+     rx-section>
     <div class="d-flex align-items-center mb-2 py-2 <?= @$selectable ? 'px-2' : 'border-top' ?> border-bottom">
 
         @if(!@$selectable)
@@ -35,8 +38,7 @@
                 <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                 <input type="hidden" name="category" value="rx">
                 <div class="mb-2">
-                    <textarea class="form-control form-control-sm" rows="8"
-                              name="contentTexts" value=""
+                    <textarea class="form-control form-control-sm" rows="8" name="contentTexts"
                               placeholder="Medications"></textarea>
                 </div>
                 <div class="d-flex align-items-center">

+ 1 - 1
routes/web.php

@@ -115,7 +115,7 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/patients-suggest', 'HomeController@patientsSuggest');
 
     // embeddable sections
-    Route::get('/embed/{patient}/{section}', 'PatientController@embedSection')->name('embed-section');
+    Route::get('/embed/{patient}/{section}/{selectable}', 'PatientController@embedSection')->name('embed-section');
 
     // AJAX presence poll
     Route::get('/patients/{patient}/presence', 'PatientController@presence');