function delete_product(product_id, confirm) { if (!confirm) { var p = $('

') .addClass('note error') .append("Are you sure you want to delete the product?
This can't be undone.") .append("

") .append($("").attr('type', 'button').val('Yes').click(function() { delete_product(product_id, true); })) .append(' ') .append($("").attr('type', 'button').val('No').click(function() { cancel_delete_product(product_id); })); modal.autosize(p); return; } modal.autosize("

Deleting product...

"); $.ajax({ url: '/admin/products/' + product_id, type: 'delete', success: function(resp) { if (resp.error) modal.autosize("

" + resp.error + "

"); if (resp.redirect) window.location = resp.redirect; } }); } function cancel_delete_product(product_id) { var p = $('

').append($("").attr('type', 'button').val('Delete this product').click(function() { delete_product(product_id); })); modal.autosize(p); } function add_variant(product_id) { modal.autosize("

Adding variant...

"); $.ajax({ url: '/admin/products/' + product_id + '/variants', type: 'post', success: function(resp) { if (resp.error) modal.autosize("

" + resp.error + "

"); if (resp.refresh) window.location.reload(true); } }) } function delete_variant(variant_id, confirm) { if (!confirm) { var p = $('

') .addClass('note error') .append("Are you sure you want to delete the variant?
This can't be undone.

") .append($("").attr('type', 'button').val('Confirm').click(function() { delete_variant(variant_id, true); })) .append(' ') .append($("").attr('type', 'button').val('Cancel').click(function() { cancel_delete_variant(variant_id); })); modal.autosize(p); return; } modal.autosize("

Deleting product...

"); $.ajax({ url: '/admin/variants/' + variant_id, type: 'delete', success: function(resp) { if (resp.error) modal.autosize("

" + resp.error + "

"); if (resp.redirect) window.location = resp.redirect; } }); } function cancel_delete_variant(variant_id) { var link = $('').attr('href','#').click(function(e) { e.preventDefault(); delete_variant(variant_id); }); modal.autosize(link); }