config.php
138 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('vaphtml.assets.select2'); |
| 15 | |
| 16 | /** |
| 17 | * Layout variables |
| 18 | * ----------------- |
| 19 | * @var array $dashboard An array |
| 20 | */ |
| 21 | extract($displayData); |
| 22 | |
| 23 | $vik = VAPApplication::getInstance(); |
| 24 | |
| 25 | $layout = new JLayoutFile('form.fields'); |
| 26 | |
| 27 | ?> |
| 28 | |
| 29 | <div class="inspector-form" id="inspector-config-form"> |
| 30 | |
| 31 | <?php |
| 32 | // iterate all positions |
| 33 | foreach ($dashboard as $widgets) |
| 34 | { |
| 35 | // iterate position widgets |
| 36 | foreach ($widgets as $widget) |
| 37 | { |
| 38 | ?> |
| 39 | <div |
| 40 | class="inspector-fieldset" |
| 41 | data-id="<?php echo $widget->getID(); ?>" |
| 42 | data-widget="<?php echo $widget->getName(); ?>" |
| 43 | style="display: none;"> |
| 44 | |
| 45 | <h3><?php echo $widget->getTitle(); ?></h3> |
| 46 | |
| 47 | <?php |
| 48 | // get widget description |
| 49 | $desc = $widget->getDescription(); |
| 50 | |
| 51 | if ($desc) |
| 52 | { |
| 53 | // display description before configuration form |
| 54 | echo $vik->alert($desc, 'info'); |
| 55 | } |
| 56 | |
| 57 | // prepare layout data |
| 58 | $data = array( |
| 59 | 'fields' => $widget->getForm(), |
| 60 | 'params' => $widget->getParams(), |
| 61 | 'prefix' => $widget->getName() . '_' . $widget->getID() . '_', |
| 62 | ); |
| 63 | |
| 64 | // display widget configuration |
| 65 | echo $layout->render($data); |
| 66 | ?> |
| 67 | |
| 68 | </div> |
| 69 | <?php |
| 70 | } |
| 71 | } |
| 72 | ?> |
| 73 | |
| 74 | </div> |
| 75 | |
| 76 | <script> |
| 77 | |
| 78 | (function($) { |
| 79 | 'use strict'; |
| 80 | |
| 81 | $(function() { |
| 82 | VikRenderer.chosen('.inspector-form', '100%'); |
| 83 | }); |
| 84 | })(jQuery); |
| 85 | |
| 86 | function setupWidgetConfig(id) { |
| 87 | jQuery('.inspector-fieldset').hide(); |
| 88 | jQuery('.inspector-fieldset[data-id="' + id + '"]').show(); |
| 89 | } |
| 90 | |
| 91 | function updateWidgetConfig(id, key, value) { |
| 92 | // extract widget name |
| 93 | var widget = jQuery('.inspector-fieldset[data-id="' + id + '"]').data('widget'); |
| 94 | // find target input |
| 95 | const input = jQuery('*[name="' + widget + '_' + id + '_' + key + '"]'); |
| 96 | |
| 97 | if (input.length == 0) { |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | if (input.is(':checkbox')) { |
| 102 | input.prop('checked', value ? true : false); |
| 103 | } else { |
| 104 | input.val(value); |
| 105 | |
| 106 | // check whether the input owns an alternative value to update (such as the calendar) |
| 107 | if (input.attr('data-alt-value') !== undefined) { |
| 108 | // update it too |
| 109 | input.attr('data-alt-value', value); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | function getWidgetConfig(id) { |
| 117 | var config = {}; |
| 118 | |
| 119 | var widget = jQuery('.inspector-fieldset[data-id="' + id + '"]').data('widget'); |
| 120 | |
| 121 | jQuery('.inspector-fieldset[data-id="' + id + '"]') |
| 122 | .find('input,select') |
| 123 | .filter('[name^="' + widget + '_"]') |
| 124 | .each(function() { |
| 125 | var name = jQuery(this).attr('name').replace(new RegExp('^' + widget + '_' + id + '_'), ''); |
| 126 | |
| 127 | if (jQuery(this).is(':checkbox')) { |
| 128 | config[name] = jQuery(this).is(':checked') ? 1 : 0; |
| 129 | } else { |
| 130 | config[name] = jQuery(this).val(); |
| 131 | } |
| 132 | }); |
| 133 | |
| 134 | return config; |
| 135 | } |
| 136 | |
| 137 | </script> |
| 138 |