Subversion Repositories SmartDukaan

Rev

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

Rev 15526 Rev 15550
Line 42... Line 42...
42
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
42
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
43
	    });
43
	    });
44
	};
44
	};
45
	function fetchLivePrice(obj){		
45
	function fetchLivePrice(obj){		
46
		ga('send', 'event', 'liveprice', 'fetch', $(obj).data('bundle_id'));
46
		ga('send', 'event', 'liveprice', 'fetch', $(obj).data('bundle_id'));
-
 
47
		var properties = {};
-
 
48
		properties.bundle_id = String($(obj).data('bundle_id'));
-
 
49
		pma.send('products','livescore','fetch',me,properties);
47
		var that = obj;	
50
		var that = obj;	
48
		var inStock = false;		
51
		var inStock = false;		
49
		var req = $.ajax({
52
		var req = $.ajax({
50
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
53
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
51
			// Tell jQuery we're expecting JSONP
54
			// Tell jQuery we're expecting JSONP
Line 100... Line 103...
100
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
103
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
101
							$('#bestpricecontainer').removeClass('hidden');
104
							$('#bestpricecontainer').removeClass('hidden');
102
						} 
105
						} 
103
					} else{
106
					} else{
104
						ga('send', 'event', 'liveprice', 'outofstock', response.products[0]._id);
107
						ga('send', 'event', 'liveprice', 'outofstock', response.products[0]._id);
-
 
108
						var properties = {};
-
 
109
						properties.sku = String(response.products[0]._id);
-
 
110
						pma.send('products','livescore','outofstock',me,properties);
105
						outOfStockCount++;
111
						outOfStockCount++;
106
						$(that).parent().parent().remove();	
112
						$(that).parent().parent().remove();	
107
					}
113
					}
108
					if(!response.products[0].available_price){
114
					if(!response.products[0].available_price){
109
						// outOfStockCount++;
115
						// outOfStockCount++;
110
						// $(that).parent().parent().remove();	
116
						// $(that).parent().parent().remove();	
111
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
117
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
112
						$(that).html(btn);
118
						$(that).html(btn);
113
						ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
119
						ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
-
 
120
						properties = {};
-
 
121
						properties.sku = String(response.products[0]._id); 
-
 
122
						pma.send('products','liveprice','failed',me,properties);
114
					}					
123
					}					
115
				} else{
124
				} else{
116
					// outOfStockCount++;
125
					// outOfStockCount++;
117
					// $(that).parent().parent().remove();
126
					// $(that).parent().parent().remove();
118
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
127
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
119
					$(that).html(btn);
128
					$(that).html(btn);
120
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
129
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
-
 
130
					properties = {};
-
 
131
					properties.sku = String(response.products[0]._id); 
-
 
132
					pma.send('products','liveprice','failure',me,properties);
121
				}
133
				}
122
				checkForOutStocks(outOfStockCount);
134
				checkForOutStocks(outOfStockCount);
123
			},
135
			},
124
			error: function(request, status, err) {            	
136
			error: function(request, status, err) {            	
125
        		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
137
        		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
126
				$(that).html(btn);
138
				$(that).html(btn);
127
				try{
139
				try{
128
					if(response){
140
					if(response){
129
						ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
141
						ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
-
 
142
						var properties = {};
-
 
143
						properties.sku = String(response.products[0]._id);
-
 
144
						pma.send('products','livescore','error',me,properties);
130
					}						
145
					}						
131
				} catch(e){}
146
				} catch(e){}
132
			}
147
			}
133
		});
148
		});
134
		livePriceCalls.push(req);
149
		livePriceCalls.push(req);
Line 195... Line 210...
195
					$('#preferences-'+$(that).data('id')).addClass('hidden');
210
					$('#preferences-'+$(that).data('id')).addClass('hidden');
196
				}
211
				}
197
			}
212
			}
198
		});
213
		});
199
		ga('send', 'event', 'preferences', 'update', me);
