Add sorting and search to CA/Certs. Implements #9412

(cherry picked from commit 1497305875)
This commit is contained in:
jim-p 2019-03-18 16:53:46 -04:00
parent df40c93b75
commit ebfbb3620f
2 changed files with 179 additions and 2 deletions

View File

@ -330,11 +330,46 @@ display_top_tabs($tab_array);
if (!($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors)) {
?>
<div class="panel panel-default" id="search-panel">
<div class="panel-heading">
<h2 class="panel-title">
<?=gettext('Search')?>
<span class="widget-heading-icon pull-right">
<a data-toggle="collapse" href="#search-panel_panel-body">
<i class="fa fa-plus-circle"></i>
</a>
</span>
</h2>
</div>
<div id="search-panel_panel-body" class="panel-body collapse in">
<div class="form-group">
<label class="col-sm-2 control-label">
<?=gettext("Search term")?>
</label>
<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
<div class="col-sm-2">
<select id="where" class="form-control">
<option value="0"><?=gettext("Name")?></option>
<option value="1"><?=gettext("Distinguished Name")?></option>
<option value="2" selected><?=gettext("Both")?></option>
</select>
</div>
<div class="col-sm-3">
<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
</div>
<div class="col-sm-10 col-sm-offset-2">
<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Certificate Authorities')?></h2></div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-hover table-rowdblclickedit">
<table id="catable" class="table table-striped table-hover table-rowdblclickedit sortable-theme-bootstrap" data-sortable>
<thead>
<tr>
<th><?=gettext("Name")?></th>
@ -435,6 +470,61 @@ foreach ($a_ca as $i => $ca):
<?=gettext("Add")?>
</a>
</nav>
?>
<script type="text/javascript">
//<![CDATA[
events.push(function() {
// Make these controls plain buttons
$("#btnsearch").prop('type', 'button');
$("#btnclear").prop('type', 'button');
// Search for a term in the entry name and/or dn
$("#btnsearch").click(function() {
var searchstr = $('#searchstr').val().toLowerCase();
var table = $("table tbody");
var where = $('#where').val();
table.find('tr').each(function (i) {
var $tds = $(this).find('td'),
shortname = $tds.eq(0).text().trim().toLowerCase(),
dn = $tds.eq(4).text().trim().toLowerCase();
regexp = new RegExp(searchstr);
if (searchstr.length > 0) {
if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(dn) && (where != 0))) {
$(this).hide();
} else {
$(this).show();
}
} else {
$(this).show(); // A blank search string shows all
}
});
});
// Clear the search term and unhide all rows (that were hidden during a previous search)
$("#btnclear").click(function() {
var table = $("table tbody");
$('#searchstr').val("");
table.find('tr').each(function (i) {
$(this).show();
});
});
// Hitting the enter key will do the same as clicking the search button
$("#searchstr").on("keyup", function (event) {
if (event.keyCode == 13) {
$("#btnsearch").get(0).click();
}
});
});
//]]>
</script>
<?php
include("foot.inc");
exit;

View File

@ -1096,11 +1096,45 @@ if ($act == "new" || (($_POST['save'] == gettext("Save")) && $input_errors)) {
print($form);
} else {
?>
<div class="panel panel-default" id="search-panel">
<div class="panel-heading">
<h2 class="panel-title">
<?=gettext('Search')?>
<span class="widget-heading-icon pull-right">
<a data-toggle="collapse" href="#search-panel_panel-body">
<i class="fa fa-plus-circle"></i>
</a>
</span>
</h2>
</div>
<div id="search-panel_panel-body" class="panel-body collapse in">
<div class="form-group">
<label class="col-sm-2 control-label">
<?=gettext("Search term")?>
</label>
<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
<div class="col-sm-2">
<select id="where" class="form-control">
<option value="0"><?=gettext("Name")?></option>
<option value="1"><?=gettext("Distinguished Name")?></option>
<option value="2" selected><?=gettext("Both")?></option>
</select>
</div>
<div class="col-sm-3">
<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
</div>
<div class="col-sm-10 col-sm-offset-2">
<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to search package names and descriptions.')?></span>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Certificates')?></h2></div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<table class="table table-striped table-hover sortable-theme-bootstrap" data-sortable>
<thead>
<tr>
<th><?=gettext("Name")?></th>
@ -1276,6 +1310,59 @@ foreach ($a_cert as $i => $cert):
<?=gettext("Add/Sign")?>
</a>
</nav>
<script type="text/javascript">
//<![CDATA[
events.push(function() {
// Make these controls plain buttons
$("#btnsearch").prop('type', 'button');
$("#btnclear").prop('type', 'button');
// Search for a term in the entry name and/or dn
$("#btnsearch").click(function() {
var searchstr = $('#searchstr').val().toLowerCase();
var table = $("table tbody");
var where = $('#where').val();
table.find('tr').each(function (i) {
var $tds = $(this).find('td'),
shortname = $tds.eq(0).text().trim().toLowerCase(),
dn = $tds.eq(2).text().trim().toLowerCase();
regexp = new RegExp(searchstr);
if (searchstr.length > 0) {
if (!(regexp.test(shortname) && (where != 1)) && !(regexp.test(dn) && (where != 0))) {
$(this).hide();
} else {
$(this).show();
}
} else {
$(this).show(); // A blank search string shows all
}
});
});
// Clear the search term and unhide all rows (that were hidden during a previous search)
$("#btnclear").click(function() {
var table = $("table tbody");
$('#searchstr').val("");
table.find('tr').each(function (i) {
$(this).show();
});
});
// Hitting the enter key will do the same as clicking the search button
$("#searchstr").on("keyup", function (event) {
if (event.keyCode == 13) {
$("#btnsearch").get(0).click();
}
});
});
//]]>
</script>
<?php
include("foot.inc");
exit;