Subversion Repositories SmartDukaan

Rev

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

Rev 17635 Rev 17691
Line 294... Line 294...
294
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
294
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
295
		$('.brandselector').each(function(){
295
		$('.brandselector').each(function(){
296
			if($(this).data('catid')==$(that).data('id')){
296
			if($(this).data('catid')==$(that).data('id')){
297
				$(this).addClass('active');
297
				$(this).addClass('active');
298
			}
298
			}
-
 
299
		});
-
 
300
		$('.subcategoryselector').each(function(){
-
 
301
			if($(this).data('catid')==$(that).data('id')){
-
 
302
				$(this).addClass('active');
-
 
303
			}
299
		});		
304
		});		
300
	});
305
	});
301
	$('.categorytab').on('click','.savecategorypreferences',function(e){
306
	$('.categorytab').on('click','.savecategorypreferences',function(e){
302
		var that = $(this);
307
		var that = $(this);
303
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
308
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
Line 731... Line 736...
731
		$(this).prop('checked',false);
736
		$(this).prop('checked',false);
732
	});	
737
	});	
733
	ga('send', 'event', 'filter', 'brand', 'reset');
738
	ga('send', 'event', 'filter', 'brand', 'reset');
734
	pma.send('filters','brands','reset',me);
739
	pma.send('filters','brands','reset',me);
735
});
740
});
-
 
741
 
-
 
