5 include( '/elements/select-part_pkg.html',
7 #strongly recommended (you want your forms to be "sticky" on errors, right?)
8 'curr_value' => 'current_value',
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
15 #select-table.html options
20 <& /elements/select-table.html,
21 'table' => 'part_pkg',
25 'empty_label' => 'Select package', #should this be the default?
26 'label_callback' => $opt{'label_callback'} || sub { shift->pkg_comment_only },
28 $opt{'toggle_disabled'} ? (
29 'extra_option_attributes' => [ 'disabled' ],
30 'hidden_sub' => sub { my $rec = shift; $rec->disabled; },
35 % if ($opt{'toggle_disabled'}) {
36 % unless ($toggle_disabled_init) {
37 % $toggle_disabled_init = 1;
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;
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) };
54 % } # unless $toggle_disabled_init
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>
62 % } # if $opt{'toggle_disabled'}
65 my $toggle_disabled_init = 0;
71 $opt{'records'} = delete $opt{'part_pkg'}
74 $opt{'showdisabled'} = 1 if $opt{'toggle_disabled'};
77 $hash{'disabled'} = '' unless $opt{'showdisabled'};
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
87 $opt{'select'} = 'part_pkg.*, setup_option.optionvalue AS _setup_fee,
88 recur_option.optionvalue AS _recur_fee'
89 unless $opt{'select'};
90 $opt{'addl_from'} .= FS::part_pkg->join_options_sql;
92 $opt{'extra_sql'} .= ( keys(%hash) ? ' AND ' : ' WHERE ' ).
93 FS::part_pkg->curuser_pkgs_sql;