diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Record.pm | 37 | ||||
-rw-r--r-- | FS/FS/part_svc.pm | 5 | ||||
-rwxr-xr-x | FS/FS/part_virtual_field.pm | 14 |
3 files changed, 49 insertions, 7 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 2bffdc377..af8c10196 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -4,7 +4,7 @@ use strict; use charnames ':full'; use vars qw( $AUTOLOAD @ISA @EXPORT_OK $DEBUG %virtual_fields_cache - $money_char $lat_lower $lon_upper + %virtual_fields_hash_cache $money_char $lat_lower $lon_upper $me $nowarn_identical $nowarn_classload $no_update_diff $no_history $qsearch_qualify_columns @@ -1621,6 +1621,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 b387085f5..7bf3d5aaf 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -708,6 +708,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; } } diff --git a/FS/FS/part_virtual_field.pm b/FS/FS/part_virtual_field.pm index 4e6d2e4bd..1df4984e1 100755 --- a/FS/FS/part_virtual_field.pm +++ b/FS/FS/part_virtual_field.pm @@ -62,6 +62,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 ] @@ -84,19 +85,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!"!; |