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);
23
		var param = "PARAMETERS_"+ catalogid;
24
 
25
		var select = $('#colorselector');
26
		var options = select.attr('options');
27
		$('option', select).remove();
28
		$.each(eval(param), function(val, text) {
29
		    options[options.length] = new Option(text, val);
30
		    //alert(val + ": " + text);
31
		});
32
		$( "#dialog-form" ).dialog( "open" );
33
	});
34
 
35
	$( "#dialog-form" ).dialog({
36
		autoOpen: false,
37
		height: 200,
38
		width: 250,
39
		modal: true,
40
		buttons: {
41
			Ok: function() {
42
				var bValid = true;
43
				var selected = $("#colorselector option:selected");
44
				var itemid = selected.val();
45
				addToCart(itemid,'list');
46
				$( this ).dialog( "close" );
47
				},
48
			Cancel: function() {
49
				$( this ).dialog( "close" );
50
				}
51
			},
52
			close: function() {
53
 
54
			}
55
		});
56
 
57
});
58
 
59
 
60
function onSelectChange(itemid){
61
	alert("selected color is"+itemid);
62
}
63
 
64
 
538 rajveer 65
function addResearch(refdivid,reqtype){
66
     var research_tot=$("#research_total").val();
67
     var seldata="";
68
     var tot=0;
69
     var saprt="";
70
 
71
     if(reqtype=="multi"){
72
          var containerdiv = "#" + refdivid;     
73
          var par= containerdiv + " input[type=checkbox]:checked";
74
          $(par).each(function(){
75
               saprt = (tot>0)? "_":"";
76
               seldata += saprt+$(this).val();
637 rajveer 77
               tot++;
538 rajveer 78
          });
79
     }else if(reqtype=="single"){
80
          var seldata=$("#item_id").val();
81
          var tot=1;
82
     }else if(reqtype=="list"){
83
 
84
          var seldata=refdivid;
85
          var tot=1;
86
     }
87
 
88
     if(tot>0){
89
          alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
90
          jQuery.ajax({
91
               type: "POST",
92
                      url: "../myresearch",
93
                      data: "productid="+seldata,
94
                      success: function(msg){
95
 
96
                           if(msg == 0){
97
                                alert( "Please register/signin to use myresearch tool" );
98
                           }else if(msg == 1){
99
                                alert( "Product is already in my research" );
100
                           }else {
101
                                var t=(research_tot*1)+(tot*1);
102
                                $("#research_total").val(t);
103
                                if(t > 0){
104
                                     $("#research_default").css("display","none");
105
                                }     
106
                                $("#pane1").prepend(msg);
107
                                $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
108
 
109
                                if(reqtype == "multi"){
110
                                     var arrayprod_id=seldata.split("_");
111
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
112
                                          var tblid="#pane1 #"+objValue+ " td";
113
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
114
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
115
                                     });
116
 
117
                                }else if(reqtype == "single"){
118
                                     var tblid="#pane1 #"+seldata+ " td";
119
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
120
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
121
                                }else if(reqtype == "list"){
122
                                     var tblid="#pane1 #"+seldata+ " td";
123
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
124
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
125
                                }    
126
                           }
127
                           alert( "Data Saved: " + msg );
128
                      }
129
          });
130
 
131
     }else{
132
          alert("Please select atleast one product");
133
     }
134
}
135
 
136
 
137
function addToCart(refdivid,reqtype){
138
     var seldata="";
139
     var tot=0;
140
     var saprt="";
141
     if(reqtype == "multi"){
142
          var containerdiv = "#" + refdivid;
143
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 144
          var isMulti = false;
538 rajveer 145
          $(par).each(function(){
637 rajveer 146
	       	   var totalcolors = $(this).attr('totalcolors');
147
	           if(totalcolors != 1){
148
	        	   isMulti = true; 
149
	       	   }
150
	           saprt = (tot>0)? "_":"";
151
               seldata += saprt+$(this).attr('itemid');
152
               tot++;
538 rajveer 153
          });
637 rajveer 154
          if(isMulti == true){
155
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
156
        	  return;
157
          }
538 rajveer 158
     }else if(reqtype == "single"){
159
          seldata = $("#item_id").val();
160
          tot=1;
161
     }else if(reqtype == "list"){
637 rajveer 162
    	  var seldata=refdivid;
538 rajveer 163
          var tot=1;
164
     }
165
 
166
     if(tot>0){
167
          alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
168
          jQuery.ajax({
169
               type: "POST",
170
                      url: "../cart",
171
                      data: "productid="+seldata,
172
                      success: function(msg){
173
                           $("#cartItemCount").html(msg*1);
174
                           alert( "Data Saved: " + msg );
175
                      }
176
          });
177
     }else{
178
          alert("Please select atleast one product");
179
     }
180
 
637 rajveer 181
}
182
 
183
function selectProduct(itemId){
184
	alert("Selected item is "+ itemId);
458 rajveer 185
}