Subversion Repositories SmartDukaan

Rev

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