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"){
107
          var seldata=$("#item_id").val();
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",
119
                      url: "../myresearch",
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(){
637 rajveer 173
	       	   var totalcolors = $(this).attr('totalcolors');
174
	           if(totalcolors != 1){
175
	        	   isMulti = true; 
176
	       	   }
177
	           saprt = (tot>0)? "_":"";
178
               seldata += saprt+$(this).attr('itemid');
179
               tot++;
538 rajveer 180
          });
637 rajveer 181
          if(isMulti == true){
182
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
183
        	  return;
184
          }
538 rajveer 185
     }else if(reqtype == "single"){
186
          seldata = $("#item_id").val();
187
          tot=1;
188
     }else if(reqtype == "list"){
637 rajveer 189
    	  var seldata=refdivid;
538 rajveer 190
          var tot=1;
191
     }
192
 
193
     if(tot>0){
194
          alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
195
          jQuery.ajax({
196
               type: "POST",
197
                      url: "../cart",
198
                      data: "productid="+seldata,
199
                      success: function(msg){
200
                           $("#cartItemCount").html(msg*1);
201
                           alert( "Data Saved: " + msg );
202
                      }
203
          });
204
     }else{
205
          alert("Please select atleast one product");
206
     }
207
 
637 rajveer 208
}
209
 
210
function selectProduct(itemId){
211
	alert("Selected item is "+ itemId);
458 rajveer 212
}