]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/popup_helper.js
Release 6.2.2
[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-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
37
38
39 function send_back(module, id)
40 {
41         var associated_row_data = associated_javascript_data[id];
42
43         // cn: bug 12274 - stripping false-positive security envelope
44         eval("var temp_request_data = " + window.document.forms['popup_query_form'].request_data.value);
45         if(temp_request_data.jsonObject) {
46                 var request_data = temp_request_data.jsonObject;
47         } else {
48                 var request_data = temp_request_data; // passed data that is NOT incorrectly encoded via JSON.encode();
49         }
50         // cn: end bug 12274 fix
51         
52         var passthru_data = Object();
53         if(typeof(request_data.passthru_data) != 'undefined')
54         {
55                 passthru_data = request_data.passthru_data;
56         }
57         var form_name = request_data.form_name;
58         var field_to_name_array = request_data.field_to_name_array;
59         
60         var call_back_function = eval("window.opener." + request_data.call_back_function);
61         var array_contents = Array();
62
63         // constructs the array of values associated to the bean that the user clicked
64         for(var the_key in field_to_name_array)
65         {
66                 if(the_key != 'toJSON')
67                 {
68                         var the_name = field_to_name_array[the_key];
69                         var the_value = '';
70
71                         if(module != '' && id != '')
72                         {
73                 if((the_key.toUpperCase() == 'USER_NAME' || the_key.toUpperCase() == 'LAST_NAME' || the_key.toUpperCase() == 'FIRST_NAME') && typeof(is_show_fullname) != 'undefined' && is_show_fullname && form_name != 'search_form') {//if it is from searchform, it will search by assigned_user_name like 'ABC%', then it will return nothing
74                     the_value = associated_row_data['FULL_NAME'];
75                 }
76                 else {
77                     the_value = associated_row_data[the_key.toUpperCase()];
78                }
79                         }
80                         
81                         if (typeof(the_value) == 'string') {
82                                 the_value = the_value.replace(/\r\n|\n|\r/g, '\\n');
83                         }
84                         
85                         array_contents.push('"' + the_name + '":"' + the_value + '"');
86                 }
87         }
88         
89         eval("var name_to_value_array = {" + array_contents.join(",") + "}");
90
91         var result_data = {"form_name":form_name,"name_to_value_array":name_to_value_array,"passthru_data":passthru_data};
92         var close_popup = window.opener.get_close_popup();
93         call_back_function(result_data);
94
95         if(close_popup)
96         {
97                 window.close();
98         }
99 }
100
101 function send_back_teams(module, form, field, error_message, request_data, form_team_id) {      
102         var array_contents = Array();
103         
104         if(form_team_id){
105                 array_contents.push(form_team_id);
106         }else{
107                 var j=0;
108                 for (i = 0; i < form.elements.length; i++){
109                         if(form.elements[i].name == field) { 
110                                 if (form.elements[i].checked == true) {
111                                         array_contents.push(form.elements[i].value);
112                                 }
113                         }
114                 }
115         }
116         
117         if (array_contents.length ==0 ) {
118                 window.alert(error_message);    
119                 return;
120         }
121         
122     var field_to_name_array = request_data.field_to_name_array;
123     var array_teams = new Array();
124     for(team_id in array_contents) {
125         if(typeof array_contents[team_id] == 'string') {
126                     var team = {"team_id" : associated_javascript_data[array_contents[team_id]].ID, 
127                                 "team_name" : associated_javascript_data[array_contents[team_id]].NAME};
128                     array_teams.push(team);
129         }
130         }
131         
132         var passthru_data = Object();
133         
134         if(typeof request_data.call_back_function == 'undefined' && typeof request_data == 'object') {
135                 request_data = YAHOO.lang.JSON.parse(request_data.value);
136         }       
137         
138         if(typeof(request_data.passthru_data) != 'undefined')
139         {
140                 passthru_data = request_data.passthru_data;
141         }
142         
143         var form_name = request_data.form_name;
144         var field_name = request_data.field_name;
145         var call_back_function = eval("window.opener." + request_data.call_back_function);
146
147         var result_data={"form_name":form_name,"field_name":field_name,"teams":array_teams,"passthru_data":passthru_data};
148         var close_popup = window.opener.get_close_popup();
149         call_back_function(result_data);
150         if(close_popup)
151         {
152                 window.close();
153         }       
154
155 }
156
157 function send_back_selected(module, form, field, error_message, request_data)
158 {
159         var array_contents = Array();
160         var j=0;
161         for (i = 0; i < form.elements.length; i++){
162                 if(form.elements[i].name == field) { 
163                         if (form.elements[i].checked == true) {
164                                 ++j;
165                                 array_contents.push('"' + "ID_" + j  + '":"' + form.elements[i].value + '"');
166                         }
167                 }
168         }
169         
170         if (array_contents.length ==0 ) {
171                 window.alert(error_message);    
172                 return;
173         }
174         
175         eval("var selection_list_array = {" + array_contents.join(",") + "}");
176         
177         // cn: bug 12274 - stripping false-positive security envelope
178         eval("var temp_request_data = " + window.document.forms['popup_query_form'].request_data.value);
179
180         if(temp_request_data.jsonObject) {
181                 var request_data = temp_request_data.jsonObject;
182         } else {
183                 var request_data = temp_request_data; // passed data that is NOT incorrectly encoded via JSON.encode();
184         }
185
186         // cn: end bug 12274 fix
187
188         var passthru_data = Object();
189         if(typeof(request_data.passthru_data) != 'undefined')
190         {
191                 passthru_data = request_data.passthru_data;
192         }
193         var form_name = request_data.form_name;
194         var field_to_name_array = request_data.field_to_name_array;
195         
196         var call_back_function = eval("window.opener." + request_data.call_back_function);
197         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};
198         var close_popup = window.opener.get_close_popup();
199         call_back_function(result_data);
200
201         if(close_popup)
202         {
203                 window.close();
204         }
205 }
206
207
208
209 function toggleMore(spanId, img_id, module, action, params){
210         toggle_more_go = function() {
211                 oReturn = function(body, caption, width, theme) {
212                                         return overlib(body, CAPTION, caption, STICKY, MOUSEOFF, 1000, WIDTH, width, CLOSETEXT, ('<img border=0 style="margin-left:2px; margin-right: 2px;" src=themes/' + theme + '/images/close.gif>'), CLOSETITLE, 'Click to Close', CLOSECLICK, FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass', REF, spanId, REFC, 'LL', REFX, 13);
213                                 }
214                 success = function(data) {
215                                         eval(data.responseText);
216
217                                         SUGAR.util.additionalDetailsCache[spanId] = new Array();
218                                         SUGAR.util.additionalDetailsCache[spanId]['body'] = result['body'];
219                                         SUGAR.util.additionalDetailsCache[spanId]['caption'] = result['caption'];
220                                         SUGAR.util.additionalDetailsCache[spanId]['width'] = result['width'];
221                                         SUGAR.util.additionalDetailsCache[spanId]['theme'] = result['theme'];
222                                         ajaxStatus.hideStatus();
223                                         return oReturn(SUGAR.util.additionalDetailsCache[spanId]['body'], SUGAR.util.additionalDetailsCache[spanId]['caption'], SUGAR.util.additionalDetailsCache[spanId]['width'], SUGAR.util.additionalDetailsCache[spanId]['theme']);
224                                 }
225
226                                 if(typeof SUGAR.util.additionalDetailsCache[spanId] != 'undefined')
227                                         return oReturn(SUGAR.util.additionalDetailsCache[spanId]['body'], SUGAR.util.additionalDetailsCache[spanId]['caption'], SUGAR.util.additionalDetailsCache[spanId]['width'], SUGAR.util.additionalDetailsCache[spanId]['theme']);
228
229                                 if(typeof SUGAR.util.additionalDetailsCalls[spanId] != 'undefined') // call already in progress
230                                         return;
231                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
232                                 url = 'index.php?module='+module+'&action='+action+'&'+params;
233                                 SUGAR.util.additionalDetailsCalls[spanId] = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
234
235                                 return false;
236         }
237         SUGAR.util.additionalDetailsRpcCall = window.setTimeout('toggle_more_go()', 250);
238 }
239
240 // The following line of code was copy / pasted in a whole bunch of modules.
241
242 YAHOO.util.Event.onDOMReady(function() {
243     /* initialize the popup request from the parent */
244     if(window.document.forms['popup_query_form'].request_data.value == "") {
245         window.document.forms['popup_query_form'].request_data.value
246                 = YAHOO.lang.JSON.stringify(window.opener.get_popup_request_data());
247     }
248 });