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 = ('copy_payby_fields', 'standardize_locations');
10 push @fixups, 'confirm_censustract'
11 if $conf->exists('cust_main-require_censustract');
13 push @fixups, 'check_unique'
14 if $conf->exists('cust_main-check_unique') and !$opt{'custnum'};
16 push @fixups, 'do_submit'; # always last
19 var fixups = <% encode_json(\@fixups) %>;
23 %# state machine to deal with all the asynchronous stuff we're doing
24 %# call this after each fixup on success:
25 function submit_continue() {
27 window[ fixups[fixup_position++] ].call();
32 function submit_abort() {
35 document.CustomerForm.submitButton.disabled = false;
39 function bottomfixup(what) {
41 document.CustomerForm.submitButton.disabled = true;
46 function do_submit() {
47 document.CustomerForm.submit();
50 function copy_payby_fields() {
51 var layervars = new Array(
53 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
54 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
55 'paystart_month', 'paystart_year', 'payissue',
60 var cf = document.CustomerForm;
61 var payby = cf.payby.options[cf.payby.selectedIndex].value;
62 for ( f=0; f < layervars.length; f++ ) {
63 var field = layervars[f];
64 copyelement( cf.elements[payby + '_' + field],
71 <& /elements/standardize_locations.js,
72 'callback' => 'submit_continue();',
74 'with_census' => 1, # no with_firm, apparently
77 function copyelement(from, to) {
78 if ( from == undefined ) {
80 } else if ( from.type == 'select-one' ) {
81 to.value = from.options[from.selectedIndex].value;
82 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
83 } else if ( from.type == 'checkbox' ) {
85 to.value = from.value;
90 if ( from.value == undefined ) {
93 to.value = from.value;
96 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
99 % # the value in pre+'censustract' is the confirmed censustract; if it's set,
101 function confirm_censustract() {
102 var cf = document.CustomerForm;
103 var pre = cf.elements['same'].checked ? 'bill_' : 'ship_';
104 if ( cf.elements[pre+'censustract'].value == '' ) {
105 var address_info = form_address_info();
106 address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value;
107 address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
109 '<%$p%>/misc/confirm-censustract.html',
110 'q=' + encodeURIComponent(JSON.stringify(address_info)),
112 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
113 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
114 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
118 } else submit_continue();
121 %# called from confirm-censustract.html
122 function set_censustract(tract, year) {
123 var cf = document.CustomerForm;
125 if ( cf.elements['same'].checked ) {
128 cf.elements[pre + 'censustract'].value = tract;
129 cf.elements[pre + 'censusyear'].value = year;
133 function check_unique() {
134 var search_hash = new Object;
135 % foreach ($conf->config('cust_main-check_unique')) {
136 search_hash['<% $_ %>'] = document.CustomerForm.elements['<% $_ %>'].value;
139 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
140 duplicates_form(JSON.stringify(search_hash), confirm_unique);
143 function confirm_unique(arg) {
144 if ( arg.match(/\S/) ) {
145 %# arg contains a complete form to choose an existing customer, or not
146 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
147 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
148 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
149 } else { // no duplicates