742
$(document).on('click','.clearfiltersubcategory',function(){	
-
 
743
	$('.filtersubcategory').each(function(){
-
 
744
		$(this).prop('checked',false);
-
 
745
	});	
-
 
746
	ga('send', 'event', 'filter', 'subcategory', 'reset');
-
 
747
	pma.send('filters','subcategory','reset',me);
-
 
748
});
736
$(document).on('click','.applyfilter',function(){	
749
$(document).on('click','.applyfilter',function(){	
737
	$(this).prop('disabled',true);
750
	$(this).prop('disabled',true);
738
	$('#loadingModal').modal();
751
	$('#loadingModal').modal();
739
	var brands = [];
752
	var brands = [];
740
	var brandnames = [];
753
	var brandnames = [];
-
 
754
	var subcategories = [];
-
 
755
	var subcatnames = [];
741
	$('.filterbrand').each(function(){
756
	$('.filterbrand').each(function(){
742
		if($(this).prop('checked')){
757
		if($(this).prop('checked')){
743
			brands.push($(this).val());
758
			brands.push($(this).val());
744
			brandnames.push($(this).parent().siblings('.brandname').html());
759
			brandnames.push($(this).parent().siblings('.brandname').html());
745
		}		
760
		}		
746
	});
761
	});
-
 
762
	
-
 
763
	$('.filtersubcategory').each(function(){
-
 
764
		if($(this).prop('checked')){
-
 
765
			subcategories.push($(this).val());
-
 
766
			subcatnames.push($(this).parent().siblings('.subcategoryname').html());
-
 
767
		}
-
 
768
	});
-
 
769
 
-
 
770
	if(brands.length==0 && subcategories.length==0){
-
 
771
		$('#loadingModal').modal('hide');
-
 
772
		$('#message').html('Please choose a few brands/subcategories first').removeClass('hidden');
-
 
773
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
-
 
774
		$(this).prop('disabled',false);
-
 
775
		return false;
-
 
776
	}else if(brands.length==0 && subcategories.length>0 ){
-
 
777
		setCookie('subcategorieschosen', subcategories, 0.25, true);
-
 
778
		var url = $('#subcategoryselecter').prop('action');
-
 
779
		ga('send', 'event', 'filter', 'subcategory', subcatnames.join('|'));
-
 
780
		properties = {};
-
 
781
		for(var i in subcatnames){
-
 
782
			properties['subcategories_'+i] = subcatnames[i];
-
 
783
		}
-
 
784
		pma.send('filters','subcategories','addfilter',me,properties);
-
 
785
		var postdata = {'user_id':me,'type':'subcategory','filters':subcatnames.join('|')};
-
 
786
		$.post( "/user_filters/add", postdata, function( data ) {
-
 
787
			$('#loadingModal').modal('hide');
-
 
788
			$(this).prop('disabled',false);
-
 
789
	  		document.location = url+'&subcategories='+subcategories.join('^');
-
 
790
		});	
-
 
791
	}else if(brands.length>0 && subcategories.length==0 ){
-
 
792
		setCookie('brandschosen', brands, 0.25, true);
-
 
793
		var url = $('#brandselecter').prop('action');
-
 
794
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
-
 
795
		properties = {};
-
 
796
		for(var i in brandnames){
-
 
797
			properties['brand_'+i] = brandnames[i];
-
 
798
		}
-
 
799
		pma.send('filters','brands','addfilter',me,properties);
-
 
800
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
-
 
801
		$.post( "/user_filters/add", postdata, function( data ) {
-
 
802
			$('#loadingModal').modal('hide');
-
 
803
			$(this).prop('disabled',false);
-
 
804
	  		document.location = url+'&brands='+brands.join('^');
-
 
805
		});		
-
 
806
	}else if(brands.length>0 && subcategories.length>0 ){
-
 
807
		setCookie('brandschosen', brands, 0.25, true);
-
 
808
		setCookie('subcategorieschosen', subcategories, 0.25, true);
-
 
809
		var url = $('#brandselecter').prop('action');
-
 
810
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
-
 
811
		ga('send', 'event', 'filter', 'subcategory', subcatnames.join('|'));
-
 
812
		properties = {};
-
 
813
		for(var i in brandnames){
-
 
814
			properties['brand_'+i] = brandnames[i];
-
 
815
		}
-
 
816
		for(var i in subcatnames){
-
 
817
			properties['subcategory_'+i] = subcatnames[i];
-
 
818
		}
-
 
819
		pma.send('filters','brandsnsubcategories','addfilter',me,properties);
-
 
820
		var dataStr = brandnames.join('|');
-
 
821
		dataStr = dataStr + subcatnames.join('|');
-
 
822
		var postdata = {'user_id':me,'type':'brandnsubcategory','filters':dataStr};
-
 
823
		$.post( "/user_filters/add", postdata, function( data ) {
-
 
824
			$('#loadingModal').modal('hide');
-
 
825
			$(this).prop('disabled',false);
-
 
826
	  		document.location = url+'&brands='+brands.join('^')+"&subcategories="+subcategories.join("^");
-
 
827
		});
-
 
828
	}
-
 
829
 
747
	if(brands.length==0){
830
	/*if(brands.length==0){
748
		$('#loadingModal').modal('hide');
831
		$('#loadingModal').modal('hide');
749
		$('#message').html('Please choose a few brands first').removeClass('hidden');
832
		$('#message').html('Please choose a few brands first').removeClass('hidden');
750
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
833
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
751
		$(this).prop('disabled',false);
834
		$(this).prop('disabled',false);
752
		return false;
835
		return false;
Line 763... Line 846...
763
		$.post( "/user_filters/add", postdata, function( data ) {
846
		$.post( "/user_filters/add", postdata, function( data ) {
764
			$('#loadingModal').modal('hide');
847
			$('#loadingModal').modal('hide');
765
			$(this).prop('disabled',false);
848
			$(this).prop('disabled',false);
766
	  		document.location = url+'&brands='+brands.join('^');
849
	  		document.location = url+'&brands='+brands.join('^');
767
		});		
850
		});		
768
	}	
851
	}
-
 
852
 
-
 
853
	if(subcategories.length==0){
-
 
854
		$('#loadingModal').modal('hide');
-
 
855
		$('#message').html('Please choose a few Sub-categories first').removeClass('hidden');
-
 
856
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
-
 
857
		$(this).prop('disabled',false);
-
 
858
		return false;
-
 
859
	}else{
-
 
860
		setCookie('subcategorieschosen', subcategories, 0.25, true);
-
 
861
		var url = $('#subcategoryselecter').prop('action');
-
 
862
		ga('send', 'event', 'filter', 'subcategory', brandnames.join('|'));
-
 
863
		properties = {};
-
 
864
		for(var i in brandnames){
-
 
865
			properties['brand_'+i] = brandnames[i];
-
 
866
		}
-
 
867
		pma.send('filters','subcategories','addfilter',me,properties);
-
 
868
		var postdata = {'user_id':me,'type':'subcategory','filters':subcatnames.join('|')};
-
 
869
		$.post( "/user_filters/add", postdata, function( data ) {
-
 
870
			$('#loadingModal').modal('hide');
-
 
871
			$(this).prop('disabled',false);
-
 
872
	  		document.location = url+'&brands='+brands.join('^');
-
 
873
		});		
-
 
874
	}*/	
769
});
875
});
770
$(document).on('click','#showallbrands',function(){	
876
$(document).on('click','#showallbrands',function(){	
771
	$('.hidden').removeClass('hidden');
877
	$('.hidden').removeClass('hidden');
772
	$(this).hide();
878
	$(this).hide();
773
});
879
});
Line 808... Line 914...
808
	  clicked.css({'position': 'static', 'top': 0});
914
	  clicked.css({'position': 'static', 'top': 0});
809
	  previousAll.css({'position': 'static', 'top': 0}); 
915
	  previousAll.css({'position': 'static', 'top': 0}); 
810
	}});
916
	}});
811
	}
917
	}
812
})
918
})
-
 