214
		ga('send', 'event', 'preferences', 'update', me);
-
 
215
		properties = pma.formDataToObject($('#categorypreference-'+$(this).data('id')).serializeArray());
-
 
216
		pma.send('preferences', 'update', 'set', me, properties);
200
	});
217
	});
201
	$(document).on('click','.viewproduct',function(e){
218
	$(document).on('click','.viewproduct',function(e){
202
		if(typeof livePriceCalls != undefined) {
219
		if(typeof livePriceCalls != undefined) {
203
	    	for(var i in livePriceCalls){
220
	    	for(var i in livePriceCalls){
204
	    		livePriceCalls[i].abort();
221
	    		livePriceCalls[i].abort();
Line 246... Line 263...
246
			error: function() {
263
			error: function() {
247
				document.location = url;
264
				document.location = url;
248
			}
265
			}
249
		});
266
		});
250
		ga('send', 'event', 'product', 'click', $(this).data('url'));
267
		ga('send', 'event', 'product', 'click', $(this).data('url'));
-
 
268
		var properties = {};
-
 
269
		properties.sku = String($(this).data('id'));
-
 
270
		properties.source = String($(this).data('source'));
-
 
271
		properties.url = encodeURIComponent($(this).data('url'));
-
 
272
		properties.price = String($(this).data('price'));
-
 
273
		pma.send('products','url','click',me,properties);
251
	});
274
	});
252
	$('.jscroll-inner').on('click','.likedeal',function(e){	
275
	$('.jscroll-inner').on('click','.likedeal',function(e){	
253
		var that = $(this);
276
		var that = $(this);
254
		if($(that).hasClass('active')){
277
		if($(that).hasClass('active')){
255
			//User has already liked it,so remove like
278
			//User has already liked it,so remove like
Line 274... Line 297...
274
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
297
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
275
				}
298
				}
276
			}
299
			}
277
		});
300
		});
278
		ga('send', 'event', 'product', 'like', $(this).data('id'));
301
		ga('send', 'event', 'product', 'like', $(this).data('id'));
-
 
302
		var properties = {};
-
 
303
		properties.sku = String($(this).data('id'));
-
 
304
		pma.send('products','favourites','like',me,properties);
279
	});
305
	});
280
	$('#myModal').on('click','#unlikebtn',function(e){
306
	$('#myModal').on('click','#unlikebtn',function(e){
281
		e.preventDefault();
307
		e.preventDefault();
282
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
308
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
283
		$.ajax({
309
		$.ajax({
Line 294... Line 320...
294
			success: function( response ) {
320
			success: function( response ) {
295
			}
321
			}
296
		});
322
		});
297
		$('#myModal').modal('hide');
323
		$('#myModal').modal('hide');
298
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
324
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
-
 
325
		pma.send('brands','hide',$('#myModal').find('#productToHide',0).val(),me);
299
	})
326
	})
300
	$('.jscroll-inner').on('click','.dislikedeal',function(e){			
327
	$('.jscroll-inner').on('click','.dislikedeal',function(e){			
301
		var that = $(this);
328
		var that = $(this);
302
		if($(that).hasClass('active')){
329
		if($(that).hasClass('active')){
303
			//User has already liked it,so remove like
330
			//User has already liked it,so remove like
Line 323... Line 350...
323
					$(that).parent().find('li.likedeal',0).removeClass('active');
350
					$(that).parent().find('li.likedeal',0).removeClass('active');
324
				}
351
				}
325
			}
352
			}
326
		});
353
		});
327
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
354
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
-
 
355
		var properties = {};
-
 
356
		properties.sku = String($(this).data('id'));
-
 
357
		pma.send('products','favourites','dislike',me,properties);
328
	});
358
	});
329
	$('.deletefav').on('click',function(){
359
	$('.deletefav').on('click',function(){
330
		var that = $(this);
360
		var that = $(this);
331
		$('#loadingModal').modal();
361
		$('#loadingModal').modal();
332
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
362
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
Line 347... Line 377...
347
					$('#fav-'+$(that).data('id')).hide('slow');
377
					$('#fav-'+$(that).data('id')).hide('slow');
348
				}
378
				}
349
			}
379
			}
