Subversion Repositories SmartDukaan

Rev

Rev 4372 | Rev 4922 | 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
					});
110
				}
111
			});
112
		} else	{
113
			alert("Please select atleast one product");
114
		}
115
	});
116
 
117
	// No uid cookie
118
	if (!$.cookie("uid"))	{
119
		// No uid in storage
120
		if (!$.Storage.get("uid"))	{
121
			if (!$.Storage.get("resitems"))	{
122
				$.Storage.set("resitems", "[]");
123
			}
124
			if (!$.Storage.get("histitems"))	{
125
				$.Storage.set("histitems", "[]");
126
			}
127
		}
128
		else	{			// uid in storage : logout
129
			$.Storage.remove("uid");
130
			$.Storage.set("resitems", "[]");
131
			$.Storage.set("histitems", "[]");
132
		}
133
		load_research_widget();
134
		load_history_widget();
135
	}
136
	else	{				// With uid cookie
137
		var cookie = $.cookie("uid");
138
		// Just logged in merge storage items
139
		if (!$.Storage.get("uid"))	{
140
			$.Storage.set("uid", cookie);
141
			merge_history_items();
142
			load_research_items();
143
		}
144
		else	{
145
			// UID changed
146
			if ( cookie != $.Storage.get("uid"))	{
147
				$.Storage.set("uid", cookie);
148
				$.Storage.set("resitems", "[]");
149
				$.Storage.set("histitems", "[]");
150
				merge_history_items();
151
				load_research_items();
152
			}
153
			else	{		// Uid is same
154
				if (!$.Storage.get("resitems"))	{
155
					$.Storage.set("resitems", "[]");
156
					load_research_items();
157
				}
158
				else	{
159
					load_research_widget();
160
				}
161
 
162
				if (!$.Storage.get("histitems"))	{
163
					$.Storage.set("histitems", "[]");
164
					merge_history_items();
165
				}
166
				else	{
167
					load_history_widget();
168
				}
169
			}
170
		}
171
	}
4798 varun.gupt 172
 
173
	function load_research_items(){
174
		jQuery.ajax({
175
			type: "GET",
176
			url: "/myresearch",
177
			cache: false,
178
			success: function(json) {
179
			    $.Storage.set("resitems", json);
180
			    load_research_widget();
181
		    }
182
		});
183
	}
184
 
185
	function load_research_widget(){
186
		var myResearchWidgetContainer = $("#myresearch");
187
 
188
		if($(myResearchWidgetContainer).length == 0) {
189
			return;
190
		}
191
		var resitems = $.Storage.get("resitems");
192
 
193
		if (resitems == "[]") {
194
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
195
		      <tbody>\
196
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
197
		       </tbody>\
198
		      </table>';
199
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
200
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
201
			return;
202
		}
203
		var params = "/" + resitems;
204
 
205
		jQuery.ajax({
206
			type : "GET",
207
			url : "/myresearch" + params,
208
			cache: true,
209
			success : function(html) {
210
	   		    $("#myresearch").html(html);
211
	   			updateCompareCount();
212
 
213
			    // Product Title
214
			    $("#myresearch table td div a.truncate").each(function() {
215
						$(this).truncate({addtitle : true});
216
			    });
217
 
218
			    // Product Price
219
			    $("#myresearch table td div div.price").each(function() {
220
						$(this).truncate({addtitle : true});
221
				});
222
 
223
			    // Product Details
224
			    $("#myresearch table td div div.text").each(function() {
225
						$(this).truncate( {addtitle : true});
226
				});
227
		    }
228
		});
229
	}
4126 varun.gupt 230
});