Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / search / elements / checkbox-foot.html
1 <%doc>
2 <& /elements/search.html,
3   # options...
4   html_foot => include('elements/checkbox-foot.html',
5                   actions => [
6                     { label   => 'Edit selected packages',
7                       action  => 'popup_package_edit()',
8                     },
9                     { submit  => 'Delete selected packages',
10                       confirm => 'Really delete these packages?'
11                     },
12                   ],
13                   filter        => '.name = "pkgpart"', # see below
14                ),
15 &>
16
17 This creates a footer for a search page containing a column of checkboxes.
18 Typically this is used to select several items from the search result and 
19 apply some change to all of them at once.  The footer always provides 
20 "select all" and "unselect all" buttons.
21
22 "actions" is an arrayref of action buttons to show.  Each element of the
23 array is a hashref of either:
24
25 - "submit" and, optionally, "confirm".  Creates a submit button.  The value 
26 of "submit" becomes the "value" property of the button (and thus its label).
27 If "confirm" is specified, the button will have an onclick handler that 
28 displays the value of "confirm" in a popup message box and asks the user to 
29 confirm the choice.
30
31 - "onclick" and "label".  Creates a non-submit button that executes the 
32 Javascript code in "onclick".  "label" is used as the text of the button.
33
34 If you want only a single action, you can forget the arrayref-of-hashrefs
35 business and just put "submit" and "confirm" (or "onclick" and "label") 
36 elements in the argument list.
37
38 "filter" is a javascript expression to limit which checkboxes are included in
39 the "select/unselect all" actions.  By default, any input with type="checkbox"
40 will be included.  If this option is given, it will be evaluated with the 
41 HTML node in a variable named "obj".  The expression should return true or
42 false.
43
44 </%doc>
45 <DIV ID="checkbox_footer" STYLE="display:block">
46 <INPUT TYPE="button" VALUE="<% emt('select all') %>" onclick="setAll(true)">
47 <INPUT TYPE="button" VALUE="<% emt('unselect all') %>" onclick="setAll(false)">
48 <BR>
49 % foreach my $action (@$actions) {
50 %   if ( $action->{onclick} ) {
51 <INPUT TYPE="button" <% $action->{name} %> onclick="<% $opt{onclick} %>"\
52   VALUE="<% $action->{label} |h%>">
53 %   } elsif ( $action->{submit} ) {
54 <INPUT TYPE="submit" <% $action->{name} %> <% $action->{confirm} %>\
55   VALUE="<% $action->{submit} |h%>">
56 %   } # else do nothing
57 % } #foreach
58 </DIV>
59 <SCRIPT>
60 var checkboxes = [];
61 var inputs = document.getElementsByTagName('input');
62 for (var i = 0; i < inputs.length; i++) {
63   var obj = inputs[i];
64   if ( obj.type == "checkbox" && <% $filter %> ) {
65     checkboxes.push(obj);
66   }
67 }
68 %# avoid the need for "$areboxes" late-evaluation hackery
69 if ( checkboxes.length == 0 ) {
70   document.getElementById('checkbox_footer').style.display = 'none';
71 }
72 function setAll(setTo) {
73   for (var i = 0; i < checkboxes.length; i++) {
74     checkboxes[i].checked = setTo;
75   }
76 }
77 </SCRIPT>
78 <%init>
79 my %opt = @_;
80 my $actions = $opt{'actions'} || [ \%opt ];
81 foreach (@$actions) {
82   $_->{confirm} &&= qq!onclick="return confirm('! . $_->{confirm} . qq!')"!;
83   $_->{name} &&= qq!NAME="! . $_->{name} . qq!"!;
84 }
85 my $filter = $opt{filter} || 'true';
86 </%init>