default to a session cookie instead of setting an explicit timeout, weird timezone...
[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                       onclick => 'popup_package_edit()',
8                     },
9                     { submit  => 'Delete selected packages',
10                       confirm => 'Really delete these packages?'
11                     },
12                   ],
13                   filter        => '.name = "pkgpart"', # see below
14                   minboxes      => 2, #will remove checkboxes if there aren't at least this many
15                ),
16 &>
17
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.
22
23 "actions" is an arrayref of action buttons to show.  Each element of the
24 array is a hashref of either:
25
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.
32
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.
35
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.
39
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
44 false.
45
46 </%doc>
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)">
50 <BR>
51 % foreach my $action (@$actions) {
52 %   if ( $action->{onclick} ) {
53 <INPUT TYPE="button" <% $action->{name} %> onclick="<% $action->{onclick} %>"\
54   VALUE="<% $action->{label} |h%>">
55 %   } elsif ( $action->{submit} ) {
56 <INPUT TYPE="submit" <% $action->{name} %> <% $action->{confirm} %>\
57   VALUE="<% $action->{submit} |h%>">
58 %   } # else do nothing
59 % } #foreach
60 </DIV>
61 <SCRIPT>
62 var checkboxes = [];
63 var inputs = document.getElementsByTagName('input');
64 for (var i = 0; i < inputs.length; i++) {
65   var obj = inputs[i];
66   if ( obj.type == "checkbox" && <% $filter %> ) {
67     checkboxes.push(obj);
68   }
69 }
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]);
75   }
76   checkboxes = [];
77 }
78 % }
79 if ( checkboxes.length == 0 ) {
80   document.getElementById('checkbox_footer').style.display = 'none';
81 }
82 function setAll(setTo) {
83   for (var i = 0; i < checkboxes.length; i++) {
84     checkboxes[i].checked = setTo;
85   }
86 }
87 function toCGIString() {
88   var out = '';
89   for (var i = 0; i < checkboxes.length; i++) {
90     if (checkboxes[i].checked) {
91       out += '&' + checkboxes[i].name + '=' + checkboxes[i].value;
92     }
93   }
94   return out;
95 }
96 </SCRIPT>
97 <%init>
98 my %opt = @_;
99 my $actions = $opt{'actions'} || [ \%opt ];
100 foreach (@$actions) {
101   $_->{confirm} &&= qq!onclick="return confirm('! . $_->{confirm} . qq!')"!;
102   $_->{name} &&= qq!NAME="! . $_->{name} . qq!"!;
103 }
104 my $filter = $opt{filter} || 'true';
105 </%init>