var Billing = Class.create();
Billing.prototype = {
initialize: function(form, addressUrl, saveUrl){
this.form = form;
if ($(this.form)) {
$(this.form).observe('submit', function(event){this.save();Event.stop(event);}.bind(this));
}
this.addressUrl = addressUrl;
this.saveUrl = saveUrl;
this.onAddressLoad = this.fillForm.bindAsEventListener(this);
this.onSave = this.nextStep.bindAsEventListener(this);
this.onComplete = this.resetLoadWaiting.bindAsEventListener(this);
},
setAddress: function(addressId){
if (addressId) {
request = new Ajax.Request(
this.addressUrl+addressId,
{method:'get', onSuccess: this.onAddressLoad, onFailure: checkout.ajaxFailure.bind(checkout)}
);
}
else {
this.fillForm(false);
}
},
newAddress: function(isNew){
if (isNew) {
this.resetSelectedAddress();
Element.show('billing-new-address-form');
} else {
Element.hide('billing-new-address-form');
}
},
resetSelectedAddress: function(){
var selectElement = $('billing-address-select')
if (selectElement) {
selectElement.value='';
}
},
fillForm: function(transport){
var elementValues = {};
if (transport && transport.responseText){
try{
elementValues = eval('(' + transport.responseText + ')');
}
catch (e) {
elementValues = {};
}
}
else{
this.resetSelectedAddress();
}
arrElements = Form.getElements(this.form);
for (var elemIndex in arrElements) {
if (arrElements[elemIndex].id) {
var fieldName = arrElements[elemIndex].id.replace(/^billing:/, '');
arrElements[elemIndex].value = elementValues[fieldName] ? elementValues[fieldName] : '';
if (fieldName == 'country_id' && billingForm){
billingForm.elementChildLoad(arrElements[elemIndex]);
}
}
}
},
setUseForShipping: function(flag) {
$('shipping:same_as_billing').checked = flag;
},
save: function(){
if (checkout.loadWaiting!=false) return;
var validator = new Validation(this.form);
if (validator.validate()) {
checkout.setLoadWaiting('billing');
var request = new Ajax.Request(
this.saveUrl,
{
method: 'post',
onComplete: this.onComplete,
onSuccess: this.onSave,
onFailure: checkout.ajaxFailure.bind(checkout),
parameters: Form.serialize(this.form)
}
);
}
},
resetLoadWaiting: function(transport){
checkout.setLoadWaiting(false);
},
nextStep: function(transport){
if (transport && transport.responseText){
try{
response = eval('(' + transport.responseText + ')');
}
catch (e) {
response = {};
}
}
if (response.error){
if ((typeof response.message) == 'string') {
//alert(response.message);
} else {
if (window.billingRegionUpdater) {
billingRegionUpdater.update();
}
//alert(response.message.join("\n"));
}
return false;
}
checkout.setStepResponse(response);
payment.initWhatIsCvvListeners();
}
}
в данном случае вызывается billing.save()
остальные классы с аналогичными функциями