[freeside-commits] branch FREESIDE_4_BRANCH updated. f52ea63bd7a746a3776647a5dfbb50f9df18611d

Jonathan Prykop jonathan at 420.am
Fri Mar 11 17:32:33 PST 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  f52ea63bd7a746a3776647a5dfbb50f9df18611d (commit)
       via  aabf07e986e32a4dd20c94ee8cee4b5767ba6127 (commit)
       via  031ed2267f963d8538000f9ca6b9abceca46e779 (commit)
       via  f2c029cf7e49a7597d25d17562a054d6e37731b5 (commit)
       via  80cbfd9890ba84c49ee40164e1ec27aff05c272a (commit)
      from  08963f08dc2731780dbdb1166b79c1233936724d (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 f52ea63bd7a746a3776647a5dfbb50f9df18611d
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Wed Mar 9 13:06:06 2016 -0600

    RT#21463 Option to show disabled package definitions [bug fix]

diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html
index caceb5c..1f7b42f 100644
--- a/httemplate/elements/select-part_pkg.html
+++ b/httemplate/elements/select-part_pkg.html
@@ -154,7 +154,7 @@ if ( exists($opt{'classnum'}) && defined($opt{'classnum'}) ) {
 
 # currently can't handle this, either
 die 'Use of toggle_disabled with classnum has not been implemented'
-  if exists $hash{'classnum'};
+  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

commit aabf07e986e32a4dd20c94ee8cee4b5767ba6127
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Mar 8 15:13:00 2016 -0600

    RT#21463 Option to show disabled package definitions [recently added select/addl_from defaults copied to xmlhttp]

diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html
index ba1d7b7..caceb5c 100644
--- a/httemplate/elements/select-part_pkg.html
+++ b/httemplate/elements/select-part_pkg.html
@@ -125,6 +125,7 @@ if ($opt{'toggle_disabled'}) {
     order_by
     pre_options
     post_options
+    select
   ) ) {
     die "Cannot use toggle_disabled with $someopt"
       if exists $opt{$someopt};
@@ -155,6 +156,9 @@ if ( exists($opt{'classnum'}) && defined($opt{'classnum'}) ) {
 die 'Use of toggle_disabled with classnum has not been implemented'
   if 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'};
diff --git a/httemplate/misc/xmlhttp-part_pkg.cgi b/httemplate/misc/xmlhttp-part_pkg.cgi
index 1878330..885d346 100644
--- a/httemplate/misc/xmlhttp-part_pkg.cgi
+++ b/httemplate/misc/xmlhttp-part_pkg.cgi
@@ -3,6 +3,10 @@
 
 # default returned records must maintain consistency with /elements/select-part_pkg.html
 
+my $select = 'part_pkg.*, setup_option.optionvalue AS _setup_fee,
+                          recur_option.optionvalue AS _recur_fee';
+my $addl_from .= FS::part_pkg->join_options_sql;
+
 my $extra_sql = ' WHERE ' . FS::part_pkg->curuser_pkgs_sql;
 
 # equivalent to agent_virt=1 and agent_null=1 in /elements/select-table.html
@@ -13,6 +17,8 @@ $extra_sql .= ' AND ' .
 
 my @records = qsearch( {
   'table'     => 'part_pkg',
+  'select'    => $select,
+  'addl_from' => $addl_from,
   'hashref'   => {},
   'extra_sql' => $extra_sql,
   'order_by'  => "ORDER BY pkg",
@@ -26,6 +32,4 @@ my @return = map {
   }
 } @records;
 
-print STDERR Dumper(\@return);
-
 </%init>

commit 031ed2267f963d8538000f9ca6b9abceca46e779
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Mar 8 14:45:18 2016 -0600

    RT#21463: Option to show disabled package definitions [bug fix]

diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html
index e5692a7..ba1d7b7 100644
--- a/httemplate/elements/select-part_pkg.html
+++ b/httemplate/elements/select-part_pkg.html
@@ -79,7 +79,7 @@ function toggle_disabled_part_pkg (id,showdisabled,noload) {
     if (showdisabled || selected[pkginfo.pkgpart] || !pkginfo.disabled) {
       var newopt = document.createElement('option');
       newopt.value = pkginfo.pkgpart;
-      newopt.label = pkginfo.label;
+      newopt.text = pkginfo.label;
       newopt.selected = selected[newopt.value] ? true : false;
       selectbox.appendChild(newopt);
     }

commit f2c029cf7e49a7597d25d17562a054d6e37731b5
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Wed Mar 2 22:41:51 2016 -0600

    RT#21463: Option to show disabled package definitions [v4 merge of ajax refactor]

diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html
index 9743780..e5692a7 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' ],
+   ) %>
+
 <SCRIPT>
-function toggle_disabled (id, disabled_on) {
+var toggle_disabled_part_pkg_list = undefined;
+function toggle_disabled_part_pkg (id,showdisabled,noload) {
+  // remove link text, only put it back if this works
+  var trigger = document.getElementById(id+'_switch');
+  trigger.innerHTML = '';
+  // if needed, load pkg_list before trying again
+  var pkg_list = toggle_disabled_part_pkg_list;
+  if (!pkg_list && !noload) {
+    load_part_pkg(
+      function (result) {
+        result = JSON.parse(result);
+        if (result) {
+          toggle_disabled_part_pkg_list = result;
+          toggle_disabled_part_pkg(id,showdisabled,true);
+        } else {
+          console.log('Error loading pkg list');
+        }
+      }
+    );
+    return;
+  }
+  if (!(pkg_list && pkg_list.length)) {
+    console.log('Cannot load pkg list, or pkg list empty');
+    return;
+  }
+  // remove all existing options, tracking which are selected
   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 selected = {};
+  for (var i = selectbox.length - 1; i >= 0; i--) {
+    var nextopt = selectbox.options[i];
+    selected[nextopt.value] = nextopt.selected;
+    nextopt.parentNode.removeChild(nextopt);
+  }
+  // regenerate options list from pkg list
+  for (var i = 0; i < pkg_list.length; i++) {
+    var pkginfo = pkg_list[i];
+    if (showdisabled || selected[pkginfo.pkgpart] || !pkginfo.disabled) {
+      var newopt = document.createElement('option');
+      newopt.value = pkginfo.pkgpart;
+      newopt.label = pkginfo.label;
+      newopt.selected = selected[newopt.value] ? true : false;
+      selectbox.appendChild(newopt);
     }
   }
-  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) };
+  trigger.innerHTML = showdisabled ? '<% $hidetext %>' : '<% $showtext %>';
+  trigger.onclick = function () { toggle_disabled_part_pkg(id,(showdisabled ? 0 : 1)) };
 }
 </SCRIPT>
 
@@ -56,8 +94,8 @@ function toggle_disabled (id, disabled_on) {
 <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>
+  ONCLICK="toggle_disabled_part_pkg('<% $opt{'id'} %>',<% $showdisabled ? '0' : '1' %>)"
+  ID="<% $opt{'id'} %>_switch"><% $showdisabled ? $hidetext : $showtext %></A>
 
 % } # 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,6 +151,10 @@ 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{'select'} = 'part_pkg.*, setup_option.optionvalue AS _setup_fee,
                               recur_option.optionvalue AS _recur_fee'
   unless $opt{'select'};
@@ -92,4 +163,7 @@ $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");
+
 </%init>
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html
index cc79f30..6fb6b38 100644
--- a/httemplate/elements/select-table.html
+++ b/httemplate/elements/select-table.html
@@ -51,12 +51,9 @@ Example:
                             #<SELECT> element
     'onchange'       => '', #javascript code
 
-    #params controlling the <OPTION>s
+    #params (well, a param) 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)
@@ -111,10 +108,8 @@ 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 %>"
 %           }
diff --git a/httemplate/misc/xmlhttp-part_pkg.cgi b/httemplate/misc/xmlhttp-part_pkg.cgi
new file mode 100644
index 0000000..1878330
--- /dev/null
+++ b/httemplate/misc/xmlhttp-part_pkg.cgi
@@ -0,0 +1,31 @@
+<% encode_json( \@return ) %>\
+<%init>
+
+# default returned records must maintain consistency with /elements/select-part_pkg.html
+
+my $extra_sql = ' WHERE ' . FS::part_pkg->curuser_pkgs_sql;
+
+# equivalent to agent_virt=1 and agent_null=1 in /elements/select-table.html
+$extra_sql .= ' AND ' . 
+  $FS::CurrentUser::CurrentUser->agentnums_sql(
+    'null' => 1,
+  );
+
+my @records = qsearch( {
+  'table'     => 'part_pkg',
+  'hashref'   => {},
+  'extra_sql' => $extra_sql,
+  'order_by'  => "ORDER BY pkg",
+});
+
+my @return = map { 
+  {
+    'pkgpart'  => $_->pkgpart,
+    'label'    => $_->pkg_comment_only,
+    'disabled' => $_->disabled,
+  }
+} @records;
+
+print STDERR Dumper(\@return);
+
+</%init>

commit 80cbfd9890ba84c49ee40164e1ec27aff05c272a
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 22a24be..9743780 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 6fb6b38..cc79f30 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           |  121 +++++++++++++++++++-
 httemplate/misc/xmlhttp-part_pkg.cgi               |   35 ++++++
 3 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 httemplate/misc/xmlhttp-part_pkg.cgi




More information about the freeside-commits mailing list