use service-def specific labels, at least for service pages that use {view,edit}...
[freeside.git] / httemplate / edit / elements / svc_Common.html
1 <% include( 'edit.html',
2
3                  'menubar' => [],
4
5                  'error_callback' => sub {
6                    my( $cgi, $svc_x, $fields, $opt ) = @_;
7                    #$svcnum = $svc_x->svcnum;
8                    $pkgnum  = $cgi->param('pkgnum');
9                    $svcpart = $cgi->param('svcpart');
10
11                    $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
12                    die "No part_svc entry!" unless $part_svc;
13
14                    label_fixup($part_svc, $opt);
15
16                    $svc_x->setfield('svcpart', $svcpart);
17                  },
18
19                  'edit_callback' => sub {
20                    my( $cgi, $svc_x, $fields, $opt ) = @_;
21                    #$svcnum = $svc_x->svcnum;
22                    my $cust_svc = $svc_x->cust_svc
23                      or die "Unknown (cust_svc) svcnum!";
24
25                    $pkgnum  = $cust_svc->pkgnum;
26                    $svcpart = $cust_svc->svcpart;
27   
28                    $part_svc = qsearchs ('part_svc', { svcpart=>$svcpart });
29                    die "No part_svc entry!" unless $part_svc;
30
31                    label_fixup($part_svc, $opt);
32                  },
33
34                  'new_hashref_callback' => sub {
35                    #my( $cgi, $svc_x ) = @_;
36
37                    { svcpart => $svcpart };
38
39                  },
40
41                  'new_callback' => sub {
42                     my( $cgi, $svc_x, $fields, $opt ) = @_;;
43
44                     $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
45                     die "No part_svc entry!" unless $part_svc;
46
47                     label_fixup($part_svc, $opt);
48
49                     #$svcnum='';
50
51                     $svc_x->set_default_and_fixed;
52
53                  },
54
55                  'field_callback' => sub {
56                    my ($cgi, $object, $f) = @_;
57                    my $columndef = $part_svc->part_svc_column($f->{'field'});
58                    my $flag = $columndef->columnflag;
59                    if ( $flag eq 'F' ) {
60                      $f->{'type'} = length($columndef->columnvalue)
61                                       ? 'fixed'
62                                       : 'hidden';
63                      $f->{'value'} = $columndef->columnvalue;
64                    }
65                  },
66
67                  'html_init' => sub {
68                    my $cust_main;
69                    if ( $pkgnum ) {
70                      my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum});
71                      $cust_main = $cust_pkg->cust_main if $cust_pkg;
72                    }
73                    $cust_main
74                      ? include( '/elements/small_custview.html',
75                                 $cust_main,
76                                 '',
77                                 1,
78                                 popurl(2). "view/cust_main.cgi"
79                               ). '<BR>'
80                      : '';
81
82                  },
83
84                  'html_table_bottom' => sub {
85                    my $svc_x = shift;
86                    my $html = '';
87                    foreach my $field ($svc_x->virtual_fields) {
88                      if ($part_svc->part_svc_column($field)->columnflag ne 'F'){
89                        # If the flag is X, it won't even show up
90                        # in $svc_acct->virtual_fields.
91                        $html .=
92                          $svc_x->pvf($field)->widget( 'HTML',
93                                                       'edit', 
94                                                       $svc_x->getfield($field)
95                                                     );
96                      }
97                    }
98                    $html;
99                  },
100
101                  'html_bottom' => sub {
102                    qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">!.
103                    qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">!;
104                  },
105
106                  %opt #pass through/override params
107              )
108 %>
109 <%once>
110
111 sub label_fixup {
112   my( $part_svc, $opt ) = @_;
113
114   #false laziness w/view/svc_Common.html
115   #override default labels with service-definition labels if applicable
116   my $labels = $opt->{labels}; # with -> here
117   foreach my $field ( keys %$labels ) {
118     my $col = $part_svc->part_svc_column($field);
119     $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/;
120   }
121
122 }
123
124 </%once>
125 <%init>
126
127 my %opt = @_;
128
129 #my( $svcnum, $pkgnum, $svcpart, $part_svc );
130 my( $pkgnum, $svcpart, $part_svc );
131
132 #get & untaint pkgnum & svcpart
133 if ( ! $cgi->param('error')
134      && $cgi->param('pkgnum') && $cgi->param('svcpart')
135    )
136 {
137   $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
138   $pkgnum = $1;
139   $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
140   $svcpart = $1;
141   #$cgi->delete_all(); #so edit.html treats this correctly as new??
142 }
143
144 </%init>