2 <& /elements/search.html,
4 html_foot => include('elements/checkbox-foot.html',
6 { label => 'Edit selected packages',
7 action => 'popup_package_edit()',
9 { submit => 'Delete selected packages',
10 confirm => 'Really delete these packages?'
13 filter => '.name = "pkgpart"', # see below
14 minboxes => 2, #will remove checkboxes if there aren't at least this many
18 This creates a footer for a search page containing a column of checkboxes.
19 Typically this is used to select several items from the search result and
20 apply some change to all of them at once. The footer always provides
21 "select all" and "unselect all" buttons.
23 "actions" is an arrayref of action buttons to show. Each element of the
24 array is a hashref of either:
26 - "submit" and, optionally, "confirm". Creates a submit button. The value
27 of "submit" becomes the "value" property of the button (and thus its label).
28 If "confirm" is specified, the button will have an onclick handler that
29 displays the value of "confirm" in a popup message box and asks the user to
30 confirm the choice. The hashref may also have a "name" property, which
31 sets the name of the submit button.
33 - "onclick" and "label". Creates a non-submit button that executes the
34 Javascript code in "onclick". "label" is used as the text of the button.
36 If you want only a single action, you can forget the arrayref-of-hashrefs
37 business and just put "submit" and "confirm" (or "onclick" and "label")
38 elements in the argument list.
40 "filter" is a javascript expression to limit which checkboxes are included in
41 the "select/unselect all" actions. By default, any input with type="checkbox"
42 will be included. If this option is given, it will be evaluated with the
43 HTML node in a variable named "obj". The expression should return true or
47 <DIV ID="checkbox_footer" STYLE="display:block">
48 <INPUT TYPE="button" VALUE="<% emt('select all') %>" onclick="setAll(true)">
49 <INPUT TYPE="button" VALUE="<% emt('unselect all') %>" onclick="setAll(false)">
51 % foreach my $action (@$actions) {
52 % if ( $action->{onclick} ) {
53 <INPUT TYPE="button" <% $action->{name} %> onclick="<% $opt{onclick} %>"\
54 VALUE="<% $action->{label} |h%>">
55 % } elsif ( $action->{submit} ) {
56 <INPUT TYPE="submit" <% $action->{name} %> <% $action->{confirm} %>\
57 VALUE="<% $action->{submit} |h%>">
63 var inputs = document.getElementsByTagName('input');
64 for (var i = 0; i < inputs.length; i++) {
66 if ( obj.type == "checkbox" && <% $filter %> ) {
70 %# avoid the need for "$areboxes" late-evaluation hackery
71 % if ($opt{'minboxes'}) {
72 if ( checkboxes.length < <% $opt{'minboxes'} %> ) {
73 for (i = 0; i < checkboxes.length; i++) {
74 checkboxes[i].parentNode.removeChild(checkboxes[i]);
79 if ( checkboxes.length == 0 ) {
80 document.getElementById('checkbox_footer').style.display = 'none';
82 function setAll(setTo) {
83 for (var i = 0; i < checkboxes.length; i++) {
84 checkboxes[i].checked = setTo;
87 function toCGIString() {
89 for (var i = 0; i < checkboxes.length; i++) {
90 if (checkboxes[i].checked) {
91 out += '&' + checkboxes[i].name + '=' + checkboxes[i].value;
99 my $actions = $opt{'actions'} || [ \%opt ];
100 foreach (@$actions) {
101 $_->{confirm} &&= qq!onclick="return confirm('! . $_->{confirm} . qq!')"!;
102 $_->{name} &&= qq!NAME="! . $_->{name} . qq!"!;
104 my $filter = $opt{filter} || 'true';