convert function modal to ajax request

pull/3051/head
Andrew Bauer 2020-09-19 10:18:59 -05:00
parent f7cbc2f5e0
commit ec20fdf3ad
4 changed files with 76 additions and 57 deletions

View File

@ -18,17 +18,18 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
if ( !canEdit('Monitors') ) {
$view = 'error';
return;
}
?>
if ( !canEdit('Monitors') ) return;
?>
<div id="modalFunction" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form id="function_form" action="?view=function&action=function" method="post">
<input type="hidden" name="mid"/>
<form id="function_form" action="?view=function&action=function" method="post">
<?php
// We have to manually insert the csrf key into the form when using a modal generated via ajax call
echo getCSRFinputHTML();
?>
<input type="hidden" name="mid"/>
<div class="modal-header">
<h5 class="modal-title"><?php echo translate('Function') ?> - <span id="function_monitor_name"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
@ -46,7 +47,7 @@ if ( !canEdit('Monitors') ) {
<button type="button" class="funcSaveBtn btn btn-primary"><?php echo translate('Save') ?></button>
<button type="button" class="funcCancelBtn btn btn-secondary" data-dismiss="modal"><?php echo translate('Cancel') ?></button>
</div>
</form>
</form>
</div>
</div>
</div>

View File

@ -51,11 +51,9 @@ if ( $action == 'function' ) {
if ( $newFunction != 'None' && $newFunction != 'NoDect' )
zmaControl($monitor, 'start');
}
$refreshParent = true;
} else {
ZM\Logger::Debug('No change to function, not doing anything.');
}
} // end if action
$view = 'none';
$closePopup = true;
$view = 'console';
?>

View File

@ -437,6 +437,5 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
</div>
</form>
<?php
include('function.php');
xhtmlFooter();
?>

View File

@ -127,6 +127,57 @@ function reloadWindow() {
window.location.replace( thisUrl );
}
// Manage the the Function modal and its buttons
function manageFunctionModal() {
$j('.functionLnk').click(function(evt) {
evt.preventDefault();
if ( !canEditEvents ) {
enoperm();
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 == '1';
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) {
evt.preventDefault();
$j('#modalFunction').modal('hide');
});
// Manage the SAVE modal buttons
$j('.funcSaveBtn').click(function(evt) {
evt.preventDefault();
$j('#function_form').submit();
//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)
//.done(window.location.reload(true))
//.fail(function(jqxhr, textStatus, error) {
//console.log("Request Failed: " + textStatus + ", " + error);
//console.log("Response Text: " + jqxhr.responseText);
//});
});
}
function initPage() {
reloadWindow.periodical(consoleRefreshTimeout);
if ( showVersionPopup ) {
@ -165,51 +216,21 @@ function initPage() {
// Setup the thumbnail video animation
initThumbAnimation();
$j('.functionLnk').click(function(evt) {
evt.preventDefault();
if ( !canEditEvents ) {
enoperm();
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 == '1';
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) {
evt.preventDefault();
$j('#modalFunction').modal('hide');
});
// Manage the SAVE modal buttons
$j('.funcSaveBtn').click(function(evt) {
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)
.done(window.location.reload(true))
.fail(function(jqxhr, textStatus, error) {
console.log("Request Failed: " + textStatus + ", " + error);
console.log("Response Text: " + jqxhr.responseText);
});
});
// Load the Function modal on page load
$j.getJSON(thisUrl + '?request=modal&modal=function')
.done(function(data) {
if ( $j('#modalFunction').length ) {
$j('#modalFunction').replaceWith(data.html);
} else {
$j("body").append(data.html);
}
// Manage the Function modal
manageFunctionModal();
})
.fail(function(jqxhr, textStatus, error) {
console.log("Request Failed: " + textStatus + ", " + error);
console.log("Response Text: " + jqxhr.responseText);
});
}
function applySort(event, ui) {