From 3d8dcf062ffb2da2aa4969a516c210680dab266d Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 2 Mar 2016 22:41:51 -0600 Subject: [PATCH] RT21463: Option to show disabled package definitions [refactored to use ajax] --- httemplate/elements/select-part_pkg.html | 108 ++++++++++++++++++++++++++----- httemplate/elements/select-table.html | 7 +- httemplate/misc/xmlhttp-part_pkg.cgi | 31 +++++++++ 3 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 httemplate/misc/xmlhttp-part_pkg.cgi diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html index d54f2831b..fb45c0efa 100644 --- a/httemplate/elements/select-part_pkg.html +++ b/httemplate/elements/select-part_pkg.html @@ -10,7 +10,9 @@ Example: #opt 'part_pkg' => \@records, 'showdisabled' => 1, #defaults to 0, shows disabled if true - 'toggle_disabled' => 1, #implies showdisabled, adds js to toggle display of disabled + '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 ) @@ -25,10 +27,6 @@ Example: 'empty_label' => 'Select package', #should this be the default? 'label_callback' => $opt{'label_callback'} || sub { shift->pkg_comment_only }, 'hashref' => \%hash, - $opt{'toggle_disabled'} ? ( - 'extra_option_attributes' => [ 'disabled' ], - 'hidden_sub' => sub { my $rec = shift; $rec->disabled; }, - ) : (), %opt, &> @@ -36,18 +34,58 @@ Example: % unless ($toggle_disabled_init) { % $toggle_disabled_init = 1; +<% include('/elements/xmlhttp.html', + 'url' => $fsurl.'misc/xmlhttp-part_pkg.cgi', + 'subs' => [ 'load_part_pkg' ], + ) %> + @@ -56,8 +94,8 @@ function toggle_disabled (id, disabled_on) {
<% emt("show disabled packages") %> + ONCLICK="toggle_disabled_part_pkg('<% $opt{'id'} %>',<% $showdisabled ? '0' : '1' %>)" + ID="<% $opt{'id'} %>_switch"><% $showdisabled ? $hidetext : $showtext %> % } # if $opt{'toggle_disabled'} @@ -68,13 +106,42 @@ my $toggle_disabled_init = 0; 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 + ) ) { + 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'}; -$opt{'showdisabled'} = 1 if $opt{'toggle_disabled'}; +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 ) { @@ -84,7 +151,14 @@ 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 exists $hash{'classnum'}; + $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"); + diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 7945bb450..4b6ddb40e 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -51,12 +51,9 @@ Example: #