update group editing, solving inline javascript problems and removing cruft

This commit is contained in:
Isaac Connor 2019-11-01 13:37:52 -04:00
parent 46991f04e6
commit 3653ad5ce3
2 changed files with 21 additions and 22 deletions

View File

@ -37,14 +37,14 @@ xhtmlHeaders(__FILE__, translate('Group').' - '.$newGroup->Name());
<h2><?php echo translate('Group') ?> - <?php echo validHtmlStr($newGroup->Name()); ?></h2> <h2><?php echo translate('Group') ?> - <?php echo validHtmlStr($newGroup->Name()); ?></h2>
</div> </div>
<div id="content"> <div id="content">
<form name="groupForm" method="post" action="?"> <form id="groupForm" name="groupForm" method="post" action="?">
<input type="hidden" name="view" value="<?php echo $view ?>"/> <input type="hidden" name="view" value="<?php echo $view ?>"/>
<input type="hidden" name="gid" value="<?php echo $newGroup->Id() ?>"/> <input type="hidden" name="gid" value="<?php echo $newGroup->Id() ?>"/>
<table id="contentTable" class="major"> <table id="contentTable" class="major">
<tbody> <tbody>
<tr> <tr>
<th scope="row"><?php echo translate('Name') ?></th> <th scope="row"><?php echo translate('Name') ?></th>
<td><input type="text" name="newGroup[Name]" value="<?php echo validHtmlStr($newGroup->Name()) ?>" oninput="configureButtons(this);"/></td> <td><input type="text" name="newGroup[Name]" value="<?php echo validHtmlStr($newGroup->Name()) ?>" data-on-input="configureButtons"/></td>
</tr> </tr>
<tr> <tr>
<th scope="row"><?php echo translate('ParentGroup') ?></th> <th scope="row"><?php echo translate('ParentGroup') ?></th>
@ -88,19 +88,19 @@ function get_children($Group) {
$kids = get_children($newGroup); $kids = get_children($newGroup);
if ( $newGroup->Id() ) if ( $newGroup->Id() )
$kids[] = $newGroup->Id(); $kids[] = $newGroup->Id();
$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name'; $sql = 'SELECT Id,Name FROM `Groups`'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name';
$options = array(''=>'None'); $options = array(''=>'None');
foreach ( dbFetchAll($sql, null, $kids) as $option ) { foreach ( dbFetchAll($sql, null, $kids) as $option ) {
$options[$option['Id']] = str_repeat('&nbsp;&nbsp;', $Groups[$option['Id']]->depth()) . $option['Name']; $options[$option['Id']] = str_repeat('&nbsp;&nbsp;', $Groups[$option['Id']]->depth()) . $option['Name'];
} }
echo htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);')); echo htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('data-on-change'=>'configureButtons'));
?> ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row"><?php echo translate('Monitor') ?></th> <th scope="row"><?php echo translate('Monitor') ?></th>
<td> <td>
<select name="newGroup[MonitorIds][]" class="chosen" multiple="multiple" onchange="configureButtons(this);"> <select name="newGroup[MonitorIds][]" class="chosen" multiple="multiple" data-on-change="configureButtons">
<?php <?php
$monitors = dbFetchAll('SELECT Id,Name FROM Monitors ORDER BY Sequence ASC'); $monitors = dbFetchAll('SELECT Id,Name FROM Monitors ORDER BY Sequence ASC');
$monitorIds = $newGroup->MonitorIds(); $monitorIds = $newGroup->MonitorIds();

View File

@ -1,21 +1,20 @@
function selectMonitors() { function configureButtons() {
createPopup( '?view=monitorselect&callForm=groupForm&callField=newGroup[MonitorIds]', 'zmMonitors', 'monitorselect' ); var form = $j('#groupForm')[0];
} if ( !form ) {
console.log("No groupForm found");
if ( refreshParent ) { return;
opener.location.reload(true);
}
function configureButtons( element ) {
if ( canEditGroups ) {
var form = element.form;
var disabled = false;
if ( form.elements['newGroup[Name]'].value == '' ) {
disabled = true;
}
form.saveBtn.disabled = disabled;
} }
if ( !canEditGroups ) {
console.log("Cannot edit groups");
form.elements['action'].disabled = disabled;
return;
}
var disabled = false;
if ( form.elements['newGroup[Name]'].value == '' ) {
disabled = true;
}
form.elements['action'].disabled = disabled;
} }
window.focus(); window.focus();