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

index 3202dfb..92ef085 100644 (file)
@@ -298,6 +298,10 @@ sub _shipto_label {
   join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' '
 }
 
+sub _contacts_label {
+  join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname};
+}
+
 sub form_header {
   $main::lxdebug->enter_sub();
 
@@ -319,20 +323,18 @@ sub form_header {
   $form->{is_customer}    = $form->{db}     eq 'customer';
   $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} };
   $form->{shipto_label}   = \&_shipto_label;
-  $form->{contacts_label} = sub { join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname} };
+  $form->{contacts_label} = \&_contacts_label;
   $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(contact delivery) ) ];
+  $form->{AJAX}           = [ new CGI::Ajax( map {; "get_$_" => "$form->{script}?action=get_$_" } qw(delivery) ) ];
   $form->{SHIPTO_ALL}     = [ +{ shipto_id => '0', shiptoname => $::locale->text('All') }, @{ $form->{SHIPTO} } ];
 
-  unshift @{ $form->{CONTACTS} }, +{ cp_id     => '0', cp_name => $locale->text('New contact') };
-
   $form->{title} = $form->{title_save}
                 || $locale->text("$form->{title} " . ucfirst $form->{db}) . ($form->{title} eq "Edit" ? " $form->{name}" : '');
 
   CT->query_titles_and_greetings(\%myconfig, \%$form);
-  map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(TITLES GREETINGS COMPANY_GREETINGS DEPARTMENT);
+  map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(COMPANY_GREETINGS);
 
   $form->{NOTES} ||= [ ];
 
