From 1f810c8947b68ba90746e511daa018c4746f33f1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 3 Sep 2020 18:24:45 -0400 Subject: [PATCH] Populate the function modal from the javascript monitors array before viewing. --- web/skins/classic/views/js/console.js | 44 ++++++++++++++++++--------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/web/skins/classic/views/js/console.js b/web/skins/classic/views/js/console.js index 4b804a437..436f03a08 100644 --- a/web/skins/classic/views/js/console.js +++ b/web/skins/classic/views/js/console.js @@ -135,15 +135,6 @@ function reloadWindow() { } function initPage() { - $j('.functionLnk').click(function(evt) { - if ( ! canEditEvents ) { - alert("You do not have permission to change monitor function."); - return; - } - var mid = evt.currentTarget.getAttribute("data-mid"); - evt.preventDefault(); - $j('#modalFunction-'+mid).modal('show'); - }); reloadWindow.periodical(consoleRefreshTimeout); if ( showVersionPopup ) { @@ -165,19 +156,44 @@ function initPage() { // Setup the thumbnail video animation initThumbAnimation(); + $j('.functionLnk').click(function(evt) { + evt.preventDefault(); + if ( !canEditEvents ) { + alert('You do not have permission to change monitor function.'); + return; + } + var mid = evt.currentTarget.getAttribute('data-mid'); + monitor = monitors[mid]; + if ( !monitor ) { + console.error("No monitor found for mid " + mid); + return; + } + + var function_form = document.getElementById('function_form'); + if ( !function_form ) { + console.error("Unable to find form with id function_form"); + return; + } + function_form.elements['newFunction'].value = monitor.Function; + function_form.elements['newEnabled'].checked = monitor.Enabled; + function_form.elements['mid'].value = mid; + document.getElementById('function_monitor_name').innerHTML = monitor.Name;; + + $j('#modalFunction').modal('show'); + }); // Manage the CANCEL modal buttons $j('.funcCancelBtn').click(function(evt) { - var mid = evt.currentTarget.getAttribute("data-mid"); evt.preventDefault(); - $j('#modalFunction-'+mid).modal('hide'); + $j('#modalFunction').modal('hide'); }); // Manage the SAVE modal buttons $j('.funcSaveBtn').click(function(evt) { - var mid = evt.currentTarget.getAttribute("data-mid"); - var newFunc = $j("#funcSelect-"+mid).val(); - var newEnabled = $j('#newEnabled-'+mid).is(':checked') ? 1 : 0; evt.preventDefault(); + var form = evt.currentTarget.form; + var mid = form.elements['mid'].value; + var newFunc = $j('#newFunction').val(); + var newEnabled = $j('#newEnabled').is(':checked') ? 1 : 0; $j.getJSON(thisUrl + '?view=function&action=function&mid='+mid+'&newFunction='+newFunc+'&newEnabled='+newEnabled); window.location.reload(true); });