%doc>
To be called from part_svc.cgi.
<& elements/part_svc_column.html,
'svc_acct',
# options...
'part_svc' => $part_svc, # the existing part_svc to edit
'clone' => 0, # or a svcpart to clone from
&>
%doc>
<%once>
# the semantics of this could be better
# all of these conditions are when NOT to allow that flag choice
# don't allow the 'inventory' flags (M, A) to be chosen for
# fields that aren't free-text
my $inv_sub = sub { $_[0]->{disable_inventory} || $_[0]->{type} ne 'text' };
tie my %flag, 'Tie::IxHash',
'' => { 'desc' => 'No default', 'condition' => sub { 0 } },
'D' => { 'desc' => 'Default',
'condition' =>
sub { $_[0]->{disable_default } }
},
'F' => { 'desc' => 'Fixed (unchangeable)',
'condition' =>
sub { $_[0]->{disable_fixed} },
},
'S' => { 'desc' => 'Selectable Choice',
'condition' =>
sub { $_[0]->{disable_select} },
},
'M' => { 'desc' => 'Manual selection from inventory',
'condition' => $inv_sub,
},
'A' => { 'desc' => 'Automatically fill in from inventory',
'condition' => $inv_sub,
},
'H' => { 'desc' => 'Select from hardware class',
'condition' => sub { $_[0]->{type} ne 'select-hardware' },
},
'X' => { 'desc' => 'Excluded',
'condition' => sub { 1 }, # obsolete
},
;
# the semantics of this could be much better
sub flag_condition {
my $f = shift;
not &{ $flag{$f}->{'condition'} }(@_);
}
my %communigate_fields = (
'svc_acct' => { map { $_=>1 }
qw( file_quota file_maxnum file_maxsize
password_selfchange password_recover
),
grep /^cgp_/, fields('svc_acct')
},
'svc_domain' => { map { $_=>1 }
qw( max_accounts trailer parent_svcnum ),
grep /^(cgp|acct_def)_/, fields('svc_domain')
},
);
%once>
%# include export selection
<& export_svc.html,
part_svc => $part_svc,
svcdb => $svcdb
&>
Fields
<& /elements/table-grid.html, cellpadding => 4 &>
Field
Label
Modifier
<% $manual_require ? 'Required?' : '' %>
% $part_svc->set('svcpart' => $opt{'clone'}) if $opt{'clone'}; # for now
% my $i = 0;
% foreach my $field (@fields) {
% my $def = shift @defs;
% my $part_svc_column = $part_svc->part_svc_column($field);
% my $flag = $part_svc_column->columnflag;
% my $formatter = $def->{'format'} || sub { shift };
% my $value = &{$formatter}($part_svc_column->columnvalue);
<% $def->{'label'} || $field %>
% # flag selection
% if ( $def->{'type'} eq 'disabled' ) {
% $flag = '';
No default
% } else {
% my $name = $svcdb.'__'.$field.'_flag';
% } # if $def->{'type'} eq 'disabled'
% # value entry/selection
% my $name = $svcdb.'__'.$field;
% # These are all MANDATORY SELECT types. Regardless of the flag value,
% # there will never be a text input (either in svc_* or in part_svc) for
% # these fields.
% if ( $def->{'type'} eq 'checkbox' ) {
<& /elements/checkbox.html,
'field' => $name,
'curr_value' => $value,
'value' => 'Y' &>
%
% } elsif ( $def->{'type'} eq 'select' ) {
%
% if ( $def->{'select_table'} ) {
% # set the 'select_svc' flag to enable two-step selection of services
% my $comp = '/elements/select-table.html';
% $comp = '/elements/select-svc.html' if $def->{'select_svc'};
<& $comp,
'field' => $name,
'id' => $name.'_select',
'table' => $def->{'select_table'},
'name_col' => $def->{'select_label'},
'value_col' => $def->{'select_key'},
'order_by' => dbdef->table($def->{'select_table'})->primary_key,
'multiple' => $def->{'multiple'},
'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
'curr_value' => $value,
# these can be switched between multiple and singular,
# so put the complete curr_value in an attribute
'element_etc' => 'default="'.encode_entities($value).'"',
&>
% } else {
% my (@options, %labels);
% if ( $def->{'select_list'} ) {
% @options = @{ $def->{'select_list'} };
% @labels{@options} = @options;
% } elsif ( $def->{'select_hash'} ) {
% if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
% tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
% $def->{'select_hash'} = \%hash;
% }
% @options = keys( %{ $def->{'select_hash'} } );
% %labels = %{ $def->{'select_hash'} };
% }
<& /elements/select.html,
'field' => $name,
'id' => $name.'_select',
'options' => \@options,
'labels' => \%labels,
'multiple' => $def->{'multiple'},
'curr_value' => $value,
&>
% }
% } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
<& "/elements/select-$1.html",
'field' => $name,
'id' => $name.'_select',
'multiple' => $def->{'multiple'},
'curr_value' => $value,
&>
% } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
<& /elements/communigate_pro-accessmodes.html,
'element_name_prefix' => $name.'_',
'curr_value' => $value,
&>
% } elsif ( $def->{'type'} eq 'textarea' ) {
% # special cases
% } elsif ( $def->{'type'} eq 'disabled' ) {
% } else {
% # the normal case: a text input, and a _select which is an inventory
% # or hardware class
% my $mode = 'inventory';
% my $multiple = 1;
% if ( $def->{'type'} eq 'select-hardware' ) {
% $mode = 'hardware';
% $multiple = 0;
% }
<& /elements/select-table.html,
'field' => $name.'_classnum',
'id' => $name.'_select',
'table' => $mode.'_class',
'name_col' => 'classname',
'curr_value' => $value,
'empty_label' => "Select $mode class",
'multiple' => $multiple,
&>
% }