@@ -651,14 +653,15 @@ sub get_contact {
 
   $main::auth->assert('customer_vendor_edit');
 
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
+  CT->populate_drop_down_boxes(\%::myconfig, $::form);
+  CT->query_titles_and_greetings(\%::myconfig, $::form);
+  CT->get_contact(\%::myconfig, $::form) if $::form->{cp_id};
 
-  CT->get_contact(\%myconfig, \%$form);
-  print $form->ajax_response_header(), join '__pjx__', map $form->{"cp_$_"},
-    qw(name title givenname phone1 phone2 email abteilung fax mobile1 mobile2 satphone satfax project privatphone privatemail birthday used gender);
-  $main::lxdebug->leave_sub();
+  $::form->{contacts_label} = \&_contacts_label;
 
+  print $::form->ajax_response_header(), $::form->parse_html_template('ct/_contact');
+
+  $main::lxdebug->leave_sub();
 }
 
 sub get_shipto {
diff --git a/templates/webpages/ct/_contact.html b/templates/webpages/ct/_contact.html
new file mode 100644 (file)
index 0000000..8da17e9
--- /dev/null
@@ -0,0 +1,117 @@
+[% USE L %][% USE HTML %][% USE T8 %][% USE LxERP %]
+    <table id="contact_table">
+     <input type="hidden" name="cp_id" value="[% HTML.escape(cp_id) %]">
+     <tr>
+      <th align="left">[% 'Contacts' | $T8 %]</th>
+      <td>
+       [%- L.select_tag('cp_id', L.options_for_select(CONTACTS, default => cp_id, with_empty => 1, empty_title => LxERP.t8('New contact'), value => 'cp_id', title_sub => \contacts_label),
+                        onchange => "\$('#contact_table').load('ct.pl?action=get_contact&id=' + \$('#cvid').attr('value') + '&db=' + \$('#db').attr('value') + '&cp_id=' + \$('#cp_id').attr('value'))") %]
+      </td>
+     </tr>
+
+    <tr>
+     <th align="left" nowrap>[% 'Gender' | $T8 %]</th>
+     <td>
+      <select id="cp_gender" name="cp_gender">
+       <option value="m"[% IF cp_gender == 'm' %] selected[% END %]>[% 'male' | $T8 %]</option>
+       <option value="f"[% IF cp_gender == 'f' %] selected[% END %]>[% 'female' | $T8 %]</option>
+      </select>
+     </td>
+    </tr>
+    <tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Title' | $T8 %]</th>
+      <td>
+       <input id="cp_title" name="cp_title" size="40" maxlength="75" value="[% HTML.escape(cp_title) %]">&nbsp;
+       [% L.select_tag('selected_cp_title', L.options_for_select(TITLES, with_empty => 1)) %]
+      </td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Department' | $T8 %]</th>
+      <td>
+       <input id="cp_abteilung" name="cp_abteilung" size="40" value="[% HTML.escape(cp_abteilung) %]">&nbsp;
+       [% L.select_tag('selected_cp_abteilung', L.options_for_select(DEPARTMENT, with_empty => 1)) %]
+      </td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Given Name' | $T8 %]</th>
+      <td><input id="cp_givenname" name="cp_givenname" size="40" maxlength="75" value="[% HTML.escape(cp_givenname) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Name' | $T8 %]</th>
+      <td><input id="cp_name" name="cp_name" size="40" maxlength="75" value="[% HTML.escape(cp_name) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Phone1' | $T8 %]</th>
+      <td><input id="cp_phone1" name="cp_phone1" size="40" maxlength="75" value="[% HTML.escape(cp_phone1) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Phone2' | $T8 %]</th>
+      <td><input id="cp_phone2" name="cp_phone2" size="40" maxlength="75" value="[% HTML.escape(cp_phone2) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Fax' | $T8 %]</th>
+      <td><input id="cp_fax" name="cp_fax" size="40" value="[% HTML.escape(cp_fax) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Mobile1' | $T8 %]</th>
+      <td><input id="cp_mobile1" name="cp_mobile1" size="40" value="[% HTML.escape(cp_mobile1) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Mobile2' | $T8 %]</th>
+      <td><input id="cp_mobile2" name="cp_mobile2" size="40" value="[% HTML.escape(cp_mobile2) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Sat. Phone' | $T8 %]</th>
+      <td><input id="cp_satphone" name="cp_satphone" size="40" value="[% HTML.escape(cp_satphone) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Sat. Fax' | $T8 %]</th>
+      <td><input id="cp_satfax" name="cp_satfax" size="40" value="[% HTML.escape(cp_satfax) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Project' | $T8 %]</th>
+      <td><input id="cp_project" name="cp_project" size="40" value="[% HTML.escape(cp_project) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'E-mail' | $T8 %]</th>
+      <td><input id="cp_email" name="cp_email" size="40" value="[% HTML.escape(cp_email) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Private Phone' | $T8 %]</th>
+      <td><input id="cp_privatphone" name="cp_privatphone" size="40" value="[% HTML.escape(cp_privatphone) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Private E-mail' | $T8 %]</th>
+      <td><input id="cp_privatemail" name="cp_privatemail" size="40" value="[% HTML.escape(cp_privatemail) %]"></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Birthday' | $T8 %]</th>
+      <td><input id="cp_birthday" name="cp_birthday" size="40" value="[% HTML.escape(cp_birthday) %]"></td>
+     </tr>
+
+     <tr>
+      <td colspan="2"><hr></td>
+     </tr>
+
+     <tr>
+      <th align="left" nowrap>[% 'Bcc' | $T8 %]</th>
+      <td><input name="bcc" size="40" value="[% HTML.escape(bcc) %]"></td>
+     </tr>
+    </table>
index e2e5334..a09bfe3 100644 (file)
    </div>
 
    <div id="contacts" class="tabcontent">
-    <table>
-     <input type="hidden" name="cp_id" value="[% HTML.escape(cp_id) %]">
-     <tr>
-      <th align="left">[% 'Contacts' | $T8 %]</th>
-      <td>
-       [%- INCLUDE generic/multibox.html
-             name       = 'cp_id',
-             id         = 'cp_id',
-             DATA       = CONTACTS,
-             onChange   = "on_contact_changed()",
-             id_key     = 'cp_id',
-             label_sub  = 'contacts_label',
-       -%]
-      </td>
-     </tr>
-
-    <tr>
-     <th align="left" nowrap>[% 'Gender' | $T8 %]</th>
-     <td>
-      <select id="cp_gender" name="cp_gender">
-       <option value="m"[% IF cp_gender == 'm' %] selected[% END %]>[% 'male' | $T8 %]</option>
-       <option value="f"[% IF cp_gender == 'f' %] selected[% END %]>[% 'female' | $T8 %]</option>
-      </select>
-     </td>
-    </tr>
-    <tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Title' | $T8 %]</th>
-      <td>
-       <input id="cp_title" name="cp_title" size="40" maxlength="75" value="[% HTML.escape(cp_title) %]">&nbsp;
-       [%- INCLUDE generic/multibox.html
-             name       = 'selected_cp_title',
-             id         = 'selected_cp_title',
-             DATA       = MB_TITLES,
-             show_empty = 1,
-             id_key     = 'id',
-             label_key  = 'description',
-       -%]
-      </td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Department' | $T8 %]</th>
-      <td>
-       <input id="cp_abteilung" name="cp_abteilung" size="40" value="[% HTML.escape(cp_abteilung) %]">&nbsp;
-       [%- INCLUDE generic/multibox.html
-             name       = 'selected_cp_abteilung',
-             id         = 'selected_cp_abteilung',
-             DATA       = MB_DEPARTMENT,
-             show_empty = 1,
-             id_key     = 'id',
-             label_key  = 'description',
-       -%]
-      </td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Given Name' | $T8 %]</th>
-      <td><input id="cp_givenname" name="cp_givenname" size="40" maxlength="75" value="[% HTML.escape(cp_givenname) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Name' | $T8 %]</th>
-      <td><input id="cp_name" name="cp_name" size="40" maxlength="75" value="[% HTML.escape(cp_name) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Phone1' | $T8 %]</th>
-      <td><input id="cp_phone1" name="cp_phone1" size="40" maxlength="75" value="[% HTML.escape(cp_phone1) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Phone2' | $T8 %]</th>
-      <td><input id="cp_phone2" name="cp_phone2" size="40" maxlength="75" value="[% HTML.escape(cp_phone2) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Fax' | $T8 %]</th>
-      <td><input id="cp_fax" name="cp_fax" size="40" value="[% HTML.escape(cp_fax) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Mobile1' | $T8 %]</th>
-      <td><input id="cp_mobile1" name="cp_mobile1" size="40" value="[% HTML.escape(cp_mobile1) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Mobile2' | $T8 %]</th>
-      <td><input id="cp_mobile2" name="cp_mobile2" size="40" value="[% HTML.escape(cp_mobile2) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Sat. Phone' | $T8 %]</th>
-      <td><input id="cp_satphone" name="cp_satphone" size="40" value="[% HTML.escape(cp_satphone) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Sat. Fax' | $T8 %]</th>
-      <td><input id="cp_satfax" name="cp_satfax" size="40" value="[% HTML.escape(cp_satfax) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Project' | $T8 %]</th>
-      <td><input id="cp_project" name="cp_project" size="40" value="[% HTML.escape(cp_project) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'E-mail' | $T8 %]</th>
-      <td><input id="cp_email" name="cp_email" size="40" value="[% HTML.escape(cp_email) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Private Phone' | $T8 %]</th>
-      <td><input id="cp_privatphone" name="cp_privatphone" size="40" value="[% HTML.escape(cp_privatphone) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Private E-mail' | $T8 %]</th>
-      <td><input id="cp_privatemail" name="cp_privatemail" size="40" value="[% HTML.escape(cp_privatemail) %]"></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Birthday' | $T8 %]</th>
-      <td><input id="cp_birthday" name="cp_birthday" size="40" value="[% HTML.escape(cp_birthday) %]"></td>
-     </tr>
-
-     <tr>
-      <td colspan="2"><hr></td>
-     </tr>
-
-     <tr>
-      <th align="left" nowrap>[% 'Bcc' | $T8 %]</th>
-      <td><input name="bcc" size="40" value="[% HTML.escape(bcc) %]"></td>
-     </tr>
-    </table>
+    [% INCLUDE 'ct/_contact.html' %]
 
     <input type="submit" id="delete_contact" name="action" value="[% 'Delete Contact' | $T8 %]" disabled>
     <br style="clear: left" />
        s.selectedIndex = (gender == 'f') ? 1 : 0;
      }
    }
-
-   function on_contact_changed() {
-     get_contact(['cp_id__' + $('#cp_id').attr('value')],
-                 ['cp_name','cp_title','cp_givenname','cp_phone1','cp_phone2','cp_email','cp_abteilung','cp_fax','cp_mobile1','cp_mobile2',
-                  'cp_satphone','cp_satfax','cp_project','cp_privatphone','cp_privatemail','cp_birthday',enable_delete_contact,set_gender]);
-     $('#selected_cp_title').attr('selectedIndex', 0);
-     $('#selected_cp_abteilung').attr('selectedIndex', 0);
-   }
   -->
 
   </script>