RT# 75817 - updated UI to be more intuitive
[freeside.git] / httemplate / edit / cust_main-contacts.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/edit.html,
14      'name_singular'    => 'customer contacts', #yes, we're editing all of them
15      'table'            => 'cust_main',
16      'post_url'         => popurl(1). 'process/cust_main-contacts.html',
17      'no_pkey_display'  => 1,
18      'labels'           => { 'custnum'     => ' ', #XXX supress this line entirely, its being redundant
19                              'contactnum'  => ' ', #'Contact',
20                              #'locationnum' => '&nbsp;',
21                            },
22      'fields'           => [
23        { 'field'             => 'contactnum',
24          'type'              => 'contact',
25          'colspan'           => 6,
26          'custnum'           => $custnum, 
27          'm2m_method'        => 'cust_contact',
28          'm2m_dstcol'        => 'contactnum',   
29          'm2_label'          => ' ', #'Contact',
30          'm2_error_callback' => $m2_error_callback,
31        },
32      ],
33      #'new_callback'    => $new_callback,
34      #'edit_callback'   => $edit_callback,
35      #'error_callback'  => $error_callback,
36      'agent_virt'      => 1,
37      'menubar'          => [], #remove "view all" link
38
39      #XXX it would be nice if this could instead be after the error but before
40      # the table
41      'html_init'        => include('/elements/small_custview.html',
42                                      $custnum,
43                                      $conf->config('countrydefault') || 'US',
44                                      1, #no balance
45                                   ),
46 &>
47 <%init>
48
49 my $curuser = $FS::CurrentUser::CurrentUser;
50 my $conf = new FS::Conf;
51
52 my $custnum;
53 if ( $cgi->param('error') ) {
54   $custnum = scalar($cgi->param('custnum'));
55
56   die "access denied"
57     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
58
59 } elsif ( $cgi->keywords ) { #editing
60   $custnum = ($cgi->keywords)[0];
61
62   die "access denied"
63     unless $curuser->access_right('Edit customer');
64
65 } else { #new customer
66
67   #this doesn't really work here, we're an edit only
68   die "guru meditation #32";
69
70   die "access denied"
71     unless $curuser->access_right('New customer');
72
73 }
74
75 #my $new_callback = sub {
76 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
77 #};
78
79 #my $edit_callback = sub {
80 # my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
81 #};
82
83 #my $error_callback = sub {
84 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
85 #};
86
87 my $m2_error_callback = sub {
88   my($cgi, $object) = @_;
89
90   #process_o2m fields in process/cust_main-contacts.html
91   my @fields = qw( first last title comment );
92   my @gfields = ( '', map "_$_", @fields );
93
94   map {
95         if ( /^contactnum(\d+)$/ ) {
96           my $num = $1;
97           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
98             my $x = new FS::contact {
99               'contactnum' => scalar($cgi->param("contactnum$num")),
100               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
101             };
102             $x;
103           } else {
104             ();
105           }
106         } else {
107           ();
108         }
109       }
110       $cgi->param;
111 };
112
113 </%init>