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';
12 push @fixups, 'check_unique'
13 if $conf->exists('cust_main-check_unique') and !$opt{'custnum'};
15 push @fixups, 'do_submit'; # always last
18 var fixups = <% encode_json(\@fixups) %>;
22 %# state machine to deal with all the asynchronous stuff we're doing
23 %# call this after each fixup on success:
24 function submit_continue() {
26 window[ fixups[fixup_position++] ].call();
31 function submit_abort() {
34 document.CustomerForm.submitButton.disabled = false;
38 function bottomfixup(what) {
40 document.CustomerForm.submitButton.disabled = true;
45 function do_submit() {
46 document.CustomerForm.submit();
49 function copy_payby_fields() {
50 var layervars = new Array(
52 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
53 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
54 'paystart_month', 'paystart_year', 'payissue',
59 var cf = document.CustomerForm;
60 var payby = cf.payby.options[cf.payby.selectedIndex].value;
61 for ( f=0; f < layervars.length; f++ ) {
62 var field = layervars[f];
63 copyelement( cf.elements[payby + '_' + field],
70 <% include( '/elements/standardize_locations.js',
71 'callback' => 'submit_continue();',
72 'main_prefix' => 'bill_',
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 'ship_censustract' is the confirmed censustract; if it's set,
101 function confirm_censustract() {
102 var cf = document.CustomerForm;
103 if ( cf.elements['ship_censustract'].value == '' ) {
104 var address_info = form_address_info();
105 address_info['ship_latitude'] = cf.elements['ship_latitude'].value;
106 address_info['ship_longitude'] = cf.elements['ship_longitude'].value;
108 '<%$p%>/misc/confirm-censustract.html',
109 'q=' + encodeURIComponent(JSON.stringify(address_info)),
111 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
112 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
113 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
117 } else submit_continue();
120 %# called from confirm-censustract.html
121 function set_censustract(tract, year) {
122 var cf = document.CustomerForm;
123 cf.elements['ship_censustract'].value = tract;
124 cf.elements['ship_censusyear'].value = year;
128 function check_unique() {
129 var search_hash = new Object;
130 % foreach ($conf->config('cust_main-check_unique')) {
131 search_hash['<% $_ %>'] = document.CustomerForm.elements['<% $_ %>'].value;
134 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
135 duplicates_form(JSON.stringify(search_hash), confirm_unique);
138 function confirm_unique(arg) {
139 if ( arg.match(/\S/) ) {
140 %# arg contains a complete form to choose an existing customer, or not
141 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
142 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
143 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
144 } else { // no duplicates