cgi->popup_menu durch L.select_tag (in templates/webpages/ap/form_header.html) ersetzt
authorThomas Heck <theck@linet-services.de>
Fri, 4 Jan 2013 16:05:44 +0000 (17:05 +0100)
committerThomas Heck <theck@linet-services.de>
Mon, 7 Jan 2013 13:19:25 +0000 (14:19 +0100)
bin/mozilla/ap.pl
templates/webpages/ap/form_header.html

index 7829d74..dddf6c5 100644 (file)
@@ -255,48 +255,39 @@ sub form_header {
   );
 
   my %project_labels = ();
-  my @project_values = ("");
   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
-    push(@project_values, $item->{id});
     $project_labels{$item->{id}} = $item->{projectnumber};
   }
 
-  my (%AP_amount_labels, @AP_amount_values);
-  my (%AP_labels, @AP_values);
-  my (%AP_paid_labels, @AP_paid_values);
   my %charts;
   my $taxchart_init;
 
   foreach my $item (@{ $form->{ALL_CHARTS} }) {
-    if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
-      $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
-      my $key = "$item->{accno}--$item->{tax_id}";
-      push(@AP_amount_values, $key);
-      $AP_amount_labels{$key} =
-        "$item->{accno}--$item->{description}";
-
-    } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
-      push(@AP_values, $item->{accno});
-      $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
-
-    } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
-      push(@AP_paid_values, $item->{accno});
-      $AP_paid_labels{$item->{accno}} =
-        "$item->{accno}--$item->{description}";
+    if ( grep({ $_ eq 'AP_amount' } @{ $item->{link_split} }) ) {
+      if ( $taxchart_init eq '' ) {
+        $taxchart_init = $item->{tax_id};
+      }
+
+      push(@{ $form->{ALL_CHARTS_AP_amount} }, $item);
+    }
+    elsif ( grep({ $_ eq 'AP' } @{ $item->{link_split} }) ) {
+      push(@{ $form->{ALL_CHARTS_AP} }, $item);
+    }
+    elsif ( grep({ $_ eq 'AP_paid' } @{ $item->{link_split} }) ) {
+      push(@{ $form->{ALL_CHARTS_AP_paid} }, $item);
     }
 
     $charts{$item->{accno}} = $item;
   }
 
-  my %taxchart_labels = ();
-  my @taxchart_values = ();
   my %taxcharts = ();
   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
-    my $key = "$item->{id}--$item->{rate}";
-    $taxchart_init = $key if ($taxchart_init eq $item->{id});
-    push(@taxchart_values, $key);
-    $taxchart_labels{$key} =
-      "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
+    my $key = $item->{id} .'--'. $item->{rate};
+
+    if ( $taxchart_init eq $item->{id} ) {
+      $taxchart_init = $key;
+    }
+
     $taxcharts{$item->{id}} = $item;
   }
 
@@ -310,13 +301,7 @@ sub form_header {
   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
   $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
 
-  $form->{globalprojectnumber} =
-    NTI($cgi->popup_menu('-name' => "globalproject_id",
-                         '-values' => \@project_values,
-                         '-labels' => \%project_labels,
-                         '-default' => $form->{"globalproject_id"} ));
-
-  $form->header;
+  $form->header();
 
   for my $i (1 .. $form->{rowcount}) {
 
@@ -342,56 +327,52 @@ sub form_header {
 
     $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
 
-    $form->{'selectAP_amount_'. $i} =
-      NTI($cgi->popup_menu('-name' => "AP_amount_$i",
-                           '-id' => "AP_amount_$i",
-                           '-style' => 'width:400px',
-                           '-onChange' => "setTaxkey(this, $i)",
-                           '-values' => \@AP_amount_values,
-                           '-labels' => \%AP_amount_labels,
-                           '-default' => $selected_accno_full))
-      . $cgi->hidden('-name' => "previous_AP_amount_$i",
-                     '-default' => $selected_accno_full);
-
-    $form->{'select_tax_'. $i} =
-      NTI($cgi->popup_menu('-name' => "taxchart_$i",
-                           '-id' => "taxchart_$i",
-                           '-style' => 'width:200px',
-                           '-values' => \@taxchart_values,
-                           '-labels' => \%taxchart_labels,
-                           '-default' => $selected_taxchart));
-
-    $form->{'select_projectnumber_'. $i} =
-      NTI($cgi->popup_menu('-name' => "project_id_$i",
-                           '-values' => \@project_values,
-                           '-labels' => \%project_labels,
-                           '-default' => ($i==$form->{rowcount})? $form->{globalproject_id} : $form->{"project_id_$i"} ));
+    $form->{'selected_accno_full_'. $i} = $selected_accno_full;
+
+    $form->{'selected_taxchart_'. $i} = $selected_taxchart;
   }
 
+  $form->{AP_amount_value_title_sub} = sub {
+    my $item = shift;
+    return [
+      $item->{accno} .'--'. $item->{tax_id},
+      $item->{accno} .'--'. $item->{description},
+    ];
+  };
+
+  $form->{taxchart_value_title_sub} = sub {
+    my $item = shift;
+    return [
+      $item->{id} .'--'. $item->{rate},
+      $item->{taxdescription} .' '. ($item->{rate} * 100) .' %',
+    ];
+  };
+
+  $form->{AP_paid_value_title_sub} = sub {
+    my $item = shift;
+    return [
+      $item->{accno},
+      $item->{accno} .'--'. $item->{description}
+    ];
+  };
+
+  $form->{APselected_value_title_sub} = sub {
+    my $item = shift;
+    return [
+      $item->{accno},
+      $item->{accno} .'--'. $item->{description}
+    ];
+  };
 
   $form->{invtotal_unformatted} = $form->{invtotal};
   $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
 
-  $form->{APselected} =
-    NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
-                         '-style' => 'width:400px',
-                         '-values' => \@AP_values, '-labels' => \%AP_labels,
-                         '-default' => $form->{APselected}));
-
   $form->{totalpaid} = 0;
 
   if ( $form->{'paid_'. $form->{paidaccounts}} ) {
     $form->{paidaccounts}++;
   }
   for my $i (1 .. $form->{paidaccounts}) {
-
-    $form->{'selectAP_paid_'. $i} =
-      NTI($cgi->popup_menu('-name' => "AP_paid_$i",
-                           '-id' => "AP_paid_$i",
-                           '-values' => \@AP_paid_values,
-                           '-labels' => \%AP_paid_labels,
-                           '-default' => $form->{"AP_paid_$i"}));
-
     $form->{totalpaid} += $form->{"paid_$i"};
 
     # format amounts
@@ -417,15 +398,7 @@ sub form_header {
 
     $form->{'paidaccount_changeable_'. $i} = $changeable;
 
-    if ( $changeable ) {
-      $form->{'selectpaid_project_id_'. $i} =
-        NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
-          '-values' => \@project_values,
-          '-labels' => \%project_labels,
-          '-default' => $form->{"paid_project_id_$i"}));
-    } else {
-      $form->{'labelpaid_project_id_'. $i} = $project_labels{$form->{'paid_project_id_'. $i}};
-    }
+    $form->{'labelpaid_project_id_'. $i} = $project_labels{$form->{'paid_project_id_'. $i}};
   }
 
   $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid};
