| 1 |
// $Id: uc_out_of_stock.js,v 1.1.2.7 2009/01/05 14:22:38 hanoii Exp $
|
| 2 |
|
| 3 |
$(document).ready(function(){
|
| 4 |
// Your code here
|
| 5 |
//$("form[@id*=uc-product-add-to-cart-form]").css("border","2px solid");
|
| 6 |
formid = 'uc-product-add-to-cart-form';
|
| 7 |
attrid = 'edit-attributes';
|
| 8 |
|
| 9 |
function checkStock(form) {
|
| 10 |
var product = new Object();
|
| 11 |
var attributes = new Object();
|
| 12 |
product.nid = form.attr('id').substring(formid.length+1);
|
| 13 |
attributes.found = new Object();
|
| 14 |
attributes.value = new Object();
|
| 15 |
|
| 16 |
$(":input[@name*=attributes]:not(:text)", form).each(function(index){
|
| 17 |
id = $(this).attr('name').substring(11,$(this).attr('name').length-1);
|
| 18 |
if ($(this).is(':radio')) {
|
| 19 |
attributes.found['attr'+id] = 1;
|
| 20 |
if ($(this).is(':checked')) {
|
| 21 |
if ($(this).val()) {
|
| 22 |
attributes.value['attr'+id] = 1;
|
| 23 |
product['attr'+id] = $(this).val();
|
| 24 |
}
|
| 25 |
}
|
| 26 |
} else {
|
| 27 |
attributes.found['attr'+id] = 1;
|
| 28 |
if ($(this).val()) {
|
| 29 |
attributes.value['attr'+id] = 1;
|
| 30 |
product['attr'+id] = $(this).val();
|
| 31 |
}
|
| 32 |
}
|
| 33 |
});
|
| 34 |
|
| 35 |
// Put back the normal HTML of the add to cart form before deciding
|
| 36 |
// if a request to the server is needed.
|
| 37 |
$(".uc_out_of_stock_html", form).html('');
|
| 38 |
$("input:submit", form).show();
|
| 39 |
|
| 40 |
// finding if attributes are found with no value
|
| 41 |
attributes.found.length = attributes.value.length = 0;
|
| 42 |
for (var i in attributes.found) {
|
| 43 |
if (i!='length') {
|
| 44 |
attributes.found.length++;
|
| 45 |
}
|
| 46 |
}
|
| 47 |
for (var i in attributes.value) {
|
| 48 |
if (i!='length') {
|
| 49 |
attributes.value.length++;
|
| 50 |
}
|
| 51 |
}
|
| 52 |
if (attributes.found.length != attributes.value.length) {
|
| 53 |
return;
|
| 54 |
}
|
| 55 |
|
| 56 |
$(".uc_out_of_stock_throbbing", form).addClass('uc_oos_throbbing');
|
| 57 |
$.post(Drupal.settings.base_path+'uc_out_of_stock/query', product, function (data, textStatus) {
|
| 58 |
// textStatus can be one of:
|
| 59 |
// "timeout"
|
| 60 |
// "error"
|
| 61 |
// "notmodified"
|
| 62 |
// "success"
|
| 63 |
// "parsererror"
|
| 64 |
data = data.split('|');
|
| 65 |
stock = data[0];
|
| 66 |
if (stock == parseInt(stock) && stock <= 0 && data.length == 2) {
|
| 67 |
html = data[1];
|
| 68 |
$("input:submit", form).hide();
|
| 69 |
$(".uc_out_of_stock_html", form).html(html);
|
| 70 |
}
|
| 71 |
|
| 72 |
$(".uc_out_of_stock_throbbing", form).removeClass('uc_oos_throbbing');
|
| 73 |
});
|
| 74 |
}
|
| 75 |
|
| 76 |
$("form[@id*=uc-product-add-to-cart-form]").each(function(index) {
|
| 77 |
var eachForm;
|
| 78 |
$("input:submit", $(this)).before('<div class="uc_out_of_stock_throbbing"> </div> ');
|
| 79 |
$("input:submit", $(this)).after('<div class="uc_out_of_stock_html"></div');
|
| 80 |
|
| 81 |
eachForm = $(this);
|
| 82 |
checkStock(eachForm);
|
| 83 |
|
| 84 |
$(":input[@name*=attributes]:not(:text)", $(this)).change(function(){
|
| 85 |
checkStock(eachForm);
|
| 86 |
});
|
| 87 |
|
| 88 |
});
|
| 89 |
|
| 90 |
});
|