From 444dbb459960beface852be457e6257eb2efbeaf Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 6 Jul 2023 13:15:45 +0200 Subject: [PATCH] #11386 Fix modal event sound --- .../include/javascript/pandora_events.js | 330 +++++++++++++++++- .../include/styles/js/jquery-ui_custom.css | 32 +- pandora_console/include/styles/pandora.css | 2 +- pandora_console/index.php | 2 +- pandora_console/operation/events/events.php | 39 ++- .../operation/events/sound_events.php | 4 +- 6 files changed, 400 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 7916b921d6..d307cc7b9f 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -55,7 +55,7 @@ function show_event_dialog(event, dialog_page) { title: event.evento, resizable: true, draggable: true, - modal: true, + modal: false, minWidth: 875, minHeight: 600, close: function() { @@ -943,6 +943,105 @@ function process_buffers(buffers) { } } +function openSoundEventsDialog(settings) { + settings = JSON.parse(atob(settings)); + + // Check modal exists and is open. + if ( + $("#modal-sound").hasClass("ui-dialog-content") && + $("#modal-sound").dialog("isOpen") + ) { + return; + } + // Initialize modal. + $("#modal-sound") + .empty() + .dialog({ + title: settings.title, + resizable: false, + modal: false, + width: 600, + height: 600, + open: function() { + $.ajax({ + method: "post", + url: settings.url, + data: { + page: settings.page, + drawConsoleSound: 1 + }, + dataType: "html", + success: function(data) { + $("#modal-sound").append(data); + $("#tabs-sound-modal").tabs({ + disabled: [1] + }); + + // Test sound. + $("#button-melody_sound").click(function() { + var sound = false; + if ($("#id_sound_event").length == 0) { + sound = true; + } + + test_sound_button(sound, settings.urlSound); + }); + + // Play Stop. + $("#button-start-search").click(function() { + var mode = $("#hidden-mode_alert").val(); + var action = false; + if (mode == 0) { + action = true; + } + + action_events_sound(action, settings); + }); + + // Silence Alert. + $("#button-no-alerts").click(function() { + if ($("#button-no-alerts").hasClass("silence-alerts") === true) { + // Remove audio. + remove_audio(); + + // Clean events. + $("#tabs-sound-modal .elements-discovered-alerts ul").empty(); + $("#tabs-sound-modal .empty-discovered-alerts").removeClass( + "invisible_important" + ); + + // Clean progress. + $("#progressbar_time").empty(); + + // Change img button. + $("#button-no-alerts") + .removeClass("silence-alerts") + .addClass("alerts"); + // Change value button. + $("#button-no-alerts").val(settings.noAlert); + $("#button-no-alerts > span").text(settings.noAlert); + + // Background button. + $(".container-button-alert").removeClass("fired"); + + // New progress. + listen_event_sound(settings); + } + }); + }, + error: function(error) { + console.error(error); + } + }); + }, + close: function() { + remove_audio(); + $(this).dialog("destroy"); + } + }) + .show(); +} + function openSoundEventModal(settings) { if ($("#hidden-metaconsole_activated").val() === "1") { var win = open( @@ -1045,10 +1144,12 @@ function add_audio(urlSound) { sound + "' autoplay='true' hidden='true' loop='false'>" ); + $("#button-sound_events_button").addClass("animation-blink"); } function remove_audio() { $(".actions-sound-modal audio").remove(); + $("#button-sound_events_button").removeClass("animation-blink"); } function listen_event_sound(settings) { @@ -1229,3 +1330,230 @@ function removeElement(name_select, id_modal) { .append(option); }); } +/* +############################################################################# +## +## + Compacts the Modal Sound Dialog to a tiny toolbar +## + Dynamically adds a button which can reduce/reapply the dialog size +## + If alarm gets raised & minimized, the dialog window maximizes and the toolbar flashes red for 10 seconds. +## - Works fine until a link/action gets clicked. The Toolbar shifts to the bottom of the Modal-Sound Dialog. +## +############################################################################# +*/ + +$(document).ajaxSend(function(event, jqXHR, ajaxOptions) { + const requestBody = ajaxOptions.data; + if (requestBody && requestBody.includes("drawConsoleSound=1")) { + console.log("AJAX request sent with drawConsoleSound=1:", ajaxOptions.url); + + // Find the dialog element by the aria-describedby attribute + var dialog = $('[aria-describedby="modal-sound"]'); + + // Select the close button within the dialog + var closeButton = dialog.find(".ui-dialog-titlebar-close"); + + // Add the minimize button before the close button + var minimizeButton = $("