Subversion Repositories SmartDukaan

Rev

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

Rev 23405 Rev 23500
Line 10... Line 10...
10
	$(".add-to-bag").live('click', function() {
10
	$(".add-to-bag").live('click', function() {
11
		$('#catalogModalBody').hide();
11
		$('#catalogModalBody').hide();
12
		var itemId = $(this).attr('data');
12
		var itemId = $(this).attr('data');
13
		$("#bagModel .itemId").val(itemId);
13
		$("#bagModel .itemId").val(itemId);
14
		$("#bagModel .quantity").val(0);
14
		$("#bagModel .quantity").val(0);
15
		doAjaxRequestHandler(context+"/checkItemAvailability/?itemId="+itemId, "GET", function(response){
15
		doGetAjaxRequestHandler(context+"/checkItemAvailability/?itemId="+itemId, function(response){
16
			var obj = JSON.parse(response);
16
			var obj = JSON.parse(response);
17
			console.log(obj);
17
			console.log(obj);
18
			console.log(obj.displayName);
18
			console.log(obj.displayName);
19
			$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
19
			$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
20
			$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
20
			$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
Line 37... Line 37...
37
			}
37
			}
38
			$("#bagModel .availability").val(obj.availability);
38
			$("#bagModel .availability").val(obj.availability);
39
			$('#catalogModalBody').show();
39
			$('#catalogModalBody').show();
40
		});
40
		});
41
		
41
		
42
		/*jQuery.ajax({
-
 
43
			url: ,
-
 
44
			type: 'GET',
-
 
45
			contentType:'application/json',
-
 
46
			async: false,
-
 
47
			success: function (data) {
-
 
48
				var obj = JSON.parse(data);
-
 
49
				console.log(obj);
-
 
50
				console.log(obj.displayName);
-
 
51
				$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
-
 
52
				$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
-
 
53
				$("#bagModel .availability").val(obj.availability);
-
 
54
			},
-
 
55
			cache: false,
-
 
56
			processData: false
-
 
57
		});*/
-
 
58
	});
42
	});
59
	
43
	
60
	//addToBagButton
44
	//addToBagButton
61
	
45
	
62
	$("#addToBagButton").live('click', function() {
46
	$("#addToBagButton").live('click', function() {
Line 73... Line 57...
73
		} else if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1){
57
		} else if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1){
74
			alert("Please enter valid quantity");
58
			alert("Please enter valid quantity");
75
			return;
59
			return;
76
		}
60
		}
77
		
61
		
78
		jQuery.ajax({
-
 
79
			url: context+"/checkItemAvailability/?itemId="+itemId,
62
		doGetAjaxRequestHandler(context+"/checkItemAvailability/?itemId="+itemId, function(response){
80
			type: 'GET',
-
 
81
			contentType:'application/json',
-
 
82
			async: false,
-
 
83
			success: function (data) {
-
 
84
				var obj = JSON.parse(data);
63
			var obj = JSON.parse(response);
85
				console.log(obj);
64
			console.log(obj);
86
				if (obj.availability < parseInt(quantity) || obj.availability == 0){
65
			if (obj.availability < parseInt(quantity) || obj.availability == 0){
87
					alert("You don't have enough inventory of this item");
66
				alert("You don't have enough inventory of this item");
88
					return;
67
				return;
89
				}
68
			}
90
				var obj = {'itemId':obj.itemId,'displayName':obj.displayName,'quantity':parseInt(quantity),'iconUrl':obj.iconUrl};
69
			var obj = {'itemId':obj.itemId,'displayName':obj.displayName,'quantity':parseInt(quantity),'iconUrl':obj.iconUrl};
91
				if(imeiCount > 0) {
70
			if(imeiCount > 0) {
92
					obj['imeis'] = [];
71
				obj['imeis'] = [];
93
					$('h4.bagMaodalEarlyImeis').find('input:checked').each(function(index, ele){
72
				$('h4.bagMaodalEarlyImeis').find('input:checked').each(function(index, ele){
94
						obj['imeis'].push(ele.value);
73
					obj['imeis'].push(ele.value);
95
					});
74
				});
96
				}
75
			}
97
				console.log(obj);
76
			console.log(obj);
98
				addItemInLocalStorage(obj);
77
			addItemInLocalStorage(obj);
99
				alert("Item added to bag successfully");
78
			alert("Item added to bag successfully");
100
				$('#bagModel').modal('hide');
79
			$('#bagModel').modal('hide');
101
			},
80
		
102
			cache: false,
81
		});	
103
			processData: false
-
 
104
		});
