Browse Source

Click to copy - auto-paste - edit review/plan

Vijayakrishnan 3 years ago
parent
commit
c7402c4d07

+ 1 - 1
config/app.php

@@ -65,7 +65,7 @@ return [
 
     'hrm2_url' => env('HRM2_URL'),
 
-    'asset_version' => 79,
+    'asset_version' => 80,
 
     'temp_dir' => env('TEMP_DIR'),
 

+ 21 - 4
js-dev/click-to-copy.js

@@ -1,5 +1,5 @@
 (function() {
-    function fallbackCopyTextToClipboard(text) {
+    function fallbackCopyTextToClipboard(text, pasteTo = false) {
         var textArea = document.createElement("textarea");
         textArea.value = text;
 
@@ -17,13 +17,14 @@
             var msg = successful ? 'successful' : 'unsuccessful';
             console.log('Fallback: Copying text command was ' + msg);
             toastr.success('Copied!');
+            pasteToElement(pasteTo, text);
         } catch (err) {
             console.error('Fallback: Oops, unable to copy', err);
         }
 
         document.body.removeChild(textArea);
     }
-    function copyTextToClipboard(text) {
+    function copyTextToClipboard(text, pasteTo = false) {
         if (!navigator.clipboard) {
             fallbackCopyTextToClipboard(text);
             return;
@@ -31,17 +32,33 @@
         navigator.clipboard.writeText(text).then(function() {
             console.log('Async: Copying to clipboard was successful!');
             toastr.success('Copied!');
+            pasteToElement(pasteTo, text);
         }, function(err) {
             console.error('Async: Could not copy text: ', err);
         });
     }
+    function pasteToElement(_elem, _text) {
+        if(_elem && _elem.length) {
+            // if rte
+            if(_elem.is('.ql-container') && _elem[0].__quill) {
+                let qlRoot = _elem[0].__quill.root;
+                if($.trim($(qlRoot.innerHTML).text()) === '') {
+                    _elem[0].__quill.clipboard.dangerouslyPasteHTML(0, _text);
+                    _elem[0].__quill.root.focus();
+                }
+            }
+            else _elem.val(_text);
+        }
+    }
 
     function init() {
         $(document)
             .off('click.click-to-copy', '.click-to-copy')
             .on('click.click-to-copy', '.click-to-copy', function(event) {
-            copyTextToClipboard($(this).text());
-        });
+                let self = $(this);
+                copyTextToClipboard(self.text(),
+                    self.is('[auto-paste]') ? self.closest('form').find(self.attr('auto-paste')) : false);
+            });
         window.copyTextToClipboard = copyTextToClipboard;
     }
 

+ 1 - 1
resources/views/app/patient/segment-templates/_child_plan/edit-plan-optimized-flat.php

@@ -42,7 +42,7 @@ else {
             <div class="d-flex align-items-baseline mb-1">
                 <span class="text-sm text-secondary">Previous Plan / <?= friendlier_date($previousChildPlan->created_at) ?> (click to copy)</span>
             </div>
-            <div class="p-1 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+            <div class="p-1 bg-light border inline-html-container click-to-copy" auto-paste="[data-field-name=value]"><?= $previousValue ?></div>
         </div>
         <?php endif; ?>
 

+ 1 - 1
resources/views/app/patient/segment-templates/_child_plan/edit-plan-optimized.php

@@ -42,7 +42,7 @@ else {
             <div class="d-flex align-items-baseline mb-1">
                 <span class="text-sm text-secondary">Previous Plan / <?= friendlier_date($previousChildPlan->created_at) ?> (click to copy)</span>
             </div>
-            <div class="p-1 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+            <div class="p-1 bg-light border inline-html-container click-to-copy" auto-paste="[data-field-name=value]"><?= $previousValue ?></div>
         </div>
         <?php endif; ?>
 

+ 1 - 1
resources/views/app/patient/segment-templates/_child_review/edit-review-optimized-flat.php

@@ -46,7 +46,7 @@ else {
                 <div class="d-flex align-items-baseline mb-1">
                     <span class="text-sm text-secondary">Previous Subjective / <?= friendlier_date($previousChildReview->created_at) ?> (click to copy)</span>
                 </div>
-                <div class="p-1 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+                <div class="p-1 bg-light border inline-html-container click-to-copy" auto-paste="[data-field-name=value]"><?= $previousValue ?></div>
             </div>
         <?php endif; ?>
 

+ 1 - 1
resources/views/app/patient/segment-templates/_child_review/edit-review-optimized.php

@@ -46,7 +46,7 @@ else {
                 <div class="d-flex align-items-baseline mb-1">
                     <span class="text-sm text-secondary">Previous Subjective / <?= friendlier_date($previousChildReview->created_at) ?> (click to copy)</span>
                 </div>
-                <div class="p-1 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+                <div class="p-1 bg-light border inline-html-container click-to-copy" auto-paste="[data-field-name=value]"><?= $previousValue ?></div>
             </div>
         <?php endif; ?>
 

+ 2 - 2
resources/views/app/patient/wizard-partials/common-script.blade.php

@@ -978,8 +978,8 @@ parentSegment
     });
 
 parentSegment
-    .off('click.switch-to-edit', '.point-table [if-read-mode] .inline-html-container')
-    .on('click.switch-to-edit', '.point-table [if-read-mode] .inline-html-container', function() {
+    .off('click.switch-to-edit', '.point-table [if-read-mode] .inline-html-container:not(.click-to-copy)')
+    .on('click.switch-to-edit', '.point-table [if-read-mode] .inline-html-container:not(.click-to-copy)', function() {
         let trigger = $(this).closest('[if-read-mode]')
             .find('form[url="/api/visitPoint/upsertChildReview"], form[url="/api/visitPoint/upsertChildPlan"]')
             .first().closest('[moe], [visit-moe]')