From 3ce7691203a7737406bf2d4442f7fd84b81f847e Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 23 Aug 2006 22:25:39 +0000 Subject: Will things ever be the same again? It's the final masonize --- httemplate/edit/elements/edit.html | 298 ++++++++++++++++--------------- httemplate/edit/elements/svc_Common.html | 33 ++-- 2 files changed, 167 insertions(+), 164 deletions(-) (limited to 'httemplate/edit/elements') diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index c40a00492..ac00fc5f0 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -1,197 +1,199 @@ -<% - - # options example... - # - # 'name' => - # 'table' => - # #? 'primary_key' => #required when the dbdef doesn't know...??? - # 'labels' => { - # 'column' => 'Label', - # } - # - # 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 , 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 +% # 'html_table_bottom' => '', +% # +% # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' +% # +% # 'html_bottom' => '', #string +% # 'html_bottom' => sub { +% # my $object = shift; +% # # ... +% # "html_string"; +% # }, +% +% my(%opt) = @_; +% +% #false laziness w/process.html +% my $table = $opt{'table'}; +% my $class = "FS::$table"; +% my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} || +% my $fields = $opt{'fields'} +% #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ]; +% || [ grep { $_ ne $pkey } fields($table) ]; +% #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields; +% +% my $object; +% if ( $cgi->param('error') ) { +% +% $object = $class->new( { +% 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 +% +% my $hashref = $opt{'new_hashref_callback'} +% ? &{$opt{'new_hashref_callback'}} +% : {}; +% +% $object = $class->new( $hashref ); +% +% &{$opt{'new_callback'}}($cgi, $object) +% if $opt{'new_callback'}; +% +% } +% +% my $action = $object->$pkey() ? 'Edit' : 'Add'; +% +% my $title = "$action $opt{'name'}"; +% +% my @menubar = (); +% if ( $opt{'menubar'} ) { +% @menubar = @{ $opt{'menubar'} }; +% } else { +% @menubar = ( +% 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done +% #eventually use Lingua::bs to pluralize +% "View all $opt{'name'}s" => $p. ( $opt{'viewall_dir'} || 'search' ). +% "/$table.html", +% ); +% } +% +% +<% include("/elements/header.html", $title, include( '/elements/menubar.html', @menubar ) ) %> +% if ( $cgi->param('error') ) { -<% if ( $cgi->param('error') ) { %> - Error: <%= $cgi->param('error') %> + Error: <% $cgi->param('error') %>

-<% } %> +% } -
- -<%= ( $opt{labels} && exists $opt{labels}->{$pkey} ) + + + +<% ( $opt{labels} && exists $opt{labels}->{$pkey} ) ? $opt{labels}->{$pkey} : $pkey %> -#<%= $object->$pkey() || "(NEW)" %> - -<%= ntable("#cccccc",2) %> - -<% foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} } - @$fields - ) { +#<% $object->$pkey() || "(NEW)" %> + +<% ntable("#cccccc",2) %> +% foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} } +% @$fields +% ) { +% +% &{ $opt{'field_callback'} }( $f ) +% if $opt{'field_callback'}; +% +% my $field = $f->{'field'}; +% my $type = $f->{'type'} ||= 'text'; +% +% - &{ $opt{'field_callback'} }( $f ) - if $opt{'field_callback'}; - - my $field = $f->{'field'}; - my $type = $f->{'type'} ||= 'text'; - -%> - <%= ( $opt{labels} && exists $opt{labels}->{$field} ) + <% ( $opt{labels} && exists $opt{labels}->{$field} ) ? $opt{labels}->{$field} : $field %> +% if ( $type eq 'fixed' ) { - <% if ( $type eq 'fixed' ) { %> - <%= $f->{'value'} %> - + <% $f->{'value'} %> + +% } elsif ( $type eq 'checkbox' ) { - <% } elsif ( $type eq 'checkbox' ) { %> - $field() eq $f->{'value'} ? ' CHECKED' : '' %>> + $field() eq $f->{'value'} ? ' CHECKED' : '' %>> +% } else { - <% } else { %> - + +% } - <% } %> +% } -<% } %> -<%= ref( $opt{'html_table_bottom'} ) +<% ref( $opt{'html_table_bottom'} ) ? &{ $opt{'html_table_bottom'} }( $object ) : $opt{'html_table_bottom'} %> -<%= ref( $opt{'html_bottom'} ) +<% ref( $opt{'html_bottom'} ) ? &{ $opt{'html_bottom'} }( $object ) : $opt{'html_bottom'} %>
-"> +">
-<%= include("/elements/footer.html") %> +<% include("/elements/footer.html") %> diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html index c113ad645..da59cc9ed 100644 --- a/httemplate/edit/elements/svc_Common.html +++ b/httemplate/edit/elements/svc_Common.html @@ -1,19 +1,20 @@ -<% - - 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', +% +% +% 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' => [], -- cgit v1.2.1