[freeside-commits] branch FREESIDE_4_BRANCH updated. 6e2291b7667bb71bd3e4f260af217b020f796f2c

Christopher Burger burgerc at freeside.biz
Fri Feb 22 13:35:55 PST 2019


The branch, FREESIDE_4_BRANCH has been updated
       via  6e2291b7667bb71bd3e4f260af217b020f796f2c (commit)
       via  799603d8681d4a10e87302d015d3c19602cc7676 (commit)
       via  253f2623c4ee813bd104661f0e1fdf6adb239144 (commit)
       via  167a699ce4eaa68a56cd8d38a79696840ef46679 (commit)
      from  3e97c5dddd83bd5268c6f54a59d96421b3ca8fbe (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 6e2291b7667bb71bd3e4f260af217b020f796f2c
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Thu Feb 21 12:56:24 2019 -0500

    RT# 82092 - Removed reload of DB Schema

diff --git a/httemplate/edit/process/part_virtual_field.html b/httemplate/edit/process/part_virtual_field.html
index dc03ea4c8..401e52701 100644
--- a/httemplate/edit/process/part_virtual_field.html
+++ b/httemplate/edit/process/part_virtual_field.html
@@ -29,8 +29,10 @@
             my $dbdef_file = "/usr/local/etc/freeside/dbdef.".datasrc;
             my $dbdef = new_native DBIx::DBSchema $dbh;
             $dbdef->save($dbdef_file);
-            delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload
-            reload_dbdef($dbdef_file);
+            ## Stop reload of db schema as only reload current process and not others. Could be a pain to diagnose error.  
+            ## Restart Apache to reload DB Schema for all.
+            #delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload
+            #reload_dbdef($dbdef_file);
             
             warn "cf add done schema modification, time=".time;
         }

commit 799603d8681d4a10e87302d015d3c19602cc7676
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Thu Feb 21 12:17:10 2019 -0500

    RT# 82092 - Updated text to remind customer to restart apache after creating custom field

diff --git a/httemplate/edit/part_virtual_field.html b/httemplate/edit/part_virtual_field.html
index f3fb53065..8b8b33d0b 100644
--- a/httemplate/edit/part_virtual_field.html
+++ b/httemplate/edit/part_virtual_field.html
@@ -21,8 +21,8 @@
                          ],
             'edit_callback' => $callback,
             'error_callback' => $callback,
-            'html_init'      => 'Please be patient after clicking the button as 
-                                this process may take more than 10 seconds.
+            'html_init'      => 'Please be patient after clicking the button as this process may take more than 10 seconds.<br>
+                                 You will also need to restart Apache after adding the custom field.
                                 <br><br>',
           )
 %>
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index 1711b0118..19110e18b 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -34,6 +34,11 @@ Example:
 
    'clear_on_error' => [ 'form_field1', 'form_field2', ... ],
 
+   ## message will be returned to redirect page as cookie and read by header.html
+   ## append =status, =warning, =error to change color of message box.  Default is status
+   ## status is green, warning is yellow, and error is red
+   'message'        => [ 'My message=status', 'Please restart=warning' ],
+
                   #pass an arrayref of hashrefs for multiple m2ms or m2names
                   #be certain you incorporate m2m_Common if you see error: param
 
@@ -208,7 +213,16 @@ process();
   </HTML>
 
 %} else {
-<% $cgi->redirect($redirect) %>
+%  my $cookie;
+%  $cookie = CGI::Cookie->new(
+%                        -name    => 'freeside_status',
+%                        -value   => $messages,
+%                        -expires => '+5m',
+%                      ) if $messages;
+   <% $cgi->redirect( -uri    => $redirect,
+                      -cookie => $cookie,
+      )
+   %>
 %}
 <%init>
 
@@ -510,6 +524,8 @@ if ( !$error ) {
   }
 }
 
+my $messages = $opt{'message'} ? $opt{'message'} : '';
+
 my $edit_ext = $opt{'edit_ext'} || 'html';
 my $error_redirect = $opt{'error_redirect'}
                      || popurl(2)."$table.$edit_ext";