index 124eb64..0d003c6 100644 (file)
               </tr>
               <tr>
                 <th align="right" nowrap>[% 'Project Number' | $T8 %]</th>
-                <td>[% globalprojectnumber %]</td>
+                <td>
+                  [% L.select_tag('globalproject_id', ALL_PROJECTS, with_empty = 1, default = globalproject_id, value_key = 'id', title_key = 'projectnumber') %]
+                </td>
               </tr>
             </table>
           </td>
         [% FOREACH i IN [1..rowcount] %]
           <tr>
             <td>
-              [% temp = "selectAP_amount_"_ i %][% $temp %]
+              [% selected_accno_full = "selected_accno_full_"_ i %]
+              [% L.select_tag('AP_amount_'_ i, ALL_CHARTS_AP_amount, value_title_sub = \AP_amount_value_title_sub, onchange = 'setTaxkey(this, '_ i _')', default = $selected_accno_full) %]
+
+              <input type="hidden" name="previous_AP_amount_[% i %]" value="[% $selected_accno_full %]">
               <input type="hidden" name="tax_[% i %]" value="[% temp = "tax"_ i %][% $temp | html %]">
             </td>
             <td>
               [% temp = "tax_"_ i %][% $temp | html %]
             </td>
             <td>
-              [% temp = "select_tax_"_ i %][% $temp %]
+              [% temp = 'selected_taxchart_'_ i %]
+              [% L.select_tag('taxchart_'_ i, ALL_TAXCHARTS, value_title_sub = \taxchart_value_title_sub, default = $temp) %]
             </td>
             <td>
-              [% temp = "select_projectnumber_"_ i %][% $temp %]
+              [% temp = "project_id_"_ i %]
+              [% L.select_tag(temp, ALL_PROJECTS, with_empty = 1, default = loop.last ? globalproject_id : $temp, value_key = 'id', title_key = 'projectnumber') %]
             </td>
           </tr>
         [% END %]
           </td>
         </tr>
         <tr>
-          <td>[% APselected %]</td>
+          <td>
+            [% L.select_tag('APselected', ALL_CHARTS_AP, value_title_sub = \APselected_value_title_sub, default = APselected) %]
+          </td>
           <th align="left">[% invtotal | html %]</th>
           <td colspan="4"></td>
         </tr>
             [% temp = "AP_paid_"_ i %]
             <td align="center">
               [% IF( changeable ) %]
-                [% temp = "select"_ temp %]
-                [% $temp %]
+                [% L.select_tag(temp, ALL_CHARTS_AP_paid, value_title_sub = \AP_paid_value_title_sub, default = $temp) %]
               [% ELSE %]
                 [% $temp | html %]
                 <input type="hidden" name="[% temp %]" value="[% $temp | html %]">
               [% END %]
             </td>
 
-            [% temp = "paid_project_id_"_ i %]
             <td align="center">
+              [% temp = "paid_project_id_"_ i %]
               [% IF( changeable ) %]
-                [% temp = "select"_ temp %]
-                [% $temp %]
+                [% L.select_tag(temp, ALL_PROJECTS, with_empty = 1, default = $temp, value_key = 'id', title_key = 'projectnumber') %]
               [% ELSE %]
                 <input type="hidden" name="[% temp %]" value="[% $temp | html %]">
                 [% temp = "label"_ temp %]