summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-24 22:21:31 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-24 22:21:31 +0000
commite2b0202cff81f02ce9a7e6a1cddf463704ebacf1 (patch)
tree6b80ca09a622d2335d6ee88e38b969755043c963
parentabbbc08b1380943d37cac42c3cfd17aa43d92e1e (diff)
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
-rwxr-xr-xLedgerSMB/Template.pm3
-rw-r--r--UI/am-warehouse-form.html33
-rw-r--r--bin/am.pl186
3 files changed, 112 insertions, 110 deletions
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 @@
+<?lsmb INCLUDE 'ui-header.html' ?>
+<?lsmb PROCESS elements.html ?>
+<body>
+<form method="post" action="<?lsmb form.script ?>">
+<table width="100%">
+ <tr><th class="listtop"><?lsmb form.title ?></th></tr>
+ <tr><td> </td></tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align="right"><?lsmb text('Description') ?></th>
+<?lsmb IF row_count > 1 ?>
+ <td><?lsmb PROCESS textarea element_data={name => 'description', cols => 60, rows => rows, text => form.description} ?></td>
+<?lsmb ELSE ?>
+ <td><?lsmb PROCESS input element_data={name => 'description', size => 60, value => form.description} ?></td>
+<?lsmb END ?>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr><td colspan="2"><hr size="3" noshade="noshade" /></td></tr>
+</table>
+<?lsmb FOREACH hidden IN hiddens.keys;
+ PROCESS input element_data={
+ type => 'hidden',
+ name => hidden,
+ value => hiddens.item(hidden)
+ }; END ?>
+<?lsmb FOREACH button IN buttons; PROCESS button element_data=button; END ?>
+</form>
+</body>
+</html>
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|<th width=100%><a class="listheading" href=$href>|
- . $locale->text('Description')
- . qq|</a></th>|;
-
- $form->header;
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table width=100%>
- <tr class="listheading">
-|;
-
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
- </tr>
-|;
+ 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|
- <tr valign=top class=listrow$i>
-|;
-
- $column_data{description} =
-qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
-
- 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|
- </tr>
-|;
+ push @rows, \%column_data;
}
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<form method=post action=$form->{script}>
-|;
-
$form->{type} = "warehouse";
+ $hiddens{$_} = $form->{$_} foreach qw(type callback path login sessionid);
- $form->hide_form(qw(type callback path login sessionid));
-
- print qq|
-<button class="submit" type="submit" name="action" value="add_warehouse">|
- . $locale->text('Add Warehouse')
- . qq|</button>|;
-
- if ( $form->{lynx} ) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
- </form>
-
- </body>
- </html>
-|;
+##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|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
- }
- else {
- $description =
- qq|<input name=description size=60 value="$form->{description}">|;
- }
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<input type=hidden name=id value=$form->{id}>
-<input type=hidden name=type value=warehouse>
-
-<table width=100%>
- <tr>
- <th class=listtop colspan=2>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <th align="right">| . $locale->text('Description') . qq|</th>
- <td>$description</td>
- </tr>
- <tr>
- <td colspan=2><hr size=3 noshade></td>
- </tr>
-</table>
-|;
+ $hiddens->{id} = $form->{id};
+ $hiddens->{type} = 'warehouse';
+ my $rows = $form->numtextrows( $form->{description}, 60 );
+ $rows;
}
sub save_warehouse {