]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/EmailTemplates/EmailTemplate.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / EmailTemplates / EmailTemplate.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 var focus_obj = false;
37 var label = SUGAR.language.get('app_strings', 'LBL_DEFAULT_LINK_TEXT');
38
39 function remember_place(obj) {
40   focus_obj = obj;
41 }
42
43 function showVariable() {
44         document.EditView.variable_text.value = 
45                 document.EditView.variable_name.options[document.EditView.variable_name.selectedIndex].value; 
46 }
47
48 function addVariables(the_select,the_module) {
49         the_select.options.length = 0;
50         for(var i=0;i<field_defs[the_module].length;i++) {
51                 var new_option = document.createElement("option");
52                 new_option.value = "$"+field_defs[the_module][i].name;
53                 new_option.text= field_defs[the_module][i].value;
54                 the_select.options.add(new_option,i);
55         }
56         showVariable();
57 }
58 function toggle_text_only(firstRun) {
59         if (typeof(firstRun) == 'undefined')
60                 firstRun = false;
61         var text_only = document.getElementById('text_only');
62     //Initialization of TinyMCE
63     if(firstRun){
64         setTimeout("tinyMCE.execCommand('mceAddControl', false, 'body_text');", 500);
65         var tiny = tinyMCE.getInstanceById('body_text');
66     }
67         //check to see if the toggle textonly flag is checked
68     if(document.getElementById('toggle_textonly').checked == true) {
69         //hide the html div (containing TinyMCE)
70         document.getElementById('body_text_div').style.display = 'none';
71         document.getElementById('toggle_textarea_option').style.display = 'none';
72         document.getElementById('text_div').style.display = 'block';
73         text_only.value = 1; 
74     } else {
75         //display the html div (containing TinyMCE)
76         document.getElementById('body_text_div').style.display = 'inline';
77         document.getElementById('toggle_textarea_option').style.display = 'inline';
78         document.getElementById('text_div').style.display = 'none';
79         
80         text_only.value = 0;                     
81     }
82     update_textarea_button();
83 }
84
85 function update_textarea_button()
86 {
87         if(document.getElementById('text_div').style.display == 'none') {
88                 document.getElementById('toggle_textarea_elem').value = toggle_textarea_elem_values[0];
89         } else {
90                 document.getElementById('toggle_textarea_elem').value = toggle_textarea_elem_values[1];
91         }
92 }
93
94 function toggle_textarea_edit(obj)
95 {
96         if(document.getElementById('text_div').style.display == 'none')
97         {
98         document.getElementById('text_div').style.display = 'block';
99         } else {
100         document.getElementById('text_div').style.display = 'none';
101         }
102         update_textarea_button();
103 }
104
105
106
107 //This function checks that tinyMCE is initilized before setting the text (IE bug)
108 function setTinyHTML(text) {
109     var tiny = tinyMCE.getInstanceById('body_text');
110                 
111     if (tiny.getContent() != null) {
112         tiny.setContent(text)
113     } else {
114         setTimeout(setTinyHTML(text), 1000);
115     }
116 }
117
118 function stripTags(str) {
119         var theText = new String(str);
120
121         if(theText != 'undefined') {
122                 return theText.replace(/<\/?[^>]+>/gi, '');
123         }
124 }
125 /*
126  * this function will insert variables into text area 
127 */
128 function insert_variable_text(myField, myValue) {
129         //IE support
130         if (document.selection) {
131                 myField.focus();
132                 sel = document.selection.createRange();
133                 sel.text = myValue;
134         }
135         //MOZILLA/NETSCAPE support
136         else if (myField.selectionStart || myField.selectionStart == '0') {
137                 var startPos = myField.selectionStart;
138                 var endPos = myField.selectionEnd;
139                 myField.value = myField.value.substring(0, startPos)
140                 + myValue
141                 + myField.value.substring(endPos, myField.value.length);
142         } else {
143                 myField.value += myValue;
144         }
145 }
146
147 /*
148  * This function inserts variables into a TinyMCE instance
149  */
150 function insert_variable_html(text) {
151         var inst = tinyMCE.getInstanceById("body_text");
152         if (inst)
153                     inst.getWin().focus();
154         //var html = inst.getContent(true);
155         //inst.setContent(html + text);
156         inst.execCommand('mceInsertRawHTML', false, text);
157 }
158
159 function insert_variable_html_link(text) {
160
161         the_label = document.getElementById('url_text').value;
162         if(typeof(the_label) =='undefined'){
163                 the_label = label;      
164         }
165
166         //remove surounding parenthesis around the label
167         if(the_label[0] == '{' && the_label[the_label.length-1] == '}'){
168                 the_label = the_label.substring(1,the_label.length-1);
169         }
170         
171         var thelink = "<a href='" + text + "' > "+the_label+" </a>";
172         insert_variable_html(thelink);
173 }       
174 /*
175  * this function will check to see if text only flag has been checked.
176  * If so, the it will call the text insert function, if not, then it
177  * will call the html (tinyMCE eidtor) insert function
178 */
179 function insert_variable(text) {
180         //if text only flag is checked, then insert into text field
181         if(document.getElementById('toggle_textonly').checked == true){
182                 //use text version insert 
183                 insert_variable_text(document.getElementById('body_text_plain'), text) ;
184         }else{
185                 //use html version insert 
186                 insert_variable_html(text) ;
187         }
188 }                       
189