Subversion Repositories SmartDukaan

Rev

Rev 6263 | Rev 6303 | 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(){
6261 amit.gupta 50
				trackEventWithGA('Widget', 'Safe shopping sticky banner is clicked', '');
4372 varun.gupt 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(){
6262 amit.gupta 70
				var ev = "Product Page";
6261 amit.gupta 71
				var label = document.URL.substring(document.URL.lastIndexOf('/')+1);
6264 amit.gupta 72
				if (label=="" || label=="#")
6261 amit.gupta 73
				{
6262 amit.gupta 74
					ev = "Home Page";
6261 amit.gupta 75
				}
6262 amit.gupta 76
				else if (label.indexOf("shipping") != -1){
77
					ev = "Shipping Page";
78
					var blkstr = [];
6263 amit.gupta 79
					jQuery("#cartDetail").find("span.cart-item-name").each(function(key,str){
6262 amit.gupta 80
						blkstr.push(str);
81
					});
82
					label = blkstr.join(", ");;
83
				}
6261 amit.gupta 84
				trackEventWithGA('Pickup in Store LightBox', ev, label);
6245 kshitij.so 85
			}
86
    	});
87
	});
4126 varun.gupt 88
 
5420 amit.gupta 89
	$('.common-widget-top-bar').live('click', function(e, callback){
4126 varun.gupt 90
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
91
		var widgetBox = $(this).siblings('.common-widget-content-area');
92
		var controlBox = $(this).siblings('.common-widget-control-bar');
93
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 94
 
4126 varun.gupt 95
		if (isColapsed)	{
96
			if(controlBox.length > 0)	{
97
				$(controlBox).slideDown('fast', function(){
5420 amit.gupta 98
					$(widgetBox).slideDown('fast', callback);
4126 varun.gupt 99
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
100
				});
101
			} else	{
102
				$(widgetBox).slideDown();
103
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
104
			}
105
		} else	{
106
			$(widgetBox).slideUp(function(){
107
				$(controlBox).slideUp('fast');
108
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
109
			});
110
		}
111
		$(this).data('is_colapsed', !isColapsed);
112
	});
113
 
114
	/**
115
	 * Update count of products checked for comparison
116
	 **/
117
	$('#myresearch input[type="checkbox"]').live('click', function(){
4798 varun.gupt 118
		updateCompareCount();
4126 varun.gupt 119
	});
120
 
121
	$("#research_compare").live('click', function(){
122
		var seldata = "";
5322 amit.gupta 123
		var prodnames = "";
4126 varun.gupt 124
		var tot = 1;
125
		var saprt = "";
126
		var par = $('#myresearch').find('input[type=checkbox]:checked');
4926 varun.gupt 127
		var haveSameProductType = true;
128
		var productType = null;
129
 
4126 varun.gupt 130
		$(par).each(function(){
4926 varun.gupt 131
 
132
			if(productType != null && productType != $(this).attr('producttype'))	{
133
				haveSameProductType = false;
134
			}
135
			productType = $(this).attr('producttype');
136
 
4126 varun.gupt 137
			if(tot == 1)	{
5358 amit.gupta 138
				prodnames += $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 139
				seldata += "p" + tot + "=" + $(this).val();
140
			} else	{
141
				seldata += "&p" + tot + "=" + $(this).val();
5358 amit.gupta 142
				prodnames += "-vs-" + $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 143
			}
144
			tot ++;
145
		});
4984 varun.gupt 146
 
4926 varun.gupt 147
		if(! haveSameProductType)	{
148
			alert("Only products of same category can be compared");
149
		} else if(tot > 6)	{
4126 varun.gupt 150
			alert("Can compare upto five products only.");
151
		} else if(tot > 2)	{
5552 phani.kuma 152
			window.location = "/compare-" + productType.replace(/ +/g, '-').toLowerCase() + "/" + prodnames + "?" + seldata+"&fromsrc=comparison_widget";
4126 varun.gupt 153
		} else	{
154
			alert("Please select atleast two products");
155
		}
156
	});
157
 
