Subversion Repositories SmartDukaan

Rev

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

Rev 14357 Rev 14386
Line -... Line 1...
-
 
1
var livePriceCalls = [];
1
$(function(){	
2
$(function(){	
2
	if($('.scroll > .card').length>0) {
3
	if($('.scroll > .card').length>0) {
3
		setTimeout(function(){ document.location.reload(); }, 1000*60*35);
4
		setTimeout(function(){ document.location.reload(); }, 1000*60*35);
4
		$('.scroll').jscroll({
5
		$('.scroll').jscroll({
5
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
6
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
Line 15... Line 16...
15
			var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
16
			var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
16
			calls.push(temp);
17
			calls.push(temp);
17
		});
18
		});
18
		calls = sortByKey(calls,'sort');		
19
		calls = sortByKey(calls,'sort');		
19
		for(var i in calls){
20
		for(var i in calls){
20
			console.log(calls[i]['val']);
-
 
21
			fetchLivePrice(calls[i]['val'])
21
			fetchLivePrice(calls[i]['val'])
22
		}
22
		}
23
	};
23
	};
24
	function sortByKey(array, key) {
24
	function sortByKey(array, key) {
25
	    return array.sort(function(a, b) {
25
	    return array.sort(function(a, b) {
Line 29... Line 29...
29
	};
29
	};
30
	function fetchLivePrice(obj){
30
	function fetchLivePrice(obj){
31
		console.log(obj);
31
		console.log(obj);
32
		var inStock = false;
32
		var inStock = false;
33
		var that = obj;			
33
		var that = obj;			
34
		$.ajax({
34
		var req = $.ajax({
35
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
35
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
36
			// Tell jQuery we're expecting JSONP
36
			// Tell jQuery we're expecting JSONP
37
			dataType: "json",
37
			dataType: "json",
38
			// Tell YQL what we want and that we want JSON			
38
			// Tell YQL what we want and that we want JSON			
39
			method: 'get',
39
			method: 'get',
40
			// timeout: 180000,
40
			// timeout: 30000,
41
			// Work with the response
41
			// Work with the response
42
			success: function( response ) {
42
			success: function( response ) {
43
				if(response.success){
43
				if(response.success){
44
					var i = 0;	
44
					var i = 0;	
45
					var minpriceindex = 0;				
45
					var minpriceindex = 0;				
Line 59... Line 59...
59
							}
59
							}
60
							if(response.products[i].available_price <= minprice) {
60
							if(response.products[i].available_price <= minprice) {
61
								minprice = response.products[i].available_price;
61
								minprice = response.products[i].available_price;
62
								minpriceindex = i;
62
								minpriceindex = i;
63
							} 
63
							} 
64
							// console.log(response);
-
 
65
							variants.push({'available_price' : response.products[i].available_price, 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id});
64
							variants.push({'available_price' : response.products[i].available_price, 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id});
66
						}
65
						}
67
						if(i>0){
66
						if(i>0){
68
							var variantslink = $('<span class="variants">+ '+i+' Options</span>');
67
							var variantslink = $('<span class="variants">+ '+i+' Options</span>');
69
							$(that).parent().append(variantslink);							
68
							$(that).parent().append(variantslink);							
Line 77... Line 76...
77
						if(globalminprice != 9999999) {
76
						if(globalminprice != 9999999) {
78
							$('#bestprice').html(globalminprice);
77
							$('#bestprice').html(globalminprice);
79
							$('#beststorelink').data('id',globalminsku).removeClass('hidden');
78
							$('#beststorelink').data('id',globalminsku).removeClass('hidden');
80
							$('#bestpricecontainer').removeClass('hidden');
79
							$('#bestpricecontainer').removeClass('hidden');
81
						}
80
						}
82
					}else{
81
					} else{
83
						$(that).parent().parent().remove();	
82
						$(that).parent().parent().remove();	
84
					}
83
					}
85
					if(!response.products[0].available_price){
84
					if(!response.products[0].available_price){
86
						$(that).parent().parent().remove();	
85
						$(that).parent().parent().remove();	
87
					}
86
					}
88
				}else{
87
				} else{
89
					$(that).parent().parent().remove();
88
					$(that).parent().parent().remove();
90
				}
89
				}
91
			},
90
			},
92
			error : function() {
91
			error: function(request, status, err) {
-
 
92
				//console.log(status+' '+err+' '+request);
-
 
93
            	if (status == "timeout") {
-
 
94
            		var btn = $("<a class='tryagainforliveprice' title='Try Again'>Try Again</a>");
-
 
95
					$(that).html(btn)
-
 
96
				} else {
93
				$(that).parent().parent().remove();
97
					$(that).parent().parent().remove();
-
 
98
				}
94
			}
99
			}
95
		});
100
		});
-
 
101
		livePriceCalls.push(req);
96
	};
102
	};
97
	$(document).on('click','.variants',function(){
103
	$(document).on('click','.variants',function(){
98
		$('.storeproductinfo').empty();
104
		$('.storeproductinfo').empty();
99
		var variants = $(this).data('variants');	
105
		var variants = $(this).data('variants');	
100
		$('#variantscount').html(variants.length);
106
		$('#variantscount').html(variants.length);
Line 146... Line 152...
146
		});
152
		});
147
		ga('send', 'event', 'preferences', 'update', me);
153
		ga('send', 'event', 'preferences', 'update', me);
148
	});
154
	});
149
	// $('.row').on('click','.viewproduct',function(e){
155
	// $('.row').on('click','.viewproduct',function(e){
150
	$(document).on('click','.viewproduct',function(e){
156
	$(document).on('click','.viewproduct',function(e){
-
 
157
		if(typeof livePriceCalls != undefined) {
-
 
158
	    	for(var i in livePriceCalls){
-
 
159
	    		console.log('killing ajax call '+i);
-
 
160
	    		livePriceCalls[i].abort();
-
 
161
	    	}
-
 
162
	    }
151
		$('#loadingModal').modal();
163
		$('#loadingModal').modal();
152
		console.log($(this).data('id'));
164
		console.log($(this).data('id'));
153
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
165
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
154
		$.ajax({
166
		$.ajax({
155
			url: url,
167
			url: url,
Line 343... Line 355...
343
		$(this).addClass('active');
355
		$(this).addClass('active');
344
		$('.clearfavs').addClass('hidden');
356
		$('.clearfavs').addClass('hidden');
345
		$('.card').addClass('hidden');
357
		$('.card').addClass('hidden');
346
		$('.'+$(this).data('type')).removeClass('hidden');
358
		$('.'+$(this).data('type')).removeClass('hidden');
347
	});
359
	});
-
 
360
	$(document).on('click','.brandpreferences .brands',function(){
-
 
361
		$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
-
 
362
	});
-
 
363
	$(document).on('click','.tryagainforliveprice',function(){		
-
 
364
		fetchLivePrice($(this).parent());
-
 
365
		$(this).parent().html('Getting Live Prices');
-
 
366
	});
348
});
367
});