Subversion Repositories SmartDukaan

Rev

Rev 6173 | Rev 6261 | 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
 
4798 varun.gupt 33
	function updateCompareCount()	{
34
		$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
35
	}
36
 
4126 varun.gupt 37
	/** Sidebar Widgets **/
4237 varun.gupt 38
 
39
	$('#shoppingExpInfo').click(function(){
40
		$.colorbox({
4284 varun.gupt 41
    		width: "550px",
42
    		height: "320px",
4237 varun.gupt 43
    		inline: true,
44
    		href: "<h3>Shopping with Saholic.com is completely safe</h3><br />" +
4284 varun.gupt 45
		"<b>1.</b> We are part of Spice Group - India's # 1 Mobile retailer.<br /><br />" +
46
		"<b>2.</b> We procure directly from the Manufacturers - Hence we only sell genuine products with full Manufacturer Warranty.<br /><br />" +
47
		"<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 />" +
6173 kshitij.so 48
		"<b>4.</b> We use the best Internet Security technology - Your payment is 100% secure.<br />",
4372 varun.gupt 49
			onComplete: function(){
50
				trackEventWithGA('Widget', 'Empty Cart Message Show', '');
51
			}
4237 varun.gupt 52
    	});
53
	});
6245 kshitij.so 54
 
55
 
56
	$('#pickupstoreInfo').click(function(){
57
		$.colorbox({
58
    		width: "550px",
59
    		height: "370px",
60
    		inline: true,
61
    		href: "<h3>Frequently Asked Questions</h3><br />" +
62
		"<b>Q)</b> What is 'Buy Online & Pickup in Store' ?<br /><br />" +
63
		"<b>A)</b> Buy Online from Saholic.Com and pickup your product from the nearest Spice Hotspot Retail Store.<br /><br />" +
64
		"<b>Q)</b> How do i avail this facility ?<br /><br />" +
65
		"<b>A)</b> Simply select Pickup In Store On the Shipping Page and select your nearest store. Please note this facility is available only in Delhi/NCR.</a><br /><br />"+
66
		"<b>Q)</b> When will the product be available for pickup ?<br /><br />" +
67
		"<b>A)</b> You can enter your pin code on the Product Page to find estimated time to deliver. After placing the order we will also give you the estimated date for pickup.</a><br /><br />",
68
 
69
			onComplete: function(){
70
				trackEventWithGA('Widget', 'Empty Cart Message Show', '');
71
			}
72
    	});
73
	});
4126 varun.gupt 74
 
5420 amit.gupta 75
	$('.common-widget-top-bar').live('click', function(e, callback){
4126 varun.gupt 76
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
77
		var widgetBox = $(this).siblings('.common-widget-content-area');
78
		var controlBox = $(this).siblings('.common-widget-control-bar');
79
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 80
 
4126 varun.gupt 81
		if (isColapsed)	{
82
			if(controlBox.length > 0)	{
83
				$(controlBox).slideDown('fast', function(){
5420 amit.gupta 84
					$(widgetBox).slideDown('fast', callback);
4126 varun.gupt 85
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
86
				});
87
			} else	{
88
				$(widgetBox).slideDown();
89
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
90
			}
91
		} else	{
92
			$(widgetBox).slideUp(function(){
93
				$(controlBox).slideUp('fast');
94
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
95
			});
96
		}
97
		$(this).data('is_colapsed', !isColapsed);
98
	});
99
 
100
	/**
101
	 * Update count of products checked for comparison
102
	 **/
103
	$('#myresearch input[type="checkbox"]').live('click', function(){
4798 varun.gupt 104
		updateCompareCount();
4126 varun.gupt 105
	});
106
 
107
	$("#research_compare").live('click', function(){
108
		var seldata = "";
5322 amit.gupta 109
		var prodnames = "";
4126 varun.gupt 110
		var tot = 1;
111
		var saprt = "";
112
		var par = $('#myresearch').find('input[type=checkbox]:checked');
4926 varun.gupt 113
		var haveSameProductType = true;
114
		var productType = null;
115
 
4126 varun.gupt 116
		$(par).each(function(){
4926 varun.gupt 117
 
118
			if(productType != null && productType != $(this).attr('producttype'))	{
119
				haveSameProductType = false;
120
			}
121
			productType = $(this).attr('producttype');
122
 
4126 varun.gupt 123
			if(tot == 1)	{
5358 amit.gupta 124
				prodnames += $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 125
				seldata += "p" + tot + "=" + $(this).val();
126
			} else	{
127
				seldata += "&p" + tot + "=" + $(this).val();
5358 amit.gupta 128
				prodnames += "-vs-" + $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 129
			}
130
			tot ++;
131
		});
4984 varun.gupt 132
 
4926 varun.gupt 133
		if(! haveSameProductType)	{
134
			alert("Only products of same category can be compared");
135
		} else if(tot > 6)	{
4126 varun.gupt 136
			alert("Can compare upto five products only.");
137
		} else if(tot > 2)	{
5552 phani.kuma 138
			window.location = "/compare-" + productType.replace(/ +/g, '-').toLowerCase() + "/" + prodnames + "?" + seldata+"&fromsrc=comparison_widget";
4126 varun.gupt 139
		} else	{
140
			alert("Please select atleast two products");
141
		}
142
	});
