summaryrefslogtreecommitdiff
path: root/httemplate/edit/elements
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/edit/elements')
-rw-r--r--httemplate/edit/elements/edit.html89
-rw-r--r--httemplate/edit/elements/svc_Common.html98
2 files changed, 170 insertions, 17 deletions
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index 120c03a3c..c40a00492 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -9,13 +9,38 @@
# 'column' => 'Label',
# }
#
- # listref - each item is a literal column name (or method) or (notyet) coderef
+ # listref - each item is a literal column name (or method) or hashref
+ # or (notyet) coderef
# if not specified all columns (except for the primary key) will be editable
# 'fields' => [
+ # 'columname',
+ # { 'field' => 'another_columname',
+ # 'type' => 'text', #text, fixed, hidden, checkbox
+ # #eventually more for <SELECT>, etc.
+ # 'value' => 'Y', #only for checkbox
+ # },
# ]
#
# 'menubar' => '', #menubar arrayref
#
+ # #run when re-displaying with an error
+ # 'error_callback' => sub { my( $cgi, $object ) = @_; },
+ #
+ # #run when editing
+ # 'edit_callback' => sub { my( $cgi, $object ) = @_; },
+ #
+ # # returns a hashref for the new object
+ # 'new_hashref_callback'
+ #
+ # #run when adding
+ # 'new_callback' => sub { my( $cgi, $object ) = @_; },
+ #
+ # #XXX describe
+ # 'field_callback' => sub { },
+ #
+ # #string or coderef of additional HTML to add before </TABLE>
+ # 'html_table_bottom' => '',
+ #
# 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
#
# 'html_bottom' => '', #string
@@ -43,15 +68,30 @@
map { $_ => scalar($cgi->param($_)) } fields($table)
});
+ &{$opt{'error_callback'}}($cgi, $object)
+ if $opt{'error_callback'};
+
} elsif ( $cgi->keywords ) { #editing
my( $query ) = $cgi->keywords;
$query =~ /^(\d+)$/;
$object = qsearchs( $table, { $pkey => $1 } );
+ warn "$table $pkey => $1"
+ if $opt{'debug'};
+
+ &{$opt{'edit_callback'}}($cgi, $object)
+ if $opt{'edit_callback'};
} else { #adding
- $object = $class->new( {} );
+ my $hashref = $opt{'new_hashref_callback'}
+ ? &{$opt{'new_hashref_callback'}}
+ : {};
+
+ $object = $class->new( $hashref );
+
+ &{$opt{'new_callback'}}($cgi, $object)
+ if $opt{'new_callback'};
}
@@ -91,16 +131,15 @@
<%= ntable("#cccccc",2) %>
-<% foreach my $f ( @$fields ) {
+<% foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
+ @$fields
+ ) {
+
+ &{ $opt{'field_callback'} }( $f )
+ if $opt{'field_callback'};
- my( $field, $type);
- if ( ref($f) ) {
- $field = $f->{'field'},
- $type = $f->{'type'} || 'text',
- } else {
- $field = $f;
- $type = 'text';
- }
+ my $field = $f->{'field'};
+ my $type = $f->{'type'} ||= 'text';
%>
@@ -113,18 +152,34 @@
%>
</TD>
- <%
- #eventually more options for <SELECT>, etc. fields
- %>
+ <% if ( $type eq 'fixed' ) { %>
+
+ <TD BGCOLOR="#dddddd"><%= $f->{'value'} %></TD>
+ <INPUT TYPE="hidden" NAME="<%= $field %>" VALUE="<%= $f->{'value'} %>">
+
+ <% } elsif ( $type eq 'checkbox' ) { %>
+
+ <TD>
+ <INPUT TYPE="checkbox" NAME="<%= $field %>" VALUE="<%= $f->{'value'} %>" <%= $object->$field() eq $f->{'value'} ? ' CHECKED' : '' %>>
+ </TD>
- <TD>
- <INPUT TYPE="<%= $type %>" NAME="<%= $field %>" VALUE="<%= $object->$field() %>">
- <TD>
+ <% } else { %>
+
+ <TD>
+ <INPUT TYPE="<%= $type %>" NAME="<%= $field %>" VALUE="<%= $object->$field() %>">
+ <TD>
+
+ <% } %>
</TR>
<% } %>
+<%= ref( $opt{'html_table_bottom'} )
+ ? &{ $opt{'html_table_bottom'} }( $object )
+ : $opt{'html_table_bottom'}
+%>
+
</TABLE>
<%= ref( $opt{'html_bottom'} )
diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html
new file mode 100644
index 000000000..c113ad645
--- /dev/null
+++ b/httemplate/edit/elements/svc_Common.html
@@ -0,0 +1,98 @@
+<%
+
+ my %opt = @_;
+
+ #my( $svcnum, $pkgnum, $svcpart, $part_svc );
+ my( $pkgnum, $svcpart, $part_svc );
+
+ #get & untaint pkgnum & svcpart
+ my($query) = $cgi->keywords; #they're not proper cgi params
+ if ( $query =~ /^pkgnum(\d+)-svcpart(\d+)$/ ) {
+ $pkgnum = $1;
+ $svcpart = $2;
+ $cgi->delete_all(); #so the standard edit.html treats this correctly as new
+ }
+
+%><%= include( 'edit.html',
+
+ 'menubar' => [],
+
+ 'error_callback' => sub {
+ my( $cgi, $svc_x ) = @_;
+ #$svcnum = $svc_x->svcnum;
+ $pkgnum = $cgi->param('pkgnum');
+ $svcpart = $cgi->param('svcpart');
+
+ $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
+ die "No part_svc entry!" unless $part_svc;
+ },
+
+ 'edit_callback' => sub {
+ my( $cgi, $svc_x ) = @_;
+ #$svcnum = $svc_x->svcnum;
+ my $cust_svc = $svc_x->cust_svc
+ or die "Unknown (cust_svc) svcnum!";
+
+ $pkgnum = $cust_svc->pkgnum;
+ $svcpart = $cust_svc->svcpart;
+
+ $part_svc = qsearchs ('part_svc', { svcpart=>$svcpart });
+ die "No part_svc entry!" unless $part_svc;
+ },
+
+ 'new_hash_callback' => sub {
+ #my( $cgi, $svc_x ) = @_;
+
+ { svcpart => $svcpart };
+
+ },
+
+ 'new_callback' => sub {
+ my( $cgi, $svc_x ) = @_;;
+
+ $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
+ die "No part_svc entry!" unless $part_svc;
+
+ #$svcnum='';
+
+ $svc_x->set_default_and_fixed;
+
+ },
+
+ 'field_callback' => sub {
+ my $f = shift;
+ my $columndef = $part_svc->part_svc_column($f->{'field'});
+ my $flag = $columndef->columnflag;
+ if ( $flag eq 'F' ) {
+ $f->{'type'} = 'fixed';
+ $f->{'value'} = $columndef->columnvalue;
+ }
+ },
+
+ 'html_table_bottom' => sub {
+ my $svc_x = shift;
+ my $html = '';
+ foreach my $field ($svc_x->virtual_fields) {
+ if ($part_svc->part_svc_column($field)->columnflag ne 'F'){
+ # If the flag is X, it won't even show up
+ # in $svc_acct->virtual_fields.
+ $html .=
+ $svc_x->pvf($field)->widget( 'HTML',
+ 'edit',
+ $svc_x->getfield($field)
+ );
+ }
+ }
+ $html;
+ },
+
+ 'html_bottom' => sub {
+ qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">!.
+ qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">!;
+ },
+
+ 'debug' => 1,
+
+ %opt #pass through/override params
+ )
+%>