diff --git a/httemplate/edit/process/part_virtual_field.html b/httemplate/edit/process/part_virtual_field.html
index 97be7e65e..dc03ea4c8 100644
--- a/httemplate/edit/process/part_virtual_field.html
+++ b/httemplate/edit/process/part_virtual_field.html
@@ -1,6 +1,7 @@
 <% include( 'elements/process.html',
     'table'          => 'part_virtual_field',
     'viewall_dir'    => 'browse',
+    'message'        => [ 'Your custom field has been created, but will not be available untill Apache has been restarted.=warning', ],
     'precheck_callback' => sub {
         my ($cgi) = @_;
         $act = 'edit' if $cgi->param('vfieldpart');
@@ -25,7 +26,7 @@
             $dbh->commit or die $dbh->errstr; 
 
             # reload schema
-            my $dbdef_file = "/usr/local/etc/freeside/dbdef.".datasrc # XXX: fix this
+            my $dbdef_file = "/usr/local/etc/freeside/dbdef.".datasrc;
             my $dbdef = new_native DBIx::DBSchema $dbh;
             $dbdef->save($dbdef_file);
             delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload
diff --git a/httemplate/elements/header-full.html b/httemplate/elements/header-full.html
index 5586a0a85..c73cf0463 100644
--- a/httemplate/elements/header-full.html
+++ b/httemplate/elements/header-full.html
@@ -204,8 +204,10 @@ Example:
 % if ( $cookies{freeside_status} ) {
     <BR>
 %   foreach my $status_msg ( $cookies{freeside_status}->value ) {
-      <TABLE CLASS="fsinnerbox" STYLE="background-color:#eeffee"><TR>
-        <TD><IMG SRC="<% $fsurl %>images/tick.png"> <% $status_msg |h %></TD>
+%     my ($message, $type) = split /=/, $status_msg;
+%     $type ||= 'status';
+      <TABLE CLASS="fsinnerbox" STYLE="background-color:<% $status_color{$type} %>"><TR>
+        <TD><IMG SRC="<% $fsurl %>images/tick.png"> <% $message |h %></TD>
       </TR></TABLE>
 %   }
     <script src="<% $fsurl %>elements/js.cookie.js"></script>
@@ -270,4 +272,7 @@ if ( scalar(@agentnums) == 1 ) {
   $company_url  = $conf->config('company_url');
 }
 
+## status->green(#eeffee), warning->yellow(#fdfd96), error->red(#f97c7c)
+my %status_color = ( 'status' => '#eeffee', 'warning' => '#fefbd0', 'error' => '#f97c7c', );
+
 </%init>

commit 253f2623c4ee813bd104661f0e1fdf6adb239144
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Feb 19 15:57:51 2019 -0500

    RT# 82092 - added field validation

diff --git a/httemplate/edit/process/part_virtual_field.html b/httemplate/edit/process/part_virtual_field.html
index 6a8008db7..97be7e65e 100644
--- a/httemplate/edit/process/part_virtual_field.html
+++ b/httemplate/edit/process/part_virtual_field.html
@@ -43,7 +43,9 @@
 my $act = 'add';
 
 ## make cgi->param("name") lowercase
-$cgi->param('name' => lc $cgi->param('name'));
+my $vcf_name = $cgi->param('name');
+$vcf_name =~ s/\s/_/g; $vcf_name =~ s/[^A-Za-z0-9\-_]//g;
+$cgi->param('name' => lc $vcf_name);
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

commit 167a699ce4eaa68a56cd8d38a79696840ef46679
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Feb 19 14:42:25 2019 -0500

    RT# 82092 - custom fields now save and fixed so name label is displayed insted of actual field name

diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index dfe6f1871..31cc8a054 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -5,7 +5,7 @@ use strict;
 use charnames ':full';
 use vars qw( $AUTOLOAD
              %virtual_fields_cache %fk_method_cache $fk_table_cache
-             $money_char $lat_lower $lon_upper
+             %virtual_fields_hash_cache $money_char $lat_lower $lon_upper
              $use_placeholders
            );
 use Carp qw(carp cluck croak confess);
@@ -1810,6 +1810,41 @@ sub virtual_fields {
 
 }
 
+=item virtual_fields_hash [ TABLE ]
+
+Returns a list of virtual field records as a hash defined for the table.  This should not
+be exported, and should only be called as an instance or class method.
+
+=cut
+
+sub virtual_fields_hash {
+  my $self = shift;
+  my $table;
+  $table = $self->table or confess "virtual_fields called on non-table";
+
+  confess "Unknown table $table" unless dbdef->table($table);
+
+  return () unless dbdef->table('part_virtual_field');
+
+  unless ( $virtual_fields_hash_cache{$table} ) {
+    $virtual_fields_hash_cache{$table} = [];
+    my $concat = [ "'cf_'", "name" ];
+    my $select = concat_sql($concat).' as name, label, length';
+    my @vfields = qsearch({
+      select => $select,
+      table => 'part_virtual_field',
+      hashref => { 'dbtable' => $table, },
+    });
+
+    foreach (@vfields) {
+      push @{ $virtual_fields_hash_cache{$table} }, $_->{Hash};
+    }
+  }
+
+  @{$virtual_fields_hash_cache{$table}};
+
+}
+
 =item process_batch_import JOB OPTIONS_HASHREF PARAMS
 
 Processes a batch import as a queued JSRPC job
diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm
index 49854f7ca..a565ee45b 100644
--- a/FS/FS/part_svc.pm
+++ b/FS/FS/part_svc.pm
@@ -707,6 +707,11 @@ sub _svc_defs {
         warn "skipping disabled service FS::$mod" if $DEBUG;
         next;
       }
+
+      foreach ("FS::$mod"->virtual_fields_hash) {
+        $info->{'fields'}->{$_->{'name'}} = $_->{'label'};
+      }
+
       $info{$mod} = $info;
 
       # all svc_* modules are required to have h_svc_* modules for invoice
diff --git a/FS/FS/part_virtual_field.pm b/FS/FS/part_virtual_field.pm
index 0011ec6d3..63712b763 100755
--- a/FS/FS/part_virtual_field.pm
+++ b/FS/FS/part_virtual_field.pm
@@ -59,6 +59,7 @@ Create a new record.  To add the record to the database, see "insert".
 
 sub table { 'part_virtual_field'; }
 sub virtual_fields { () }
+sub virtual_fields_hash { () }
 
 =item widget UI_TYPE MODE [ VALUE ]
 
@@ -81,19 +82,20 @@ VALUE (optional) is the current value of the field.
 
 sub widget {
   my $self = shift;
-  my ($ui_type, $mode, $value) = @_;
+  my ($ui_type, $mode, $value, $header_col_type) = @_;
+  $header_col_type = 'TD' unless $header_col_type;
   my $text;
   my $label = $self->label || $self->name;
 
   if ($ui_type eq 'HTML') {
     if ($mode eq 'view') {
-      $text = q!<TR><TD ALIGN="right">! . $label . 
-              q!</TD><TD BGCOLOR="#ffffff">! . $value .
+      $text = q!<TR><!.$header_col_type.q! ALIGN="right">! . $label .
+              q!</!.$header_col_type.q!><TD BGCOLOR="#ffffff">! . $value .
               q!</TD></TR>! . "\n";
     } elsif ($mode eq 'edit') {
-      $text = q!<TR><TD ALIGN="right">! . $label .
-              q!</TD><TD>!;
-        $text .= q!<INPUT NAME="! . $self->name .
+      $text = q!<TR><!.$header_col_type.q! ALIGN="right">! . $label .
+              q!</!.$header_col_type.q!><TD>!;
+        $text .= q!<INPUT TYPE=text NAME="! . $self->name .
                 q!" VALUE="! . escapeHTML($value) . q!"!;
         if ($self->length) {
           $text .= q! SIZE="! . $self->length . q!"!;
diff --git a/httemplate/browse/router.cgi b/httemplate/browse/router.cgi
index 85512f8df..c7713f313 100644
--- a/httemplate/browse/router.cgi
+++ b/httemplate/browse/router.cgi
@@ -7,24 +7,9 @@
                                        'extra_sql' => $extra_sql,
                                      },
                 'count_query'     => "SELECT count(*) from router $count_sql",
-                'header'          => [ 'Router name',
-                                       'Address block(s)',
-                                       'IP addressing',
-                                       'Action',
-                                     ],
-                'fields'          => [ 'routername',
-                                       sub { join( '<BR>', map { $_->NetAddr }
-                                                               shift->addr_block
-                                                 );
-                                           },
-                                       sub { shift->manual_addr ? 'Manual' : 'Automatic' },
-                                       sub { 'Delete' },
-                                     ],
-                'links'           => [ [ "${p2}edit/router.cgi?", 'routernum' ],
-                                       '',
-                                       '',
-                                       [ "${p}misc/delete-router.html?", 'routernum' ],
-                                     ],
+                'header'          => [ @header_fields ],
+                'fields'          => [ @fields ],
+                'links'           => [ @links ],
                 'agent_virt'      => 1,
                 'agent_null_right'=> "Broadband global configuration",
                 'agent_pos'       => 1,
@@ -32,6 +17,8 @@
 %>
 <%init>
 
+use CGI qw(escapeHTML);
+
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Broadband configuration')
   || $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration');
@@ -52,6 +39,26 @@ if ($cgi->param('hidecustomerrouters') eq '1') {
   $cgi->delete('hidecustomerrouters');
 }
 
+my @header_fields = ('Router name', 'Address block(s)', 'IP addressing');
+my @fields = ( 'routername',
+               sub { join( '<BR>', map { $_->NetAddr } shift->addr_block); },
+               sub { shift->manual_addr ? 'Manual' : 'Automatic' },
+             );
+my @links = ( [ "${p2}edit/router.cgi?", 'routernum' ],
+              '',
+              '',
+            );
+
+foreach (FS::router->virtual_fields_hash) {
+  push @header_fields, escapeHTML($_->{'label'});
+  push @fields, escapeHTML($_->{'name'});
+  push @links, '';
+}
+
+push @header_fields, 'Action';
+push @fields, sub { 'Delete' };
+push @links, [ "${p}misc/delete-router.html?", 'routernum' ];
+
 my $count_sql = $extra_sql.  ( $extra_sql =~ /WHERE/ ? ' AND' : 'WHERE' ).
   $FS::CurrentUser::CurrentUser->agentnums_sql(
     'null_right' => 'Broadband global configuration',
diff --git a/httemplate/edit/cust_main/basics.html b/httemplate/edit/cust_main/basics.html
index 97313aada..b45523f4f 100644
--- a/httemplate/edit/cust_main/basics.html
+++ b/httemplate/edit/cust_main/basics.html
@@ -117,7 +117,7 @@
 </SCRIPT>
 
 % foreach my $field ($cust_main->virtual_fields) {
-    <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
+    <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field), 'TH') %>
 % }
 
 %# tags
diff --git a/httemplate/edit/elements/part_svc_column.html b/httemplate/edit/elements/part_svc_column.html
index bdbce7c79..075f15e2c 100644
--- a/httemplate/edit/elements/part_svc_column.html
+++ b/httemplate/edit/elements/part_svc_column.html
@@ -97,7 +97,7 @@ my %communigate_fields = (
     <TD ROWSPAN=2 CLASS="grid">
       <INPUT NAME="<% $svcdb %>__<% $field %>_label"
              STYLE="text-align: right"
-             VALUE="<% $part_svc_column->columnlabel || $def->{'label'} |h %>">
+             VALUE="<% $part_svc_column->columnlabel || escapeHTML($def->{'label'}) |h %>">
     </TD>
 
     <TD ROWSPAN=1 CLASS="grid">
diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html
index e1c309080..e5dc55979 100644
--- a/httemplate/edit/elements/svc_Common.html
+++ b/httemplate/edit/elements/svc_Common.html
@@ -227,7 +227,8 @@
                        $html .=
                          $svc_x->pvf($field)->widget( 'HTML',
                                                       'edit', 
-                                                      $svc_x->getfield($field)
+                                                      $svc_x->getfield($field),
+                                                      'TH'
                                                     );
                      }
                    }
diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi
index e1a5bc6e2..baacd5e7e 100755
--- a/httemplate/edit/process/cust_main.cgi
+++ b/httemplate/edit/process/cust_main.cgi
@@ -97,6 +97,11 @@ my $new = new FS::cust_main ( {
   (map { ( "ship_$_", '' ) } (FS::cust_main->location_fields))
 } );
 
+# add any virtual fields to the new cust_main record
+foreach ($new->virtual_fields) {
+  $new->setfield($_, scalar($cgi->param($_)));
+}
+
 warn Dumper( $new ) if $DEBUG > 1;
 
 if ( $duplicate_of ) {
diff --git a/httemplate/edit/process/part_virtual_field.html b/httemplate/edit/process/part_virtual_field.html
index e734d9616..6a8008db7 100644
--- a/httemplate/edit/process/part_virtual_field.html
+++ b/httemplate/edit/process/part_virtual_field.html
@@ -42,6 +42,9 @@
 
 my $act = 'add';
 
+## make cgi->param("name") lowercase
+$cgi->param('name' => lc $cgi->param('name'));
+
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html
index cb465f57e..d2deae245 100644
--- a/httemplate/view/cust_main/misc.html
+++ b/httemplate/view/cust_main/misc.html
@@ -172,7 +172,7 @@
 % }
 
 % foreach (sort { $a cmp $b } $cust_main->virtual_fields) {
-    <% $cust_main->pvf($_)->widget('HTML', 'view', $cust_main->getfield($_)) %>
+    <% $cust_main->pvf($_)->widget('HTML', 'view', $cust_main->getfield($_), 'TH') %>
 % }
 
 </TABLE>

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

Summary of changes:
 FS/FS/Record.pm                                 | 37 ++++++++++++++++++++-
 FS/FS/part_svc.pm                               |  5 +++
 FS/FS/part_virtual_field.pm                     | 14 ++++----
 httemplate/browse/router.cgi                    | 43 ++++++++++++++-----------
 httemplate/edit/cust_main/basics.html           |  2 +-
 httemplate/edit/elements/part_svc_column.html   |  2 +-
 httemplate/edit/elements/svc_Common.html        |  3 +-
 httemplate/edit/part_virtual_field.html         |  4 +--
 httemplate/edit/process/cust_main.cgi           |  5 +++
 httemplate/edit/process/elements/process.html   | 18 ++++++++++-
 httemplate/edit/process/part_virtual_field.html | 14 ++++++--
 httemplate/elements/header-full.html            |  9 ++++--
 httemplate/view/cust_main/misc.html             |  2 +-
 13 files changed, 121 insertions(+), 37 deletions(-)




More information about the freeside-commits mailing list