RT#21463: Option to show disabled package definitions [does not work on IE]
[freeside.git] / httemplate / elements / select-part_pkg.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/select-part_pkg.html',
6
7     #strongly recommended (you want your forms to be "sticky" on errors, right?)
8     'curr_value' => 'current_value',
9   
10     #opt
11     'part_pkg'   => \@records,
12     'showdisabled' => 1, #defaults to 0, shows disabled if true
13     'toggle_disabled' => 1, #implies showdisabled, adds js to toggle display of disabled
14
15     #select-table.html options
16   )
17
18 </%doc>
19
20 <& /elements/select-table.html,
21      'table'          => 'part_pkg',
22      'agent_virt'     => 1,
23      'agent_null'     => 1,
24      'name_col'       => 'pkg',
25      'empty_label'    => 'Select package', #should this be the default?
26      'label_callback' => $opt{'label_callback'} || sub { shift->pkg_comment_only },
27      'hashref'        => \%hash,
28      $opt{'toggle_disabled'} ? (
29        'extra_option_attributes' => [ 'disabled' ],
30        'hidden_sub' => sub { my $rec = shift; $rec->disabled; },
31      ) : (),
32      %opt,
33 &>
34
35 % if ($opt{'toggle_disabled'}) {
36 %   unless ($toggle_disabled_init) {
37 %     $toggle_disabled_init = 1;
38
39 <SCRIPT>
40 function toggle_disabled (id, disabled_on) {
41   var selectbox = document.getElementById(id);
42   for (var i = 0; i < selectbox.length; i++) {
43     var optionbox = selectbox.options[i];
44     if (optionbox.getAttribute('data-disabled')) {
45       optionbox.hidden = (disabled_on || optionbox.selected) ? false : true;
46     }
47   }
48   var switchlink = document.getElementById(id+'_switch');
49   switchlink.innerHTML = disabled_on ? '<% emt("hide disabled packages") %>' : '<% emt("show disabled packages") %>';
50   switchlink.onclick = function () { toggle_disabled(id, disabled_on ? 0 : 1) };
51 }
52 </SCRIPT>
53
54 %   } # unless $toggle_disabled_init
55
56 <BR><A 
57   HREF="javascript:void(0)"
58   STYLE="font-size: smaller"
59   ONCLICK="toggle_disabled('<% $opt{'id'} %>',1)"
60   ID="<% $opt{'id'} %>_switch"><% emt("show disabled packages") %></A>
61
62 % } # if $opt{'toggle_disabled'}
63
64 <%shared>
65 my $toggle_disabled_init = 0;
66 </%shared>
67 <%init>
68  
69 my( %opt ) = @_;
70
71 $opt{'records'} = delete $opt{'part_pkg'}
72   if $opt{'part_pkg'};
73
74 $opt{'showdisabled'} = 1 if $opt{'toggle_disabled'};
75
76 my %hash = ();
77 $hash{'disabled'} = '' unless $opt{'showdisabled'};
78
79 if ( exists($opt{'classnum'}) && defined($opt{'classnum'}) ) {
80   if ( $opt{'classnum'} > 0 ) {
81     $hash{'classnum'} = $opt{'classnum'};
82   } elsif ( $opt{'classnum'} eq '' || $opt{'classnum'} == 0 ) {
83     $hash{'classnum'} = '';
84   } #else -1 or not specified, all classes, so don't set classnum
85 }
86
87 $opt{'extra_sql'} .= ( keys(%hash) ? ' AND ' : ' WHERE ' ).
88                      FS::part_pkg->curuser_pkgs_sql;
89
90 </%init>