default.php
237 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 | JHtml::fetch('vaphtml.assets.chartjs'); |
| 16 | |
| 17 | $vik = VAPApplication::getInstance(); |
| 18 | |
| 19 | ?> |
| 20 | |
| 21 | <style> |
| 22 | /** |
| 23 | * Hide summary badges from pie chart. |
| 24 | */ |
| 25 | .widget-floating-box { |
| 26 | display: none; |
| 27 | } |
| 28 | </style> |
| 29 | |
| 30 | <script> |
| 31 | |
| 32 | /** |
| 33 | * A lookup of preflights to be used before refreshing |
| 34 | * the contents of the widgets. |
| 35 | * |
| 36 | * If needed, a widget can register its own callback |
| 37 | * to be executed before the AJAX request is started. |
| 38 | * |
| 39 | * The property name MUST BE equals to the ID of |
| 40 | * the widget that is registering its callback. |
| 41 | * |
| 42 | * @var object |
| 43 | */ |
| 44 | var WIDGET_PREFLIGHTS = {}; |
| 45 | |
| 46 | /** |
| 47 | * A lookup of callbacks to be used when refreshing |
| 48 | * the contents of the widgets. |
| 49 | * |
| 50 | * If needed, a widget can register its own callback |
| 51 | * to be executed once the AJAX request is completed. |
| 52 | * |
| 53 | * The property name MUST BE equals to the ID of |
| 54 | * the widget that is registering its callback. |
| 55 | * |
| 56 | * @var object |
| 57 | */ |
| 58 | var WIDGET_CALLBACKS = {}; |
| 59 | |
| 60 | </script> |
| 61 | |
| 62 | <form action="index.php" method="POST" name="adminForm" id="adminForm"> |
| 63 | |
| 64 | <?php echo $vik->openCard(); ?> |
| 65 | |
| 66 | <div class="btn-toolbar" style="height: 32px;"> |
| 67 | |
| 68 | <div class="btn-group pull-left"> |
| 69 | <?php echo $vik->calendar($this->filters['datefrom'], 'datefrom', 'vapstartdate'); ?> |
| 70 | </div> |
| 71 | |
| 72 | <div class="btn-group pull-left"> |
| 73 | <?php echo $vik->calendar($this->filters['dateto'], 'dateto', 'vapenddate'); ?> |
| 74 | </div> |
| 75 | |
| 76 | <?php |
| 77 | $options = array( |
| 78 | JHtml::fetch('select.option', 'total', JText::translate('VAPREPORTSVALUETYPEOPT1')), |
| 79 | JHtml::fetch('select.option', 'count', JText::translate('VAPREPORTSVALUETYPEOPT2')), |
| 80 | ); |
| 81 | ?> |
| 82 | |
| 83 | <div class="btn-group pull-left"> |
| 84 | <select name="valuetype" id="vap-valuetype-sel"> |
| 85 | <?php echo JHtml::fetch('select.options', $options, 'value', 'text', $this->filters['valuetype'])?> |
| 86 | </select> |
| 87 | </div> |
| 88 | |
| 89 | <?php |
| 90 | $options = array( |
| 91 | JHtml::fetch('select.option', 1, JText::translate('VAPDOWNLOADREPORTOPT1')), |
| 92 | JHtml::fetch('select.option', 0, JText::translate('VAPDOWNLOADREPORTOPT2')), |
| 93 | ); |
| 94 | ?> |
| 95 | |
| 96 | <div class="btn-group pull-left"> |
| 97 | <select name="checkin" id="vap-checkin-sel"> |
| 98 | <?php echo JHtml::fetch('select.options', $options, 'value', 'text', $this->filters['checkin'])?> |
| 99 | </select> |
| 100 | </div> |
| 101 | |
| 102 | <div class="btn-group pull-left"> |
| 103 | <button type="button" class="btn" id="submit-search"> |
| 104 | <?php echo JText::translate('VAPRESERVATIONBUTTONFILTER'); ?> |
| 105 | </button> |
| 106 | </div> |
| 107 | |
| 108 | </div> |
| 109 | |
| 110 | <div class="vap-charts-pool"> |
| 111 | |
| 112 | <?php |
| 113 | foreach ($this->employees as $employee) |
| 114 | { |
| 115 | echo $vik->openFieldset($employee->nickname); ?> |
| 116 | |
| 117 | <div class="vap-empchart-box"> |
| 118 | |
| 119 | <div class="vap-linechart-container"> |
| 120 | <div class="vap-linechart-wrapper" id="widget-<?php echo $employee->lineChart->getID(); ?>" data-widget="<?php echo $this->escape($employee->lineChart->getName()); ?>"> |
| 121 | <?php echo $employee->lineChart->display(array('legend' => true)); ?> |
| 122 | </div> |
| 123 | </div> |
| 124 | |
| 125 | <div class="vap-piechart-container"> |
| 126 | <div class="vap-piechart-wrapper" id="widget-<?php echo $employee->pieChart->getID(); ?>" data-widget="<?php echo $this->escape($employee->pieChart->getName()); ?>"> |
| 127 | <?php echo $employee->pieChart->display(); ?> |
| 128 | </div> |
| 129 | </div> |
| 130 | |
| 131 | <input type="hidden" name="cid[]" value="<?php echo $employee->id; ?>" /> |
| 132 | |
| 133 | </div> |
| 134 | |
| 135 | <?php |
| 136 | echo $vik->closeFieldset(); |
| 137 | } |
| 138 | ?> |
| 139 | |
| 140 | </div> |
| 141 | |
| 142 | <?php echo $vik->closeCard(); ?> |
| 143 | |
| 144 | <input type="hidden" name="option" value="com_vikappointments" /> |
| 145 | <input type="hidden" name="view" value="reportsemp" /> |
| 146 | <input type="hidden" name="task" value="" /> |
| 147 | <input type="hidden" name="return" value="<?php echo $this->from; ?>" /> |
| 148 | |
| 149 | </form> |
| 150 | |
| 151 | <script> |
| 152 | |
| 153 | (function($) { |
| 154 | 'use strict'; |
| 155 | |
| 156 | /** |
| 157 | * Prepare any chart to be responsive. |
| 158 | */ |
| 159 | Chart.defaults.global.responsive = true; |
| 160 | |
| 161 | /** |
| 162 | * Updates the configuration of the last edited widget. |
| 163 | * |
| 164 | * @param integer id The widget ID. |
| 165 | * @param object config The widget configuration. |
| 166 | * |
| 167 | * @return void |
| 168 | */ |
| 169 | const updateWidgetContents = (id, config) => { |
| 170 | // keep a reference to the widget |
| 171 | var box = $('#widget-' + id); |
| 172 | |
| 173 | // get widget class |
| 174 | var widget = box.data('widget'); |
| 175 | |
| 176 | // prepare request data |
| 177 | Object.assign(config, { |
| 178 | id: id, |
| 179 | widget: widget, |
| 180 | tmp: true, |
| 181 | }); |
| 182 | |
| 183 | if (WIDGET_PREFLIGHTS.hasOwnProperty(id)) { |
| 184 | // let the widget prepares the contents without |
| 185 | // waiting for the request completion |
| 186 | WIDGET_PREFLIGHTS[id](box, config); |
| 187 | } |
| 188 | |
| 189 | // make request to load widget dataset |
| 190 | UIAjax.do( |
| 191 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=analytics.loadwidgetdata'); ?>', |
| 192 | config, |
| 193 | (resp) => { |
| 194 | // check if the widget registered its own update method |
| 195 | if (WIDGET_CALLBACKS.hasOwnProperty(id)) { |
| 196 | // let the widget callback finalizes the update |
| 197 | WIDGET_CALLBACKS[id](box, resp, config); |
| 198 | } else { |
| 199 | if (typeof resp === 'string') { |
| 200 | // replace widget body with returned string/HTML |
| 201 | $(box).html(resp); |
| 202 | } |
| 203 | } |
| 204 | }, |
| 205 | (error) => { |
| 206 | // do nothing on error |
| 207 | } |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | $('#submit-search').on('click', () => { |
| 212 | // manually clear task for a correct refresh |
| 213 | document.adminForm.task.value = ''; |
| 214 | // refresh form on button click |
| 215 | Joomla.submitbutton(''); |
| 216 | }); |
| 217 | |
| 218 | $(function() { |
| 219 | VikRenderer.chosen('.btn-toolbar'); |
| 220 | |
| 221 | <?php |
| 222 | // iterate dashboard widgets |
| 223 | foreach ($this->employees as $employee) |
| 224 | { |
| 225 | ?> |
| 226 | // load line chart |
| 227 | updateWidgetContents('<?php echo $employee->lineChart->getID(); ?>', <?php echo json_encode($employee->lineChart->getOptions()); ?>); |
| 228 | // load pie chart |
| 229 | updateWidgetContents('<?php echo $employee->pieChart->getID(); ?>', <?php echo json_encode($employee->pieChart->getOptions()); ?>); |
| 230 | <?php |
| 231 | } |
| 232 | ?> |
| 233 | }); |
| 234 | })(jQuery); |
| 235 | |
| 236 | </script> |
| 237 |