1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
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');
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')){
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);
59 } //return check_form(form_name);
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
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]+', ';
73 reqFields = reqFields.substring(0,reqFields.lastIndexOf(','));
74 alert(REQUIRED_LEAD_FIELDS+' '+reqFields);
77 else if(grid3.getRecordSet().getLength()==1 && grid4.getRecordSet().getLength()==1){
78 alert(LEAD_SELECT_FIELDS);
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';
95 if(direction == 'next'){
96 if(!checkFields(REQUIRED_LEAD_FIELDS,LEAD_SELECT_FIELDS)){
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';
107 function campaignPopulated(){
108 var camp_populated = document.getElementById('campaign_id');
109 if(camp_populated.value == 0){
115 function selectFields(indexes,grid){
117 for(var i=0;i<indexes.length;i++){
118 retStr=retStr+grid.getRow(indexes[i]).childNodes[0].childNodes[0].innerHTML+','+'\n';
121 return retStr.substring(0,retStr.lastIndexOf(','));
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);
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);
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);
144 addRemove.setAttribute('value',Remove_All_Fields);
145 addRemove.setAttribute('title',Remove_All_Fields);
148 function dragDropAllFields(Add_All_Fields, Remove_All_Fields){
149 //set the grids to the SUGAR_GRID grids
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));
163 if(i%2 ==1 && availibleSet.getRecord(i).getData()[0] != " "){
164 grid4.addRow(availibleSet.getRecord(i).getData(), ((i - 1) / 2));
167 for (i = availibleCount - 1; i >= 0; i--) {
168 if(grid2.getRecord(i) != null && grid2.getRecord(i).getData()[0] != " ") {
173 else if(addRemove.value==Remove_All_Fields){ //move back to the main grid if grid is empty and columns populated
175 if(grid3.getRecordSet().getLength() >= grid4.getRecordSet().getLength()){
176 count = grid3.getRecordSet().getLength();
179 count = grid4.getRecordSet().getLength();
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);
186 if(grid4.getRecord(i) != null && grid4.getRecord(i).getData()[0] != " "){
187 grid2.addRow(grid4.getRecord(i).getData(), grid2.getRecordSet().getLength() - 1);
190 for(var i = count - 1; i >= 0; i--){
191 if(grid4.getRecord(i) != null && grid4.getRecord(i).getData()[0] != " ") {
194 if(grid3.getRecord(i) != null && grid3.getRecord(i).getData()[0] != " ") {
199 displayAddRemoveButtons(Add_All_Fields,Remove_All_Fields);
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);
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;
220 if(chk_url_elm.checked==false){
221 var url_elm = document.getElementById("post_url");
222 url_elm.disabled=true;