onload in dn.pl und common.pl
authorSven Schöling <s.schoeling@linet-services.de>
Thu, 20 Sep 2012 15:58:41 +0000 (17:58 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Wed, 17 Oct 2012 14:01:00 +0000 (16:01 +0200)
bin/mozilla/common.pl
bin/mozilla/dn.pl
templates/webpages/dunning/search.html
templates/webpages/dunning/show_dunning_bottom.html
templates/webpages/dunning/show_invoices.html

index 9d78d9f..3cb850d 100644 (file)
@@ -169,12 +169,11 @@ sub part_selection_internal {
   map { $form->{$_} = $options{$_} if ($options{$_}) } qw(no_services no_assemblies assemblies click_button);
 
   my $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
-  my $onload;
 
   if (0 == scalar(@{$parts})) {
     $form->show_generic_information($locale->text("No part was found matching the search parameters."));
   } elsif (1 == scalar(@{$parts})) {
-    $onload = "part_selected('1')";
+    $::request->{layout}->add_javascripts_inline("part_selected('1')");
   }
 
   map { $parts->[$_]->{selected} = $_ ? 0 : 1; } (0..$#{$parts});
@@ -199,8 +198,7 @@ sub part_selection_internal {
   $form->{title} = $locale->text("Select a part");
   $form->header();
   print $form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
-                                                               "PARTS"  => $parts,
-                                                               "onload" => $onload });
+                                                               "PARTS"  => $parts, });
 
   $main::lxdebug->leave_sub();
 }
@@ -222,11 +220,10 @@ sub delivery_customer_selection {
   my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
   map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
 
-  my $onload;
   if (0 == scalar(@{$delivery})) {
     $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
   } elsif (1 == scalar(@{$delivery})) {
-    $onload = "customer_selected('1')";
+    $::request->{layout}->add_javascripts_inline("customer_selected('1')");
   }
 
   my $callback = "$form->{script}?action=delivery_customer_selection&";
@@ -249,8 +246,7 @@ sub delivery_customer_selection {
   $form->{"title"} = $locale->text("Select a Customer");
   $form->header();
   print $form->parse_html_template("generic/select_delivery_customer", { "HEADER"   => \@header,
-                                                                         "DELIVERY" => $delivery,
-                                                                         "onload"   => $onload });
+                                                                         "DELIVERY" => $delivery, });
 
   $main::lxdebug->leave_sub();
 }
@@ -272,11 +268,10 @@ sub vendor_selection {
   my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
   map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
 
-  my $onload;
   if (0 == scalar(@{$vendor})) {
     $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
   } elsif (1 == scalar(@{$vendor})) {
-    $onload = "vendor_selected('1')";
+    $::request->{layout}->add_javascripts_inline("vendor_selected('1')");
   }
 
   my $callback = "$form->{script}?action=vendor_selection&";
@@ -299,8 +294,7 @@ sub vendor_selection {
   $form->{"title"} = $locale->text("Select a Customer");
   $form->header();
   print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
-                                                              "VENDOR" => $vendor,
-                                                              "onload" => $onload });
+                                                              "VENDOR" => $vendor, });
 
   $main::lxdebug->leave_sub();
 }
@@ -317,7 +311,6 @@ sub calculate_qty {
 
   my ($variable_string, $formel) = split /###/,$form->{formel};
   my @variable;
-  my $onload; # note! this sub is mostly called over a javascript invocation, and it's unlikey that onload is set.
 
   foreach my $item (split m/;/, $variable_string) {
     next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x;
@@ -343,8 +336,7 @@ sub calculate_qty {
   $form->{title}  = $locale->text("Please enter values");
   $form->header();
   print $form->parse_html_template("generic/calculate_qty", { "HEADER"    => \@header,
-                                                              "VARIABLES" => \@variable,
-                                                              "onload"    => $onload });
+                                                              "VARIABLES" => \@variable, });
 
   $main::lxdebug->leave_sub();
 }
