Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 rajveer 1
/* 
2
     Author: Binay Kumar
3
     Created on: 30.09.2010
4
 
5
     Example:
6
     addResearch(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
7
     Multiple request: onclick="javascript:addResearch('pane2','multi');"
8
     Single request: onclick="javascript:addResearch('','single');"
9
 
10
     addToCart(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
11
     Multiple request: onclick="javascript:addToCart('pane2','multi');"
12
     Single request: onclick="javascript:addToCart('','single');"
13
 
14
     NOTE: incase reqtype=list then refdivid should be product id
15
 
16
*/
17
 
637 rajveer 18
$(function() {
19
 
20
	$("a.addtocart").click(function() {
21
		var catalogid = $(this).attr('catalogid');
22
		//alert("clicked add to cart" + catalogid);
762 rajveer 23
 
24
		var radBtn = "";
25
		var param = "PARAMETERS_" + catalogid;
26
 
27
		$.each(eval(param), function(val, text) {
28
			radBtn += '<label><input type="radio" name="radColorSel" value="' + val + '" /> <span>' + text + '</span></label>';
29
		});
30
 
31
		radBtn += '<div class="clearBoth"></div>';
32
		$(".colorSelLightBoxColor .content").html(radBtn);
637 rajveer 33
 
762 rajveer 34
		$.fn.colorbox({inline:true, href:".colorSelLightBoxColor", open:true});
35
 
36
		/*
637 rajveer 37
		var select = $('#colorselector');
38
		var options = select.attr('options');
39
		$('option', select).remove();
40
		$.each(eval(param), function(val, text) {
41
		    options[options.length] = new Option(text, val);
42
		    //alert(val + ": " + text);
43
		});
44
		$( "#dialog-form" ).dialog( "open" );
762 rajveer 45
		*/
637 rajveer 46
	});
762 rajveer 47
 
48
	/*
637 rajveer 49
	$( "#dialog-form" ).dialog({
50
		autoOpen: false,
51
		height: 200,
52
		width: 250,
53
		modal: true,
54
		buttons: {
55
			Ok: function() {
56
				var bValid = true;
57
				var selected = $("#colorselector option:selected");
58
				var itemid = selected.val();
59
				addToCart(itemid,'list');
60
				$( this ).dialog( "close" );
61
				},
62
			Cancel: function() {
63
				$( this ).dialog( "close" );
64
				}
65
			},
66
			close: function() {
67
 
68
			}
69
		});
762 rajveer 70
 	*/
637 rajveer 71
});
72
 
73
 
762 rajveer 74
function selectColor(){
75
	var bValid = true;
76
	var selected = $(".colorSelLightBoxColor .content input[name='radColorSel']:checked");
77
	var itemid = selected.val();
78
 
79
	if(itemid == undefined){
80
		alert('Please select a color.');
81
	}else{
82
		addToCart(itemid,'list');
83
		$.colorbox.close();
84
	}
85
}
86
 
637 rajveer 87
function onSelectChange(itemid){
879 rajveer 88
	//alert("selected color is"+itemid);
637 rajveer 89
}
90
 
91
 
538 rajveer 92
function addResearch(refdivid,reqtype){
93
     var research_tot=$("#research_total").val();
94
     var seldata="";
95
     var tot=0;
96
     var saprt="";
97
 
98
     if(reqtype=="multi"){
99
          var containerdiv = "#" + refdivid;     
100
          var par= containerdiv + " input[type=checkbox]:checked";
101
          $(par).each(function(){
102
               saprt = (tot>0)? "_":"";
103
               seldata += saprt+$(this).val();
637 rajveer 104
               tot++;
538 rajveer 105
          });
106
     }else if(reqtype=="single"){
809 rajveer 107
          var seldata=$("#product_id").val();
538 rajveer 108
          var tot=1;
109
     }else if(reqtype=="list"){
110
 
111
          var seldata=refdivid;
112
          var tot=1;
113
     }
114
 
115
     if(tot>0){
879 rajveer 116
          //alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
538 rajveer 117
          jQuery.ajax({
118
               type: "POST",
809 rajveer 119
                      url: "/myresearch",
538 rajveer 120
                      data: "productid="+seldata,
1032 varun.gupt 121
                      success: function(msg)	{
122
                    	  if(msg == 1)	{
123
                    		  alert( "Product is already in my research" );
124
                    	  } else if(msg == 0)	{
125
                    		  alert( "Please register/signin to use myresearch tool" );
126
                    	  } else	{
127
                    		  var t=(research_tot*1)+(tot*1);
538 rajveer 128
                                $("#research_total").val(t);
129
                                if(t > 0){
130
                                     $("#research_default").css("display","none");
131
                                }     
132
                                $("#pane1").prepend(msg);
133
                                $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
134
 
135
                                if(reqtype == "multi"){
136
                                     var arrayprod_id=seldata.split("_");
137
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
138
                                          var tblid="#pane1 #"+objValue+ " td";
139
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
140
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
141
                                     });
142
 
143
                                }else if(reqtype == "single"){
144
                                     var tblid="#pane1 #"+seldata+ " td";
145
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
146
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
147
                                }else if(reqtype == "list"){
148
                                     var tblid="#pane1 #"+seldata+ " td";
149
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
150
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
151
                                }    
152
                           }
879 rajveer 153
                           //alert( "Data Saved: " + msg );
538 rajveer 154
                      }
155
          });
156
 
157
     }else{
158
          alert("Please select atleast one product");
159
     }
160
}
161
 
162
 
163
function addToCart(refdivid,reqtype){
164
     var seldata="";
165
     var tot=0;
166
     var saprt="";
167
     if(reqtype == "multi"){
168
          var containerdiv = "#" + refdivid;
169
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 170
          var isMulti = false;
538 rajveer 171
          $(par).each(function(){
809 rajveer 172
 
637 rajveer 173
	       	   var totalcolors = $(this).attr('totalcolors');
879 rajveer 174
	       	   //alert(totalcolors);
637 rajveer 175
	           if(totalcolors != 1){
176
	        	   isMulti = true; 
177
	       	   }
178
	           saprt = (tot>0)? "_":"";
179
               seldata += saprt+$(this).attr('itemid');
180
               tot++;
538 rajveer 181
          });
879 rajveer 182
          //alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
637 rajveer 183
          if(isMulti == true){
184
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
185
        	  return;
186
          }
538 rajveer 187
     }else if(reqtype == "single"){
188
          seldata = $("#item_id").val();
189
          tot=1;
190
     }else if(reqtype == "list"){
637 rajveer 191
    	  var seldata=refdivid;
538 rajveer 192
          var tot=1;
193
     }
194
 
195
     if(tot>0){
879 rajveer 196
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
538 rajveer 197
          jQuery.ajax({
198
               type: "POST",
809 rajveer 199
                      url: "/cart",
538 rajveer 200
                      data: "productid="+seldata,
201
                      success: function(msg){
202
                           $("#cartItemCount").html(msg*1);
879 rajveer 203
                           //alert( "Data Saved: " + msg );
538 rajveer 204
                      }
205
          });
206
     }else{
207
          alert("Please select atleast one product");
208
     }
209
 
637 rajveer 210
}
211
 
212
function selectProduct(itemId){
879 rajveer 213
	//alert("Selected item is "+ itemId);
458 rajveer 214
}