make function view a modal

pull/3040/head
Andrew Bauer 2020-08-26 11:39:48 -05:00
parent f003dd7782
commit ac7867eab3
3 changed files with 59 additions and 34 deletions

View File

@ -244,7 +244,7 @@ echo $table_head;
for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
$monitor = $displayMonitors[$monitor_i];
$Monitor = new ZM\Monitor($monitor);
include('function.php');
if ( $monitor_i and ( $monitor_i % 100 == 0 ) ) {
echo '</table>';
echo $table_head;
@ -325,7 +325,7 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
?>
</div></td>
<td class="colFunction">
<?php echo makePopupLink( '?view=function&amp;mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$function_class.'">'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', <span class="disabledText">disabled</span>' : '' ) .'</span>', canEdit('Monitors') ) ?><br/>
<a class="functionLnk <?php echo $function_class ?>" data-mid="<?php echo $monitor['Id'] ?>" id="functionLnk-<?php echo $monitor['Id'] ?>" href="#"><?php echo translate('Fn'.$monitor['Function']) ?></a><br/>
<?php echo translate('Status'.$monitor['Status']) ?><br/>
<div class="small text-nowrap text-muted">
<?php

View File

@ -22,42 +22,35 @@ if ( !canEdit('Monitors') ) {
$view = 'error';
return;
}
$monitor = ZM\Monitor::find_one(array('Id'=>$_REQUEST['mid']));
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('Function').' - '.validHtmlStr($monitor->Name()));
?>
<body>
<div id="page">
<div id="header">
<h2><?php echo translate('Function').' - '.validHtmlStr($monitor->Name()) ?></h2>
</div>
<div id="content">
<form name="contentForm" id="contentForm" method="post" action="?">
<input type="hidden" name="view" value="function"/>
<input type="hidden" name="action" value="function"/>
<input type="hidden" name="mid" value="<?php echo $monitor->Id() ?>"/>
<div id="modalFunction-<?php echo $Monitor->Id() ?>" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php echo translate('Function').' - '.validHtmlStr($Monitor->Name()) ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>
<select name="newFunction">
<?php
foreach ( getEnumValues('Monitors', 'Function') as $optFunction ) {
?>
<option value="<?php echo $optFunction ?>"<?php if ( $optFunction == $monitor->Function() ) { ?> selected="selected"<?php } ?>><?php echo translate('Fn'.$optFunction) ?></option>
<?php
}
?>
<select name="newFunction" id="funcSelect-<?php echo $monitor['Id'] ?>">
<?php
foreach ( getEnumValues('Monitors', 'Function') as $optFunction ) {
$selected = ( $optFunction == $Monitor->Function() ) ? ' selected="selected"' : '';
echo '<option value="' .$optFunction. '"'. $selected. '>' .translate('Fn'.$optFunction). '</option>'.PHP_EOL;
}
?>
</select>
<label for="newEnabled"><?php echo translate('Enabled') ?></label>
<input type="checkbox" name="newEnabled" id="newEnabled" value="1"<?php echo $monitor->Enabled() ?' checked="checked"' : '' ?>/>
<input type="checkbox" name="newEnabled" id="newEnabled-<?php echo $monitor['Id'] ?>" value="1"<?php echo $Monitor->Enabled() ?' checked="checked"' : '' ?>/>
</p>
<div id="contentButtons">
<button type="submit" value="Save"><?php echo translate('Save') ?></button>
<button type="button" data-on-click="closeWindow"><?php echo translate('Cancel') ?></button>
</div>
</form>
</div>
<div class="modal-footer">
<button data-mid="<?php echo $monitor['Id'] ?>" type="button" class="funcSaveBtn btn btn-primary"><?php echo translate('Save') ?></button>
<button data-mid="<?php echo $monitor['Id'] ?>" type="button" class="funcCancelBtn btn btn-secondary" data-dismiss="modal"><?php echo translate('Cancel') ?></button>
</div>
</div>
</div>
</body>
</html>
</div>

View File

@ -135,6 +135,18 @@ 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 ) {
createPopup('?view=version', 'zmVersion', 'version');
@ -154,6 +166,26 @@ function initPage() {
// Setup the thumbnail video animation
initThumbAnimation();
// Manage the CANCEL modal buttons
$j('.funcCancelBtn').click(function(evt) {
var mid = evt.currentTarget.getAttribute("data-mid");
evt.preventDefault();
$j('#modalFunction-'+mid).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();
$j.getJSON(thisUrl + '?view=function&action=function&mid='+mid+'&newFunction='+newFunc+'&newEnabled='+newEnabled);
window.location.reload(true);
});
}
function applySort(event, ui) {