350
		});
380
		});
351
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
381
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
-
 
382
		var properties = {};
-
 
383
		properties.sku = String($(this).data('id'));
-
 
384
		pma.send('products','favourites','remove',me,properties);
352
	});
385
	});
353
	$('.clearfavs').on('click',function(){
386
	$('.clearfavs').on('click',function(){
354
		var that = $(this);
387
		var that = $(this);
355
		$('#loadingModal').modal();
388
		$('#loadingModal').modal();
356
		var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');			
389
		var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');			
Line 374... Line 407...
374
				}
407
				}
375
				$(that).hide();
408
				$(that).hide();
376
			}
409
			}
377
		});
410
		});
378
		ga('send', 'event', 'favourites', 'removeall', me);
411
		ga('send', 'event', 'favourites', 'removeall', me);
-
 
412
		pma.send('products','favourites','removeall',me);
379
	});
413
	});
380
	$('.revealbrands').on('click',function(){
414
	$('.revealbrands').on('click',function(){
381
		$(this).parent().find('.notfeatured').toggleClass('hidden');
415
		$(this).parent().find('.notfeatured').toggleClass('hidden');
382
		if($(this).html()=='Others'){
416
		if($(this).html()=='Others'){
383
			$(this).html('Hide');
417
			$(this).html('Hide');
Line 427... Line 461...
427
		fetchLivePrice($(this).parent());
461
		fetchLivePrice($(this).parent());
428
		$(this).parent().html('Getting Live Prices');
462
		$(this).parent().html('Getting Live Prices');
429
	});
463
	});
430
	$(document).on('click','.alert > a',function(){		
464
	$(document).on('click','.alert > a',function(){		
431
		ga('send', 'event', 'notifications', 'click', $(this).html());
465
		ga('send', 'event', 'notifications', 'click', $(this).html());
-
 
466
		pma.send('notifications','click',$(this).html(),me);
432
	});
467
	});
433
	$(document).on('click','.banner',function(){		
468
	$(document).on('click','.banner',function(){		
434
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
469
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
-
 
470
		pma.send('banners','click',$(this).data('name'),me);
435
	});
471
	});
436
});
472
});
437
function setCookie(cname, cvalue, days, forceCookie) {
473
function setCookie(cname, cvalue, days, forceCookie) {
438
	if(typeof(Storage) !== "undefined" && !forceCookie) {
474
	if(typeof(Storage) !== "undefined" && !forceCookie) {
439
		localStorage.setItem(cname, cvalue);
475
		localStorage.setItem(cname, cvalue);
Line 523... Line 559...
523
$('.notificationok').on('click',function(e){
559
$('.notificationok').on('click',function(e){
524
	e.preventDefault();
560
	e.preventDefault();
525
	$('.notificationmodal').modal('hide');
561
	$('.notificationmodal').modal('hide');
526
	// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
562
	// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
527
	ga('send', 'event', 'popupnotification', 'ok', me);
563
	ga('send', 'event', 'popupnotification', 'ok', me);
-
 
564
	pma.send('popupnotification','click','ok',me);
528
	document.location = $(this).parent().prop('href');
565
	document.location = $(this).parent().prop('href');
529
});
566
});
530
$(document).on('click','.clearfilter',function(){	
567
$(document).on('click','.clearfilter',function(){	
531
	$('.filterbrand').each(function(){
568
	$('.filterbrand').each(function(){
532
		$(this).prop('checked',false);
569
		$(this).prop('checked',false);
533
	});	
570
	});	
534
	ga('send', 'event', 'filter', 'brand', 'clearfilter');
571
	ga('send', 'event', 'filter', 'brand', 'reset');
-
 
572
	pma.send('filters','brands','reset',me);
535
});
573
});
536
$(document).on('click','.applyfilter',function(){	
574
$(document).on('click','.applyfilter',function(){	
537
	var brands = [];
575
	var brands = [];
538
	var brandnames = [];
576
	var brandnames = [];
539
	$('.filterbrand').each(function(){
577
	$('.filterbrand').each(function(){
Line 548... Line 586...
548
		return false;
586
		return false;
549
	}else{
587
	}else{
550
		setCookie('brandschosen', brands, 1, true);
588
		setCookie('brandschosen', brands, 1, true);
551
		var url = $('#brandselecter').prop('action');
589
		var url = $('#brandselecter').prop('action');
552
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
590
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
-
 
591
		properties = {};
-
 
592
		for(var i in brandnames){
-
 
593
			properties['brand_'+i] = brandnames[i];
-
 
594
		}
-
 
595
		pma.send('filters','brands','addfilter',me,properties);
553
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
596
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
554
		$.post( "/user_filters/add", postdata, function( data ) {
597
		$.post( "/user_filters/add", postdata, function( data ) {
555
		  document.location = url+'&brands='+brands.join('^');
598
		  document.location = url+'&brands='+brands.join('^');
556
		});		
599
		});		
557
	}	
600
	}	
Line 600... Line 643...
600
	}
643
	}
601
})
644
})
602
$(document).on('click','.clearfilters',function(){
645
$(document).on('click','.clearfilters',function(){
603
	setCookie('brandschosen', '', -1, true);
646
	setCookie('brandschosen', '', -1, true);
604
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
647
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
-
 
648
	pma.send('filters','brands','clearfilters',me);
605
	var postdata = {'user_id':me,'type':'clear'};
649
	var postdata = {'user_id':me,'type':'clear'};
606
	$.post("/user_filters/add", postdata, function( data ) {
650
	$.post("/user_filters/add", postdata, function( data ) {
607
	  document.location.reload();
651
	  document.location.reload();
608
	});	
652
	});	
609
});
653
});
Line 755... Line 799...
755
                i += 3;
799
                i += 3;
756
            }
800
            }
757
        }
801
        }
