RT#41671 Fix double click prevention for all legacy buttons [renamed all from submit...
[freeside.git] / httemplate / edit / elements / part_svc_column.html
1 <%doc>
2 To be called from part_svc.cgi.
3 <& elements/part_svc_column.html, 
4     'svc_acct',
5     # options...
6     'part_svc'  => $part_svc, # the existing part_svc to edit
7     'clone'     => 0,         # or a svcpart to clone from
8 &>
9
10 </%doc>
11 <%once>
12 # the semantics of this could be better
13
14 # all of these conditions are when NOT to allow that flag choice
15 # don't allow the 'inventory' flags (M, A) to be chosen for 
16 # fields that aren't free-text
17 my $inv_sub = sub { $_[0]->{disable_inventory} || $_[0]->{type} ne 'text' };
18 tie my %flag, 'Tie::IxHash',
19   ''  => { 'desc' => 'No default', 'condition' => sub { 0 } },
20   'D' => { 'desc' => 'Default', 
21            'condition' =>
22              sub { $_[0]->{disable_default } }
23          },
24   'F' => { 'desc' => 'Fixed (unchangeable)',
25            'condition' =>
26              sub { $_[0]->{disable_fixed} },
27          },
28   'S' => { 'desc' => 'Selectable Choice',
29            'condition' =>
30              sub { $_[0]->{disable_select} },
31          },
32   'M' => { 'desc' => 'Manual selection from inventory',
33            'condition' => $inv_sub,
34          },
35   'A' => { 'desc' => 'Automatically fill in from inventory',
36            'condition' => $inv_sub,
37          },
38   'H' => { 'desc' => 'Select from hardware class',
39            'condition' => sub { $_[0]->{type} ne 'select-hardware' },
40          },
41   'X' => { 'desc' => 'Excluded',
42            'condition' => sub { 1 }, # obsolete
43          },
44 ;
45
46 # the semantics of this could be much better
47 sub flag_condition {
48   my $f = shift;
49   not &{ $flag{$f}->{'condition'} }(@_);
50 }
51
52 my %communigate_fields = (
53   'svc_acct'        => { map { $_=>1 }
54                             qw( file_quota file_maxnum file_maxsize
55                                 password_selfchange password_recover
56                               ),
57                             grep /^cgp_/, fields('svc_acct')
58   },
59   'svc_domain'      => { map { $_=>1 }
60                             qw( max_accounts trailer parent_svcnum ),
61                             grep /^(cgp|acct_def)_/, fields('svc_domain')
62   },
63 );
64 </%once>
65 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $svcdb %>">
66 <BR>
67 %# include export selection
68 <& export_svc.html,
69   part_svc => $part_svc,
70   svcdb => $svcdb
71 &>
72
73 <FONT CLASS="fsinnerbox-title">Fields</FONT>
74 <& /elements/table-grid.html, cellpadding => 4 &>
75   <TR>
76     <TH BGCOLOR="#cccccc">Field</TH>
77     <TH BGCOLOR="#cccccc">Label</TH>
78     <TH BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>
79     <TH BGCOLOR="#cccccc"><% $manual_require ? 'Required?' : '' %></TH>
80   </TR>
81 % $part_svc->set('svcpart' => $opt{'clone'}) if $opt{'clone'}; # for now
82 % my $i = 0;
83 % foreach my $field (@fields) {
84 %   my $def = shift @defs;
85 %   my $part_svc_column = $part_svc->part_svc_column($field);
86 %   my $flag = $part_svc_column->columnflag;
87 %   my $formatter = $def->{'format'} || sub { shift };
88 %   my $value = &{$formatter}($part_svc_column->columnvalue);
89   <TR CLASS="row<%$i%>">
90     <TD ROWSPAN=2 CLASS="grid" ALIGN="right">
91       <% $def->{'label'} || $field %>
92     </TD>
93     <TD ROWSPAN=2 CLASS="grid">
94       <INPUT NAME="<% $svcdb %>__<% $field %>_label"
95              STYLE="text-align: right"
96              VALUE="<% $part_svc_column->columnlabel || $def->{'label'} |h %>">
97     </TD>
98
99     <TD ROWSPAN=1 CLASS="grid">
100 %   # flag selection
101 %   if ( $def->{'type'} eq 'disabled' ) {
102 %     $flag = '';
103       No default
104 %   } else {
105 %     my $name = $svcdb.'__'.$field.'_flag';
106       <SELECT NAME="<%$name%>"
107               ID="<%$name%>"
108               STYLE="width:100%"
109               onchange="flag_changed(this)">
110 %     foreach my $f (keys %flag) {
111 %       if ( flag_condition($f, $def, $svcdb, $field) ) {
112           <OPTION VALUE="<%$f%>"<% $flag eq $f ? ' SELECTED' : ''%>>
113             <% $flag{$f}->{desc} %>
114           </OPTION>
115 %       }
116 %     }
117       </SELECT>
118 %   } # if $def->{'type'} eq 'disabled'
119     </TD>
120     <TD CLASS="grid">
121 %   # value entry/selection
122 %   my $name = $svcdb.'__'.$field;
123 %   # These are all MANDATORY SELECT types.  Regardless of the flag value,
124 %   # there will never be a text input (either in svc_* or in part_svc) for
125 %   # these fields.
126 %   if ( $def->{'type'} eq 'checkbox' ) {
127       <& /elements/checkbox.html,
128           'field'       => $name,
129           'curr_value'  => $value,
130           'value'       => 'Y' &>
131 %
132 %   } elsif ( $def->{'type'} eq 'select' ) {
133 %
134 %     if ( $def->{'select_table'} ) {
135       <& /elements/select-table.html,
136           'field'       => $name,
137           'id'          => $name.'_select',
138           'table'       => $def->{'select_table'},
139           'name_col'    => $def->{'select_label'},
140           'value_col'   => $def->{'select_key'},
141           'order_by'    => dbdef->table($def->{'select_table'})->primary_key,
142           'multiple'    => $def->{'multiple'},
143           'disable_empty' => $def->{'select_allow_empty'} ? undef : 1,
144           'empty_label' => $def->{'select_allow_empty'} ? ' ' : undef,
145           'curr_value'  => $value,
146           # these can be switched between multiple and singular,
147           # so put the complete curr_value in an attribute
148           'element_etc' => 'default="'.encode_entities($value).'"',
149       &>
150 %     } else {
151 %       my (@options, %labels);
152 %       if ( $def->{'select_list'} ) {
153 %         @options = @{ $def->{'select_list'} };
154 %         @labels{@options} = @options;
155 %       } elsif ( $def->{'select_hash'} ) {
156 %         if ( ref($def->{'select_hash'}) eq 'ARRAY' ) {
157 %           tie my %hash, 'Tie::IxHash', @{ $def->{'select_hash'} };
158 %           $def->{'select_hash'} = \%hash;
159 %         }
160 %         @options = keys( %{ $def->{'select_hash'} } );
161 %         %labels = %{ $def->{'select_hash'} };
162 %       }
163       <& /elements/select.html,
164           'field'       => $name,
165           'id'          => $name.'_select',
166           'options'     => \@options,
167           'labels'      => \%labels,
168           'multiple'    => $def->{'multiple'},
169           'curr_value'  => $value,
170       &>
171 %     }
172 %   } elsif ( $def->{'type'} =~ /^select-(.*?)(.html)?$/ && $1 ne 'hardware' ) {
173       <& "/elements/select-$1.html",
174           'field'       => $name,
175           'id'          => $name.'_select',
176           'multiple'    => $def->{'multiple'},
177           'curr_value'  => $value,
178       &>
179 %   } elsif ( $def->{'type'} eq 'communigate_pro-accessmodes' ) {
180       <& /elements/communigate_pro-accessmodes.html,
181           'element_name_prefix' => $name.'_',
182           'curr_value'  => $value,
183       &>
184 %   } elsif ( $def->{'type'} eq 'textarea' ) {
185 %   # special cases
186       <TEXTAREA NAME="<%$name%>"><% $value |h %></TEXTAREA>
187 %   } elsif ( $def->{'type'} eq 'disabled' ) {
188       <INPUT TYPE="hidden" NAME="<%$name%>" VALUE="">
189 %   } else {
190 %     # the normal case: a text input, and a _select which is an inventory
191 %     # or hardware class
192       <INPUT TYPE="text"
193              NAME="<%$name%>"
194              ID="<%$name%>" 
195              VALUE="<%$value%>">
196 %     my $mode = 'inventory';
197 %     my $multiple = 1;
198 %     if ( $def->{'type'} eq 'select-hardware' ) {
199 %       $mode = 'hardware';
200 %       $multiple = 0;
201 %     }
202       <& /elements/select-table.html,
203           'field'       => $name.'_classnum',
204           'id'          => $name.'_select',
205           'table'       => $mode.'_class',
206           'name_col'    => 'classname',
207           'curr_value'  => $value,
208           'empty_label' => "Select $mode class",
209           'multiple'    => $multiple,
210       &>
211 %   }
212     </TD>
213     <TD>
214 %   if ($manual_require && 
215 %       (!$def->{'type'} || !(grep {$_ eq $def->{'type'}} ('checkbox','disabled')))
216 %   ) {
217       <INPUT ID="<% $name.'_required' %>" TYPE="checkbox" NAME="<% $svcdb %>__<% $field %>_required" VALUE="Y" 
218         <% ($part_svc_column->required || $def->{'required'}) ? 'CHECKED' : '' %> 
219         <% $def->{'required'} ? 'DISABLED' : '' %>
220        >
221 %   }
222     </TD>
223   </TR>
224   <TR CLASS="row<%$i%>">
225     <TD COLSPAN=3 CLASS="def_info">
226 %   if ( $def->{def_info} ) {
227       (<% $def->{def_info} %>)
228     </TD>
229   </TR>
230 %   }
231 % $i = 1-$i;
232 % } # foreach my $field
233 %
234 % # special case: svc_acct password edit ACL
235 % if ( $svcdb eq 'svc_acct' ) {
236 %   push @fields, 'restrict_edit_password';
237   <TR>
238     <TD COLSPAN=3 ALIGN="right">
239       <% emt('Require "Provision" access right to edit password') %>
240     </TD>
241     <TD COLSPAN=2>
242       <INPUT TYPE="checkbox" NAME="restrict_edit_password" VALUE="Y" \
243       <% $part_svc->restrict_edit_password ? 'CHECKED' : '' %>>
244     </TD>
245   </TR>
246 % }
247 % # special case: services with attached routers (false laziness...)
248 % if ( $svcdb eq 'svc_acct'
249 %      or $svcdb eq 'svc_broadband'
250 %      or $svcdb eq 'svc_dsl'
251 %      or $svcdb eq 'svc_circuit' ) {
252 %   push @fields, 'has_router';
253   <TR>
254     <TD COLSPAN=3 ALIGN="right">
255       <% emt('This service has an attached router') %>
256     </TD>
257     <TD COLSPAN=2>
258       <INPUT TYPE="checkbox" NAME="has_router" VALUE="Y" \
259       <% $part_svc->has_router ? 'CHECKED' : '' %>>
260     </TD>
261   </TR>
262 % }
263 </TABLE>
264 <& /elements/progress-init.html,
265   $svcdb, #form name
266   [ # form fields to send
267     qw(svc svcpart classnum selfservice_access disabled preserve exportnum),
268     @fields
269   ],
270   'process/part_svc.cgi',   # target
271   $p.'browse/part_svc.cgi', # redirect landing
272   $svcdb, #key
273 &>
274 % $svcpart = '' if $opt{clone};
275 <BR>
276 <INPUT NAME="submitButton"
277        TYPE="button"
278        VALUE="<% emt($svcpart ? 'Apply changes' : 'Add service') %>"
279        onclick="fixup_submit('<%$svcdb%>')"
280 >
281 <%init>
282 my $svcdb = shift;
283 my %opt = @_;
284 my $count = 0;
285 my $communigate = 0;
286 my $conf = FS::Conf->new;
287
288 my $part_svc = $opt{'part_svc'} || FS::part_svc->new;
289
290 # see if there are communigate exports configured
291 if ( exists $communigate_fields{$svcdb} ) {
292   $communigate = FS::part_export->count("exporttype like 'communigate%'");
293 }
294
295 my $svcpart = $opt{'clone'} || $part_svc->svcpart;
296
297 my @fields;
298 if ( defined( dbdef->table($svcdb) ) ) { # when is it ever not defined?
299   @fields = grep {
300     $_ ne 'svcnum'
301       and ( $communigate || ! $communigate_fields{$svcdb}->{$_} )
302       and ( !FS::part_svc->svc_table_fields($svcdb)->{$_}->{disable_part_svc_column}
303             || $part_svc->part_svc_column($_)->columnflag )
304   } fields($svcdb);
305 }
306 if ( $svcdb eq 'svc_acct'
307       or ( $svcdb eq 'svc_broadband' and $conf->exists('svc_broadband-radius') )
308    )
309 {
310   push @fields, 'usergroup';
311 }
312
313 my @defs = map { FS::part_svc->svc_table_fields($svcdb)->{$_} } @fields;
314 my $manual_require = FS::part_svc->svc_table_info($svcdb)->{'manual_require'};
315 </%init>