diff options
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/elements/select-part_pkg.html | 41 | ||||
-rw-r--r-- | httemplate/elements/select-table.html | 7 |
2 files changed, 47 insertions, 1 deletions
diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html index 237d7df0a..d54f2831b 100644 --- a/httemplate/elements/select-part_pkg.html +++ b/httemplate/elements/select-part_pkg.html @@ -9,6 +9,8 @@ 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 #select-table.html options ) @@ -23,8 +25,45 @@ 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, &> + +% if ($opt{'toggle_disabled'}) { +% unless ($toggle_disabled_init) { +% $toggle_disabled_init = 1; + +<SCRIPT> +function toggle_disabled (id, disabled_on) { + var selectbox = document.getElementById(id); + for (var i = 0; i < selectbox.length; i++) { + var optionbox = selectbox.options[i]; + if (optionbox.getAttribute('data-disabled')) { + optionbox.hidden = (disabled_on || optionbox.selected) ? false : true; + } + } + var switchlink = document.getElementById(id+'_switch'); + switchlink.innerHTML = disabled_on ? '<% emt("hide disabled packages") %>' : '<% emt("show disabled packages") %>'; + switchlink.onclick = function () { toggle_disabled(id, disabled_on ? 0 : 1) }; +} +</SCRIPT> + +% } # unless $toggle_disabled_init + +<BR><A + HREF="javascript:void(0)" + STYLE="font-size: smaller" + ONCLICK="toggle_disabled('<% $opt{'id'} %>',1)" + ID="<% $opt{'id'} %>_switch"><% emt("show disabled packages") %></A> + +% } # if $opt{'toggle_disabled'} + +<%shared> +my $toggle_disabled_init = 0; +</%shared> <%init> my( %opt ) = @_; @@ -32,6 +71,8 @@ my( %opt ) = @_; $opt{'records'} = delete $opt{'part_pkg'} if $opt{'part_pkg'}; +$opt{'showdisabled'} = 1 if $opt{'toggle_disabled'}; + my %hash = (); $hash{'disabled'} = '' unless $opt{'showdisabled'}; diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 4b6ddb40e..7945bb450 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -51,9 +51,12 @@ Example: #<SELECT> element 'onchange' => '', #javascript code - #params (well, a param) controlling the <OPTION>s + #params controlling the <OPTION>s 'extra_option_attributes' => [ 'field' ], #field or method in $table objects #(are prefixed w/data- per HTML5) + 'hidden_sub' => sub { my $rec = shift; $rec->disabled; }, #sets option hidden att if true + #won't hide selected options + #hidden att not supported IE < 11 #special return options 'js_only' => 0, #set true to return only the JS portions (i.e. nothing) @@ -108,8 +111,10 @@ Example: % $selected = ( ref($value) && $value->{$recvalue} ) % || ( $value && $value eq $recvalue ); #not == because of value_col % } +% $opt{'hidden_sub'} ||= sub { 0 }; <OPTION VALUE="<% $recvalue %>" <% $selected ? ' SELECTED' : '' %> + <% (&{$opt{'hidden_sub'}}($record) && !$selected) ? ' hidden' : '' %> % foreach my $att ( @{ $opt{'extra_option_attributes'} } ) { data-<% $att %>="<% $record->$att() |h %>" % } |