758
        return string;
802
        return string;
759
    }
803
    }
-
 
804
}
-
 
805
 
-
 
806
 
-
 
807
var pma = new function() {
-
 
808
    // this.apiurl = "http://45.33.50.227:8081/";
-
 
809
    this.apiurl = "http://127.0.0.1:8081/";
-
 
810
    this.endpoints = {'identify':'identify','profile':'profile','track':'track'};
-
 
811
 
-
 
812
    this.send = function (category,action,label,user_id,properties) {
-
 
813
 		$.ajax({
-
 
814
			url: this.apiurl + this.endpoints.track,
-
 
815
			data: {'category':category,'action':action,'label':label,'user_id':user_id,'properties':cassandraMAP.stringify(properties)},
-
 
816
			// Tell jQuery we're expecting JSONP
-
 
817
			dataType: "json",
-
 
818
			// Tell YQL what we want and that we want JSON			
-
 
819
			method: 'post',
-
 
820
			// Work with the response
-
 
821
			success: function( response ) {
-
 
822
				//Well, well, well :)
-
 
823
			}
-
 
824
		});       
-
 
825
    };
-
 
826
 
-
 
827
    this.formDataToObject = function(formdata){
-
 
828
    	var properties = {};
-
 
829
    	var keys = [];
-
 
830
		var formdata = JSON.parse(JSON.stringify(formdata));
-
 
831
		for (var i in formdata) {
-
 
832
			var key = formdata[i].name;
-
 
833
			if(index = keys.indexOf(key)==-1){
-
 
834
				properties[key] = formdata[i].value;
-
 
835
			}else{
-
 
836
				properties[key+'_'+i] = formdata[i].value;
-
 
837
			}
-
 
838
			keys.push(key);
-
 
839
		};
-
 
840
		return properties;
-
 
841
	}
760
}
842
}
761
843