]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/WebToLead.js
Release 6.5.0
[Github/sugarcrm.git] / 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 var grid2,grid3,grid4,grid3F,grid4F;var add_all_fields=SUGAR.language.get('app_strings','LBL_ADD_ALL_LEAD_FIELDS');var remove_all_fields=SUGAR.language.get('app_strings','LBL_REMOVE_ALL_LEAD_FIELDS');function addGrids(form_name){if(!check_form('WebToLeadCreation')){return false;}
36 else{grid3=SUGAR_GRID_grid1;grid4=SUGAR_GRID_grid2;var webFormDiv=document.getElementById('webformfields');addCols(grid3,'colsFirst',webFormDiv);addCols(grid4,'colsSecond',webFormDiv);return true;}}
37 function checkFields(REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS){grid2=SUGAR_GRID_grid0;grid3=SUGAR_GRID_grid1;grid4=SUGAR_GRID_grid2;var reqFields='';for(var i=0;i<grid2.getRecordSet().getLength();i++){if(grid2.getRecord(i).getData()[2]!=null){reqFields=reqFields+grid2.getRecord(i).getData()[0]+', ';}}
38 if(reqFields){reqFields=reqFields.substring(0,reqFields.lastIndexOf(','));alert(REQUIRED_LEAD_FIELDS+' '+reqFields);return false;}
39 else if(grid3.getRecordSet().getLength()==1&&grid4.getRecordSet().getLength()==1){alert(LEAD_SELECT_FIELDS);return false;}
40 else{return true;}}
41 function askLeadQ(direction,REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS){if(direction=='back'){var grid_Div=document.getElementById('grid_Div');var lead_Div=document.getElementById('lead_queries_Div');grid_Div.style.display='block';lead_Div.style.display='none';}
42 if(direction=='next'){if(!checkFields(REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS)){return false;}
43 else{var lead_Div=document.getElementById('lead_queries_Div');var grid_Div=document.getElementById('grid_Div');lead_Div.style.display='block';grid_Div.style.display='none';}}}
44 function campaignPopulated(){var camp_populated=document.getElementById('campaign_id');if(camp_populated.value==0){return true;};return true;}
45 function selectFields(indexes,grid){var retStr='';for(var i=0;i<indexes.length;i++){retStr=retStr+grid.getRow(indexes[i]).childNodes[0].childNodes[0].innerHTML+','+'\n';retStr=retStr+'\n';}
46 return retStr.substring(0,retStr.lastIndexOf(','));}
47 function displayAddRemoveDragButtons(Add_All_Fields,Remove_All_Fields){var addRemove=document.getElementById("lead_add_remove_button");if(grid2.getRecordSet().getLength()==0){addRemove.setAttribute('value',Remove_All_Fields);addRemove.setAttribute('title',Remove_All_Fields);}
48 else if(grid3.getRecordSet().getLength()==0&&grid4.getRecordSet().getLength()==0){addRemove.setAttribute('value',Add_All_Fields);addRemove.setAttribute('title',Add_All_Fields);}}
49 function displayAddRemoveButtons(Add_All_Fields,Remove_All_Fields){var addRemove=document.getElementById("lead_add_remove_button");if(grid2.getRecordSet().getLength()>1){addRemove.setAttribute('value',Add_All_Fields);addRemove.setAttribute('title',Add_All_Fields);}
50 else{addRemove.setAttribute('value',Remove_All_Fields);addRemove.setAttribute('title',Remove_All_Fields);}}
51 function dragDropAllFields(Add_All_Fields,Remove_All_Fields){grid2=SUGAR_GRID_grid0;grid3=SUGAR_GRID_grid1;grid4=SUGAR_GRID_grid2;var addRemove=document.getElementById("lead_add_remove_button");var availibleSet=grid2.getRecordSet();var availibleCount=availibleSet.getLength();if(addRemove.value==Add_All_Fields&&availibleCount>1){for(var i=0;i<availibleCount;i++){if(i%2==0&&availibleSet.getRecord(i).getData()[0]!=" "){grid3.addRow(availibleSet.getRecord(i).getData(),(i / 2));}
52 if(i%2==1&&availibleSet.getRecord(i).getData()[0]!=" "){grid4.addRow(availibleSet.getRecord(i).getData(),((i-1)/ 2));}}
53 for(i=availibleCount-1;i>=0;i--){if(grid2.getRecord(i)!=null&&grid2.getRecord(i).getData()[0]!=" "){grid2.deleteRow(i);}}}
54 else if(addRemove.value==Remove_All_Fields){var count=0;if(grid3.getRecordSet().getLength()>=grid4.getRecordSet().getLength()){count=grid3.getRecordSet().getLength();}
55 else{count=grid4.getRecordSet().getLength();}
56 for(var i=0;i<count;i++){if(grid3.getRecord(i)!=null&&grid3.getRecord(i).getData()[0]!=" "){grid2.addRow(grid3.getRecord(i).getData(),grid2.getRecordSet().getLength()-1);}
57 if(grid4.getRecord(i)!=null&&grid4.getRecord(i).getData()[0]!=" "){grid2.addRow(grid4.getRecord(i).getData(),grid2.getRecordSet().getLength()-1);}}
58 for(var i=count-1;i>=0;i--){if(grid4.getRecord(i)!=null&&grid4.getRecord(i).getData()[0]!=" "){grid4.deleteRow(i);}
59 if(grid3.getRecord(i)!=null&&grid3.getRecord(i).getData()[0]!=" "){grid3.deleteRow(i);}}}
60 displayAddRemoveButtons(Add_All_Fields,Remove_All_Fields);}
61 function addCols(grid,colsNumber,webFormDiv){for(var i=0;i<grid.getRecordSet().getLength()-1;i++){var selectedEl=grid.getRecord(i).getData()[1];var webField=document.createElement('input');webField.setAttribute('id',colsNumber+i);webField.setAttribute('name',colsNumber+'[]');webField.setAttribute('type','hidden');webField.setAttribute('value',selectedEl);webFormDiv.appendChild(webField);}}
62 function editUrl(){var chk_url_elm=document.getElementById("chk_edit_url");if(chk_url_elm.checked==true){var url_elm=document.getElementById("post_url");url_elm.disabled=false;}
63 if(chk_url_elm.checked==false){var url_elm=document.getElementById("post_url");url_elm.disabled=true;}}