82
		
105
	});
83
	});
106
	
84
	
107
	$(".cart-trash").live('click',function(){
85
	$(".cart-trash").live('click',function(){
108
		var itemId = $(this).attr('data');
86
		var itemId = $(this).attr('data');
109
		removeItemFromLocalStorage(itemId);
87
		removeItemFromLocalStorage(itemId);
Line 177... Line 155...
177
 
155
 
178
function loadCart(domId){
156
function loadCart(domId){
179
	var params = {
157
	var params = {
180
			"cartData":localStorage.getItem("bag")
158
			"cartData":localStorage.getItem("bag")
181
		}
159
		}
182
	doAjaxRequestWithParamsHandler(context+"/cart", "POST", params, function(response){
160
	doPostAjaxRequestWithParamsHandler(context+"/cart", params, function(response){
183
		$('#' + domId).html(response);
161
		$('#' + domId).html(response);
184
	});
162
	});
185
}
163
}
186
 
164
 
187
function checkout(domId){
165
function checkout(domId){
188
	var params = {
166
	var params = {
189
			"cartData":localStorage.getItem("bag")
167
			"cartData":localStorage.getItem("bag")
190
		}
168
		}
191
	doAjaxRequestWithParamsHandler(context+"/validate-cart", "POST", params, function(response){
169
	doPostAjaxRequestWithParamsHandler(context+"/validate-cart", params, function(response){
192
		$('#' + domId).html(response);
170
		$('#' + domId).html(response);
193
		var obj = JSON.parse(response);
171
		var obj = JSON.parse(response);
194
		redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
172
		redirectCart(obj.redirectUrl, obj.params, "main-content");
195
		$('#main-content').html(response);
173
		$('#main-content').html(response);
196
	});
174
	});
197
}
175
}
198
 
176
 
199
function redirectCart(url, cartData, method, domId){
177
function redirectCart(url, cartData, domId){
200
	jQuery.ajax({
178
	var params = {
201
        type : method,
-
 
202
        data: {"cartData":cartData},
179
		"cartData":cartData	
203
        url : context+url,
-
 
-
 
180
	}
204
        success : function(response) {
181
	doPostAjaxRequestWithParamsHandler(context + url, params, function(response){
205
            $('#' + domId).html(response);
182
        $('#' + domId).html(response);
206
            cartData = JSON.parse(cartData);
183
        cartData = JSON.parse(cartData);
207
            for(itemId in cartData) {
184
        for(itemId in cartData) {
208
            	if('imeis' in cartData[itemId]){
185
        	if('imeis' in cartData[itemId]){
209
            		$('#order-details').find('input[name="serialNumber"][itemId="' + itemId + '"]').each(function(i,e){
186
        		$('#order-details').find('input[name="serialNumber"][itemId="' + itemId + '"]').each(function(i,e){
210
            			e.value = cartData[itemId].imeis[i];
187
        			e.value = cartData[itemId].imeis[i];
211
            		});
188
        		});
212
            	}
189
        	}
213
            }
-
 
214
            window.dispatchEvent(new Event('resize'));
-
 
215
        }
190
        }
-
 
191
        window.dispatchEvent(new Event('resize'));
216
    });  
192
	}); 
217
}
193
}
218
194