]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Users/UserEditView.js
Release 6.4.0beta4
[Github/sugarcrm.git] / jssource / src_files / modules / Users / UserEditView.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 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 function setSymbolValue(id) {
37     document.getElementById('symbol').value = currencies[id];
38 }
39
40 function user_status_display(field){
41                 switch (field.value){
42                 case 'Administrator':
43                     document.getElementById('UserTypeDesc').innerHTML=SUGAR.language.get('Users',"LBL_ADMIN_DESC");
44                     document.getElementById('is_admin').value='1';
45                 break;
46                 case 'RegularUser':
47                         document.getElementById('is_admin').value='0';
48                         document.getElementById('UserTypeDesc').innerHTML=SUGAR.language.get('Users',"LBL_REGULAR_DESC");
49                 break;
50                 case 'UserAdministrator':
51                         document.getElementById('is_admin').value='0';
52                         document.getElementById('UserTypeDesc').innerHTML=SUGAR.language.get('Users',"LBL_USER_ADMIN_DESC");
53                 break;
54         case 'GROUP':
55             document.getElementById('is_admin').value='0';
56             document.getElementById('is_group').value='1';
57                         document.getElementById('UserTypeDesc').innerHTML=SUGAR.language.get('Users',"LBL_GROUP_DESC");
58         break;
59         case 'PORTAL_ONLY':
60             document.getElementById('is_admin').value='0';
61             document.getElementById('is_group').value='0';
62             document.getElementById('portal_only').value='1';
63             document.getElementById('UserTypeDesc').innerHTML=SUGAR.language.get('Users','LBL_PORTAL_ONLY_DESC');
64         break;
65         }
66 }
67
68
69 function startOutBoundEmailSettingsTest()
70 {
71     var loader = new YAHOO.util.YUILoader({
72     require : ["element","sugarwidgets"],
73     loadOptional: true,
74     skin: { base: 'blank', defaultSkin: '' },
75     onSuccess: testOutboundSettings,
76     allowRollup: true,
77     base: "include/javascript/yui/build/"
78     });
79     loader.addModule({
80         name :"sugarwidgets",
81         type : "js",
82         fullpath: "include/javascript/sugarwidgets/SugarYUIWidgets.js",
83         varName: "YAHOO.SUGAR",
84         requires: ["datatable", "dragdrop", "treeview", "tabview"]
85     });
86     loader.insert();
87
88 }
89
90 function testOutboundSettings()
91 {
92         var errorMessage = '';
93         var isError = false;
94         var fromAddress = document.getElementById("outboundtest_from_address").value;
95     var errorMessage = '';
96     var isError = false;
97     var smtpServer = document.getElementById('mail_smtpserver').value;
98
99     var mailsmtpauthreq = document.getElementById('mail_smtpauth_req');
100     if(trim(smtpServer) == '' || trim(mail_smtpport) == '')
101     {
102         isError = true;
103         errorMessage += SUGAR.language.get('Users',"LBL_MISSING_DEFAULT_OUTBOUND_SMTP_SETTINGS") + "<br/>";
104         overlay(SUGAR.language.get('app_strings',"ERR_MISSING_REQUIRED_FIELDS"), errorMessage, 'alert');
105         return false;
106     }
107
108
109     if(document.getElementById('mail_smtpuser') && trim(document.getElementById('mail_smtpuser').value) == '')
110     {
111         isError = true;
112         errorMessage += SUGAR.language.get('app_strings',"LBL_EMAIL_ACCOUNTS_SMTPUSER") + "<br/>";
113     }
114
115
116     if(isError) {
117         overlay(SUGAR.language.get('app_strings',"ERR_MISSING_REQUIRED_FIELDS"), errorMessage, 'alert');
118         return false;
119     }
120
121     testOutboundSettingsDialog();
122 }
123
124 function sendTestEmail()
125 {
126     var toAddress = document.getElementById("outboundtest_from_address").value;
127     var fromAddress = document.getElementById("outboundtest_from_address").value;
128
129     if (trim(fromAddress) == "")
130     {
131         overlay(SUGAR.language.get('app_strings',"ERR_MISSING_REQUIRED_FIELDS"), SUGAR.language.get('app_strings',"LBL_EMAIL_SETTINGS_FROM_TO_EMAIL_ADDR"), 'alert');
132         return;
133     }
134     else if (!isValidEmail(fromAddress)) {
135         overlay(SUGAR.language.get('app_strings',"ERR_INVALID_REQUIRED_FIELDS"), SUGAR.language.get('app_strings',"LBL_EMAIL_SETTINGS_FROM_TO_EMAIL_ADDR"), 'alert');
136         return;
137     }
138
139     //Hide the email address window and show a message notifying the user that the test email is being sent.
140     EmailMan.testOutboundDialog.hide();
141     overlay(SUGAR.language.get('app_strings',"LBL_EMAIL_PERFORMING_TASK"), SUGAR.language.get('app_strings',"LBL_EMAIL_ONE_MOMENT"), 'alert');
142
143     var callbackOutboundTest = {
144         success : function(o) {
145                 hideOverlay();
146                 overlay(SUGAR.language.get('app_strings',"LBL_EMAIL_TEST_OUTBOUND_SETTINGS"), SUGAR.language.get('app_strings',"LBL_EMAIL_TEST_NOTIFICATION_SENT"), 'alert');
147         }
148     };
149     var smtpServer = document.getElementById('mail_smtpserver').value;
150
151     if(document.getElementById('mail_smtpuser') && document.getElementById('mail_smtppass')){
152     var postDataString = 'mail_sendtype=SMTP&mail_smtpserver=' + smtpServer + "&mail_smtpport=" + mail_smtpport + "&mail_smtpssl=" + mail_smtpssl + "&mail_smtpauth_req=true&mail_smtpuser=" + trim(document.getElementById('mail_smtpuser').value) + "&mail_smtppass=" + trim(document.getElementById('mail_smtppass').value) + "&outboundtest_from_address=" + fromAddress + "&outboundtest_to_address=" + toAddress;
153     }
154     else{
155         var postDataString = 'mail_sendtype=SMTP&mail_smtpserver=' + smtpServer + "&mail_smtpport=" + mail_smtpport + "&mail_smtpssl=" + mail_smtpssl + "&outboundtest_from_address=" + fromAddress + "&outboundtest_to_address=" + toAddress;
156     }
157         YAHOO.util.Connect.asyncRequest("POST", "index.php?action=testOutboundEmail&mail_name=system&module=EmailMan&to_pdf=true&sugar_body_only=true", callbackOutboundTest, postDataString);
158 }
159 function testOutboundSettingsDialog() {
160         // lazy load dialogue
161         if(!EmailMan.testOutboundDialog) {
162                 EmailMan.testOutboundDialog = new YAHOO.widget.Dialog("testOutboundDialog", {
163                 modal:true,
164                                 visible:true,
165                 fixedcenter:true,
166                 constraintoviewport: true,
167                 width   : 600,
168                 shadow  : false
169             });
170             EmailMan.testOutboundDialog.setHeader(SUGAR.language.get('app_strings',"LBL_EMAIL_TEST_OUTBOUND_SETTINGS"));
171             YAHOO.util.Dom.removeClass("testOutboundDialog", "yui-hidden");
172         } // end lazy load
173
174         EmailMan.testOutboundDialog.render();
175         EmailMan.testOutboundDialog.show();
176 } // fn
177
178 function overlay(reqtitle, body, type) {
179     var config = { };
180     config.type = type;
181     config.title = reqtitle;
182     config.msg = body;
183     YAHOO.SUGAR.MessageBox.show(config);
184 }
185
186 function hideOverlay() {
187         YAHOO.SUGAR.MessageBox.hide();
188 }
189
190
191
192 function verify_data(form)
193 {
194     // handles any errors in the email widget
195     var isError = !check_form("EditView");
196         
197     if (trim(form.last_name.value) == "") {
198                 add_error_style('EditView',form.last_name.name,
199                         SUGAR.language.get('app_strings','ERR_MISSING_REQUIRED_FIELDS') + SUGAR.language.get('Users','LBL_LIST_NAME') );
200         isError = true;
201         }
202         if (trim(form.user_name.value) == "") {
203                 add_error_style('EditView',form.user_name.name,
204                         SUGAR.language.get('app_strings','ERR_MISSING_REQUIRED_FIELDS') + SUGAR.language.get('Users','LBL_USER_NAME') );
205         isError = true;
206         }
207         
208     if (document.getElementById("required_password").value=='1' 
209             && document.getElementById("new_password").value == "") {
210                 add_error_style('EditView',form.new_password.name,
211                         SUGAR.language.get('app_strings','ERR_MISSING_REQUIRED_FIELDS') + SUGAR.language.get('Users','LBL_NEW_PASSWORD') );
212         isError = true;
213         }
214         
215         if (isError == true) {
216         return false;
217     }
218         
219         if (document.EditView.return_id.value != '' && (document.EditView.return_id.value == form.reports_to_id.value)) {
220                 alert(SUGAR.language.get('app_strings','ERR_SELF_REPORTING'));
221                 return false;
222         }
223         
224         if (document.EditView.dec_sep.value != '' && (document.EditView.dec_sep.value == "'")) {
225                 alert(SUGAR.language.get('app_strings','ERR_NO_SINGLE_QUOTE') + SUGAR.language.get('Users','LBL_DECIMAL_SEP'));
226                 return false;
227         }
228     
229         if (document.EditView.num_grp_sep.value != '' && (document.EditView.num_grp_sep.value == "'")) {
230                 alert(SUGAR.language.get('app_strings','ERR_NO_SINGLE_QUOTE') + SUGAR.language.get('Users','LBL_NUMBER_GROUPING_SEP'));
231                 return false;
232         }
233     
234         if (document.EditView.num_grp_sep.value == document.EditView.dec_sep.value) {
235                 alert(SUGAR.language.get('app_strings','ERR_DECIMAL_SEP_EQ_THOUSANDS_SEP'));
236                 return false;
237         }
238         if( document.getElementById("portal_only") && document.getElementById("portal_only")=='1' &&
239                 typeof(document.getElementById("new_password")) != "undefined" && typeof(document.getElementById("new_password").value) != "undefined") {
240                 if(document.getElementById("new_password").value != '' || document.getElementById("confirm_pwd").value != '') {
241                         if(document.getElementById("new_password").value != document.getElementById("confirm_pwd").value) {
242                                 alert(SUGAR.language.get('Users','ERR_PASSWORD_MISMATCH'));
243                                 return false;
244                         }
245                 }
246         }
247         
248         return true;
249 }
250     
251     
252 function set_chooser()
253 {
254     var display_tabs_def = '';
255     var hide_tabs_def = '';
256     var remove_tabs_def = '';
257     
258     var display_td = document.getElementById('display_tabs_td');
259     var hide_td    = document.getElementById('hide_tabs_td');
260     var remove_td  = document.getElementById('remove_tabs_td');
261     
262     var display_ref = display_td.getElementsByTagName('select')[0];
263     
264     for(i=0; i < display_ref.options.length ;i++)
265     {
266         display_tabs_def += "display_tabs[]="+display_ref.options[i].value+"&";
267     }
268     
269     if(hide_td != null)
270     {
271             var hide_ref = hide_td.getElementsByTagName('select')[0];
272         
273         for(i=0; i < hide_ref.options.length ;i++)
274             {
275             hide_tabs_def += "hide_tabs[]="+hide_ref.options[i].value+"&";
276             }
277     }
278     
279     if(remove_td != null)
280     {
281         var remove_ref = remove_td.getElementsByTagName('select')[0];
282         
283         for(i=0; i < remove_ref.options.length ;i++)
284             {
285             remove_tabs_def += "remove_tabs[]="+remove_ref.options[i].value+"&";
286             }
287             
288     }
289     
290     document.EditView.display_tabs_def.value = display_tabs_def;
291     document.EditView.hide_tabs_def.value = hide_tabs_def;
292     document.EditView.remove_tabs_def.value = remove_tabs_def;
293 }
294
295 // Brought this over from Forms.php, pretty sure it's not needed.
296 function add_checks(f) {
297     return true;
298 }
299
300
301 // Autoruns
302 function onUserEditView() {
303     YAHOO.util.Event.onContentReady('user_theme_picker',function() {
304         document.getElementById('user_theme_picker').onchange = function() {
305             document.getElementById('themePreview').src =
306                 "index.php?entryPoint=getImage&themeName=" + document.getElementById('user_theme_picker').value + "&imageName=themePreview.png";
307             if (typeof themeGroupList[document.getElementById('user_theme_picker').value] != 'undefined' &&
308                 themeGroupList[document.getElementById('user_theme_picker').value] ) {
309                 document.getElementById('use_group_tabs_row').style.display = '';
310             } else {
311                 document.getElementById('use_group_tabs_row').style.display = 'none';
312             }
313         }
314     });
315
316     setSymbolValue(document.getElementById('currency_select').options[document.getElementById('currency_select').selectedIndex].value);
317     setSigDigits();
318     user_status_display(document.getElementById('UserType'));
319 }