Subversion Repositories SmartDukaan

Rev

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