[freeside-commits] branch master updated. 5ebeeda12a588c1db792fcc8954aeeedb54a84b2

Jonathan Prykop jonathan at 420.am
Sat Feb 27 05:39:33 PST 2016


The branch, master has been updated
       via  5ebeeda12a588c1db792fcc8954aeeedb54a84b2 (commit)
      from  6fd39bf8dfa989aaedea59e5e3cd609642f9e024 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5ebeeda12a588c1db792fcc8954aeeedb54a84b2
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Sat Feb 27 07:38:19 2016 -0600

    RT#21463: Option to show disabled package definitions [does not work on IE]

diff --git a/FS/FS/part_event/Condition/has_referral_pkgpart.pm b/FS/FS/part_event/Condition/has_referral_pkgpart.pm
index 7062f6c..4409444 100644
--- a/FS/FS/part_event/Condition/has_referral_pkgpart.pm
+++ b/FS/FS/part_event/Condition/has_referral_pkgpart.pm
@@ -13,6 +13,7 @@ sub option_fields {
     'if_pkgpart' => { 'label'    => 'Only packages: ',
                       'type'     => 'select-part_pkg',
                       'multiple' => 1,
+                      'toggle_disabled' => 1,
                     },
   );
 }
diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html
index 237d7df..d54f283 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 4b6ddb4..7945bb4 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 %>"
 %           }

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event/Condition/has_referral_pkgpart.pm |    1 +
 httemplate/elements/select-part_pkg.html           |   41 ++++++++++++++++++++
 httemplate/elements/select-table.html              |    7 +++-
 3 files changed, 48 insertions(+), 1 deletion(-)




More information about the freeside-commits mailing list