Lieferadressentab mit jQuery & AJAX neu laden lassen, nicht via CGI::AJAX
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 22 Jul 2011 11:07:15 +0000 (13:07 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 22 Jul 2011 11:07:15 +0000 (13:07 +0200)
bin/mozilla/ct.pl
templates/webpages/ct/_shipto.html [new file with mode: 0644]
templates/webpages/ct/form_header.html

index b25509e..3202dfb 100644 (file)
@@ -293,6 +293,11 @@ sub edit {
   $main::lxdebug->leave_sub();
 }
 
+sub _shipto_label {
+  my $s = shift(@_);
+  join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' '
+}
+
 sub form_header {
   $main::lxdebug->enter_sub();
 
@@ -313,14 +318,14 @@ sub form_header {
   $form->{is_admin}       = $myconfig{role} eq 'admin';
   $form->{is_customer}    = $form->{db}     eq 'customer';
   $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} };
-  $form->{shipto_label}   = sub { my $s = shift(@_); join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' ' };
+  $form->{shipto_label}   = \&_shipto_label;
   $form->{contacts_label} = sub { join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname} };
   $form->{taxzone_id}     = 0                                                               if !$form->{id};
   $form->{jsscript}       = 1;
   $form->{fokus}          = "ct.greeting";
-  $form->{AJAX}           = [ new CGI::Ajax( map {; "get_$_" => "$form->{script}?action=get_$_" } qw(shipto contact delivery) ) ];
+  $form->{AJAX}           = [ new CGI::Ajax( map {; "get_$_" => "$form->{script}?action=get_$_" } qw(contact delivery) ) ];
+  $form->{SHIPTO_ALL}     = [ +{ shipto_id => '0', shiptoname => $::locale->text('All') }, @{ $form->{SHIPTO} } ];
 
-  unshift @{ $form->{SHIPTO} },   +{ shipto_id => '0', shiptoname => '' }, +{ shipto_id => '0', shiptoname => 'Alle' };
   unshift @{ $form->{CONTACTS} }, +{ cp_id     => '0', cp_name => $locale->text('New contact') };
 
   $form->{title} = $form->{title_save}
