Change the way we select the invoice address to be able to modify the choice if the user has js disabled

This commit is contained in:
touffies
2013-11-12 13:52:43 +01:00
parent a703a37560
commit 34376a0bb9

View File

@@ -162,7 +162,7 @@
</form> </form>
{/form} {/form}
{form name="thelia.order.payment"} {form name="thelia.order.payment"}
{assign var="isPost" value="{$smarty.post|count}"}
<form id="form-cart-payment" action="{url path="/order/invoice"}" method="post" {form_enctype form=$form}> <form id="form-cart-payment" action="{url path="/order/invoice"}" method="post" {form_enctype form=$form}>
{form_hidden_fields form=$form} {form_hidden_fields form=$form}
@@ -191,7 +191,6 @@
</div> </div>
{form_field form=$form field='invoice-address'} {form_field form=$form field='invoice-address'}
<div class="panel"> <div class="panel">
<div class="panel-heading">{intl l="Billing address"}s</div> <div class="panel-heading">{intl l="Billing address"}s</div>
@@ -201,65 +200,19 @@
<div class="panel-body"> <div class="panel-body">
<table class="col-md-12"> {loop type="address" name="invoice-address"}
{assign var="isInvoiceAddressChecked" value="0"}
{if !$error && $value} {if $isPost}
{assign defaultParam '*'} {if $value == $ID}
{else} {assign var="isInvoiceAddressChecked" value="1"}
{assign defaultParam 'true'} {/if}
{/if} {elseif $DEFAULT}
{if !$error && $value} {assign var="isInvoiceAddressChecked" value="1"}
{assign idParam $value}
{else}
{assign idParam '*'}
{/if}
{loop type="address" name="invoice-address" default=$defaultParam id=$idParam}
<tr>
<td>
<span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span>
<span class="org">{$COMPANY}</span>
<address class="adr">
<span class="street-address">{$ADDRESS1}</span><br>
{if $ADDRESS2 != ""}
<span class="street-address">{$ADDRESS2}</span><br>
{/if}
{if $ADDRESS3 != ""}
<span class="street-address">{$ADDRESS3}</span><br>
{/if}
<span class="postal-code">{$ZIPCODE}</span>
<span class="locality">{$CITY}, <span class="country-name">{loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}</span></span>
</address>
</td>
<td>
<input class="js-invoice-address-selector {if !$error}hidden{/if}" type="radio" name="{$name}" value="{$ID}" {if $value == $ID OR !$error}checked="checked"{/if}>
</td>
</tr>
{if !$error}
<tr class="js-change-invoice-address">
<td colspan="2">
<a href="#" class="btn btn-change-address">{intl l="Change address"}</a>
</td>
</tr>
{/if} {/if}
{/loop} <div class="radio">
<label for="invoice-address_{$ID}">
{if !$error && $value} <input type="radio" name="{$name}" id="invoice-address_{$ID}" value="{$ID}"{if $isInvoiceAddressChecked} checked="checked"{/if}>
{assign defaultParam '*'}
{else}
{assign defaultParam 'false'}
{/if}
{if !$error && $value}
{assign excludeParam $value}
{else}
{assign excludeParam 'none'}
{/if}
{loop type="address" name="invoice-address" default=$defaultParam exclude=$excludeParam}
<tr class="js-other-invoice-address {if !$error}hidden{/if}">
<td>
<span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span> <span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span>
<span class="org">{$COMPANY}</span> <span class="org">{$COMPANY}</span>
<address class="adr"> <address class="adr">
@@ -273,15 +226,11 @@
<span class="postal-code">{$ZIPCODE}</span> <span class="postal-code">{$ZIPCODE}</span>
<span class="locality">{$CITY}, <span class="country-name">{loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}</span></span> <span class="locality">{$CITY}, <span class="country-name">{loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}</span></span>
</address> </address>
</td> </label>
<td> </div>
<input class="js-invoice-address-selector {if !$error}hidden{/if}" type="radio" name="{$name}" value="{$ID}" {if $value == $ID}checked="checked"{/if}>
</td>
</tr>
{/loop} {/loop}
</table> <a href="#" class="btn btn-change-address hidden">{intl l="Change address"}</a>
</div> </div>
@@ -342,15 +291,21 @@
{block name="javascript-initialization"} {block name="javascript-initialization"}
<script type="text/javascript"> <script type="text/javascript">
jQuery(function($order) { jQuery(function($) {
$order('.js-change-invoice-address').on('click', 'a', function(e) { $('#cart-address').each(function(){
e.preventDefault(); var $radio = $('.radio', this),
$btn = $('.btn-change-address');
$order('.js-other-invoice-address').removeClass('hidden'); // Hide other invoice address
$order('.js-invoice-address-selector').removeClass('hidden'); $radio.filter( function(){ return !$(this).find(':radio').is(':checked'); }).hide();
$btn
.removeClass('hidden')
.bind('click.btn-change-address', function(){
$radio.show();
$(this).hide();
$order('#js-invoice-address-default-selector').unbind().remove(); return false;
$order('.js-change-invoice-address').unbind().remove(); });
}); });
}); });
</script> </script>