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, 'fetch_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 <% include( '/elements/standardize_locations.js',
72 'callback' => 'submit_continue();'
76 function copyelement(from, to) {
77 if ( from == undefined ) {
79 } else if ( from.type == 'select-one' ) {
80 to.value = from.options[from.selectedIndex].value;
81 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
82 } else if ( from.type == 'checkbox' ) {
84 to.value = from.value;
89 if ( from.value == undefined ) {
92 to.value = from.value;
95 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
98 function check_unique() {
99 var search_hash = new Object;
100 % foreach ($conf->config('cust_main-check_unique')) {
101 search_hash['<% $_ %>'] = document.CustomerForm.elements['<% $_ %>'].value;
104 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
105 duplicates_form(JSON.stringify(search_hash), confirm_unique);
108 function confirm_unique(arg) {
109 if ( arg.match(/\S/) ) {
110 %# arg contains a complete form to choose an existing customer, or not
111 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
112 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
113 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
114 } else { // no duplicates