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 # currently doesn't work; disable to avoid problems
14 #push @fixups, 'check_unique'
15 # if $conf->exists('cust_main-check_unique') and !$opt{'custnum'};
17 push @fixups, 'do_submit'; # always last
20 var fixups = <% encode_json(\@fixups) %>;
24 %# state machine to deal with all the asynchronous stuff we're doing
25 %# call this after each fixup on success:
26 function submit_continue() {
28 window[ fixups[fixup_position++] ].call();
33 function submit_abort() {
36 document.CustomerForm.submitButton.disabled = false;
40 function bottomfixup(what) {
42 document.CustomerForm.submitButton.disabled = true;
47 function do_submit() {
48 document.CustomerForm.submit();
51 function copy_payby_fields() {
52 var layervars = new Array(
54 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
55 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
56 'paystart_month', 'paystart_year', 'payissue',
61 var cf = document.CustomerForm;
62 var payby = cf.payby.options[cf.payby.selectedIndex].value;
63 for ( f=0; f < layervars.length; f++ ) {
64 var field = layervars[f];
65 copyelement( cf.elements[payby + '_' + field],
72 <& /elements/standardize_locations.js,
73 'callback' => 'submit_continue();',
75 'with_census' => 1, # no with_firm, apparently
78 function copyelement(from, to) {
79 if ( from == undefined ) {
81 } else if ( from.type == 'select-one' ) {
82 to.value = from.options[from.selectedIndex].value;
83 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
84 } else if ( from.type == 'checkbox' ) {
86 to.value = from.value;
91 if ( from.value == undefined ) {
94 to.value = from.value;
97 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
100 % # the value in pre+'censustract' is the confirmed censustract; if it's set,
102 function confirm_censustract() {
103 var cf = document.CustomerForm;
104 var pre = cf.elements['same'].checked ? 'bill_' : 'ship_';
105 if ( cf.elements[pre+'censustract'].value == '' ) {
106 var address_info = form_address_info();
107 address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value;
108 address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
110 '<%$p%>/misc/confirm-censustract.html',
111 'q=' + encodeURIComponent(JSON.stringify(address_info)),
113 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
114 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
115 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
119 } else submit_continue();
122 %# called from confirm-censustract.html
123 function set_censustract(tract, year) {
124 var cf = document.CustomerForm;
126 if ( cf.elements['same'].checked ) {
129 cf.elements[pre + 'censustract'].value = tract;
130 cf.elements[pre + 'censusyear'].value = year;
134 function check_unique() {
135 var search_hash = new Object;
136 % foreach ($conf->config('cust_main-check_unique')) {
137 search_hash['<% $_ %>'] = document.CustomerForm.elements['<% $_ %>'].value;
140 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
141 duplicates_form(JSON.stringify(search_hash), confirm_unique);
144 function confirm_unique(arg) {
145 if ( arg.match(/\S/) ) {
146 %# arg contains a complete form to choose an existing customer, or not
147 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
148 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
149 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
150 } else { // no duplicates