]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/javascript/email_popup_helper.js
Release 6.5.0
[Github/sugarcrm.git] / modules / Emails / javascript / email_popup_helper.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 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_selected(module, form, field, error_message, field_to_name_array)
40 {
41         // cn: bug 12274 - stripping false-positive security envelope
42         var temp_request_data = request_data;
43         if(temp_request_data.jsonObject) {
44                 request_data = temp_request_data.jsonObject;
45         } else {
46                 request_data = temp_request_data; // passed data that is NOT incorrectly encoded via JSON.encode();
47         }
48         // cn: end bug 12274 fix
49
50         var passthru_data = Object();
51         if(typeof(request_data.passthru_data) != 'undefined')
52         {
53                 passthru_data = request_data.passthru_data;
54         }
55         var form_name = request_data.form_name;
56         var field_to_name_array = request_data.field_to_name_array;
57         var call_back_function = eval("window.opener." + request_data.call_back_function);
58         
59         var array_contents = Array();
60         var j=0;
61         for (i = 0; i < form.elements.length; i++){
62                 if(form.elements[i].name == field) { 
63                         if (form.elements[i].checked == true) {
64                                 ++j;
65                                 var id = form.elements[i].value;
66                                 array_contents_row = Array();
67                                 for(var the_key in field_to_name_array)
68                                 {
69                                         if(the_key != 'toJSON')
70                                         {
71                                                 var the_name = field_to_name_array[the_key];
72                                                 var the_value = '';
73                         
74                                                 if(/*module != '' && */id != '')
75                                                 {
76                                                         the_value = associated_javascript_data[id][the_key.toUpperCase()];
77                                                 }
78                                                 
79                                                 array_contents_row.push('"' + the_name + '":"' + the_value + '"');
80                                         }
81                                 }
82                                 eval("array_contents.push({" + array_contents_row.join(",") + "})");
83                         }
84                 }
85         }
86                                 
87         var result_data = {"form_name":form_name,"name_to_value_array":array_contents};
88
89         if (array_contents.length ==0 ) {
90                 window.alert(error_message);    
91                 return;
92         }
93         
94         call_back_function(result_data);
95         var close_popup = window.opener.get_close_popup();
96
97         if(close_popup)
98         {
99                 window.close();
100         }
101 }
102
103 function send_back(module, id)
104 {
105         var associated_row_data = associated_javascript_data[id];
106
107         // cn: bug 12274 - stripping false-positive security envelope
108         eval("var temp_request_data = " + window.document.forms['popup_query_form'].request_data.value);
109         if(temp_request_data.jsonObject) {
110                 var request_data = temp_request_data.jsonObject;
111         } else {
112                 var request_data = temp_request_data; // passed data that is NOT incorrectly encoded via JSON.encode();
113         }
114         // cn: end bug 12274 fix
115
116         var passthru_data = Object();
117         if(typeof(request_data.passthru_data) != 'undefined')
118         {
119                 passthru_data = request_data.passthru_data;
120         }
121         var form_name = request_data.form_name;
122         var field_to_name_array = request_data.field_to_name_array;
123         var call_back_function = eval("window.opener." + request_data.call_back_function);
124         var array_contents = Array();
125
126         // constructs the array of values associated to the bean that the user clicked
127         for(var the_key in field_to_name_array)
128         {
129                 if(the_key != 'toJSON')
130                 {
131                         var the_name = field_to_name_array[the_key];
132                         var the_value = '';
133
134                         if(module != '' && id != '')
135                         {
136                                 the_value = associated_row_data[the_key.toUpperCase()];
137                         }
138                         
139                         array_contents.push('"' + the_name + '":"' + the_value + '"');
140                 }
141         }
142         
143         eval("var name_to_value_array = {'0' : {" + array_contents.join(",") + "}}");
144
145         var result_data = {"form_name":form_name,"name_to_value_array":name_to_value_array,"passthru_data":passthru_data};
146         var close_popup = window.opener.get_close_popup();
147         
148         call_back_function(result_data);
149
150         if(close_popup)
151         {
152                 window.close();
153         }
154 }