919
$(document).on('click','.filtersubcategory',function(){
-
 
920
	var clicked = $(this).parent().parent();
-
 
921
	// all the LIs above the clicked one
-
 
922
	var previousAll = clicked.prevAll();
-
 
923
 
-
 
924
	// only proceed if it's not already on top (no previous siblings)
-
 
925
	if(previousAll.length > 0) {
-
 
926
	// top LI
-
 
927
	var top = $(previousAll[previousAll.length - 1]);
-
 
928
 
-
 
929
	// immediately previous LI
-
 
930
	var previous = $(previousAll[0]);
-
 
931
 
-
 
932
	// how far up do we need to move the clicked LI?
-
 
933
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
-
 
934
 
-
 
935
	// how far down do we need to move the previous siblings?
-
 
936
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
-
 
937
 
-
 
938
	// let's move stuff
-
 
939
	clicked.css('position', 'relative');
-
 
940
	previousAll.css('position', 'relative');
-
 
941
	clicked.animate({'top': -moveUp});
-
 
942
	previousAll.animate({'top': moveDown}, {complete: function() {
-
 
943
	  // rearrange the DOM and restore positioning when we're done moving
-
 
944
	  clicked.parent().prepend(clicked);
-
 
945
	  clicked.css({'position': 'static', 'top': 0});
-
 
946
	  previousAll.css({'position': 'static', 'top': 0}); 
-
 
947
	}});
-
 
948
	}
-
 
949
})
813
$(document).on('click','.clearfilters',function(){
950
$(document).on('click','.clearfilters',function(){
814
	setCookie('brandschosen', '', -1, true);
951
	setCookie('brandschosen', '', -1, true);
-
 
952
	setCookie('subcategorieschosen','',-1, true);
815
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
953
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
-
 
954
	ga('send', 'event', 'filter', 'subcategory', 'clearfilters');
816
	pma.send('filters','brands','clearfilters',me);
955
	pma.send('filters','brands','clearfilters',me);
-
 
956
	pma.send('filters','subcategory','clearfilters',me);
817
	var postdata = {'user_id':me,'type':'clear'};
957
	var postdata = {'user_id':me,'type':'clear'};
818
	$('#loadingModal').modal('show');
958
	$('#loadingModal').modal('show');
819
	$.post("/user_filters/add", postdata, function( data ) {		
959
	$.post("/user_filters/add", postdata, function( data ) {		
820
	  	// document.location.reload();
960
	  	// document.location.reload();
821
	  	window.location.replace(window.location.href.split('?')[0]);
961
	  	window.location.replace(window.location.href.split('?')[0]);
822
	});	
962
	});	
823
});
963
});
824
function selectChosenBrands(){
964
function selectChosenBrands(){
825
	var brandschosen = decodeURIComponent(getCookie('brandschosen',true));
965
	var brandschosen = decodeURIComponent(getCookie('brandschosen',true));
-
 
966
	var subcategorieschosen = decodeURIComponent(getCookie('subcategorieschosen',true));
826
	if(brandschosen && brandschosen.length>0){
967
	if(brandschosen && brandschosen.length>0){
827
		var brands = brandschosen.split(',');
968
		var brands = brandschosen.split(',');
828
		for(var i in brands){
969
		for(var i in brands){
829
			$('.brand').filter(function() { 
970
			$('.brand').filter(function() { 
830
			  	return $(this).data("brandid") == brands[i];
971
			  	return $(this).data("brandid") == brands[i];
831
			}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
972
			}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
832
		}
973
		}
833
	}
974
	}
-
 
975
	if(subcategorieschosen && subcategorieschosen.length>0){
-
 
976
		var subcategories = subcategorieschosen.split(',');
-
 
977
		for(var i in subcategories){
-
 
978
			$('.subcategory').filter(function() { 
-
 
979
			  	return $(this).data("brandid") == subcategories[i];
-
 
980
			}).removeClass('hidden').find('.filtersubcategory',0).trigger( "click" );
-
 
981
		}
-
 
982
	}
834
}
983
}
835
function showPosition(position) {
984
function showPosition(position) {
836
    setCookie('latitude',position.coords.latitude,1,true); 
985
    setCookie('latitude',position.coords.latitude,1,true); 
837
    setCookie('longitude',position.coords.longitude,1,true);	
986
    setCookie('longitude',position.coords.longitude,1,true);	
838
}
987
}
Line 901... Line 1050...
901
$(document).on('click','.selectbrand',function(e){
1050
$(document).on('click','.selectbrand',function(e){
902
	e.preventDefault();
1051
	e.preventDefault();
903
	var brands = $(this).data('id');
1052
	var brands = $(this).data('id');
904
	var brandname = $(this).html();
1053
	var brandname = $(this).html();
905
	console.log(brandname);
1054
	console.log(brandname);
-
 
1055
	
906
	setCookie('brandschosen', brands, 1, true);
1056
	setCookie('brandschosen', brands, 1, true);
907
	var url = $(this).data('href');
1057
	var url = $(this).data('href');
908
	ga('send', 'event', 'selectbrand', 'brand', brandname);
1058
	ga('send', 'event', 'selectbrand', 'brand', brandname);
909
	properties = {};
1059
	properties = {};
910
	properties['brand'] = brandname;
1060
	properties['brand'] = brandname;