158
	$("#research_delete").live('click', function(){
159
		var research_tot = $("#research_total").val();
160
		var seldata = [];
161
		var tot = 0;
162
		var saprt = "";
163
		var par = $('#myresearch').find('input[type=checkbox]:checked');
164
 
165
		$(par).each(function(){
166
			seldata.unshift($(this).val());
167
			tot ++;
168
		});
169
 
170
		if(tot > 0)	{
171
			var t = (research_tot * 1) - (tot * 1);
172
			$("#research_total").val(t);
173
 
174
			jQuery.ajax({
175
				type: "GET",
176
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
177
				success: function(msg)	{
178
					jQuery.each(seldata, function(intIndex, objValue){
179
						delete_from_storage_set("resitems", objValue);
180
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
181
							$(this).remove();
182
							if(t === 0)	{
183
								$("#research_default").css("display", "block");
184
							}
185
						});
186
					});
4984 varun.gupt 187
 
4922 varun.gupt 188
					//Updating the count
189
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4984 varun.gupt 190
 
191
					if ($('#myresearch input[type="checkbox"]').length - seldata.length <= 0)	{
192
						$("#myresearch").children(".common-widget-top-bar").trigger('click');
193
					}
4126 varun.gupt 194
				}
195
			});
196
		} else	{
197
			alert("Please select atleast one product");
198
		}
199
	});
200
 
201
	// No uid cookie
202
	if (!$.cookie("uid"))	{
203
		// No uid in storage
204
		if (!$.Storage.get("uid"))	{
205
			if (!$.Storage.get("resitems"))	{
206
				$.Storage.set("resitems", "[]");
207
			}
208
			if (!$.Storage.get("histitems"))	{
209
				$.Storage.set("histitems", "[]");
210
			}
211
		}
212
		else	{			// uid in storage : logout
213
			$.Storage.remove("uid");
214
			$.Storage.set("resitems", "[]");
215
			$.Storage.set("histitems", "[]");
216
		}
217
		load_research_widget();
218
		load_history_widget();
219
	}
220
	else	{				// With uid cookie
221
		var cookie = $.cookie("uid");
222
		// Just logged in merge storage items
223
		if (!$.Storage.get("uid"))	{
224
			$.Storage.set("uid", cookie);
225
			merge_history_items();
226
			load_research_items();
227
		}
228
		else	{
229
			// UID changed
230
			if ( cookie != $.Storage.get("uid"))	{
231
				$.Storage.set("uid", cookie);
232
				$.Storage.set("resitems", "[]");
233
				$.Storage.set("histitems", "[]");
234
				merge_history_items();
235
				load_research_items();
236
			}
237
			else	{		// Uid is same
238
				if (!$.Storage.get("resitems"))	{
239
					$.Storage.set("resitems", "[]");
240
					load_research_items();
241
				}
242
				else	{
243
					load_research_widget();
244
				}
245
 
246
				if (!$.Storage.get("histitems"))	{
247
					$.Storage.set("histitems", "[]");
248
					merge_history_items();
249
				}
250
				else	{
251
					load_history_widget();
252
				}
253
			}
254
		}
255
	}
4798 varun.gupt 256
 
257
	function load_research_items(){
258
		jQuery.ajax({
259
			type: "GET",
260
			url: "/myresearch",
261
			cache: false,
262
			success: function(json) {
263
			    $.Storage.set("resitems", json);
264
			    load_research_widget();
265
		    }
266
		});
267
	}
268
 
269
	function load_research_widget(){
270
		var myResearchWidgetContainer = $("#myresearch");
271
 
272
		if($(myResearchWidgetContainer).length == 0) {
273
			return;
274
		}
275
		var resitems = $.Storage.get("resitems");
276
 
277
		if (resitems == "[]") {
278
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
279
		      <tbody>\
280
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
281
		       </tbody>\
282
		      </table>';
283
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
284
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
285
			return;
286
		}
287
		var params = "/" + resitems;
288
 
289
		jQuery.ajax({
290
			type : "GET",
291
			url : "/myresearch" + params,
292
			cache: true,
293
			success : function(html) {
294
	   		    $("#myresearch").html(html);
295
	   			updateCompareCount();
296
 
297
			    // Product Title
298
			    $("#myresearch table td div a.truncate").each(function() {
299
						$(this).truncate({addtitle : true});
300
			    });
301
 
302
			    // Product Price
303
			    $("#myresearch table td div div.price").each(function() {
304
						$(this).truncate({addtitle : true});
305
				});
306
 
307
			    // Product Details
308
			    $("#myresearch table td div div.text").each(function() {
309
						$(this).truncate( {addtitle : true});
310
				});
311
		    }
312
		});
313
	}
4126 varun.gupt 314
});