RT# 75817 - fixed issue with contact edit on edit customer page
[freeside.git] / httemplate / edit / cust_main / contacts_new.html
1 <SCRIPT>
2   function checkPasswordValidation(fieldid)  {
3     var validationResult = document.getElementById(fieldid+'_result').innerHTML;
4     if (validationResult.match(/Password valid!/)) {
5       return true;
6     }
7     else {
8       return false;
9     }
10   }
11 </SCRIPT>
12
13 <& '/elements/validate_password_js.html', &>
14
15 <DIV ID="contacts_div" STYLE="display:<% $display %>">
16 <BR>
17 <FONT CLASS="fsinnerbox-title">Contacts</FONT>
18 <% include('/edit/elements/edit.html',
19      'embed'           => $opt{cust_main},
20      'table'           => 'cust_main',
21      'agent_virt'       => 1,
22      'submit_id'        => $opt{submit_id},
23      'labels'          => { 'contactnum'  => 'Contact',
24                             #'locationnum' => '&nbsp;',
25                           },
26      'fields'          => [
27        { 'field'             => 'contactnum',
28          'type'              => 'contact',
29          'colspan'           => 6,
30          'm2m_method'        => 'cust_contact',
31          'm2m_dstcol'        => 'contactnum',   
32          'm2_label'          => 'Contact',
33          'm2_error_callback' => $m2_error_callback,
34        },
35      ],
36     )
37 %>
38 </DIV>
39 <%init>
40
41 my %opt = @_;
42
43 my $display = ($opt{'cust_main'}->residential_commercial eq 'Commercial')
44                 ? ''
45                 : 'none';
46
47 my $curuser = $FS::CurrentUser::CurrentUser;
48 my $conf = new FS::Conf;
49
50 my $m2_error_callback = sub {
51   my($cgi, $object) = @_;
52
53   #process_o2m fields in process/cust_main-contacts.html
54   my $fields = FS::contact->cgi_contact_fields;
55   my @gfields = ( '', map "_$_", @$fields );
56
57   map {
58         if ( /^contactnum(\d+)$/ ) {
59           my $num = $1;
60           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
61             my $x = new FS::contact {
62               'contactnum' => scalar($cgi->param("contactnum$num")),
63               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @$fields,
64             };
65             $x;
66           } else {
67             ();
68           }
69         } else {
70           ();
71         }
72       }
73       $cgi->param;
74 };
75
76 </%init>