API

Adresy zákazníka

<form class="address">
    <input type="text" name="firstName">
    <input type="text" name="lastName">
    <input type="text" name="street">
    <input type="text" name="city">
    <input type="text" name="region">
    <input type="text" name="zip">
    <input type="text" name="country">
    <input type="email" name="email">
    <input type="tel" name="phone">
    <input type="text" name="companyName">
    <input type="text" name="companyId">
    <input type="text" name="vatId">
</form>
document.querySelector('form.address').addEventListener('submit', function(event){
    event.preventDefault();

    // @todo loading
    api.user.address.add(new FormData(this))
        .then(function(response){
            // reload page?
        })
        .catch(function(error){
            // display error
        });
});

document.querySelector('form.address').addEventListener('submit', function(event){
    event.preventDefault();

    // @todo loading
    api.user.address.update(123456789, new FormData(this))
        .then(function(response){
            // reload page?
        })
        .catch(function(error){
            // display error
        });
});

document.querySelector('a.delete-address').addEventListener('click', function(event){
    event.preventDefault();

    // @todo loading
    api.user.address.delete(123456789)
        .then(function(response){
            // reload page?
        })
        .catch(function(error){
            // display error
        });
});

// @todo loading
api.user.address.get(123456789)
    .then(function(response){
        // fill form?
    })
    .catch(function(error){
        // display error
    });

Objednávka

document.querySelector('a.delete-order').addEventListener('click', function(event){
    event.preventDefault();

    // @todo loading
    api.order.delete()
        .then(function(response){
            // reload page?
        })
        .catch(function(error){
            // display error
        });
});