Subversion Repositories SmartDukaan

Rev

Rev 4922 | Rev 4984 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4126 varun.gupt 1
$(function(){
4798 varun.gupt 2
 
3
	function updateCompareCount()	{
4
		$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
5
	}
6
 
4126 varun.gupt 7
	/** Sidebar Widgets **/
4237 varun.gupt 8
 
9
	$('#shoppingExpInfo').click(function(){
10
		$.colorbox({
4284 varun.gupt 11
    		width: "550px",
12
    		height: "320px",
4237 varun.gupt 13
    		inline: true,
14
    		href: "<h3>Shopping with Saholic.com is completely safe</h3><br />" +
4284 varun.gupt 15
		"<b>1.</b> We are part of Spice Group - India's # 1 Mobile retailer.<br /><br />" +
16
		"<b>2.</b> We procure directly from the Manufacturers - Hence we only sell genuine products with full Manufacturer Warranty.<br /><br />" +
17
		"<b>3.</b> We provide free Next Day Delivery to most locations - You can check the delivery time to your location by entering your pin code on the product page.<br /><br />" +
4372 varun.gupt 18
		"<b>4.</b> We use the best Internet Security technlology - Your payment is 100% secure.<br />",
19
			onComplete: function(){
20
				trackEventWithGA('Widget', 'Empty Cart Message Show', '');
21
			}
4237 varun.gupt 22
    	});
23
	});
4126 varun.gupt 24
 
25
	$('.common-widget-top-bar').live('click', function(){
26
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
27
		var widgetBox = $(this).siblings('.common-widget-content-area');
28
		var controlBox = $(this).siblings('.common-widget-control-bar');
29
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 30
 
4126 varun.gupt 31
		if (isColapsed)	{
32
			if(controlBox.length > 0)	{
33
				$(controlBox).slideDown('fast', function(){
34
					$(widgetBox).slideDown();
35
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
36
				});
37
			} else	{
38
				$(widgetBox).slideDown();
39
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
40
			}
41
		} else	{
42
			$(widgetBox).slideUp(function(){
43
				$(controlBox).slideUp('fast');
44
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
45
			});
46
		}
47
		$(this).data('is_colapsed', !isColapsed);
48
	});
49
 
50
	/**
51
	 * Update count of products checked for comparison
52
	 **/
53
	$('#myresearch input[type="checkbox"]').live('click', function(){
4798 varun.gupt 54
		updateCompareCount();
4126 varun.gupt 55
	});
56
 
57
	$("#research_compare").live('click', function(){
58
		var seldata = "";
59
		var tot = 1;
60
		var saprt = "";
61
		var par = $('#myresearch').find('input[type=checkbox]:checked');
4926 varun.gupt 62
		var haveSameProductType = true;
63
		var productType = null;
64
 
4126 varun.gupt 65
		$(par).each(function(){
4926 varun.gupt 66
 
67
			if(productType != null && productType != $(this).attr('producttype'))	{
68
				haveSameProductType = false;
69
			}
70
			productType = $(this).attr('producttype');
71
 
4126 varun.gupt 72
			if(tot == 1)	{
73
				seldata += "p" + tot + "=" + $(this).val();
74
			} else	{
75
				seldata += "&p" + tot + "=" + $(this).val();
76
			}
77
			tot ++;
78
		});
79
 
4926 varun.gupt 80
		if(! haveSameProductType)	{
81
			alert("Only products of same category can be compared");
82
		} else if(tot > 6)	{
4126 varun.gupt 83
			alert("Can compare upto five products only.");
84
		} else if(tot > 2)	{
85
			window.location = "/compare-mobile-phones?" + seldata;
86
		} else	{
87
			alert("Please select atleast two products");
88
		}
89
	});
90
 
91
	$("#research_delete").live('click', function(){
92
		var research_tot = $("#research_total").val();
93
		var seldata = [];
94
		var tot = 0;
95
		var saprt = "";
96
		var par = $('#myresearch').find('input[type=checkbox]:checked');
97
 
98
		$(par).each(function(){
99
			seldata.unshift($(this).val());
100
			tot ++;
101
		});
102
 
103
		if(tot > 0)	{
104
			var t = (research_tot * 1) - (tot * 1);
105
			$("#research_total").val(t);
106
 
107
			jQuery.ajax({
108
				type: "GET",
109
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
110
				success: function(msg)	{
111
					jQuery.each(seldata, function(intIndex, objValue){
112
						delete_from_storage_set("resitems", objValue);
113
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
114
							$(this).remove();
115
							if(t === 0)	{
116
								$("#research_default").css("display", "block");
117
							}
118
						});
119
					});
4922 varun.gupt 120
					//Updating the count
121
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4126 varun.gupt 122
				}
123
			});
124
		} else	{
125
			alert("Please select atleast one product");
126
		}
127
	});
