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