]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/popup_helper.js
Release 6.5.16
[Github/sugarcrm.git] / jssource / src_files / include / javascript / popup_helper.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2013 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 /**
40  * Helper function used in send_backs to close the popup window if closePopup is true.
41  */
42 function closePopup() {
43         var closePopup = window.opener.get_close_popup();
44         if (closePopup)
45         {
46                 window.close();
47         }       
48 }
49
50 /**
51  * Bug: 48726
52  * Helper function used in send_backs to show confirm dialog with appropriate message. 
53  * Collects label data from the the parent window.
54  * 
55  * If similar bugs appear, please refer to Bug 48726, and use these helper functions.
56  */
57 function confirmDialog(arrayContents, formName) {
58         var newData = '';
59         var labels = '';
60         var oldData = '';
61         eval("var data = {" + arrayContents.join(",") + "}");
62         var opener = window.opener.document;
63         for (var key in data)
64         {
65                 var displayValue = replaceHTMLChars(data[key]);
66                 if (opener.forms[formName] && opener.getElementById(key + '_label') != null && !key.match(/account/))
67                 {
68                 var dataLabel = opener.getElementById(key + '_label').innerHTML.replace(/\n/gi,'').replace(/<\/?[^>]+(>|$)/g, "");
69                 labels += dataLabel + ' \n';
70                         newData += dataLabel + ' ' + displayValue + '\n';
71                         if(window.opener.document.forms[formName].elements[key]) {
72                                 oldData += dataLabel + ' ' + opener.forms[formName].elements[key].value + '\n';
73                         }
74                 }
75         }
76
77         var popupConfirm = 0;
78         if (data['account_id'] && (newData.split("\n").length - 1) > 2)
79         {
80                 if(newData != oldData && oldData != labels)
81                 {
82                         if(confirm(SUGAR.language.get('app_strings', 'NTC_OVERWRITE_ADDRESS_PHONE_CONFIRM') + '\n\n' + newData))
83                         {
84                                 popupConfirm = 1;
85                         } else {
86                                 popupConfirm = -1;      
87                         }
88                 }
89         }
90         
91         return popupConfirm;
92 }
93
94 function send_back(module, id)
95 {
96         var associated_row_data = associated_javascript_data[id];
97
98         // cn: bug 12274 - stripping false-positive security envelope
99         eval("var temp_request_data = " + window.document.forms['popup_query_form'].request_data.value);
100         if(temp_request_data.jsonObject) {
101                 var request_data = temp_request_data.jsonObject;
102         } else {
103                 var request_data = temp_request_data; // passed data that is NOT incorrectly encoded via JSON.encode();
104         }
105         // cn: end bug 12274 fix
106         
107         var passthru_data = Object();
108         if(typeof(request_data.passthru_data) != 'undefined')
109         {
110                 passthru_data = request_data.passthru_data;
111         }
112         var form_name = request_data.form_name;
113         var field_to_name_array = request_data.field_to_name_array;
114         
115         var call_back_function = eval("window.opener." + request_data.call_back_function);
116         var array_contents = Array();
117
118         // constructs the array of values associated to the bean that the user clicked
119     var fill_array_contents = function(the_key, the_name)
120     {
121         var the_value = '';
122         if (module != '' && id != '') {
123             if (associated_row_data['DOCUMENT_NAME'] && the_key.toUpperCase() == "NAME") {
124                 the_value = associated_row_data['DOCUMENT_NAME'];
125             } else if ((the_key.toUpperCase() == 'USER_NAME' || the_key.toUpperCase() == 'LAST_NAME' || the_key.toUpperCase() == 'FIRST_NAME')
126                         && typeof(is_show_fullname) != 'undefined' && is_show_fullname && form_name != 'search_form') {
127                         //if it is from searchform, it will search by assigned_user_name like 'ABC%', then it will return nothing
128                 the_value = associated_row_data['FULL_NAME'];
129             } else {
130                 the_value = associated_row_data[the_key.toUpperCase()];
131             }
132         }
133
134         if (typeof(the_value) == 'string') {
135             the_value = the_value.replace(/\r\n|\n|\r/g, '\\n');
136         }
137
138         array_contents.push('"' + the_name + '":"' + the_value + '"');
139     }
140
141         for(var the_key in field_to_name_array)
142         {
143                 if(the_key != 'toJSON')
144                 {
145             if (YAHOO.lang.isArray(field_to_name_array[the_key])) {
146                 for (var i = 0; i < field_to_name_array[the_key].length; i++) {
147                     fill_array_contents(the_key, field_to_name_array[the_key][i]);
148                 }
149             }
150             else {
151                 fill_array_contents(the_key, field_to_name_array[the_key]);
152             }
153                 }
154         }
155
156         var popupConfirm = confirmDialog(array_contents, form_name);
157         
158         eval("var name_to_value_array = {" + array_contents.join(",") + "}");
159         
160         closePopup();
161
162         var result_data = {"form_name":form_name,"name_to_value_array":name_to_value_array,"passthru_data":passthru_data,"popupConfirm":popupConfirm};
163         call_back_function(result_data);
164 }
165
166 function send_back_teams(module, form, field, error_message, request_data, form_team_id)
167 {       
168         var array_contents = Array();
169         
170         if(form_team_id){
171                 array_contents.push(form_team_id);
172         }else{
173                 var j=0;
174                 for (i = 0; i < form.elements.length; i++){
175                         if(form.elements[i].name == field) { 
176                                 if (form.elements[i].checked == true) {
177                                         array_contents.push(form.elements[i].value);
178                                 }
179                         }
180                 }
181         }
182         
183         if (array_contents.length ==0 ) {
184                 window.alert(error_message);    
185                 return;
186         }
187         
188     var field_to_name_array = request_data.field_to_name_array;
189     var array_teams = new Array();
190     for(team_id in array_contents) {
191         if(typeof array_contents[team_id] == 'string') {
192                     var team = {"team_id" : associated_javascript_data[array_contents[team_id]].ID, 
193                                 "team_name" : associated_javascript_data[array_contents[team_id]].NAME};
194                     array_teams.push(team);
195         }
196         }
197         
198         var passthru_data = Object();
199         
200         if(typeof request_data.call_back_function == 'undefined' && typeof request_data == 'object') {
201                 request_data = YAHOO.lang.JSON.parse(request_data.value);
202         }       
203         
204         if(typeof(request_data.passthru_data) != 'undefined')
205         {
206                 passthru_data = request_data.passthru_data;
207         }
208         
209         var form_name = request_data.form_name;
210         var field_name = request_data.field_name;
211
212         closePopup();
213         
214         var call_back_function = eval("window.opener." + request_data.call_back_function);
215         var result_data={"form_name":form_name,"field_name":field_name,"teams":array_teams,"passthru_data":passthru_data};
216         call_back_function(result_data);
217
218 }
219
220 function send_back_selected(module, form, field, error_message, request_data)
221 {
222         var array_contents = Array();
223         var j=0;
224         for (i = 0; i < form.elements.length; i++){
225                 if(form.elements[i].name == field) { 
226                         if (form.elements[i].checked == true) {
227                                 ++j;
228                                 array_contents.push('"' + "ID_" + j  + '":"' + form.elements[i].value + '"');
229                         }
230                 }
231         }
232         
233         if (array_contents.length ==0 ) {
234                 window.alert(error_message);    
235                 return;
236         }
237         
238         eval("var selection_list_array = {" + array_contents.join(",") + "}");
239         
240         // cn: bug 12274 - stripping false-positive security envelope
241         eval("var temp_request_data = " + window.document.forms['popup_query_form'].request_data.value);
242
243         if(temp_request_data.jsonObject) {
244                 var request_data = temp_request_data.jsonObject;
245         } else {
246                 var request_data = temp_request_data; // passed data that is NOT incorrectly encoded via JSON.encode();
247         }
248
249         // cn: end bug 12274 fix
250
251         var passthru_data = Object();
252         if(typeof(request_data.passthru_data) != 'undefined')
253         {
254                 passthru_data = request_data.passthru_data;
255         }
256         var form_name = request_data.form_name;
257         var field_to_name_array = request_data.field_to_name_array;
258         
259         closePopup();
260         
261         var call_back_function = eval("window.opener." + request_data.call_back_function);
262         var result_data={"form_name":form_name,"selection_list":selection_list_array ,"passthru_data":passthru_data,"select_entire_list":form.select_entire_list.value,"current_query_by_page":form.current_query_by_page.value};
263         call_back_function(result_data);
264 }
265
266
267
268 function toggleMore(spanId, img_id, module, action, params){
269         toggle_more_go = function() {
270                                 oReturn = function(body, caption, width, theme) {
271                                         
272                                         $(".ui-dialog").find(".open").dialog("close");
273
274                                         var el = '#'+spanId+ ' img';
275                                         if (action == 'DisplayInlineTeams')
276                                         {
277                                             el = '#'+spanId;
278                                         }
279                                         var $dialog = $('<div class="open"></div>')
280                                         .html(body)
281                                         .dialog({
282                                                 autoOpen: false,
283                                                 title: caption,
284                                                 width: 300,
285                                                 position: {
286                                                     my: 'right top',
287                                                     at: 'left top',
288                                                     of: $(el)
289                                           }
290                                         });
291
292                                         var width = $dialog.dialog( "option", "width" );
293                                         var pos = $(el).offset();
294                                         var ofWidth = $(el).width();
295
296                                         if((pos.left + ofWidth) - 40 < width) {
297                                             $dialog.dialog("option","position",{my: 'left top',at: 'right top',of: $(el)})      ;
298                                         }
299
300                                         $dialog.dialog('open');
301
302                                 }
303                                 
304                 success = function(data) {
305                                         eval(data.responseText);
306
307                                         SUGAR.util.additionalDetailsCache[spanId] = new Array();
308                                         SUGAR.util.additionalDetailsCache[spanId]['body'] = result['body'];
309                                         SUGAR.util.additionalDetailsCache[spanId]['caption'] = result['caption'];
310                                         SUGAR.util.additionalDetailsCache[spanId]['width'] = result['width'];
311                                         SUGAR.util.additionalDetailsCache[spanId]['theme'] = result['theme'];
312                                         ajaxStatus.hideStatus();
313                                         return oReturn(SUGAR.util.additionalDetailsCache[spanId]['body'], SUGAR.util.additionalDetailsCache[spanId]['caption'], SUGAR.util.additionalDetailsCache[spanId]['width'], SUGAR.util.additionalDetailsCache[spanId]['theme']);
314                                 }
315
316                                 if(typeof SUGAR.util.additionalDetailsCache[spanId] != 'undefined')
317                                         return oReturn(SUGAR.util.additionalDetailsCache[spanId]['body'], SUGAR.util.additionalDetailsCache[spanId]['caption'], SUGAR.util.additionalDetailsCache[spanId]['width'], SUGAR.util.additionalDetailsCache[spanId]['theme']);
318
319                                 if(typeof SUGAR.util.additionalDetailsCalls[spanId] != 'undefined') // call already in progress
320                                         return;
321                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
322                                 url = 'index.php?module='+module+'&action='+action+'&'+params;
323                                 SUGAR.util.additionalDetailsCalls[spanId] = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
324
325                                 return false;
326         }
327         SUGAR.util.additionalDetailsRpcCall = window.setTimeout('toggle_more_go()', 250);
328 }
329
330 // The following line of code was copy / pasted in a whole bunch of modules.
331 SUGAR.util.doWhen("window.document.forms['popup_query_form'] != null "
332         + "&& typeof(window.document.forms['popup_query_form'].request_data) != 'undefined'",
333     function() {
334         /* initialize the popup request from the parent */
335         if(window.document.forms['popup_query_form'].request_data.value == "")
336         {
337             window.document.forms['popup_query_form'].request_data.value = window.opener.get_popup_request_data();
338         }
339     }
340 );
341 $(document).ready(function(){
342     $("ul.clickMenu").each(function(index, node){
343         $(node).sugarActionMenu();
344     });
345 });