| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2025 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 |
* Obtain vars from arguments received in the layout file. |
| 16 |
* |
| 17 |
* @var string $caller The identifier of who's calling this layout file. |
| 18 |
* @var array $events List of JS events to trigger. |
| 19 |
* @var array $filters The current View filters. |
| 20 |
*/ |
| 21 |
extract($displayData); |
| 22 |
|
| 23 |
// load context menu assets |
| 24 |
VikBooking::getVboApplication()->loadContextMenuAssets(); |
| 25 |
|
| 26 |
// define the default events |
| 27 |
if (!isset($events) || !is_array($events)) { |
| 28 |
$events = []; |
| 29 |
} |
| 30 |
$events['filter_status'] = $events['filter_status'] ?? 'vbo-tm-apply-filters'; |
| 31 |
|
| 32 |
// get current filters |
| 33 |
$filters = (array) ($filters ?? []); |
| 34 |
|
| 35 |
// access the task manager |
| 36 |
$taskManager = VBOFactory::getTaskManager(); |
| 37 |
|
| 38 |
// make TASK_MANAGER_STATUSES var global |
| 39 |
JHtml::fetch('vbohtml.tmscripts.statuses'); |
| 40 |
|
| 41 |
// find the active status, if any |
| 42 |
$activeStatus = []; |
| 43 |
|
| 44 |
foreach ($taskManager->getStatusGroupElements() as $groupId => $group) { |
| 45 |
// iterate over the statuses of this group |
| 46 |
foreach ($group['elements'] as $statusType) { |
| 47 |
// check if it's the active one |
| 48 |
if ($statusType['id'] == ($filters['statusId'] ?? null)) { |
| 49 |
// active status found |
| 50 |
$activeStatus = $statusType; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
?> |
| 56 |
|
| 57 |
<button type="button" class="btn vbo-context-menu-btn vbo-context-menu-tm-statuses<?php echo $activeStatus ? ' vbo-tm-filter-active' : ''; ?>"> |
| 58 |
<?php |
| 59 |
if ($activeStatus) { |
| 60 |
// active filter |
| 61 |
?> |
| 62 |
<span class="vbo-context-menu-lbl"><?php echo $activeStatus['text']; ?></span> |
| 63 |
<span class="vbo-context-menu-lbl-orig" style="display: none;"><?php echo JText::translate('VBSTATUS'); ?></span> |
| 64 |
<?php |
| 65 |
} else { |
| 66 |
// filter not set |
| 67 |
?> |
| 68 |
<span class="vbo-context-menu-lbl"><?php echo JText::translate('VBSTATUS'); ?></span> |
| 69 |
<?php |
| 70 |
} |
| 71 |
?> |
| 72 |
<span class="vbo-context-menu-ico"><?php VikBookingIcons::e('sort-down'); ?></span> |
| 73 |
</button> |
| 74 |
|
| 75 |
<script type="text/javascript"> |
| 76 |
jQuery(function() { |
| 77 |
|
| 78 |
// build buttons |
| 79 |
let btns = []; |
| 80 |
|
| 81 |
// push unset status filter button |
| 82 |
btns.push({ |
| 83 |
statusId: null, |
| 84 |
class: 'vbo-context-menu-entry-secondary', |
| 85 |
searchable: false, |
| 86 |
separator: false, |
| 87 |
text: <?php echo json_encode(JText::translate('VBANYTHING')); ?>, |
| 88 |
icon: '<?php echo VikBookingIcons::i('times'); ?>', |
| 89 |
visible: () => { |
| 90 |
return vboTmFilters && vboTmFilters?.statusId; |
| 91 |
}, |
| 92 |
action: function(root, config) { |
| 93 |
// remove status filter |
| 94 |
VBOCore.emitEvent('<?php echo $events['filter_status']; ?>', { |
| 95 |
filters: { |
| 96 |
statusId: null, |
| 97 |
}, |
| 98 |
}); |
| 99 |
|
| 100 |
if (jQuery(root).find('.vbo-context-menu-lbl-orig').length) { |
| 101 |
// restore default label |
| 102 |
jQuery(root) |
| 103 |
.find('.vbo-context-menu-lbl') |
| 104 |
.remove(); |
| 105 |
|
| 106 |
jQuery(root) |
| 107 |
.find('.vbo-context-menu-lbl-orig') |
| 108 |
.attr('class', '') |
| 109 |
.addClass('vbo-context-menu-lbl') |
| 110 |
.show(); |
| 111 |
} |
| 112 |
|
| 113 |
jQuery(root).removeClass('vbo-tm-filter-active'); |
| 114 |
}, |
| 115 |
}); |
| 116 |
|
| 117 |
window.TASK_MANAGER_STATUSES.forEach((elem, index) => { |
| 118 |
// build button icon element |
| 119 |
let btnIconEl = jQuery('<span></span>') |
| 120 |
.addClass('vbo-colortag-circle') |
| 121 |
.addClass('vbo-tm-colortag-circle') |
| 122 |
.addClass('vbo-tm-statustype-circle'); |
| 123 |
|
| 124 |
if (elem?.color) { |
| 125 |
btnIconEl.addClass(elem.color); |
| 126 |
} |
| 127 |
|
| 128 |
// push status button |
| 129 |
btns.push({ |
| 130 |
statusId: elem.id, |
| 131 |
class: elem.id ? 'vbo-context-menu-entry-secondary' : 'btngroup', |
| 132 |
searchable: elem.id ? true : false, |
| 133 |
text: elem.text, |
| 134 |
icon: elem.id ? btnIconEl : null, |
| 135 |
disabled: () => { |
| 136 |
return !elem.id || (vboTmFilters && vboTmFilters?.statusId == elem.id); |
| 137 |
}, |
| 138 |
action: function(root, config) { |
| 139 |
if (this.statusId) { |
| 140 |
// apply status filter |
| 141 |
VBOCore.emitEvent('<?php echo $events['filter_status']; ?>', { |
| 142 |
filters: { |
| 143 |
statusId: this.statusId, |
| 144 |
}, |
| 145 |
}); |
| 146 |
|
| 147 |
let color = elem?.color || ''; |
| 148 |
let name = elem.text || this.text; |
| 149 |
|
| 150 |
if (jQuery(root).find('.vbo-context-menu-lbl-orig').length) { |
| 151 |
// filter changed |
| 152 |
jQuery(root) |
| 153 |
.find('.vbo-context-menu-lbl') |
| 154 |
.attr('class', '') |
| 155 |
.addClass('vbo-context-menu-lbl') |
| 156 |
.text(name); |
| 157 |
} else { |
| 158 |
// filter set for the first time |
| 159 |
jQuery(root) |
| 160 |
.find('.vbo-context-menu-lbl') |
| 161 |
.attr('class', '') |
| 162 |
.addClass('vbo-context-menu-lbl-orig') |
| 163 |
.hide(); |
| 164 |
|
| 165 |
jQuery(root) |
| 166 |
.find('.vbo-context-menu-lbl-orig') |
| 167 |
.parent() |
| 168 |
.prepend( |
| 169 |
jQuery('<span></span>') |
| 170 |
.addClass('vbo-context-menu-lbl') |
| 171 |
.text(name) |
| 172 |
); |
| 173 |
} |
| 174 |
|
| 175 |
jQuery(root).addClass('vbo-tm-filter-active'); |
| 176 |
} |
| 177 |
}, |
| 178 |
}); |
| 179 |
}); |
| 180 |
|
| 181 |
// start context menu on the proper button element |
| 182 |
jQuery('.vbo-context-menu-tm-statuses').vboContextMenu({ |
| 183 |
placement: 'bottom-left', |
| 184 |
buttons: btns, |
| 185 |
search: true, |
| 186 |
}); |
| 187 |
|
| 188 |
}); |
| 189 |
</script> |
| 190 |
|