[freeside-commits] branch master updated. 057fc61586d26199005660b908ece68a7a1da681

Christopher Burger burgerc at freeside.biz
Wed Jan 9 09:28:47 PST 2019


The branch, master has been updated
       via  057fc61586d26199005660b908ece68a7a1da681 (commit)
      from  0edb6050aeb65200869a12d83d8de794ed384154 (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 057fc61586d26199005660b908ece68a7a1da681
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Wed Jan 9 12:28:19 2019 -0500

    RT# 81249 - added ability to validate price plan option fields

diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index fb0570647..356c0c038 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -693,6 +693,14 @@ sub replace {
   '';
 }
 
+sub validate_number {
+  my ($option, $valref) = @_;
+  $$valref = 0 unless $$valref;
+  return "Invalid $option"
+    unless ($$valref) = ($$valref =~ /^\s*(\d+)\s*$/);
+  return '';
+}
+
 =item check
 
 Checks all fields to make sure this is a valid package definition.  If
diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm
index 49e43e915..715d5c09b 100644
--- a/FS/FS/part_pkg/voip_cdr.pm
+++ b/FS/FS/part_pkg/voip_cdr.pm
@@ -166,9 +166,13 @@ tie my %accountcode_tollfree_field, 'Tie::IxHash',
                          },
 
     'use_cdrtypenum' => { 'name' => 'Only charge for CDRs where the CDR Type is set to this cdrtypenum: ',
+                          'validate' => \&FS::part_pkg::validate_number,
+                          'js_validate' => 'digits',
                          },
     
     'ignore_cdrtypenum' => { 'name' => 'Do not charge for CDRs where the CDR Type is set to this cdrtypenum: ',
+                             'validate' => \&FS::part_pkg::validate_number,
+                             'js_validate' => 'digits',
                          },
 
     'use_calltypenum' => { 'name' => 'Only charge for CDRs where the CDR Call Type is set to this calltypenum: ',
diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm
index efaf586ab..67c53af25 100644
--- a/FS/FS/part_pkg/voip_inbound.pm
+++ b/FS/FS/part_pkg/voip_inbound.pm
@@ -64,9 +64,13 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                          },
 
     'use_cdrtypenum' => { 'name' => 'Only charge for CDRs where the CDR Type is set to this cdrtypenum: ',
+                          'validate' => \&FS::part_pkg::validate_number,
+                          'js_validate' => 'digits',
                          },
     
     'ignore_cdrtypenum' => { 'name' => 'Do not charge for CDRs where the CDR Type is set to this cdrtypenum: ',
+                             'validate' => \&FS::part_pkg::validate_number,
+                             'js_validate' => 'digits',
                          },
 
     'use_calltypenum' => { 'name' => 'Only charge for CDRs where the CDR Call Type is set to this cdrtypenum: ',
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index feec098f3..5e7b30674 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -820,6 +820,18 @@ Example:
       : $opt{'html_bottom'}
 %>
 
+%     ## set extra field values for validation.  ie price plan fields
+%     my $extra_fields_to_validate = $opt{'extra_fields_validate'};
+%     my %validate_error_messages = (
+%       'digits' => 'Please only enter numbers here.',
+%       'email'  => 'Please enter a valid email here.',
+%     );
+%     foreach my $extra_fields (keys %$extra_fields_to_validate) {
+%       my $validate_type = $extra_fields_to_validate->{$extra_fields};
+%       $js_form_validate->{edit_topform}->{validate_fields}{$extra_fields} = $validate_type.': true';
+%       $js_form_validate->{edit_topform}->{error_message}{$extra_fields} = $validate_error_messages{$validate_type};
+%     }
+
 % unless ($opt{'embed'}) {
 
   <BR>
diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi
index dd8cb13a2..78e4427e0 100755
--- a/httemplate/edit/part_pkg.cgi
+++ b/httemplate/edit/part_pkg.cgi
@@ -12,6 +12,7 @@
                                 include('/elements/init_calendar.html').
                                 $javascript,
      'html_bottom'           => $html_bottom,
+     'extra_fields_validate' => $validate_priceplan_fields,
      'body_etc'              =>
        'onLoad="agent_changed(document.edit_topform.agentnum);
                 aux_planchanged(document.edit_topform.plan);
@@ -896,6 +897,15 @@ tie my %plan_labels, 'Tie::IxHash',
   map {  $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
       keys %plans;
 
+my $validate_priceplan_fields = {};
+foreach my $priceplan (keys %plans) {
+  my $plan_fields = $plans{$priceplan}->{fields};
+  foreach my $price_plan_field (keys %$plan_fields) {
+    $validate_priceplan_fields->{$priceplan."__".$price_plan_field} = $plan_fields->{$price_plan_field}->{"js_validate"}
+      if exists $plan_fields->{$price_plan_field}->{"js_validate"};
+  }
+}
+
 my $html_bottom = sub {
   my( $object ) = @_;
 

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

Summary of changes:
 FS/FS/part_pkg.pm                  |  8 ++++++++
 FS/FS/part_pkg/voip_cdr.pm         |  4 ++++
 FS/FS/part_pkg/voip_inbound.pm     |  4 ++++
 httemplate/edit/elements/edit.html | 12 ++++++++++++
 httemplate/edit/part_pkg.cgi       | 10 ++++++++++
 5 files changed, 38 insertions(+)




More information about the freeside-commits mailing list