diff options
| author | ivan <ivan> | 2009-01-09 04:06:26 +0000 | 
|---|---|---|
| committer | ivan <ivan> | 2009-01-09 04:06:26 +0000 | 
| commit | 20bddf47a41b6d064b3cfa4c41e55c157cf0c3de (patch) | |
| tree | 61b285cb23ccb27b145bdee84ff0c7421477eaba /httemplate/misc/order_pkg.html | |
| parent | 2b8ffc98529637ffddfe7cbf6b4f9b8deb90f0fa (diff) | |
pick/enter a location when ordering a package, RT#4499
Diffstat (limited to 'httemplate/misc/order_pkg.html')
| -rw-r--r-- | httemplate/misc/order_pkg.html | 131 | 
1 files changed, 123 insertions, 8 deletions
| diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html index 852b51ce4..f91143154 100644 --- a/httemplate/misc/order_pkg.html +++ b/httemplate/misc/order_pkg.html @@ -1,13 +1,79 @@  <% include('/elements/header-popup.html', 'Order new package' ) %> +<% include('/elements/xmlhttp.html', +              'url'  => $p.'misc/location.cgi', +              'subs' => [ 'get_location' ], +           ) +%> +  <SCRIPT TYPE="text/javascript"> -function enable_order_pkg () { -  if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) { -    document.OrderPkgForm.submit.disabled = false; -  } else { -    document.OrderPkgForm.submit.disabled = true; + +  function locationnum_changed(what) { +    var locationnum = what.options[what.selectedIndex].value; +    if ( locationnum == -1 ) { + +%     for (@location_fields) {  +        what.form.<%$_%>.disabled = false; +        what.form.<%$_%>.style.backgroundColor = '#ffffff'; +%     }  + +      what.form.address1.value = ''; +      what.form.address2.value = ''; +      what.form.city.value = ''; +      what.form.zip.value = ''; +      changeSelect(what.form.country, <% $countrydefault |js_string %>); +%#shouldn't we sleep/wait here until the state dropdown is updated? +%#(is it even triggered???) +      changeSelect(what.form.state, <% $statedefault |js_string %>); +      what.form.county.selectedIndex = 0; + +    } else { + +      if ( locationnum == 0 ) { +        what.form.address1.value = <% $cust_main->address1 |js_string %>; +        what.form.address2.value = <% $cust_main->address2 |js_string %>; +        what.form.city.value = <% $cust_main->city |js_string %>; +        what.form.zip.value = <% $cust_main->zip |js_string %>; +        changeSelect(what.form.country, <% $cust_main->country | js_string %> ); +%#shouldn't we sleep/wait here until the state dropdown is updated? +%#(is it even triggered???) +        changeSelect(what.form.state, <% $cust_main->state | js_string %> ); +%#shouldn't we sleep/wait here until the county dropdown is updated? +%#(is it even triggered???) +        changeSelect(what.form.county, <% $cust_main->county | js_string %> ); +      } else { +        get_location( locationnum, update_location ); +      }  + +%#sleep/wait until dropdowns are updated? +%     for (@location_fields) {  +        what.form.<%$_%>.disabled = true; +        what.form.<%$_%>.style.backgroundColor = '#dddddd'; +%     }  + +    }    } -} + +  function changeSelect(what, value) { +    for ( var i=0; i<what.length; i++) { +      if ( what.options[i].value == value ) { +        what.selectedIndex = i; +      } +    } +  } + +  function update_location( hash ) { +    alert(hash); +  } + +  function enable_order_pkg () { +    if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) { +      document.OrderPkgForm.submit.disabled = false; +    } else { +      document.OrderPkgForm.submit.disabled = true; +    } +  } +  </SCRIPT>  <% include('/elements/error.html') %> @@ -19,7 +85,7 @@ function enable_order_pkg () {  <% ntable("#cccccc", 2) %>  <TR>    <TH ALIGN="right">Package</TH> -  <TD> +  <TD COLSPAN=7>      <% include('/elements/select-cust-part_pkg.html',                   'curr_value' => $pkgpart,                   'cust_main'  => $cust_main, @@ -34,10 +100,36 @@ function enable_order_pkg () {                 'curr_value'    => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,                 'disable_empty' => 1,                 'multiple'      => $conf->exists('pkg_referral-multiple'), +               'colspan'       => 7,              )    %>  % } +<TR> +  <TH ALIGN="right">Service location</TH> +  <TD COLSPAN=7> +    <SELECT NAME="locationnum" onChange="locationnum_changed(this);"> +      <OPTION VALUE="">(default service address) +%     foreach my $loc ( $cust_main->cust_location ) { +        <OPTION VALUE="<% $loc->locationnum %>" +                <% $locationnum == $loc->locationnum ? 'SELECTED' : '' %> +        ><% $loc->line |h %> +%     } +      <OPTION VALUE="-1" +              <% $locationnum == -1 ? 'SELECTED' : '' %> +      >Add new location +    </SELECT> +  </TD> +</TR> + +<% include('/elements/location.html', +             'object'       => $cust_location, +             #'onchange' ?  probably not +             'disabled'     => ( $locationnum == -1 ? '' : 'DISABLED' ), +             'no_asterisks' => 1, +          ) +%> +  </TABLE>  <BR> @@ -46,14 +138,22 @@ function enable_order_pkg () {  </FORM>  </BODY>  </HTML> +<%once> + +my @location_fields = qw( address1 address2 city county state zip country ); + +</%once>  <%init>  die "access denied"    unless $FS::CurrentUser::CurrentUser->access_right('Order customer package');  my $conf = new FS::Conf; +my $countrydefault = $conf->config('countrydefault') || 'US'; +my $statedefault = $conf->config('statedefault') +                   || ($countrydefault eq 'US' ? 'CA' : ''); -$cgi->param('custnum') =~ /^(\d+)$/; +$cgi->param('custnum') =~ /^(\d+)$/ or die "no custnum";  my $custnum = $1;  my $cust_main = qsearchs({    'table'     => 'cust_main', @@ -63,4 +163,19 @@ my $cust_main = qsearchs({  my $pkgpart = scalar($cgi->param('pkgpart')); +$cgi->param('locationnum') =~ /^(\d*)$/ or die "illegal locationnum"; +my $locationnum = $1; +my $cust_location; +if ( $locationnum ) { +  $cust_location = qsearchs('cust_location', { 'locationnum' => $locationnum } ) +    or die "unknown locationnum"; +} else { +  $cust_location = new FS::cust_location; +  if ( $cgi->param('error') && $locationnum == -1 ) { +    $cust_location->$_( $cgi->param($_) ) foreach @location_fields; +  } else { +    $cust_location->$_( $cust_main->$_() ) foreach @location_fields; +  } +} +  </%init> | 
