Subversion Repositories SmartDukaan

Rev

Rev 3881 | Rev 4222 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1463 varun.gupt 1
var totalAmount = 0.00;
2
 
794 rajveer 3
$(document).ready(function(){
801 rajveer 4
 
3830 chandransh 5
	checkIfUserHasAddress();
6
 
7
	$('#checkout').click(function(){
8
		window.location.href = "/shipping";
9
	});
10
 
11
	$('#proceedToPay').click(function(){
12
		var canProceedToPay = parseInt($('#canProceedToPay').val())
13
 
14
		if (canProceedToPay == 1)	{
15
 
16
			trackProceedToPay();
17
			$('#formProceedToPay').submit();
18
		} else	{
19
 
20
			alert($('#reasonActionDisability').val());
21
		}
22
	});
1190 varun.gupt 23
 
3830 chandransh 24
	$('#cart .remove-quantitybttn').click(function(){
25
		var itemId = $(this).attr('id').split('_')[1];
26
		window.location.href = "/cart/"  + itemId + "?_method=delete" + "&productid=" + itemId;
1463 varun.gupt 27
	});
1981 varun.gupt 28
 
3830 chandransh 29
	$('#computeEstimate').click(function(){
30
		changeEstimate();
3941 varun.gupt 31
		$('#cartDetail').find('thead .dev-pincode').html($('#zipcode').val());
3830 chandransh 32
	});
33
 
1981 varun.gupt 34
	$('#applyCoupon').click(function(){
35
		$('#couponAction').val('applycoupon');
36
		$('#frmCouponCode').submit();
37
	});
38
 
39
	$('#removeCoupon').click(function(){
40
		$('#couponAction').val('removecoupon');
41
		$('#frmCouponCode').submit();
42
	});
3830 chandransh 43
 
44
	$('.cart-item-quantity').change(function(){
45
		var itemId = $(this).attr("id").split('_')[1];
46
		var quantity = parseInt($(this).val());
47
 
48
		if (quantity > 5)	{
49
			alert("You can not order more than 5 pieces of same product.");
50
			$(obj).focus();
51
		}
52
		else	{
53
			jQuery.ajax({
54
				type: "POST",
55
				url: "/cart/" + itemId + "?_method=put&productid=" + itemId + "&quantity=" + quantity,
56
				data: "productid=" + itemId + "&quantity=" + quantity,
57
				success: function(msg){
58
					window.location.reload();
59
				}
60
			});
61
		}
62
	});
63
 
64
	$('#submitAddress').click(function(){
65
		$('#frmShippingAddress').submit();
66
	});
67
 
68
	$('#addAddress').click(function(){
69
		showAddAddressForm();
70
	});
71
 
72
	$('#closeAddAddressForm').click(function(){
73
		showAddressList();
74
	});
75
 
76
	$('#addresses .button-address-select').click(function(){
77
		var addressId = $(this).attr('id').split('_')[1];
78
		$('#formChangeAddressTo_' + addressId).submit();
79
	});
80
 
81
	$('#addresses .delete-address').click(function(){
82
		var addressId = $(this).attr('id').split('_')[1];
83
 
1460 varun.gupt 84
		jQuery.ajax({
85
			type: "POST",
3830 chandransh 86
			url: "/address",
87
			data: "action=delete&addressid=" + addressId,
1460 varun.gupt 88
			success: function(msg){
89
				window.location.reload();
90
			}
91
		});
3830 chandransh 92
	});
93
 
94
	function checkIfUserHasAddress()	{
95
		var addressEmpty = parseInt($('#addressEmpty').val());
96
 
97
		if (addressEmpty == 1)	{
98
			showAddAddressForm();
99
		}
1460 varun.gupt 100
	}
3830 chandransh 101
 
102
	function showAddAddressForm(){
103
		$('#addresses').hide();
104
		$('#frmShippingAddress').show();
105
	}
106
 
107
	function showAddressList()	{
108
		$('#frmShippingAddress').hide();
109
		$('#addresses').show();
110
	}
111
});
794 rajveer 112
 
1463 varun.gupt 113
function sumOfColumns(tableID, columnIndex, hasHeader)	{
114
	var tot = 0;
115
	var inc = 1;
116
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
117
	var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
118
 
119
	tableChildren.each(function() {
120
		var currentVal = document.getElementById('totalPrice' + inc).innerHTML;
121
		inc ++;
122
		var splitVal = currentVal.split("Rs.");
123
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
124
		tot += parseFloat(num);
125
	});
126
	totalAmount = tot;
127
	var formated_value = $().number_format(tot, {
128
		numberOfDecimals:2,
129
		decimalSeparator: '.',
130
		thousandSeparator: ',',
131
		symbol: 'Rs.'
132
	});
133
	return formated_value;
794 rajveer 134
}
135
 
136
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
1463 varun.gupt 137
	var tot = 0;
138
 
139
	$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")).children("td:nth-child(" + columnIndex + ")").each(function(){
140
		var currentVal=$(this).html();
141
		var splitVal=currentVal.split("Rs.");
142
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
143
		tot += parseInt(num);
144
	});
145
 
146
	var formated_value = $().number_format(tot, {
147
		numberOfDecimals: 2,
148
		decimalSeparator: '.',
149
		thousandSeparator: ',',
150
		symbol: 'Rs.'
151
	});
152
	return formated_value;
794 rajveer 153
}
154
 
1463 varun.gupt 155
function changeEstimate(item_id)	{
156
	if(item_id == null )	{
3830 chandransh 157
		$("#cartDetail tbody tr").each(function(index, item){
158
			var itemId = $(item).attr("id");
1463 varun.gupt 159
			changeEstimate(itemId);
3830 chandransh 160
		});
161
 
1463 varun.gupt 162
	} else	{
163
		jQuery.ajax({
164
			type: "GET",
165
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
166
			beforeSend: function(){
167
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
3830 chandransh 168
				$("#shipping_time_" + item_id).html('<img src="/images/loader_l.gif">');
1463 varun.gupt 169
			},
3830 chandransh 170
			success: function(data){
171
				var response = eval('(' + data + ')');
172
				var deliveryEstimate = parseInt(response['delivery_estimate']);
173
 
174
				if(deliveryEstimate == -1)	{
175
					$("#shipping_time_" + item_id).html('Location is not serviceable');
176
 
177
				} else if(deliveryEstimate == 1)	{
178
					$("#shipping_time" + "_" + item_id).html('FREE DELIVERY in 1 Business Day');
179
				}
180
				else	{
181
					$("#shipping_time" + "_" + item_id).html('FREE DELIVERY in ' + deliveryEstimate + ' Business Days');
182
				}
1463 varun.gupt 183
			}
184
		});
185
	}
186
}