Subversion Repositories SmartDukaan

Rev

Rev 23967 | Rev 24203 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23967 Rev 24202
Line 1... Line 1...
1
$(function() {
1
$(function() {
-
 
2
	callback = function(value) {
-
 
3
		if(isNaN(value)) {
-
 
4
			bootbox("No of watches should be a number. Set '0' specifically");
-
 
5
			return;
-
 
6
		}else {
-
 
7
			loadCart("main-content", value);
-
 
8
		}
-
 
9
	}
2
	$(".cart_icon_header").live('click', function() {
10
	$(".cart_icon_header").live('click', function() {
-
 
11
		if(hasGift) {
-
 
12
			bootBoxObj = { 
-
 
13
						size: "medium",
-
 
14
						title: "Add Number of Watch as Gift", 
-
 
15
						callback: callback,
-
 
16
						inputType:'number'
-
 
17
					};
-
 
18
			
-
 
19
			bootbox.prompt(bootBoxObj);
-
 
20
		} else {
3
		loadCart("main-content");
21
				loadCart('main-content', 0);
-
 
22
		}
4
	});
23
	});
5
	
24
	
-
 
25
	
6
	$(".cart-checkout").live('click', function() {
26
	$(".cart-checkout").live('click', function() {
7
		checkout("main-content");
27
		checkout("main-content");
8
	});
28
	});
9
	
29
	
10
	$(".add-to-bag").live('click', function() {
30
	$(".add-to-bag").live('click', function() {
-
 
31
		added=false;
11
		$('#catalogModalBody').hide();
32
		$('#catalogModalBody').hide();
12
		var itemId = $(this).attr('data');
33
		var itemId = $(this).attr('data');
13
		$("#bagModel .itemId").val(itemId);
34
		$("#bagModel .itemId").val(itemId);
14
		$("#bagModel .quantity").val(0);
35
		$("#bagModel .quantity").val(0);
15
		doGetAjaxRequestHandler(context+"/checkItemAvailability/?itemId="+itemId, function(response){
36
		doGetAjaxRequestHandler(context+"/checkItemAvailability/?itemId="+itemId, function(response){
Line 39... Line 60...
39
			}
60
			}
40
			$("#bagModel .availability").val(obj.availability);
61
			$("#bagModel .availability").val(obj.availability);
41
			$('#catalogModalBody').show();
62
			$('#catalogModalBody').show();
42
		});
63
		});
43
		
64
		
-
 
65
		
44
	});
66
	});
45
	
67
	
46
	//addToBagButton
68
	// addToBagButton
47
	
69
	
48
	$("#addToBagButton").live('click', function() {
70
	$("#addToBagButton").live('click', function() {
49
		var itemId = $("#bagModel .itemId").val();
71
		var itemId = $("#bagModel .itemId").val();
50
		var tempAvailability = $("#bagModel .availability").val();
72
		var tempAvailability = $("#bagModel .availability").val();
51
		var quantity = $("#bagModel .quantity").val();
73
		var quantity = $("#bagModel .quantity").val();
Line 135... Line 157...
135
}
157
}
136
 
158
 
137
 
159
 
138
function changeQuantityInLocalStorage(itemId, newQuantity){
160
function changeQuantityInLocalStorage(itemId, newQuantity){
139
	var bag = JSON.parse(localStorage.getItem("bag"));
161
	var bag = JSON.parse(localStorage.getItem("bag"));
-
 
162
	if (typeof bag[itemId]=="undefined") {
-
 
163
		bag[itemId] = {};
-
 
164
		bag[itemId].itemId=itemId;
-
 
165
		bag[itemId].displayName = "SmartDukaan Gift Watch";
-
 
166
		
-
 
167
	}
140
	bag[itemId].quantity = newQuantity;
168
	bag[itemId].quantity = newQuantity;
141
	localStorage.setItem("bag",JSON.stringify(bag));
169
	localStorage.setItem("bag",JSON.stringify(bag));
142
}
170
}
143
 
171
 
144
function removeItemFromLocalStorage(itemId){
172
function removeItemFromLocalStorage(itemId){
Line 148... Line 176...
148
		localStorage.setItem("bag",JSON.stringify(bag));
176
		localStorage.setItem("bag",JSON.stringify(bag));
149
		$("#cart_bar").find('span').text(Object.keys(bag).length);
177
		$("#cart_bar").find('span').text(Object.keys(bag).length);
150
	}
178
	}
151
}
179
}
152
 
180
 
-
 
181
function addGiftQty(giftQty) {
-
 
182
	if (localStorage.getItem("bag")!=null){
-
 
183
		var bag = JSON.parse(localStorage.getItem("bag"));
-
 
184
		bag["giftQty"] = giftQty;
-
 
185
		localStorage.setItem("bag",JSON.stringify(bag));
-
 
186
		$("#cart_bar").find('span').text(Object.keys(bag).length);
-
 
187
	}
-
 
188
}
-
 
189
 
153
function emptyBag(){
190
function emptyBag(){
154
	localStorage.setItem("bag",JSON.stringify({}));
191
	localStorage.setItem("bag",JSON.stringify({}));
155
	$("#cart_bar").find('span').text(0);
192
	$("#cart_bar").find('span').text(0);
156
}
193
}
157
 
194
 
158
function loadCart(domId){
195
function loadCart(domId, giftQty){
-
 
196
	addGiftQty(giftQty);
159
	var params = {
197
	var params = {
160
			"cartData":localStorage.getItem("bag")
198
			"cartData":localStorage.getItem("bag")
161
		}
199
		}
162
	doPostAjaxRequestWithParamsHandler(context+"/cart", params, function(response){
200
	doPostAjaxRequestWithParamsHandler(context+"/cart", params, function(response){
163
		$('#' + domId).html(response);
201
		$('#' + domId).html(response);