2 my %opt = @_; # custnum
3 my $conf = new FS::Conf;
5 my $company_latitude = $conf->config('company_latitude');
6 my $company_longitude = $conf->config('company_longitude');
8 my @fixups = ('standardize_locations');
10 push @fixups, 'confirm_censustract_bill', 'confirm_censustract_ship'
11 if $conf->exists('cust_main-require_censustract');
13 my $uniqueness = $conf->config('cust_main-check_unique');
14 push @fixups, 'check_unique'
15 if $uniqueness and !$opt{'custnum'};
17 push @fixups, 'do_submit'; # always last
19 var fixups = <% encode_json(\@fixups) %>;
23 <&| /elements/onload.js &>
27 %# state machine to deal with all the asynchronous stuff we're doing
28 %# call this after each fixup on success:
29 function submit_continue() {
31 window[ fixups[fixup_position++] ].call();
36 function submit_abort() {
39 document.CustomerForm.submitButton.disabled = false;
43 function bottomfixup(what) {
45 document.CustomerForm.submitButton.disabled = true;
50 function do_submit() {
51 document.CustomerForm.submit();
54 <& /elements/standardize_locations.js,
55 'callback' => 'submit_continue();',
57 'with_census' => 1, # no with_firm, apparently
60 % # the value in pre+'censustract' is the confirmed censustract (either from
61 % # the previous saved record, or from address standardization (if the backend
62 % # supports it), or from an aborted previous submit. only need to reconfirm
64 function confirm_censustract(pre) {
65 var cf = document.CustomerForm;
66 if ( cf.elements[pre+'censustract'].value == '' ) {
67 var address_info = form_address_info();
68 address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value;
69 address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
70 address_info['prefix'] = pre;
72 '<%$p%>/misc/confirm-censustract.html',
73 'q=' + encodeURIComponent(JSON.stringify(address_info)),
75 if ( OLresponseAJAX ) {
76 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
77 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
78 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
84 } else submit_continue();
86 function confirm_censustract_bill() {
87 confirm_censustract('bill_');
90 function confirm_censustract_ship() {
91 var cf = document.CustomerForm;
92 if ( cf.elements['same'].checked ) {
95 confirm_censustract('ship_');
99 %# called from confirm-censustract.html
100 function set_censustract(tract, year, pre) {
101 var cf = document.CustomerForm;
102 cf.elements[pre + 'censustract'].value = tract;
103 cf.elements[pre + 'censusyear'].value = year;
107 function check_unique() {
108 var search_hash = {};
109 % if ($uniqueness eq 'address') {
110 search_hash['address'] = [
111 document.CustomerForm.elements['bill_address1'].value,
112 document.CustomerForm.elements['ship_address1'].value
115 %# no other options yet
117 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
118 duplicates_form(JSON.stringify(search_hash), confirm_unique);
121 function confirm_unique(arg) {
122 if ( arg.match(/\S/) ) {
123 %# arg contains a complete form to choose an existing customer, or not
124 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
125 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
126 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
127 } else { // no duplicates