From e2b0202cff81f02ce9a7e6a1cddf463704ebacf1 Mon Sep 17 00:00:00 2001 From: tetragon Date: Wed, 24 Oct 2007 22:21:31 +0000 Subject: Converting forms that use warehouse_header to templates git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1814 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template.pm | 3 + UI/am-warehouse-form.html | 33 ++++++++ bin/am.pl | 186 +++++++++++++++++++--------------------------- 3 files changed, 112 insertions(+), 110 deletions(-) create mode 100644 UI/am-warehouse-form.html diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 03bcbc34..28c1f40e 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -122,6 +122,7 @@ package LedgerSMB::Template; use warnings; use strict; +use Carp; use Error qw(:try); use LedgerSMB::Sysconfig; @@ -212,6 +213,7 @@ sub render { my $cleanvars; if ($self->{no_escape}) { + carp 'no_escape mode enabled in rendering'; $cleanvars = $vars; } else { $cleanvars = $format->can('preprocess')->($vars); @@ -271,6 +273,7 @@ sub _http_output { } if ($self->{mimetype} =~ /^text/) { print "Content-Type: $self->{mimetype}; charset=utf-8$disposition\n\n"; + binmode STDOUT, ':utf8'; } else { print "Content-Type: $self->{mimetype}$disposition\n\n"; binmode STDOUT, ':bytes'; diff --git a/UI/am-warehouse-form.html b/UI/am-warehouse-form.html new file mode 100644 index 00000000..1ed6975f --- /dev/null +++ b/UI/am-warehouse-form.html @@ -0,0 +1,33 @@ + + + +
+ + + + + + + +
+ + + + 1 ?> + + + + + +
'description', cols => 60, rows => rows, text => form.description} ?> 'description', size => 60, value => form.description} ?>
+

+ 'hidden', + name => hidden, + value => hiddens.item(hidden) + }; END ?> + +
+ + diff --git a/bin/am.pl b/bin/am.pl index 60c73bf0..3bb2468f 100644 --- a/bin/am.pl +++ b/bin/am.pl @@ -1985,8 +1985,21 @@ sub add_warehouse { "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; - &warehouse_header; - &form_footer; + my %hiddens; + my @buttons; + my $rows = &warehouse_header(\%hiddens); + &form_footer_buttons(\%hiddens, \@buttons); + + my $template = LedgerSMB::Template->new_UI( + user => \%myconfig, + locale => $locale, + template => 'am-warehouse-form'); + $template->render({ + form => $form, + row_count => $rows, + buttons => \@buttons, + hiddens => \%hiddens, + }); } @@ -1996,16 +2009,29 @@ sub edit_warehouse { AM->get_warehouse( \%myconfig, \%$form ); - &warehouse_header; - &form_footer; + my %hiddens; + my @buttons; + my $rows = &warehouse_header(\%hiddens); + &form_footer_buttons(\%hiddens, \@buttons); + my $template = LedgerSMB::Template->new_UI( + user => \%myconfig, + locale => $locale, + template => 'am-warehouse-form'); + $template->render({ + form => $form, + row_count => $rows, + buttons => \@buttons, + hiddens => \%hiddens, + }); } sub list_warehouse { AM->warehouses( \%myconfig, \%$form ); + my %hiddens; - $href = + my $href = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->sort_order(); @@ -2013,95 +2039,64 @@ sub list_warehouse { $form->{callback} = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; - $callback = $form->escape( $form->{callback} ); + my $callback = $form->escape( $form->{callback} ); $form->{title} = $locale->text('Warehouses'); - @column_index = qw(description); - - $column_header{description} = - qq|| - . $locale->text('Description') - . qq||; - - $form->header; - - print qq| - - - - - - - - - - - - - -
$form->{title}
- - -|; - - for (@column_index) { print "$column_header{$_}\n" } - - print qq| - -|; + my @column_index = qw(description); + my %column_header; + $column_header{description} = { + href => $href, + text => $locale->text('Description'), + }; - foreach $ref ( @{ $form->{ALL} } ) { + my @rows; + my $i; + foreach my $ref ( @{ $form->{ALL} } ) { + my %column_data; $i++; $i %= 2; + $column_data{i} = $i; - print qq| - -|; - - $column_data{description} = -qq||; - - for (@column_index) { print "$column_data{$_}\n" } + $column_data{description} = { + href => "$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback", + text => $ref->{description}, + }; - print qq| - -|; + push @rows, \%column_data; } - print qq| -
{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}
-

- -
-
{script}> -|; - $form->{type} = "warehouse"; + $hiddens{$_} = $form->{$_} foreach qw(type callback path login sessionid); - $form->hide_form(qw(type callback path login sessionid)); - - print qq| -|; - - if ( $form->{lynx} ) { - require "bin/menu.pl"; - &menubar; - } - - print qq| -
- - - -|; +##SC: Temporary commenting +## if ( $form->{lynx} ) { +## require "bin/menu.pl"; +## &menubar; +## } + my @buttons = ({ + name => 'action', + value => 'add_warehouse', + text => $locale->text('Add Warehouse'), + }); + my $template = LedgerSMB::Template->new_UI( + user => \%myconfig, + locale => $locale, + template => 'form-dynatable'); + $template->render({ + form => $form, + buttons => \@buttons, + hiddens => \%hiddens, + columns => \@column_index, + heading => \%column_header, + rows => \@rows, + }); } sub warehouse_header { + my $hiddens = shift; $form->{title} = $locale->text("$form->{title} Warehouse"); @@ -2110,40 +2105,11 @@ sub warehouse_header { $form->{description} = $form->quote( $form->{description} ); - if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { - $description = -qq||; - } - else { - $description = - qq||; - } - - $form->header; - - print qq| - - -
{script}> - -{id}> - - - - - - - - - - - - - - -
$form->{title}
| . $locale->text('Description') . qq|$description

-|; + $hiddens->{id} = $form->{id}; + $hiddens->{type} = 'warehouse'; + my $rows = $form->numtextrows( $form->{description}, 60 ); + $rows; } sub save_warehouse { -- cgit v1.2.3