X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Felements%2Fselect-part_pkg.html;h=1f7b42f8698b4510f2d9c0e05d6ca041d8fe7d1c;hp=885bb806bfb9371e2915db0e855f4a5816b0d612;hb=37e92c220a54636ebc7900cd59ec6ce56790ede8;hpb=bcd66fbe1db02a31aff3a106a3a85c7d1be407b9 diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html index 885bb806b..1f7b42f86 100644 --- a/httemplate/elements/select-part_pkg.html +++ b/httemplate/elements/select-part_pkg.html @@ -9,33 +9,140 @@ Example: #opt 'part_pkg' => \@records, + 'showdisabled' => 1, #defaults to 0, shows disabled if true + 'toggle_disabled' => 1, #adds js to toggle display of disabled + #currently cannot be used with many other options + #currently must be used with multiple or disable_empty #select-table.html options ) -<% include( '/elements/select-table.html', - 'table' => 'part_pkg', - 'agent_virt' => 1, - 'agent_null' => 1, - 'name_col' => 'pkg', - 'empty_label' => 'Select package', #should this be the default? - 'label_callback' => sub { shift->pkg_comment }, - 'hashref' => \%hash, - 'extra_option_attributes' => [ 'can_discount' ], - %opt, - ) -%> +<& /elements/select-table.html, + 'table' => 'part_pkg', + 'agent_virt' => 1, + 'agent_null' => 1, + 'name_col' => 'pkg', + 'empty_label' => 'Select package', #should this be the default? + 'label_callback' => $opt{'label_callback'} || sub { shift->pkg_comment_only }, + 'hashref' => \%hash, + %opt, +&> + +% if ($opt{'toggle_disabled'}) { +% unless ($toggle_disabled_init) { +% $toggle_disabled_init = 1; + +<% include('/elements/xmlhttp.html', + 'url' => $fsurl.'misc/xmlhttp-part_pkg.cgi', + 'subs' => [ 'load_part_pkg' ], + ) %> + + + +% } # unless $toggle_disabled_init + +
<% $showdisabled ? $hidetext : $showtext %> + +% } # if $opt{'toggle_disabled'} + +<%shared> +my $toggle_disabled_init = 0; + <%init> my( %opt ) = @_; +# toggle_disabled relies on matching search/label options with xmlhttp-part_pkg +# it would be difficult to handle these in the current xmlhttp implementation +# this is defensive coding, not a guarantee it'll work with options not listed here +if ($opt{'toggle_disabled'}) { + foreach my $someopt ( qw( + records + part_pkg + table + agent_virt + agent_null + agent_null_right + name_col + label_callback + hashref + extra_sql + addl_from + order_by + pre_options + post_options + select + ) ) { + die "Cannot use toggle_disabled with $someopt" + if exists $opt{$someopt}; + } +} + +# this would be fairly easy to implement, but not needed right now +die 'Use of toggle_disabled without multiple or disable_empty has not been implemented' + if $opt{'toggle_disabled'} && !($opt{'multiple'} || $opt{'disable_empty'}); + $opt{'records'} = delete $opt{'part_pkg'} if $opt{'part_pkg'}; +my $showdisabled = $opt{'showdisabled'}; + my %hash = (); -$hash{'disabled'} = '' unless $opt{'showdisabled'}; +$hash{'disabled'} = '' unless $showdisabled; if ( exists($opt{'classnum'}) && defined($opt{'classnum'}) ) { if ( $opt{'classnum'} > 0 ) { @@ -45,7 +152,22 @@ if ( exists($opt{'classnum'}) && defined($opt{'classnum'}) ) { } #else -1 or not specified, all classes, so don't set classnum } +# currently can't handle this, either +die 'Use of toggle_disabled with classnum has not been implemented' + if $opt{'toggle_disabled'} && exists($hash{'classnum'}); + +# CAUTION: For proper functioning of toggle_disabled, +# please ensure changes to default options are synced with misc/xmlhttp-part_pkg.cgi + +$opt{'select'} = 'part_pkg.*, setup_option.optionvalue AS _setup_fee, + recur_option.optionvalue AS _recur_fee' + unless $opt{'select'}; +$opt{'addl_from'} .= FS::part_pkg->join_options_sql; + $opt{'extra_sql'} .= ( keys(%hash) ? ' AND ' : ' WHERE ' ). FS::part_pkg->curuser_pkgs_sql; +my $showtext = emt("show disabled packages"); +my $hidetext = emt("hide disabled packages"); +