default.php
3 days ago
default_appointments.php
3 days ago
default_billing.php
3 days ago
default_draft.php
3 days ago
default_notes.php
3 days ago
default_packages.php
3 days ago
index.html
3 days ago
default_draft.php
165 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | JHtml::fetch('formbehavior.chosen'); |
| 15 | |
| 16 | $vik = VAPApplication::getInstance(); |
| 17 | |
| 18 | ?> |
| 19 | |
| 20 | <div class="user-note-box note-draft"> |
| 21 | <div class="textarea-box"> |
| 22 | <textarea placeholder="<?php echo $this->escape(JText::translate('VAPNOTESDRAFTPLACEHOLDER')); ?>" id="area-draft"></textarea> |
| 23 | </div> |
| 24 | |
| 25 | <div class="tip-box"> |
| 26 | <?php |
| 27 | echo $vik->createPopover(array( |
| 28 | // show popover on the left side, otherwise the popover would exceed the screen bounds |
| 29 | 'placement' => 'left', |
| 30 | 'title' => JText::translate('VAPNOTESDRAFTTITLE'), |
| 31 | 'content' => JText::translate('VAPNOTESDRAFTHELP'), |
| 32 | )); |
| 33 | ?> |
| 34 | </div> |
| 35 | |
| 36 | <div class="tags-box"> |
| 37 | <?php |
| 38 | foreach (JHtml::fetch('vaphtml.admin.tags', 'usernotes') as $tag) |
| 39 | { |
| 40 | ?> |
| 41 | <a href="javascript:void(0)" class="toggle-note-tag"> |
| 42 | <?php echo JHtml::fetch('vikappointments.tag', $tag, 'icon', array('data-tag' => $tag->name)); ?> |
| 43 | </a> |
| 44 | <?php |
| 45 | } |
| 46 | ?> |
| 47 | </div> |
| 48 | |
| 49 | <div class="status-box"> |
| 50 | <?php |
| 51 | $options = array( |
| 52 | JHtml::fetch('select.option', 0, 'VAPPRIVATE'), |
| 53 | JHtml::fetch('select.option', 1, 'VAPPUBLIC'), |
| 54 | ); |
| 55 | ?> |
| 56 | <select id="note-status-select"> |
| 57 | <?php echo JHtml::fetch('select.options', $options, 'value', 'text', 0, true); ?> |
| 58 | </select> |
| 59 | </div> |
| 60 | </div> |
| 61 | |
| 62 | <?php |
| 63 | JText::script('JLIB_APPLICATION_SAVE_SUCCESS'); |
| 64 | JText::script('VAP_AJAX_GENERIC_ERROR'); |
| 65 | ?> |
| 66 | |
| 67 | <script> |
| 68 | |
| 69 | (function($) { |
| 70 | 'use strict'; |
| 71 | |
| 72 | const draft = { |
| 73 | id: 0, |
| 74 | cache: null, |
| 75 | tags: [], |
| 76 | }; |
| 77 | |
| 78 | const textarea = $('#area-draft'); |
| 79 | |
| 80 | // commit changes |
| 81 | const saveDrafts = () => { |
| 82 | var content = textarea.val(); |
| 83 | var state = $('#note-status-select').val(); |
| 84 | |
| 85 | if (!content.length || content == draft.cache) { |
| 86 | // nothing to save |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | UIAjax.do( |
| 91 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=usernote.savedraftajax'); ?>', |
| 92 | { |
| 93 | id: draft.id, |
| 94 | id_user: <?php echo $this->customer->id; ?>, |
| 95 | status: state, |
| 96 | draft: content, |
| 97 | tags: draft.tags, |
| 98 | }, |
| 99 | (resp) => { |
| 100 | // keep current ID to update future changes |
| 101 | draft.id = resp.id; |
| 102 | // update current text |
| 103 | draft.cache = content; |
| 104 | |
| 105 | ToastMessage.enqueue({ |
| 106 | status: 1, |
| 107 | text: Joomla.JText._('JLIB_APPLICATION_SAVE_SUCCESS'), |
| 108 | delay: 1000, |
| 109 | }); |
| 110 | }, |
| 111 | (error) => { |
| 112 | // display error message |
| 113 | ToastMessage.enqueue({ |
| 114 | status: 0, |
| 115 | text: error.responseText || Joomla.JText._('VAP_AJAX_GENERIC_ERROR'), |
| 116 | }); |
| 117 | } |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | $(function() { |
| 122 | VikRenderer.chosen('.note-draft'); |
| 123 | |
| 124 | // auto-save after 3 seconds |
| 125 | textarea.on('keyup', VikTimer.debounce('draftautosave', saveDrafts, 3000)); |
| 126 | |
| 127 | $('#note-status-select').on('change', function() { |
| 128 | if (!VikTimer.isRunning('draftautosave') && draft.id) { |
| 129 | // unset draft cache to force update |
| 130 | draft.cache = ''; |
| 131 | // update notes |
| 132 | saveDrafts(); |
| 133 | } |
| 134 | }); |
| 135 | |
| 136 | $('.toggle-note-tag').on('click', function() { |
| 137 | const icon = $(this).find('[data-tag]'); |
| 138 | let tag = $(icon).data('tag'); |
| 139 | |
| 140 | var index = draft.tags.indexOf(tag); |
| 141 | |
| 142 | if (index === -1) { |
| 143 | // include tag |
| 144 | draft.tags.push(tag); |
| 145 | |
| 146 | $(this).css('opacity', 1); |
| 147 | } else { |
| 148 | // remove tag |
| 149 | draft.tags.splice(index, 1); |
| 150 | |
| 151 | $(this).css('opacity', 0.4); |
| 152 | } |
| 153 | |
| 154 | if (!VikTimer.isRunning('draftautosave') && draft.id) { |
| 155 | // unset draft cache to force update |
| 156 | draft.cache = ''; |
| 157 | // update notes |
| 158 | saveDrafts(); |
| 159 | } |
| 160 | }); |
| 161 | }); |
| 162 | })(jQuery); |
| 163 | |
| 164 | </script> |
| 165 |