diff options
author | levinse <levinse> | 2011-07-22 18:59:27 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-07-22 18:59:27 +0000 |
commit | c405e80203f323a83b447d6fc899dbba32d52f2a (patch) | |
tree | aa7cc7ad31c43eb012ad3d9b787ee0a51bb6b4ac /httemplate | |
parent | 99e8e2006117bd4b97ebb1daf897cc257265dc3f (diff) |
custom fields, RT11714
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/part_virtual_field.html | 35 | ||||
-rw-r--r-- | httemplate/edit/cust_main/top_misc.html | 4 | ||||
-rwxr-xr-x | httemplate/edit/part_svc.cgi | 13 | ||||
-rw-r--r-- | httemplate/edit/part_virtual_field.html | 44 | ||||
-rw-r--r-- | httemplate/edit/process/part_virtual_field.html | 48 | ||||
-rw-r--r-- | httemplate/elements/menu.html | 2 | ||||
-rw-r--r-- | httemplate/view/cust_main/misc.html | 4 |
7 files changed, 136 insertions, 14 deletions
diff --git a/httemplate/browse/part_virtual_field.html b/httemplate/browse/part_virtual_field.html new file mode 100644 index 000000000..1d8fad4c6 --- /dev/null +++ b/httemplate/browse/part_virtual_field.html @@ -0,0 +1,35 @@ +<% include( 'elements/browse.html', + 'title' => 'Custom field definitions', + 'menubar' => [ 'Add a new field' => $p.'edit/part_virtual_field.html', ], + 'name' => 'custom fields', + 'query' => { 'table' => 'part_virtual_field', + 'hashref' => {}, + 'order_by' => 'ORDER BY dbtable', + }, + 'count_query' => 'SELECT COUNT(1) from part_virtual_field', + 'header' => [ '#', + 'Table', + 'Name', + 'Length', + 'Label', + ], + 'fields' => [ 'vfieldpart', + 'dbtable', + 'name', + 'length', + 'label', + ], + 'links' => [ [ $p.'edit/part_virtual_field.html?', 'vfieldpart' ], + '', + '', + '', + '', + ], + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +</%init> diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html index a7545a045..1277d148e 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/top_misc.html @@ -1,5 +1,9 @@ <% &ntable("#cccccc") %> +% foreach my $field ($cust_main->virtual_fields) { + <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %> +% } + %# tags <& /elements/tr-select-cust_tag.html, 'custnum' => $custnum, diff --git a/httemplate/edit/part_svc.cgi b/httemplate/edit/part_svc.cgi index 8ca019649..964e08821 100755 --- a/httemplate/edit/part_svc.cgi +++ b/httemplate/edit/part_svc.cgi @@ -15,20 +15,7 @@ Service <INPUT TYPE="text" NAME="svc" VALUE="<% $hashref->{svc} %>"><BR> <BR> - -% #YUCK. false laziness w/part_svc.pm. go away virtual fields, please % my %vfields; -% foreach my $svcdb ( FS::part_svc->svc_tables() ) { -% eval "use FS::$svcdb;"; -% my $self = "FS::$svcdb"->new; -% $vfields{$svcdb} = {}; -% foreach my $field ($self->virtual_fields) { # svc_Common::virtual_fields with a null svcpart returns all of them -% my $pvf = $self->pvf($field); -% $vfields{$svcdb}->{$field} = $pvf; -% #warn "\$vfields{$svcdb}->{$field} = $pvf"; -% } #next $field -% } #next $svcdb -% % #code duplication w/ edit/part_svc.cgi, should move this hash to part_svc.pm % # and generalize the subs % # condition sub is tested to see whether to disable display of this choice diff --git a/httemplate/edit/part_virtual_field.html b/httemplate/edit/part_virtual_field.html new file mode 100644 index 000000000..f3fb53065 --- /dev/null +++ b/httemplate/edit/part_virtual_field.html @@ -0,0 +1,44 @@ +<% include('elements/edit.html', + 'name_singular' => 'custom field', + 'viewall_dir' => 'browse', + 'table' => 'part_virtual_field', + 'labels' => { 'vfieldpart' => '', + 'dbtable' => 'Table', + 'name' => 'Name', + 'length' => 'Length', + 'label' => 'Label', + 'dbtable_dummy' => 'Table', + }, + 'fields' => [ + { field=>'vfieldpart', type=>'hidden', }, + { field=>'name', type=>'text', }, + { field => 'dbtable', + type => 'select', + options => [ 'svc_broadband', 'router', 'cust_main', ], + }, + { field=>'label', type=>'text', }, + { field=>'length', type=>'text', }, + ], + 'edit_callback' => $callback, + 'error_callback' => $callback, + 'html_init' => 'Please be patient after clicking the button as + this process may take more than 10 seconds. + <br><br>', + ) +%> +<%init> + +my $callback = sub { + my ($cgi, $object, $fields) = (shift, shift, shift); + my @edit_fixed_fields = qw( dbtable name length ); + foreach my $f ( @{$fields} ) { + # XXX: editing anything other than label is disabled for now + $f->{type} = 'fixed' + if $object->vfieldpart && grep { $f->{field} eq $_ } @edit_fixed_fields; + } +}; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +</%init> diff --git a/httemplate/edit/process/part_virtual_field.html b/httemplate/edit/process/part_virtual_field.html new file mode 100644 index 000000000..e734d9616 --- /dev/null +++ b/httemplate/edit/process/part_virtual_field.html @@ -0,0 +1,48 @@ +<% include( 'elements/process.html', + 'table' => 'part_virtual_field', + 'viewall_dir' => 'browse', + 'precheck_callback' => sub { + my ($cgi) = @_; + $act = 'edit' if $cgi->param('vfieldpart'); + my @permitted_tables = qw( svc_broadband router cust_main ); + return 'Table not in list of permitted tables' + unless $cgi->param('dbtable') + && grep { $_ eq $cgi->param('dbtable') } @permitted_tables; + ''; + }, + 'noerror_callback' => sub { + my ($cgi, $object) = @_; + if ( $act eq 'add' ) { + use FS::Schema qw( reload_dbdef ); + warn "cf add started schema modification, time=".time; + my $dbh = dbh; + my $sql = "ALTER TABLE ".$object->dbtable." ADD COLUMN cf_".$object->name." varchar(".$object->length.")"; + $dbh->do($sql) or die $dbh->errstr; + $sql = "ALTER TABLE h_".$object->dbtable." ADD COLUMN cf_".$object->name." varchar(".$object->length.")"; + $dbh->do($sql) or die $dbh->errstr; + + # apparently nothing happens w/o commit here - but is this OK? + $dbh->commit or die $dbh->errstr; + + # reload schema + my $dbdef_file = "/usr/local/etc/freeside/dbdef.".datasrc # XXX: fix this + 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); + + warn "cf add done schema modification, time=".time; + } + # XXX: edit is going to be harder: possibly add editing length and renaming column + ''; + }, +) +%> +<%init> + +my $act = 'add'; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +</%init> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index cd9fe06a1..9214819f2 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -538,7 +538,7 @@ $config_misc{'Advertising sources'} = [ $fsurl.'browse/part_referral.html', 'Whe if $curuser->access_right('Edit advertising sources') || $curuser->access_right('Edit global advertising sources'); if ( $curuser->access_right('Configuration') ) { - $config_misc{'Virtual fields'} = [ $fsurl.'browse/part_virtual_field.cgi', 'Locally defined fields', ]; + $config_misc{'Custom fields'} = [ $fsurl.'browse/part_virtual_field.html', 'Locally defined fields', ]; $config_misc{'Message catalog'} = [ $fsurl.'browse/msgcat.html', 'Change error messages and other customizable labels for each locale' ]; } $config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ] diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html index 5987459a5..9346aba4a 100644 --- a/httemplate/view/cust_main/misc.html +++ b/httemplate/view/cust_main/misc.html @@ -125,6 +125,10 @@ % } +% foreach (sort { $a cmp $b } $cust_main->virtual_fields) { + <% $cust_main->pvf($_)->widget('HTML', 'view', $cust_main->getfield($_)) %> +% } + % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) { <TR> |