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
 
18
function addResearch(refdivid,reqtype){
19
     var research_tot=$("#research_total").val();
20
     var seldata="";
21
     var tot=0;
22
     var saprt="";
23
 
24
     if(reqtype=="multi"){
25
          var containerdiv = "#" + refdivid;     
26
          var par= containerdiv + " input[type=checkbox]:checked";
27
          $(par).each(function(){
28
               saprt = (tot>0)? "_":"";
29
               seldata += saprt+$(this).val();
30
               tot++
31
          });
32
     }else if(reqtype=="single"){
33
          var seldata=$("#item_id").val();
34
          var tot=1;
35
     }else if(reqtype=="list"){
36
 
37
          var seldata=refdivid;
38
          var tot=1;
39
     }
40
 
41
     if(tot>0){
42
          alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
43
          jQuery.ajax({
44
               type: "POST",
45
                      url: "../myresearch",
46
                      data: "productid="+seldata,
47
                      success: function(msg){
48
 
49
                           if(msg == 0){
50
                                alert( "Please register/signin to use myresearch tool" );
51
                           }else if(msg == 1){
52
                                alert( "Product is already in my research" );
53
                           }else {
54
                                var t=(research_tot*1)+(tot*1);
55
                                $("#research_total").val(t);
56
                                if(t > 0){
57
                                     $("#research_default").css("display","none");
58
                                }     
59
                                $("#pane1").prepend(msg);
60
                                $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
61
 
62
                                if(reqtype == "multi"){
63
                                     var arrayprod_id=seldata.split("_");
64
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
65
                                          var tblid="#pane1 #"+objValue+ " td";
66
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
67
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
68
                                     });
69
 
70
                                }else if(reqtype == "single"){
71
                                     var tblid="#pane1 #"+seldata+ " td";
72
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
73
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
74
                                }else if(reqtype == "list"){
75
                                     var tblid="#pane1 #"+seldata+ " td";
76
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
77
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
78
                                }    
79
                           }
80
                           alert( "Data Saved: " + msg );
81
                      }
82
          });
83
 
84
     }else{
85
          alert("Please select atleast one product");
86
     }
87
}
88
 
89
 
90
function addToCart(refdivid,reqtype){
91
     var seldata="";
92
     var tot=0;
93
     var saprt="";
94
     if(reqtype == "multi"){
95
          var containerdiv = "#" + refdivid;
96
          var par= containerdiv + " input[type=checkbox]:checked";
97
          $(par).each(function(){
98
               saprt = (tot>0)? "_":"";
99
               seldata += saprt+$(this).val();
100
               tot++
101
          });
102
     }else if(reqtype == "single"){
103
          seldata = $("#item_id").val();
104
          tot=1;
105
     }else if(reqtype == "list"){
106
          var seldata=refdivid;
107
          var tot=1;
108
     }
109
 
110
     if(tot>0){
111
          alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
112
          jQuery.ajax({
113
               type: "POST",
114
                      url: "../cart",
115
                      data: "productid="+seldata,
116
                      success: function(msg){
117
                           $("#cartItemCount").html(msg*1);
118
                           alert( "Data Saved: " + msg );
119
                      }
120
          });
121
     }else{
122
          alert("Please select atleast one product");
123
     }
124
 
458 rajveer 125
}