]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Campaigns/WebToLead.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / Campaigns / WebToLead.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37 //grid functions
38
39 var grid2, grid3, grid4, grid3F,grid4F;
40 var add_all_fields = SUGAR.language.get('app_strings', 'LBL_ADD_ALL_LEAD_FIELDS');
41 var remove_all_fields = SUGAR.language.get('app_strings', 'LBL_REMOVE_ALL_LEAD_FIELDS');
42
43 function addGrids(form_name) {
44     //check if any vals selected in grid3 and grid4
45     // if none then prompt for validation
46     //alert(check_form('WebToLeadCreation'));
47   if(!check_form('WebToLeadCreation')){
48           return false;
49         //stop
50   }        
51    else{
52           grid3 = SUGAR_GRID_grid1;
53       grid4 = SUGAR_GRID_grid2;         
54       var webFormDiv = document.getElementById('webformfields');         
55       //add columns to webformfields div          
56       addCols(grid3,'colsFirst',webFormDiv);
57       addCols(grid4,'colsSecond',webFormDiv);  
58       return true;           
59   }                                                       //return check_form(form_name);       
60 }
61 function checkFields(REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS){
62      grid2 = SUGAR_GRID_grid0;
63          grid3 = SUGAR_GRID_grid1;
64          grid4 = SUGAR_GRID_grid2;
65          //check if all required fields are selected
66          var reqFields = '';
67          for(var i=0; i < grid2.getRecordSet().getLength(); i++){
68                 if(grid2.getRecord(i).getData()[2] != null){                    
69                         reqFields = reqFields+grid2.getRecord(i).getData()[0]+', ';        
70                 }
71          }
72          if(reqFields){
73                 reqFields = reqFields.substring(0,reqFields.lastIndexOf(','));
74         alert(REQUIRED_LEAD_FIELDS+' '+reqFields);  
75         return false;           
76      }
77          else if(grid3.getRecordSet().getLength()==1 && grid4.getRecordSet().getLength()==1){        
78        alert(LEAD_SELECT_FIELDS);
79        return false;
80       }           
81      else{
82        return true;
83      }    
84 }
85
86 function askLeadQ(direction,REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS){                
87     //change current step value to that of the step being navigated to
88     if(direction == 'back'){
89        var grid_Div = document.getElementById('grid_Div');
90        var lead_Div = document.getElementById('lead_queries_Div');
91                 grid_Div.style.display='block';
92         lead_Div.style.display='none';
93     }
94     
95     if(direction == 'next'){
96       if(!checkFields(REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS)){
97           return false;
98        }
99       else{
100        var lead_Div = document.getElementById('lead_queries_Div');
101        var grid_Div = document.getElementById('grid_Div');
102        lead_Div.style.display='block';
103        grid_Div.style.display='none';
104        } 
105     }    
106 }
107  function campaignPopulated(){
108     var camp_populated = document.getElementById('campaign_id');
109     if(camp_populated.value == 0){ 
110       return true;
111      };
112     return true; 
113   }
114  
115  function selectFields(indexes,grid){
116         var retStr='';
117         for(var i=0;i<indexes.length;i++){
118                 retStr=retStr+grid.getRow(indexes[i]).childNodes[0].childNodes[0].innerHTML+','+'\n';
119                 retStr=retStr+'\n';
120         }
121         return retStr.substring(0,retStr.lastIndexOf(','));
122  }
123 //            grid4.render();
124
125 function displayAddRemoveDragButtons(Add_All_Fields,Remove_All_Fields){
126     var addRemove = document.getElementById("lead_add_remove_button");    
127     if(grid2.getRecordSet().getLength() ==0) {
128     addRemove.setAttribute('value',Remove_All_Fields);  
129      addRemove.setAttribute('title',Remove_All_Fields); 
130     }
131     else if(grid3.getRecordSet().getLength() ==0 && grid4.getRecordSet().getLength() ==0){
132       addRemove.setAttribute('value',Add_All_Fields);   
133      addRemove.setAttribute('title',Add_All_Fields);            
134    }    
135 }
136
137 function displayAddRemoveButtons(Add_All_Fields,Remove_All_Fields){
138     var addRemove = document.getElementById("lead_add_remove_button");    
139     if(grid2.getRecordSet().getLength() > 1) {
140         addRemove.setAttribute('value',Add_All_Fields); 
141         addRemove.setAttribute('title',Add_All_Fields);         
142     }
143     else{
144         addRemove.setAttribute('value',Remove_All_Fields);      
145         addRemove.setAttribute('title',Remove_All_Fields);              
146     }   
147 }
148 function dragDropAllFields(Add_All_Fields, Remove_All_Fields){
149    //set the grids to the SUGAR_GRID grids
150    
151    grid2 = SUGAR_GRID_grid0;
152    grid3 = SUGAR_GRID_grid1;
153    grid4 = SUGAR_GRID_grid2;
154    //move from main grid to columns 1&2
155    var addRemove = document.getElementById("lead_add_remove_button");   
156    var availibleSet = grid2.getRecordSet();
157    var availibleCount = availibleSet.getLength() ;
158    if(addRemove.value == Add_All_Fields && availibleCount > 1) { //Contains more than the empty node
159      for(var i=0; i < availibleCount; i++){
160         if(i%2 ==0 && availibleSet.getRecord(i).getData()[0] != " "){
161                 grid3.addRow(availibleSet.getRecord(i).getData(),  (i / 2));      
162         }
163         if(i%2 ==1 && availibleSet.getRecord(i).getData()[0] != " "){
164                 grid4.addRow(availibleSet.getRecord(i).getData(), ((i - 1) / 2));          
165         }                                                       
166          }
167      for (i = availibleCount - 1; i >= 0; i--) {
168          if(grid2.getRecord(i) != null && grid2.getRecord(i).getData()[0] != " ") {
169                  grid2.deleteRow(i);
170          }
171      }
172    }        
173    else if(addRemove.value==Remove_All_Fields){ //move back to the main grid if grid is empty and columns populated
174            var count =0;
175        if(grid3.getRecordSet().getLength() >= grid4.getRecordSet().getLength()){
176            count = grid3.getRecordSet().getLength();
177        }
178        else{
179            count = grid4.getRecordSet().getLength();
180        }
181            //put back into grid2 in the same order
182            for(var i = 0; i < count; i++){
183                    if(grid3.getRecord(i) != null && grid3.getRecord(i).getData()[0] != " "){
184                            grid2.addRow(grid3.getRecord(i).getData(), grid2.getRecordSet().getLength() - 1);              
185                    }
186                    if(grid4.getRecord(i) != null && grid4.getRecord(i).getData()[0] != " "){
187                            grid2.addRow(grid4.getRecord(i).getData(), grid2.getRecordSet().getLength() - 1);              
188                    }
189            }
190            for(var i = count - 1; i >= 0; i--){
191                    if(grid4.getRecord(i) != null && grid4.getRecord(i).getData()[0] != " ") {
192                            grid4.deleteRow(i);
193                    }
194                    if(grid3.getRecord(i) != null && grid3.getRecord(i).getData()[0] != " ") {
195                            grid3.deleteRow(i);
196                    }
197            }
198    }
199    displayAddRemoveButtons(Add_All_Fields,Remove_All_Fields);
200 }
201
202  
203  function addCols(grid, colsNumber, webFormDiv){
204          for(var i = 0; i < grid.getRecordSet().getLength() - 1; i++){          
205      var selectedEl = grid.getRecord(i).getData()[1];
206      var webField = document.createElement('input');
207      webField.setAttribute('id', colsNumber+i);    
208      webField.setAttribute('name',colsNumber+'[]');    
209      webField.setAttribute('type', 'hidden');    
210      webField.setAttribute('value',selectedEl);
211      webFormDiv.appendChild(webField);             
212     } 
213  }   
214  function editUrl(){     
215      var chk_url_elm = document.getElementById("chk_edit_url");     
216      if(chk_url_elm.checked==true){      
217        var url_elm = document.getElementById("post_url");       
218         url_elm.disabled=false;
219       }
220      if(chk_url_elm.checked==false){
221        var url_elm = document.getElementById("post_url");
222         url_elm.disabled=true;
223       }
224  }
225
226