Subversion Repositories SmartDukaan

Rev

Rev 4798 | Rev 4926 | 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');
62
 
63
		$(par).each(function(){
64
			if(tot == 1)	{
65
				seldata += "p" + tot + "=" + $(this).val();
66
			} else	{
67
				seldata += "&p" + tot + "=" + $(this).val();
68
			}
69
			tot ++;
70
		});
71
 
72
		if(tot > 6)	{
73
			alert("Can compare upto five products only.");
74
		} else if(tot > 2)	{
75
			window.location = "/compare-mobile-phones?" + seldata;
76
		} else	{
77
			alert("Please select atleast two products");
78
		}
79
	});
80
 
81
	$("#research_delete").live('click', function(){
82
		var research_tot = $("#research_total").val();
83
		var seldata = [];
84
		var tot = 0;
85
		var saprt = "";
86
		var par = $('#myresearch').find('input[type=checkbox]:checked');
87
 
88
		$(par).each(function(){
89
			seldata.unshift($(this).val());
90
			tot ++;
91
		});
92
 
93
		if(tot > 0)	{
94
			var t = (research_tot * 1) - (tot * 1);
95
			$("#research_total").val(t);
96
 
97
			jQuery.ajax({
98
				type: "GET",
99
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
100
				success: function(msg)	{
101
					jQuery.each(seldata, function(intIndex, objValue){
102
						delete_from_storage_set("resitems", objValue);
103
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
104
							$(this).remove();
105
							if(t === 0)	{
106
								$("#research_default").css("display", "block");
107
							}
108
						});
109
					});
4922 varun.gupt 110
					//Updating the count
111
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4126 varun.gupt 112
				}
113
			});
114
		} else	{
115
			alert("Please select atleast one product");
116
		}
117
	});
118
 
119
	// No uid cookie
120
	if (!$.cookie("uid"))	{
121
		// No uid in storage
122
		if (!$.Storage.get("uid"))	{
123
			if (!$.Storage.get("resitems"))	{
124
				$.Storage.set("resitems", "[]");
125
			}
126
			if (!$.Storage.get("histitems"))	{
127
				$.Storage.set("histitems", "[]");
128
			}
129
		}
130
		else	{			// uid in storage : logout
131
			$.Storage.remove("uid");
132
			$.Storage.set("resitems", "[]");
133
			$.Storage.set("histitems", "[]");
134
		}
135
		load_research_widget();
136
		load_history_widget();
137
	}
138
	else	{				// With uid cookie
139
		var cookie = $.cookie("uid");
140
		// Just logged in merge storage items
141
		if (!$.Storage.get("uid"))	{
142
			$.Storage.set("uid", cookie);
143
			merge_history_items();
144
			load_research_items();
145
		}
146
		else	{
147
			// UID changed
148
			if ( cookie != $.Storage.get("uid"))	{
149
				$.Storage.set("uid", cookie);
150
				$.Storage.set("resitems", "[]");
151
				$.Storage.set("histitems", "[]");
152
				merge_history_items();
153
				load_research_items();
154
			}
155
			else	{		// Uid is same
156
				if (!$.Storage.get("resitems"))	{
157
					$.Storage.set("resitems", "[]");
158
					load_research_items();
159
				}
160
				else	{
161
					load_research_widget();
162
				}
163
 
164
				if (!$.Storage.get("histitems"))	{
165
					$.Storage.set("histitems", "[]");
166
					merge_history_items();
167
				}
168
				else	{
169
					load_history_widget();
170
				}
171
			}
172
		}
173
	}
4798 varun.gupt 174
 
175
	function load_research_items(){
176
		jQuery.ajax({
177
			type: "GET",
178
			url: "/myresearch",
179
			cache: false,
180
			success: function(json) {
181
			    $.Storage.set("resitems", json);
182
			    load_research_widget();
183
		    }
184
		});
185
	}
186
 
187
	function load_research_widget(){
188
		var myResearchWidgetContainer = $("#myresearch");
189
 
190
		if($(myResearchWidgetContainer).length == 0) {
191
			return;
192
		}
193
		var resitems = $.Storage.get("resitems");
194
 
195
		if (resitems == "[]") {
196
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
197
		      <tbody>\
198
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
199
		       </tbody>\
200
		      </table>';
201
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
202
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
203
			return;
204
		}
205
		var params = "/" + resitems;
206
 
207
		jQuery.ajax({
208
			type : "GET",
209
			url : "/myresearch" + params,
210
			cache: true,
211
			success : function(html) {
212
	   		    $("#myresearch").html(html);
213
	   			updateCompareCount();
214
 
215
			    // Product Title
216
			    $("#myresearch table td div a.truncate").each(function() {
217
						$(this).truncate({addtitle : true});
218
			    });
219
 
220
			    // Product Price
221
			    $("#myresearch table td div div.price").each(function() {
222
						$(this).truncate({addtitle : true});
223
				});
224
 
225
			    // Product Details
226
			    $("#myresearch table td div div.text").each(function() {
227
						$(this).truncate( {addtitle : true});
228
				});
229
		    }
230
		});
231
	}
4126 varun.gupt 232
});