[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1814] trunk



Revision: 1814
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1814&view=rev
Author:   tetragon
Date:     2007-10-24 15:21:31 -0700 (Wed, 24 Oct 2007)

Log Message:
-----------
Converting forms that use warehouse_header to templates

Modified Paths:
--------------
    trunk/LedgerSMB/Template.pm
    trunk/bin/am.pl

Added Paths:
-----------
    trunk/UI/am-warehouse-form.html

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2007-10-24 21:36:16 UTC (rev 1813)
+++ trunk/LedgerSMB/Template.pm	2007-10-24 22:21:31 UTC (rev 1814)
@@ -122,6 +122,7 @@
 
 use warnings;
 use strict;
+use Carp;
 
 use Error qw(:try);
 use LedgerSMB::Sysconfig;
@@ -212,6 +213,7 @@
 
 	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 @@
 	}
 	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';

Added: trunk/UI/am-warehouse-form.html
===================================================================
--- trunk/UI/am-warehouse-form.html	                        (rev 0)
+++ trunk/UI/am-warehouse-form.html	2007-10-24 22:21:31 UTC (rev 1814)
@@ -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>

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2007-10-24 21:36:16 UTC (rev 1813)
+++ trunk/bin/am.pl	2007-10-24 22:21:31 UTC (rev 1814)
@@ -1985,9 +1985,22 @@
 "$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, ..hidden..);
 
+    my $template = LedgerSMB::Template->new_UI(
+        user => \%myconfig, 
+        locale => $locale,
+        template => 'am-warehouse-form');
+    $template->render({
+        form => $form,
+        row_count => $rows,
+        buttons => ..hidden..,
+        hiddens => \%hiddens,
+    });
+
 }
 
 sub edit_warehouse {
@@ -1996,16 +2009,29 @@
 
     AM->get_warehouse( \%myconfig, \%$form );
 
-    &warehouse_header;
-    &form_footer;
+    my %hiddens;
+    my @buttons;
+    my $rows = &warehouse_header(\%hiddens);
+    &form_footer_buttons(\%hiddens, ..hidden..);
 
+    my $template = LedgerSMB::Template->new_UI(
+        user => \%myconfig, 
+        locale => $locale,
+        template => 'am-warehouse-form');
+    $template->render({
+        form => $form,
+        row_count => $rows,
+        buttons => ..hidden..,
+        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 @@
     $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);
+    my @column_index = qw(description);
+    my %column_header;
+    $column_header{description} = {
+        href => $href,
+        text => $locale->text('Description'),
+        };
 
-    $column_header{description} =
-        qq|<th width=100%><a class="listheading" href=$href>|
-      . $locale->text('Description')
-      . qq|</a></th>|;
+    my @rows;
+    my $i;
+    foreach my $ref ( @{ $form->{ALL} } ) {
 
-    $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>
-|;
-
-    foreach $ref ( @{ $form->{ALL} } ) {
-
+        my %column_data;
         $i++;
         $i %= 2;
+        $column_data{i} = $i;
 
-        print qq|
-        <tr valign=top class=listrow$i>
-|;
+        $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},
+            };
 
-        $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" }
-
-        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));
+##SC: Temporary commenting
+##    if ( $form->{lynx} ) {
+##        require "bin/menu.pl";
+##        &menubar;
+##    }
+    my @buttons = ({
+        name => 'action',
+        value => 'add_warehouse',
+        text => $locale->text('Add Warehouse'),
+        });
 
-    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> 
-|;
-
+    my $template = LedgerSMB::Template->new_UI(
+        user => \%myconfig, 
+        locale => $locale,
+        template => 'form-dynatable');
+    $template->render({
+        form => $form,
+        buttons => ..hidden..,
+	hiddens => \%hiddens,
+        columns => ..hidden..,
+        heading => \%column_header,
+        rows => ..hidden..,
+    });
 }
 
 sub warehouse_header {
+    my $hiddens = shift;
 
     $form->{title} = $locale->text("$form->{title} Warehouse");
 
@@ -2110,40 +2105,11 @@
 
     $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}">|;
-    }
+    $hiddens->{id} = $form->{id};
+    $hiddens->{type} = 'warehouse';
 
-    $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>
-|;
-
+    my $rows = $form->numtextrows( $form->{description}, 60 );
+    $rows;
 }
 
 sub save_warehouse {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.