1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 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 * this function hides a div element using the passed in id value
41 function hide(divname){
42 var elem1 = document.getElementById(divname);
43 elem1.style.display = 'none';
47 * this function shows a div using the passed in value
50 var elem1 = document.getElementById(div);
51 elem1.style.display = '';
54 * this function calls the methods to hide all divs and show the passed in div
56 function showdiv(div){
62 * this function iterates through all "stepx" divs (ie. step1, step2,etc) and hides them
65 var last_val = document.getElementById('wiz_total_steps');
66 var last = parseInt(last_val.value);
67 for(i=1; i<=last; i++){
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
80 function showfirst(wiz_mode){
81 //no validation needed.
87 var current_step = document.getElementById('wiz_current_step');
88 current_step.value="1";
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');
99 save_button.disabled = true;
100 back_button_div.style.display = 'none';
101 save_button_div.style.display = 'none';
103 if(wiz_mode == 'marketing'){
104 back_button_div.style.display = '';
108 hilite(current_step.value);
115 /*this function runs on each navigation in the wizard. It will call the methods that:
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
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);
128 //validation needed. (specialvalidation, plus step number, plus submit button)
129 if(validate_wiz(current_step.value,direction)){
131 //change current step value to that of the step being navigated to
132 if(direction == 'back'){
133 current_step.value = currentValue-1;
135 if(direction == 'next'){
136 current_step.value = currentValue+1;
138 if(direction == 'direct'){
139 //no need to modify current step, this is a direct navigation
143 showdiv("step"+current_step.value);
146 hilite(current_step.value);
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';
162 if(current_step.value<2){
163 back_button_div.style.display = 'none';
165 back_button_div.style.display = '';
167 var next_button = document.getElementById('wiz_next_button');
168 next_button_div.style.display = '';
169 save_button_div.style.display = 'none';
174 //error occurred, do nothing
180 * This function highlites the right title on the navigation div.
181 * It also changes the title to a navigational link
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 = '';
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';
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
202 function link_navs(beg, end){
207 var last = document.getElementById('wiz_total_steps').value;
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>";
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
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);
229 //validation needed. (specialvalidation, plus step number, plus submit button)
230 if(validate_wiz(current_step.value,'direct')){
232 //lets set the current step to the selected step and invoke navigation
233 current_step.value = stepnumber;
236 //do nothing, validation failed
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
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.
253 function validate_wiz(step, direction){
254 var total = document.getElementById('wiz_total_steps').value;
255 var wiz_message = document.getElementById('wiz_message');
257 if(direction =='back'){
258 //cancel and alert if on step1
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>";
264 wiz_message.innerHTML = '';
268 if(direction =='next'){
269 //cancel and alert if on last step
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>";
275 wiz_message.innerHTML = '';
278 if(direction =='direct'){
279 //no need to perform navigation validation
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))){