Преглед изворни кода

Note sections - templates support [WIP #4]

Vijayakrishnan Krishnan пре 4 година
родитељ
комит
22a9e03951
2 измењених фајлова са 54 додато и 54 уклоњено
  1. 0 53
      app/Helpers/helpers.php
  2. 54 1
      resources/views/app/patient/note/dashboard.blade.php

+ 0 - 53
app/Helpers/helpers.php

@@ -87,56 +87,3 @@ if(!function_exists('sanitize_field_name')) {
         return preg_replace("/[^0-9a-z]/i", "_", $result);
     }
 }
-
-if(!function_exists('renderNoteTemplates')) {
-
-    function _renderNoteTemplate($template, $topLevel) {
-        echo
-            '<div class="note-template-item" ' .
-                'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
-                'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
-                '>' .
-            '<div class="note-template-text">';
-        echo '<span class="label">' .
-            '<input type="checkbox" />' .
-            '<span>' . $template->text . '</span>' .
-            '</span></div>';
-        if(isset($template->children) && count($template->children)) {
-            echo '<i class="fa fa-chevron-right has-children"></i>';
-            echo '<div class="note-template-children">';
-            foreach ($template->children as $t) {
-                _renderNoteTemplate($t, false);
-            }
-            echo '</div>';
-        }
-        else if(isset($template->type) && $template->type === 'text') {
-            echo '<i class="fa fa-chevron-right has-children"></i>';
-            echo '<div class="note-template-children">';
-            echo '<textarea class="form-control form-control-sm"></textarea>';
-            echo '</div>';
-        }
-        echo '</div>';
-    }
-
-    function renderNoteTemplates($path) {
-        $templates = json_decode(file_get_contents($path));
-//        echo '<pre class="border my-3">';
-//        print_r($templates);
-//        echo '</pre>';
-        echo '<div class="note-template-container">';
-        echo '<div class="position-relative w-100">' .
-                '<div class="note-template-output">' .
-                    '<div class="font-weight-bold text-secondary">Result:</div>' .
-                    '<div class="note-template-output-text"></div>' .
-                '</div>' .
-                '<div class="note-template-buttons d-flex align-items-center">' .
-                    '<button class="btn btn-sm btn-default bg-white border text-primary border-primary note-template-apply-trigger">Apply</button>' .
-                    '<button class="btn btn-sm btn-default bg-light border text-secondary border-secondary note-template-close-trigger">Close</button>' .
-                '</div>' .
-            '</div>';
-        foreach ($templates as $template) {
-            _renderNoteTemplate($template, true);
-        }
-        echo '</div>';
-    }
-}

+ 54 - 1
resources/views/app/patient/note/dashboard.blade.php

@@ -227,7 +227,55 @@
         </div>
         <div class="card-body p-0">
             <div>
+                <?php
+                function _renderNoteTemplate($template, $topLevel) {
+                    echo
+                        '<div class="note-template-item" ' .
+                            'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
+                            'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
+                            '>' .
+                            '<div class="note-template-text">' .
+                                '<span class="label">' .
+                                '<input type="checkbox" />' .
+                                '<span>' . $template->text . '</span>' .
+                                '</span>
+                            </div>';
+                    if(isset($template->children) && count($template->children)) {
+                        echo '<i class="fa fa-chevron-right has-children"></i>';
+                        echo '<div class="note-template-children">';
+                        foreach ($template->children as $t) {
+                            _renderNoteTemplate($t, false);
+                        }
+                        echo '</div>';
+                    }
+                    else if(isset($template->type) && $template->type === 'text') {
+                        echo '<i class="fa fa-chevron-right has-children"></i>';
+                        echo '<div class="note-template-children">' .
+                                '<textarea class="form-control form-control-sm"></textarea>' .
+                            '</div>';
+                    }
+                    echo '</div>';
+                }
 
+                function renderNoteTemplates($path) {
+                    $templates = json_decode(file_get_contents($path));
+                    echo '<div class="note-template-container">';
+                    echo '<div class="position-relative w-100">' .
+                            '<div class="note-template-output">' .
+                                '<div class="font-weight-bold text-secondary">Result:</div>' .
+                                '<div class="note-template-output-text"></div>' .
+                            '</div>' .
+                            '<div class="note-template-buttons d-flex align-items-center">' .
+                                '<button class="btn btn-sm btn-default bg-white border text-primary border-primary note-template-apply-trigger">Apply</button>' .
+                                '<button class="btn btn-sm btn-default bg-light border text-secondary border-secondary note-template-close-trigger">Close</button>' .
+                            '</div>' .
+                        '</div>';
+                    foreach ($templates as $template) {
+                        _renderNoteTemplate($template, true);
+                    }
+                    echo '</div>';
+                }
+                ?>
                 <div class="mb-3">
                     <div>
                         <?php
@@ -465,7 +513,12 @@
                     .off('click.note-templates-trigger')
                     .on('click.note-templates-trigger', function() {
                         $('.note-templates-underlay').show();
-                        $(this).closest('.note-section').find('.note-template-container').show();
+                        let container = $(this).closest('.note-section').find('.note-template-container');
+                        container.find('.note-template-children').hide();
+                        container.find('.note-template-item.selected').removeClass('selected');
+                        container.find('input[type="checkbox"]').prop('checked', false);
+                        container.find('.note-template-output-text').empty();
+                        container.show();
                         return false;
                     });