PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / layouts / inspector / sidebar.php
vikappointments / admin / layouts / inspector Last commit date
index.html 2 days ago sidebar.php 2 days ago
sidebar.php
184 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 /**
15 * Layout variables
16 * -----------------
17 * @param string id The ID of the inspector sidebar.
18 * @param string title An optional inspector title.
19 * @param boolean closeButton True to display the close button (false by default).
20 * @param boolean keyboard True to dismiss the inspector by pressing ESC (false by default).
21 * @param string placement Where the inspector should be placed (left or right).
22 * Left by default, if not specified.
23 * @param mixed url An optional URL to render the body within a <iframe>.
24 * @param mixed body An optional HTML string to be placed within the body. In case the URL
25 * is specified, the body string will be ignored.
26 * @param mixed footer An optional footer to be placed at bottom.
27 */
28 extract($displayData);
29
30 JText::script('VAP_CONFIRM_MESSAGE_UNSAVE');
31 JText::script('VAPSYSTEMCONFIRMATIONMSG');
32
33 ?>
34
35 <div class="record-inspector-overlay">
36
37 <div
38 class="record-inspector <?php echo $placement == 'left' ? 'left' : 'right'; ?>-side<?php echo $class ? ' ' . $class : ''; ?>"
39 id="<?php echo $id; ?>"
40 style="<?php echo $width ? 'min-width:' . $width . ';max-width: ' . $width . ';' : ''; ?>"
41 data-esc="<?php echo $keyboard ? 1 : 0; ?>"
42 >
43
44 <div class="inspector-head<?php echo ($title || $closeButton ? '' : ' empty'); ?>">
45 <?php
46 if ($title)
47 {
48 ?>
49 <h3><?php echo $title; ?></h3>
50 <?php
51 }
52
53 if ($closeButton)
54 {
55 ?>
56 <a class="dismiss"><i class="fas fa-times"></i></a>
57 <?php
58 }
59 ?>
60 </div>
61
62 <div class="inspector-body">
63 <?php
64 if ($url)
65 {
66 ?>
67 <iframe src="<?php echo $url; ?>"></iframe>
68 <?php
69 }
70 else
71 {
72 echo $body;
73 }
74 ?>
75 </div>
76
77 <?php
78 if ($footer)
79 {
80 ?>
81 <div class="inspector-footer"><?php echo $footer; ?></div>
82 <?php
83 }
84 ?>
85
86 </div>
87
88 </div>
89
90 <script>
91
92 jQuery(function($) {
93 const inspector = $('#<?php echo addslashes($id); ?>');
94
95 let formObserver = null;
96
97 // observe the form changes in case of button with "save" role
98 if (inspector.find('.inspector-footer button[data-role="save"]').length) {
99 formObserver = new VikFormObserver(inspector.find('.inspector-body'));
100
101 // register current form state when the inspector fade in
102 inspector.on('inspector.aftershow', function() {
103 // freeze form at the current state
104 formObserver.freeze();
105 });
106
107 // check for any changes when the inspector is closed
108 inspector.on('inspector.close', function(event) {
109 if (formObserver.isChanged()) {
110 // something has changed, warn the user about the
111 // possibility of losing any changes
112 let discard = confirm(Joomla.JText._('VAP_CONFIRM_MESSAGE_UNSAVE'));
113
114 if (!discard) {
115 // the user denied the closure of the inspector, stop the
116 // event propagation in order to prevent the action
117 event.preventDefault();
118 event.stopPropagation();
119 return false;
120 }
121 }
122 });
123 }
124
125 // Trigger an event when a button in the footer is clicked.
126 // The button must specify a data-role attribute in order to
127 // be invoked. The triggered event will be built as:
128 // inspector.[ROLE]
129 inspector.find('.inspector-footer button[data-role]').on('click', function() {
130 let role = $(this).data('role');
131
132 // check for SAVE role
133 if (role == 'save' && formObserver) {
134 // force observer to always return false when checking for
135 // new changes, as they have been properly saved
136 formObserver.unchanged();
137 }
138 // check for DELETE role
139 else if (role == 'delete') {
140 // ask a confirmation before to trigger the DELETE role
141 let discard = confirm(Joomla.JText._('VAPSYSTEMCONFIRMATIONMSG'));
142
143 if (!discard) {
144 // the user denied the action, abort all
145 event.preventDefault();
146 event.stopPropagation();
147 return false;
148 }
149
150 // force observer to always return false when checking for
151 // new changes, as we are going to delete the whole record
152 formObserver.unchanged();
153 }
154
155 // trigger role event
156 $(this).trigger('inspector.' + role);
157 });
158
159 // Registers an event to allow the callers to manually commit the
160 // changes of the inspector, since the initialization may be done
161 // asynchronously.
162 inspector.on('inspector.commit', () => {
163 if (formObserver) {
164 // freeze form again
165 formObserver.freeze();
166 }
167 });
168
169 <?php
170 if ($keyboard)
171 {
172 ?>
173 $(window).on('keydown', (event) => {
174 if (event.keyCode == 27) {
175 vapCloseInspector('<?php echo $id; ?>');
176 }
177 });
178 <?php
179 }
180 ?>
181 });
182
183 </script>
184