Fixes FS#45379. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- Changes since v1: * Use jQuery * Allow for better localization * Without JS there won't be any counter listed web/html/packages.php | 18 ++++++++++++++++++ web/template/pkg_search_results.php | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/web/html/packages.php b/web/html/packages.php index bf3daf8..9d4b34b 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -71,6 +71,24 @@ $(document).ready(function() { collapseDependsList("#pkgdepslist"); collapseDependsList("#pkgreqslist"); collapseDependsList("#pkgsrcslist"); + + function update_checked_count() { + var one_pkg = '<?= __("1 package selected") ?>'; + var pkgs = '<?= __("%s packages selected") ?>'; + + var count = $('.package-checkbox:checked').length; + if (count === 1) { + var res = one_pkg; + } else { + var res = pkgs; + } + $('#pkglist-checked-count').text(res.replace('%s', count.toString())); + } + + var elements = $('.package-checkbox'); + for (var i = 0, len = elements.length; i < len; i++) { + elements[i].onchange = update_checked_count; + } }); </script> diff --git a/web/template/pkg_search_results.php b/web/template/pkg_search_results.php index cce533c..4d99dd6 100644 --- a/web/template/pkg_search_results.php +++ b/web/template/pkg_search_results.php @@ -9,6 +9,7 @@ if (!$result): ?> <p> <?= _n('%d package found.', '%d packages found.', $total) ?> <?= __('Page %d of %d.', $current, $pages) ?> + <span id="pkglist-checked-count"></span> </p> <?php if (count($templ_pages) > 1): ?> <p class="pkglist-nav"> @@ -49,7 +50,7 @@ if (!$result): ?> <?php while (list($indx, $row) = each($searchresults)): ?> <tr class="<?= ($indx % 2 == 0) ? 'odd' : 'even' ?>"> <?php if ($SID): ?> - <td><input type="checkbox" name="IDs[<?= $row["PackageBaseID"] ?>]" value="1" /></td> + <td><input class="package-checkbox" type="checkbox" name="IDs[<?= $row["PackageBaseID"] ?>]" value="1" /></td> <?php endif; ?> <td><a href="<?= htmlspecialchars(get_pkg_uri($row["Name"]), ENT_QUOTES); ?>"><?= htmlspecialchars($row["Name"]) ?></a></td> <td<?php if ($row["OutOfDateTS"]): ?> class="flagged"<?php endif; ?>><?= htmlspecialchars($row["Version"]) ?></td> @@ -89,6 +90,8 @@ if (!$result): ?> <p> <?= _n('%d package found.', '%d packages found.', $total) ?> <?= __('Page %d of %d.', $current, $pages) ?> + + <span id="pkglist-checked-count"></span> </p> <?php if (count($templ_pages) > 1): ?> <p class="pkglist-nav"> -- 2.4.5