RT#21463: Option to show disabled package definitions [does not work on IE]
authorJonathan Prykop <jonathan@freeside.biz>
Sat, 27 Feb 2016 13:38:19 +0000 (07:38 -0600)
committerJonathan Prykop <jonathan@freeside.biz>
Sat, 27 Feb 2016 13:38:19 +0000 (07:38 -0600)
FS/FS/part_event/Condition/has_referral_pkgpart.pm
httemplate/elements/select-part_pkg.html
httemplate/elements/select-table.html

index 7062f6c..4409444 100644 (file)
@@ -13,6 +13,7 @@ sub option_fields {
     'if_pkgpart' => { 'label'    => 'Only packages: ',
                       'type'     => 'select-part_pkg',
                       'multiple' => 1,
+                      'toggle_disabled' => 1,
                     },
   );
 }
index 237d7df..d54f283 100644 (file)
@@ -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'};
 
index 4b6ddb4..7945bb4 100644 (file)
@@ -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 %>"
 %           }