@@ -661,13 +666,14 @@ sub get_shipto {
 
   $main::auth->assert('customer_vendor_edit');
 
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
+  CT->populate_drop_down_boxes(\%::myconfig, $::form);
+  CT->get_shipto(\%::myconfig, $::form) if $::form->{shipto_id};
 
-  CT->get_shipto(\%myconfig, \%$form);
-  print $form->ajax_response_header(), join('__pjx__', map($form->{"shipto$_"}, qw(name department_1 department_2 street zipcode city country contact phone fax email used)));
-  $main::lxdebug->leave_sub();
+  $::form->{shipto_label} = \&_shipto_label;
 
+  print $::form->ajax_response_header(), $::form->parse_html_template('ct/_shipto');
+
+  $main::lxdebug->leave_sub();
 }
 
 sub get_delivery {
diff --git a/templates/webpages/ct/_shipto.html b/templates/webpages/ct/_shipto.html
new file mode 100644 (file)
index 0000000..46d8444
--- /dev/null
@@ -0,0 +1,69 @@
+[% USE L %][% USE HTML %][% USE T8 %][% USE LxERP %]
+    <table width="100%" id="shipto_table">
+     <tr>
+      <th align="right">[% 'Shipping Address' | $T8 %]</th>
+      <td>
+       [%- INCLUDE generic/multibox.html
+             name       = 'shipto_id',
+             id         = 'shipto_id',
+             DATA       = SHIPTO,
+             onChange   = "\$('#shipto_table').load('ct.pl?action=get_shipto&id=' + \$('#cvid').attr('value') + '&db=' + \$('#db').attr('value') + '&shipto_id=' + this.value)",
+             id_key     = 'shipto_id',
+             label_sub  = 'shipto_label',
+             label_key  = 'shipto_label',
+             show_empty = 1,
+       -%]
+      </td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Company Name' | $T8 %]</th>
+      <td><input id="shiptoname" name="shiptoname" size="35" maxlength="75" value="[% HTML.escape(shiptoname) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Abteilung' | $T8 %]</th>
+      <td>
+       <input id="shiptodepartment_1" name="shiptodepartment_1" size="16" maxlength="75" value="[% HTML.escape(shiptodepartment_1) %]">
+       <input id="shiptodepartment_2" name="shiptodepartment_2" size="16" maxlength="75" value="[% HTML.escape(shiptodepartment_2) %]">
+      </td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Street' | $T8 %]</th>
+      <td><input id="shiptostreet" name="shiptostreet" size="35" maxlength="75" value="[% HTML.escape(shiptostreet) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Zipcode' | $T8 %]/[% 'City' | $T8 %]</th>
+      <td>
+       <input id="shiptozipcode" name="shiptozipcode" size="5" maxlength="75" value="[% HTML.escape(shiptozipcode) %]">
+       <input id="shiptocity" name="shiptocity" size="30" maxlength="75" value="[% HTML.escape(shiptocity) %]">
+      </td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Country' | $T8 %]</th>
+      <td><input id="shiptocountry" name="shiptocountry" size="35" maxlength="75" value="[% HTML.escape(shiptocountry) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Contact' | $T8 %]</th>
+      <td><input id="shiptocontact" name="shiptocontact" size="30" maxlength="75" value="[% HTML.escape(shiptocontact) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Phone' | $T8 %]</th>
+      <td><input id="shiptophone" name="shiptophone" size="30" maxlength="30" value="[% HTML.escape(shiptophone) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'Fax' | $T8 %]</th>
+      <td><input id="shiptofax" name="shiptofax" size="30" maxlength="30" value="[% HTML.escape(shiptofax) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="right" nowrap>[% 'E-mail' | $T8 %]</th>
+      <td><input id="shiptoemail" name="shiptoemail" size="45" value="[% HTML.escape(shiptoemail) %]"></td>
+     </tr>
+    </table>
index 1473a71..e2e5334 100644 (file)
    </div>
 
    <div id="shipto" class="tabcontent">
-
-    <table width="100%">
-     <tr>
-      <th align="right">[% 'Shipping Address' | $T8 %]</th>
-      <td>
-       [%- INCLUDE generic/multibox.html
-             name       = 'shipto_id',
-             id         = 'shipto_id',
-             DATA       = SHIPTO,
-             onChange   = "get_shipto(['shipto_id__' + this.value], ['shiptoname','shiptodepartment_1', 'shiptodepartment_2','shiptostreet','shiptozipcode','shiptocity','shiptocountry','shiptocontact','shiptophone','shiptofax','shiptoemail',enable_delete_shipto,set_gender])",
-             id_key     = 'shipto_id',
-             label_sub  = 'shipto_label',
-             label_key  = 'shipto_label',
-       -%]
-      </td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Company Name' | $T8 %]</th>
-      <td><input id="shiptoname" name="shiptoname" size="35" maxlength="75" value="[% HTML.escape(shiptoname) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Abteilung' | $T8 %]</th>
-      <td>
-       <input id="shiptodepartment_1" name="shiptodepartment_1" size="16" maxlength="75" value="[% HTML.escape(shiptodepartment_1) %]">
-       <input id="shiptodepartment_2" name="shiptodepartment_2" size="16" maxlength="75" value="[% HTML.escape(shiptodepartment_2) %]">
-      </td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Street' | $T8 %]</th>
-      <td><input id="shiptostreet" name="shiptostreet" size="35" maxlength="75" value="[% HTML.escape(shiptostreet) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Zipcode' | $T8 %]/[% 'City' | $T8 %]</th>
-      <td>
-       <input id="shiptozipcode" name="shiptozipcode" size="5" maxlength="75" value="[% HTML.escape(shiptozipcode) %]">
-       <input id="shiptocity" name="shiptocity" size="30" maxlength="75" value="[% HTML.escape(shiptocity) %]">
-      </td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Country' | $T8 %]</th>
-      <td><input id="shiptocountry" name="shiptocountry" size="35" maxlength="75" value="[% HTML.escape(shiptocountry) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Contact' | $T8 %]</th>
-      <td><input id="shiptocontact" name="shiptocontact" size="30" maxlength="75" value="[% HTML.escape(shiptocontact) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Phone' | $T8 %]</th>
-      <td><input id="shiptophone" name="shiptophone" size="30" maxlength="30" value="[% HTML.escape(shiptophone) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'Fax' | $T8 %]</th>
-      <td><input id="shiptofax" name="shiptofax" size="30" maxlength="30" value="[% HTML.escape(shiptofax) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="right" nowrap>[% 'E-mail' | $T8 %]</th>
-      <td><input id="shiptoemail" name="shiptoemail" size="45" value="[% HTML.escape(shiptoemail) %]"></td>
-     </tr>
-
-     <tr>
-      <td>&nbsp;</td>
-     </tr>
-     <tr>
-      <td>&nbsp;</td>
-     </tr>
-    </table>
+    [% INCLUDE 'ct/_shipto.html' %]
 
     <input type="submit" id="delete_shipto" name="action" value="[% 'Delete Shipto' | $T8 %]" disabled>
     <br style="clear: left" />
        [%- INCLUDE generic/multibox.html
              name       = 'delivery_id',
              id         = 'delivery_id',
-             DATA       = SHIPTO,
+             DATA       = SHIPTO_ALL,
              onChange   = "get_delivery(['shipto_id__' + this.value, 'from__' + from.value, 'to__' + to.value, 'id__' + cvid.value, 'db__' + db.value], ['delivery'])",
              id_key     = 'shipto_id',
              label_sub  = 'shipto_label',
+             show_empty = 1,
        -%]
       </td>
      </tr>