128
 
129
	// No uid cookie
130
	if (!$.cookie("uid"))	{
131
		// No uid in storage
132
		if (!$.Storage.get("uid"))	{
133
			if (!$.Storage.get("resitems"))	{
134
				$.Storage.set("resitems", "[]");
135
			}
136
			if (!$.Storage.get("histitems"))	{
137
				$.Storage.set("histitems", "[]");
138
			}
139
		}
140
		else	{			// uid in storage : logout
141
			$.Storage.remove("uid");
142
			$.Storage.set("resitems", "[]");
143
			$.Storage.set("histitems", "[]");
144
		}
145
		load_research_widget();
146
		load_history_widget();
147
	}
148
	else	{				// With uid cookie
149
		var cookie = $.cookie("uid");
150
		// Just logged in merge storage items
151
		if (!$.Storage.get("uid"))	{
152
			$.Storage.set("uid", cookie);
153
			merge_history_items();
154
			load_research_items();
155
		}
156
		else	{
157
			// UID changed
158
			if ( cookie != $.Storage.get("uid"))	{
159
				$.Storage.set("uid", cookie);
160
				$.Storage.set("resitems", "[]");
161
				$.Storage.set("histitems", "[]");
162
				merge_history_items();
163
				load_research_items();
164
			}
165
			else	{		// Uid is same
166
				if (!$.Storage.get("resitems"))	{
167
					$.Storage.set("resitems", "[]");
168
					load_research_items();
169
				}
170
				else	{
171
					load_research_widget();
172
				}
173
 
174
				if (!$.Storage.get("histitems"))	{
175
					$.Storage.set("histitems", "[]");
176
					merge_history_items();
177
				}
178
				else	{
179
					load_history_widget();
180
				}
181
			}
182
		}
183
	}
4798 varun.gupt 184
 
185
	function load_research_items(){
186
		jQuery.ajax({
187
			type: "GET",
188
			url: "/myresearch",
189
			cache: false,
190
			success: function(json) {
191
			    $.Storage.set("resitems", json);
192
			    load_research_widget();
193
		    }
194
		});
195
	}
196
 
197
	function load_research_widget(){
198
		var myResearchWidgetContainer = $("#myresearch");
199
 
200
		if($(myResearchWidgetContainer).length == 0) {
201
			return;
202
		}
203
		var resitems = $.Storage.get("resitems");
204
 
205
		if (resitems == "[]") {
206
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
207
		      <tbody>\
208
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
209
		       </tbody>\
210
		      </table>';
211
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
212
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
213
			return;
214
		}
215
		var params = "/" + resitems;
216
 
217
		jQuery.ajax({
218
			type : "GET",
219
			url : "/myresearch" + params,
220
			cache: true,
221
			success : function(html) {
222
	   		    $("#myresearch").html(html);
223
	   			updateCompareCount();
224
 
225
			    // Product Title
226
			    $("#myresearch table td div a.truncate").each(function() {
227
						$(this).truncate({addtitle : true});
228
			    });
229
 
230
			    // Product Price
231
			    $("#myresearch table td div div.price").each(function() {
232
						$(this).truncate({addtitle : true});
233
				});
234
 
235
			    // Product Details
236
			    $("#myresearch table td div div.text").each(function() {
237
						$(this).truncate( {addtitle : true});
238
				});
239
		    }
240
		});
241
	}
4126 varun.gupt 242
});