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){
88
	alert("selected color is"+itemid);
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){
116
          alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
117
          jQuery.ajax({
118
               type: "POST",
809 rajveer 119
                      url: "/myresearch",
538 rajveer 120
                      data: "productid="+seldata,
121
                      success: function(msg){
122
 
123
                           if(msg == 0){
124
                                alert( "Please register/signin to use myresearch tool" );
125
                           }else if(msg == 1){
126
                                alert( "Product is already in my research" );
127
                           }else {
128
                                var t=(research_tot*1)+(tot*1);
129
                                $("#research_total").val(t);
130
                                if(t > 0){
131
                                     $("#research_default").css("display","none");
132
                                }     
133
                                $("#pane1").prepend(msg);
134
                                $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
135
 
136
                                if(reqtype == "multi"){
137
                                     var arrayprod_id=seldata.split("_");
138
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
139
                                          var tblid="#pane1 #"+objValue+ " td";
140
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
141
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
142
                                     });
143
 
144
                                }else if(reqtype == "single"){
145
                                     var tblid="#pane1 #"+seldata+ " td";
146
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
147
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
148
                                }else if(reqtype == "list"){
149
                                     var tblid="#pane1 #"+seldata+ " td";
150
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
151
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
152
                                }    
153
                           }
154
                           alert( "Data Saved: " + msg );
155
                      }
156
          });
157
 
158
     }else{
159
          alert("Please select atleast one product");
160
     }
161
}
162
 
163
 
164
function addToCart(refdivid,reqtype){
165
     var seldata="";
166
     var tot=0;
167
     var saprt="";
168
     if(reqtype == "multi"){
169
          var containerdiv = "#" + refdivid;
170
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 171
          var isMulti = false;
538 rajveer 172
          $(par).each(function(){
809 rajveer 173
 
637 rajveer 174
	       	   var totalcolors = $(this).attr('totalcolors');
809 rajveer 175
	       	alert(totalcolors);
637 rajveer 176
	           if(totalcolors != 1){
177
	        	   isMulti = true; 
178
	       	   }
179
	           saprt = (tot>0)? "_":"";
180
               seldata += saprt+$(this).attr('itemid');
181
               tot++;
538 rajveer 182
          });
809 rajveer 183
          alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
637 rajveer 184
          if(isMulti == true){
185
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
186
        	  return;
187
          }
538 rajveer 188
     }else if(reqtype == "single"){
189
          seldata = $("#item_id").val();
190
          tot=1;
191
     }else if(reqtype == "list"){
637 rajveer 192
    	  var seldata=refdivid;
538 rajveer 193
          var tot=1;
194
     }
195
 
196
     if(tot>0){
197
          alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
198
          jQuery.ajax({
199
               type: "POST",
809 rajveer 200
                      url: "/cart",
538 rajveer 201
                      data: "productid="+seldata,
202
                      success: function(msg){
203
                           $("#cartItemCount").html(msg*1);
204
                           alert( "Data Saved: " + msg );
205
                      }
206
          });
207
     }else{
208
          alert("Please select atleast one product");
209
     }
210
 
637 rajveer 211
}
212
 
213
function selectProduct(itemId){
214
	alert("Selected item is "+ itemId);
458 rajveer 215
}