api.quicksearch.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Renders the search form and frontend controller for live cameras list
  4. *
  5. * @return string
  6. */
  7. function wr_QuickSearchRenderForm() {
  8. global $ubillingConfig;
  9. $modList = array('livecams', 'archive', 'export');
  10. $denyList = array('livechannel', 'viewchannel', 'exportchannel');
  11. $result = '';
  12. if ($ubillingConfig->getAlterParam('QUICKSEARCH_ENABLED')) {
  13. if (ubRouting::checkGet('module')) {
  14. $modList = array_flip($modList);
  15. $curModule = ubRouting::get('module', 'gigasafe');
  16. $skipRenderFlag = (ubRouting::checkGet($denyList, true, true)) ? true : false;
  17. if (isset($modList[$curModule]) and !$skipRenderFlag) {
  18. $result .= wf_tag('div', false, 'searchform');
  19. $result .= wf_TextInput('camsearch', ' ' . '', '', false, 15, '', '', 'camsearch', 'placeholder="' . __('Quick search') . '...' . '"');
  20. $result .= wf_tag('button', false, 'clear-btn', 'type="button" aria-label="Clear search"') . '&times;' . wf_tag('button', true);
  21. $result .= wf_tag('div', true);
  22. $result .= wf_tag('script');
  23. $result .= "
  24. document.getElementById('camsearch').addEventListener('input', function () {
  25. const searchValue = this.value.toLowerCase();
  26. const cameras = document.querySelectorAll('[id^=\"wrcamcont_\"]');
  27. const statusContainer = document.getElementById('wrqsstatus');
  28. let visibleCount = 0;
  29. cameras.forEach(camera => {
  30. const idText = camera.id.toLowerCase();
  31. if (searchValue === '' || idText.includes(searchValue)) {
  32. camera.classList.remove('hiddencam');
  33. camera.style.display = 'block';
  34. requestAnimationFrame(() => camera.style.opacity = '1');
  35. visibleCount++;
  36. } else {
  37. camera.classList.add('hiddencam');
  38. setTimeout(() => {
  39. if (camera.classList.contains('hiddencam')) {
  40. camera.style.display = 'none';
  41. }
  42. }, 300);
  43. }
  44. });
  45. //no cameras found
  46. if (visibleCount === 0) {
  47. statusContainer.textContent = '" . __('Nothing found') . "';
  48. } else {
  49. statusContainer.textContent = '';
  50. }
  51. });
  52. document.addEventListener('DOMContentLoaded', () => {
  53. const searchInput = document.getElementById('camsearch');
  54. const clearButton = document.querySelector('.clear-btn');
  55. searchInput.addEventListener('input', () => {
  56. if (searchInput.value.trim() !== '') {
  57. clearButton.style.display = 'flex';
  58. } else {
  59. clearButton.style.display = 'none';
  60. }
  61. });
  62. clearButton.addEventListener('click', () => {
  63. searchInput.value = '';
  64. clearButton.style.display = 'none';
  65. searchInput.dispatchEvent(new Event('input'));
  66. searchInput.focus();
  67. });
  68. });
  69. ";
  70. $result .= wf_tag('script', true);
  71. }
  72. }
  73. }
  74. return ($result);
  75. }