]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Campaigns/wizard.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / Campaigns / wizard.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
38         /*
39          * this function hides a div element using the passed in id value
40          */
41     function hide(divname){
42         var elem1 = document.getElementById(divname);
43         elem1.style.display = 'none';
44     }
45
46         /*
47          * this function shows a div using the passed in value
48          */
49     function show(div){
50         var elem1 = document.getElementById(div);
51         elem1.style.display = '';
52     }
53         /*
54          * this function calls the methods to hide all divs and show the passed in div
55          */
56     function showdiv(div){
57         hideall();
58         show(div);
59     }
60         
61         /*
62          * this function iterates through all "stepx" divs (ie. step1, step2,etc) and hides them
63          */
64     function hideall(){
65         var last_val = document.getElementById('wiz_total_steps');
66         var last = parseInt(last_val.value);
67         for(i=1; i<=last; i++){
68             hide('step'+i);
69         }
70     }
71     
72     
73     /*this function should be run first.  It will call the methods that:
74     *  1.hide the divs initially
75     *  2.show the first div
76     *  3.shows/hides the proper buttons
77     *  4.highlites the step title
78     *  5.adjusts the step location message
79     */
80     function showfirst(wiz_mode){
81         //no validation needed.
82         
83        //show first step        
84         showdiv('step1');
85     
86         //set div value
87         var current_step = document.getElementById('wiz_current_step');
88         current_step.value="1";
89         
90         //set button values
91    
92
93         var save_button = document.getElementById('wiz_submit_button');
94                 var next_button = document.getElementById('wiz_next_button');
95                 var save_button_div = document.getElementById('save_button_div');               
96                 var next_button_div = document.getElementById('next_button_div');       
97                 var back_button_div = document.getElementById('back_button_div');                       
98
99         save_button.disabled = true;
100                 back_button_div.style.display = 'none';
101                 save_button_div.style.display = 'none';         
102                 next_button.focus();
103                 if(wiz_mode == 'marketing'){
104                         back_button_div.style.display = '';
105                 }
106         
107         //set nav hi-lite
108         hilite(current_step.value);
109         
110
111     }
112
113
114     
115     /*this function runs on each navigation in the wizard.  It will call the methods that:
116     *  1.hide the divs
117     *  2.show the div being navigated to
118     *  3.shows/hides the proper buttons
119     *  4.highlites the step title
120     *  5.adjusts the step location message
121     */
122
123     function navigate(direction){
124         //get the current step
125         var current_step = document.getElementById('wiz_current_step');
126         var currentValue = parseInt(current_step.value);
127     
128         //validation needed. (specialvalidation,  plus step number, plus submit button)
129         if(validate_wiz(current_step.value,direction)){
130             
131             //change current step value to that of the step being navigated to
132             if(direction == 'back'){
133                 current_step.value = currentValue-1;
134             }
135             if(direction == 'next'){
136                 current_step.value = currentValue+1;
137             }
138             if(direction == 'direct'){
139             //no need to modify current step, this is a direct navigation
140             }
141                 
142             //show next step        
143             showdiv("step"+current_step.value);
144         
145             //set nav hi-lite
146             hilite(current_step.value);
147
148             //enable save button if on last step
149             var total = document.getElementById('wiz_total_steps').value;
150             var save_button = document.getElementById('wiz_submit_button');
151                         var back_button_div = document.getElementById('back_button_div');
152                         var save_button_div = document.getElementById('save_button_div');               
153                         var next_button_div = document.getElementById('next_button_div');               
154             if(current_step.value==total){
155                 //save_button.display='';
156                 save_button.disabled = false;
157                                 back_button_div.style.display = '';
158                                 save_button_div.style.display = '';             
159                                 next_button_div.style.display = 'none';
160                 
161             }else{
162                     if(current_step.value<2){                
163                             back_button_div.style.display = 'none';     
164                     }else{
165                             back_button_div.style.display = '';                         
166                     }
167                                 var next_button = document.getElementById('wiz_next_button');               
168                                 next_button_div.style.display = '';
169                                 save_button_div.style.display = 'none';         
170                                 next_button.focus();                
171             }
172
173         }else{
174          //error occurred, do nothing   
175         }    
176     
177     }
178
179     /*
180      * This function highlites the right title on the navigation div.
181      * It also changes the title to a navigational link
182      * */
183      var already_linked ='';
184     function hilite(hilite){
185                 var last = parseInt(document.getElementById('wiz_total_steps').value);
186                 for(i=1; i<=last; i++){
187                     var nav_step = document.getElementById('nav_step'+i);
188                       nav_step.className   = '';
189                 }
190                 var nav_step = document.getElementById('nav_step'+hilite);
191                         nav_step.className   = '';
192                         if(already_linked.indexOf(hilite)<0){
193                         nav_step.innerHTML= "<a href='#'  onclick=\"javascript:direct('"+hilite+"');\">" +nav_step.innerHTML+ "</a>";
194                         already_linked +=',hilite'; 
195                         }
196     }
197     
198     /*
199      * Given a start and end, This function highlights the right title on the navigation div.
200      * It also changes the title to a navigational link
201      * */
202     function link_navs(beg, end){
203                 if(beg==''){
204                         beg=1;
205                 }
206                 if(end==''){
207                 var last = document.getElementById('wiz_total_steps').value;                    
208                         end=last;
209                 }               
210                 beg =parseInt(beg);
211                 end =parseInt(end);     
212
213         for(i=beg; i<=end; i++){
214                 var nav_step = document.getElementById('nav_step'+ i);
215                 nav_step.innerHTML= "<a href='#'  onclick=\"javascript:direct('"+i+"');\">" +nav_step.innerHTML+ "</a>";
216         }
217         
218     }    
219
220     /**
221      * This function is called when clicking on a title that has already been changed
222      * to show a link.  It is a direct navigation link
223      */
224     function direct(stepnumber){
225         //get the current step
226         var current_step = document.getElementById('wiz_current_step');
227         var currentValue = parseInt(current_step.value);
228
229         //validation needed. (specialvalidation,  plus step number, plus submit button)
230         if(validate_wiz(current_step.value,'direct')){
231
232             //lets set the current step to the selected step and invoke navigation
233             current_step.value = stepnumber;
234             navigate('direct'); 
235         }else{
236          //do nothing, validation failed   
237         }
238     }
239
240
241 /*
242  * This is a generic create summary function.  It scrapes the form for all elements that 
243  * are not hidden and displays it's value.  It uses the "title" parameter as the title
244  * in the summary  There is also a provision for overriding this function and providing more
245  * precise summary functions
246  */
247     
248     /*
249      * This function will perform basic navigation validation, and then call the customized 
250      * form validation specified for this step.  This custom call should reside on wizard page itself.
251      *
252      */
253     function validate_wiz(step, direction){
254         var total = document.getElementById('wiz_total_steps').value;
255         var wiz_message = document.getElementById('wiz_message');
256         //validate step
257          if(direction =='back'){
258             //cancel and alert if on step1
259             if(step=='1'){
260                 var msg = SUGAR.language.get('mod_strings', 'LBL_WIZARD_FIRST_STEP_MESSAGE');
261                 wiz_message.innerHTML = "<font color=\'red\' size=\'2\'><b>"+msg+"</b></font>";
262                 return false;
263             }else{
264                 wiz_message.innerHTML = '';
265             }
266          }
267
268         if(direction =='next'){
269            //cancel and alert if on last step
270             if(step==total){
271                 var msg = SUGAR.language.get('mod_strings', 'LBL_WIZARD_LAST_STEP_MESSAGE');
272                 wiz_message.innerHTML = "<font color=\'red\' size=\'2\'><b>"+msg+"</b></font>";
273                 return false;
274             }else{
275                 wiz_message.innerHTML = '';
276             }        
277          }
278          if(direction =='direct'){
279             //no need to perform navigation validation
280          }
281     
282          //make call to custom form validation, do not call if this is a direct navigation
283          //if this is a direct navigation, then validation has already happened, calling twice 
284          //will not allow page to navigate
285         if((direction !='direct')  && ( window.validate_wiz_form ) && (!validate_wiz_form('step'+step))){
286             return false;
287          }
288          
289         return true;        
290     }
291