143
 
144
	$("#research_delete").live('click', function(){
145
		var research_tot = $("#research_total").val();
146
		var seldata = [];
147
		var tot = 0;
148
		var saprt = "";
149
		var par = $('#myresearch').find('input[type=checkbox]:checked');
150
 
151
		$(par).each(function(){
152
			seldata.unshift($(this).val());
153
			tot ++;
154
		});
155
 
156
		if(tot > 0)	{
157
			var t = (research_tot * 1) - (tot * 1);
158
			$("#research_total").val(t);
159
 
160
			jQuery.ajax({
161
				type: "GET",
162
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
163
				success: function(msg)	{
164
					jQuery.each(seldata, function(intIndex, objValue){
165
						delete_from_storage_set("resitems", objValue);
166
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
167
							$(this).remove();
168
							if(t === 0)	{
169
								$("#research_default").css("display", "block");
170
							}
171
						});
172
					});
4984 varun.gupt 173
 
4922 varun.gupt 174
					//Updating the count
175
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4984 varun.gupt 176
 
177
					if ($('#myresearch input[type="checkbox"]').length - seldata.length <= 0)	{
178
						$("#myresearch").children(".common-widget-top-bar").trigger('click');
179
					}
4126 varun.gupt 180
				}
181
			});
182
		} else	{
183
			alert("Please select atleast one product");
184
		}
185
	});
186
 
187
	// No uid cookie
188
	if (!$.cookie("uid"))	{
189
		// No uid in storage
190
		if (!$.Storage.get("uid"))	{
191
			if (!$.Storage.get("resitems"))	{
192
				$.Storage.set("resitems", "[]");
193
			}
194
			if (!$.Storage.get("histitems"))	{
195
				$.Storage.set("histitems", "[]");
196
			}
197
		}
198
		else	{			// uid in storage : logout
199
			$.Storage.remove("uid");
200
			$.Storage.set("resitems", "[]");
201
			$.Storage.set("histitems", "[]");
202
		}
203
		load_research_widget();
204
		load_history_widget();
205
	}
206
	else	{				// With uid cookie
207
		var cookie = $.cookie("uid");
208
		// Just logged in merge storage items
209
		if (!$.Storage.get("uid"))	{
210
			$.Storage.set("uid", cookie);
211
			merge_history_items();
212
			load_research_items();
213
		}
214
		else	{
215
			// UID changed
216
			if ( cookie != $.Storage.get("uid"))	{
217
				$.Storage.set("uid", cookie);
218
				$.Storage.set("resitems", "[]");
219
				$.Storage.set("histitems", "[]");
220
				merge_history_items();
221
				load_research_items();
222
			}
223
			else	{		// Uid is same
224
				if (!$.Storage.get("resitems"))	{
225
					$.Storage.set("resitems", "[]");
226
					load_research_items();
227
				}
228
				else	{
229
					load_research_widget();
230
				}
231
 
232
				if (!$.Storage.get("histitems"))	{
233
					$.Storage.set("histitems", "[]");
234
					merge_history_items();
235
				}
236
				else	{
237
					load_history_widget();
238
				}
239
			}
240
		}
241
	}
4798 varun.gupt 242
 
243
	function load_research_items(){
244
		jQuery.ajax({
245
			type: "GET",
246
			url: "/myresearch",
247
			cache: false,
248
			success: function(json) {
249
			    $.Storage.set("resitems", json);
250
			    load_research_widget();
251
		    }
252
		});
253
	}
254
 
255
	function load_research_widget(){
256
		var myResearchWidgetContainer = $("#myresearch");
257
 
258
		if($(myResearchWidgetContainer).length == 0) {
259
			return;
260
		}
261
		var resitems = $.Storage.get("resitems");
262
 
263
		if (resitems == "[]") {
264
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
265
		      <tbody>\
266
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
267
		       </tbody>\
268
		      </table>';
269
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
270
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
271
			return;
272
		}
273
		var params = "/" + resitems;
274
 
275
		jQuery.ajax({
276
			type : "GET",
277
			url : "/myresearch" + params,
278
			cache: true,
279
			success : function(html) {
280
	   		    $("#myresearch").html(html);
281
	   			updateCompareCount();
282
 
283
			    // Product Title
284
			    $("#myresearch table td div a.truncate").each(function() {
285
						$(this).truncate({addtitle : true});
286
			    });
287
 
288
			    // Product Price
289
			    $("#myresearch table td div div.price").each(function() {
290
						$(this).truncate({addtitle : true});
291
				});
292
 
293
			    // Product Details
294
			    $("#myresearch table td div div.text").each(function() {
295
						$(this).truncate( {addtitle : true});
296
				});
297
		    }
298
		});
299
	}
4126 varun.gupt 300
});