Fixes for restoreSession logic. (#4378)
[openemr.git] / library / js / CustomTemplateApi.js
blob72ef0cd4bd3dec7b76416cdfd8f1d8e4ff924334
1 /**
2  * custom templates dynamic api
3  *
4  * @package   OpenEMR
5  * @link      http://www.open-emr.org
6  * @author    Jerry Padgett <sjpadgett@gmail.com>
7  * @copyright Copyright (c) 2019-2021 Jerry Padgett <sjpadgett@gmail.com>
8  * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
9  */
11 function doTemplateEditor(_this, event, oContext = '') {
12     // has to be one of two.
13     let id = event.target.id;
14     let ccFlag = 'id';
15     if (!id) {
16         id = event.target.name;
17         ccFlag = 'name';
18     }
19     let title = '<i class="fa fa-th"></i><h4 class="ml-2">'+ xl("Text Templates") +'</h4>';
20     let url = top.webroot_url + "/library/custom_template/custom_template.php?type=" + encodeURIComponent(id) + "&ccFlag=" + encodeURIComponent(ccFlag) + "&contextName=" + encodeURIComponent(oContext);
21     dlgopen(url, '', 'modal-lg', 800, '', '', {
22         buttons: [
23             {text: xl('Do Nothing'), close: true, style: 'secondary'}
24         ],
25         type: 'iframe'
26     });
27     return false;
30 const bindTextArea = function () {
31     const teventElement = document.querySelectorAll("textarea, input[type='text']");
32     if (typeof teventElement === 'undefined' || teventElement === null) {
33         return false;
34     }
35     teventElement.forEach(item => {
36         item.addEventListener('dblclick', event => {
37             if (event.target.nodeName === "TEXTAREA") {
38                 doTemplateEditor(this, event, event.target.dataset.textcontext);
39             } else if (event.target.nodeName === "INPUT" && event.target.type === "text") {
40                 doTemplateEditor(this, event, 'Sentence');
41             } else {
42                 return false;
43             }
44         })
45     });
47     console.log("Bound text events: ['" + location + "']");