-small svc_dsl UI and flow changes, RT7111
[freeside.git] / httemplate / view / elements / svc_Common.html
1 <%doc>
2
3 #Example:
4
5   include( 'elements/svc_Common.html, 
6
7              'table' => 'svc_something'
8
9              'labels' => {
10                            'column' => 'Label',
11                          },
12
13              #listref - each item is a literal column name (or method) or
14              # (notyet) coderef.  if not specified all columns (except for the
15              #primary key) will be viewable
16              'fields' => [
17                          ]
18
19              # defaults to "edit/$table.cgi?", will have svcnum appended
20              'edit_url' => 
21
22              #at the very bottom (well, as low as you can go from here)
23              'html_foot'  => '',
24
25          )
26
27 </%doc>
28 <SCRIPT>
29 function areyousure(href) {
30   if (confirm("Permanently delete this <% $label %>?") == true)
31     window.location.href = href;
32 }
33 </SCRIPT>
34
35 % if ( $custnum ) { 
36
37   <% include("/elements/header.html","View $label: $value") %>
38
39   <% include( '/elements/small_custview.html', $custnum, '', 1,
40      "${p}view/cust_main.cgi") %>
41   <BR>
42
43 % } else { 
44
45   <% include("/elements/header.html","View $label: $value", menubar(
46       "Cancel this (unaudited) $label" =>
47             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')"
48   )) %>
49
50 % } 
51
52 Service #<B><% $svcnum %></B>
53 % my $url = $opt{'edit_url'} || $p. 'edit/'. $opt{'table'}. '.cgi?';
54 | <A HREF="<%$url%><%$svcnum%>">Edit this <% $label %></A>
55
56 | <A HREF="javascript:areyousure('<%$p.'misc/unprovision.cgi?'.$svcnum%>')">
57 Unprovision this Service</A>
58 <BR>
59
60 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
61
62 % foreach my $f ( @$fields ) {
63 %
64 %   my($field, $type, $value, $hack_strict_refs);
65 %   if ( ref($f) ) {
66 %     $field = $f->{'field'};
67 %     $hack_strict_refs = \&{ $f->{'value'} } if $f->{'value'};
68 %     $value = $f->{'value'} ? &$hack_strict_refs($svc_x) : $svc_x->$field;
69 %     $type  = $f->{'type'} || 'text';
70 %   } else {
71 %     $field = $f;
72 %     $value = $svc_x->$field;
73 %     $type = 'text';
74 %   }
75 %
76 %   my $columndef = $part_svc->part_svc_column($field);
77 %   unless ($columndef->columnflag eq 'F' && !length($columndef->columnvalue)) {
78
79       <TR>
80         <TD ALIGN="right">
81           <% ( $opt{labels} && exists $opt{labels}->{$field} )
82                   ? $opt{labels}->{$field}
83                   : $field
84           %>
85         </TD>
86
87 %       $value = time2str($date_format,$value) if ( $type eq 'date' && $value );
88 %       $value = time2str("$date_format %H:%M",$value) if ( $type eq 'datetime' && $value );
89 %       $value = $value eq 'Y' ? 'Yes' : 'No' if ( $type eq 'checkbox' );
90 %       #eventually more options for <SELECT>, etc. fields
91
92         <TD BGCOLOR="#ffffff"><% $value %><TD>
93
94       </TR>
95
96 %   }
97 %
98 % } 
99
100 % foreach (sort { $a cmp $b } $svc_x->virtual_fields) { 
101   <% $svc_x->pvf($_)->widget('HTML', 'view', $svc_x->getfield($_)) %>
102 % } 
103
104
105 </TABLE></TD></TR></TABLE>
106
107 <BR>
108
109 % if ( defined($opt{'html_foot'}) ) {
110
111   <% ref($opt{'html_foot'})
112        ? &{ $opt{'html_foot'} }($svc_x)
113        : $opt{'html_foot'}
114   %>
115   <BR>
116
117 % }
118
119 <% joblisting({'svcnum'=>$svcnum}, 1) %>
120
121 <% include('/elements/footer.html') %>
122 <%init>
123
124 die "access denied"
125   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
126
127 my(%opt) = @_;
128
129 my $conf = new FS::Conf;
130 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
131
132 my $table = $opt{'table'};
133
134 my $fields = $opt{'fields'}
135              #|| [ grep { $_ ne 'svcnum' } dbdef->table($table)->columns ];
136              || [ grep { $_ ne 'svcnum' } fields($table) ];
137
138 my $svcnum;
139 if ( $cgi->param('svcnum') ) {
140   $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum";
141   $svcnum = $1;
142 } else {
143   my($query) = $cgi->keywords;
144   $query =~ /^(\d+)$/ or die "no svcnum";
145   $svcnum = $1;
146 }
147 my $svc_x = qsearchs({
148   'select'    => $opt{'table'}.'.*',
149   'table'     => $opt{'table'},
150   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
151                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
152                  ' LEFT JOIN cust_main USING ( custnum ) ',
153   'hashref'   => { 'svcnum' => $svcnum },
154   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
155                             'null_right' => 'View/link unlinked services'
156                           ),
157 }) or die "Unknown svcnum $svcnum in ". $opt{'table'}. " table\n";
158
159 my $cust_svc = $svc_x->cust_svc;
160 my($label, $value, $svcdb) = $cust_svc->label;
161
162 my $part_svc = $cust_svc->part_svc;
163
164   #false laziness w/edit/svc_Common.html
165   #override default labels with service-definition labels if applicable
166   my $labels = $opt{labels}; #not -> here
167   foreach my $field ( keys %$labels ) {
168     my $col = $part_svc->part_svc_column($field);
169     $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/;
170   }
171
172 my $pkgnum = $cust_svc->pkgnum;
173
174 my($cust_pkg, $custnum);
175 if ($pkgnum) {
176   $cust_pkg = $cust_svc->cust_pkg;
177   $custnum = $cust_pkg->custnum;
178 } else {
179   $cust_pkg = '';
180   $custnum = '';
181 }
182
183 &{ $opt{'svc_callback'} }( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, \%opt ) 
184     if $opt{'svc_callback'};
185 </%init>