@@ -549,11 +541,10 @@ sub cov_selection_internal {
   my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
   map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
 
-  my $onload;
   if (0 == scalar(@{$covs})) {
     $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
   } elsif (1 == scalar(@{$covs})) {
-    $onload = "cov_selected('1')";
+    $::request->{layout}->add_javascripts_inline("cov_selected('1')");
   }
 
   my $callback = "$form->{script}?action=cov_selection_internal&";
@@ -585,8 +576,7 @@ sub cov_selection_internal {
   $form->{"title"} = $form->{is_vendor} ? $locale->text("Select a vendor") : $locale->text("Select a customer");
   $form->header();
   print($form->parse_html_template("generic/cov_selection", { "HEADER" => \@header,
-                                                              "COVS" => $covs,
-                                                              "onload" => $onload }));
+                                                              "COVS" => $covs, }));
 
   $main::lxdebug->leave_sub();
 }
index 90d5607..ea2c3d4 100644 (file)
@@ -154,8 +154,6 @@ sub show_invoices {
                                           'no_opendocument' => 1,);
 
   $form->header();
-  $form->{onload} = "document.getElementsByName('language_id')[0].disabled =
-        !document.getElementsByName('force_lang')[0].checked;";
   print $form->parse_html_template("dunning/show_invoices");
 
   $main::lxdebug->leave_sub();
@@ -312,7 +310,7 @@ sub search {
 
   $form->{jsscript} = 1;
   $form->{title}    = $locale->text('Dunnings');
-  $form->{fokus}    = "search.customer";
+  $::request->{layout}->focus('#customer');
 
   $form->header();
 
@@ -456,8 +454,6 @@ sub show_dunning {
 
   $report->set_options_from_form();
 
-  $form->{onload} = "document.getElementsByName('language_id')[0].disabled =
-        !document.getElementsByName('force_lang')[0].checked;";
   $report->generate_with_headers();
 
   $main::lxdebug->leave_sub();
index d4a092c..a56bbef 100644 (file)
        <th align="right">[% 'Customer' | $T8 %]</th>
        <td colspan="3">
         [% IF SHOW_CUSTOMER_DDBOX %]
-         <select name="customer_id">
+         <select id='customer' name="customer_id">
           <option value=""></option>
           [% FOREACH row = ALL_CUSTOMERS %]<option value="[% HTML.escape(row.id) %]">[% HTML.escape(row.name) %]</option>
           [% END %]
          </select>
          [% ELSE %]
-         <input name="customer" size="35">
+         <input id='customer' name="customer" size="35">
         [% END %]
        </td>
       </tr>
index 2f05d15..ee85ec0 100644 (file)
@@ -2,7 +2,7 @@
 [% USE HTML %]  <input type="hidden" name="rowcount" value="[% rowcount %]">
 
   <p>
-    <input type="checkbox" name="force_lang" size="6" value="1" onclick="document.getElementsByName('language_id')[0].disabled = !document.getElementsByName('force_lang')[0].checked;">
+    <input type="checkbox" id='force_lang' name="force_lang" size="6" value="1">
     [% 'Override invoice language' | $T8 %]
     [% PRINT_OPTIONS %]
   </p>
@@ -15,3 +15,7 @@
   </p>
 
  </form>
+ <script type='text/javascript'>
+   $(function(){$("select[name='language_id']").attr('disabled', $('#force_lang').attr('checked') ? '' : 'disabled')})
+   $('#force_lang').click(function(){ $('select[name="language_id"]').attr('disabled', $('#force_lang').attr('checked') ? '' : 'disabled') })
+ </script>
index 2c3b9d3..968e67d 100644 (file)
@@ -77,7 +77,7 @@
 
   <hr size=3 noshade>
 
-  <input type="checkbox" name="force_lang" size="6" value="1" onclick="document.getElementsByName('language_id')[0].disabled = !document.getElementsByName('force_lang')[0].checked;">
+  <input type="checkbox" id='force_lang' name="force_lang" size="6" value="1">
   [% 'Override invoice language' | $T8 %]
   [% PRINT_OPTIONS %]
 
@@ -95,3 +95,8 @@
          [% UNLESS DEBUG_DUNNING %]onclick="this.disabled=true; this.value='[% 'The dunning process started' | $T8 %]'; document.Form.submit()"[% END %]>
 
  </form>
+ <script type='text/javascript'>
+   $(function(){$("select[name='language_id']").attr('disabled', $('#force_lang').attr('checked') ? '' : 'disabled')})
+   $('#force_lang').click(function(){ $('select[name="language_id"]').attr('disabled', $('#force_lang').attr('checked') ? '' : 'disabled') })
+ </script>
+