]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/EmailTemplates/EmailTemplate.js
Release 6.1.4
[Github/sugarcrm.git] / jssource / src_files / modules / EmailTemplates / EmailTemplate.js
1 /*********************************************************************************
2  * SugarCRM 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 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('toggle_textarea_elem').checked = true;
73         document.getElementById('text_div').style.display = 'inline';
74         
75         text_only.value = 1; 
76     } else {
77         //display the html div (containing TinyMCE)
78         document.getElementById('body_text_div').style.display = 'inline';
79         document.getElementById('toggle_textarea_option').style.display = 'inline';
80         document.getElementById('toggle_textarea_elem').checked = false;
81         document.getElementById('text_div').style.display = 'none';
82         
83         text_only.value = 0;                     
84     }
85 }
86
87 //This function checks that tinyMCE is initilized before setting the text (IE bug)
88 function setTinyHTML(text) {
89     var tiny = tinyMCE.getInstanceById('body_text');
90                 
91     if (tiny.getContent() != null) {
92         tiny.setContent(text)
93     } else {
94         setTimeout(setTinyHTML(text), 1000);
95     }
96 }
97
98 function stripTags(str) {
99         var theText = new String(str);
100
101         if(theText != 'undefined') {
102                 return theText.replace(/<\/?[^>]+>/gi, '');
103         }
104 }
105 /*
106  * this function will insert variables into text area 
107 */
108 function insert_variable_text(myField, myValue) {
109         //IE support
110         if (document.selection) {
111                 myField.focus();
112                 sel = document.selection.createRange();
113                 sel.text = myValue;
114         }
115         //MOZILLA/NETSCAPE support
116         else if (myField.selectionStart || myField.selectionStart == '0') {
117                 var startPos = myField.selectionStart;
118                 var endPos = myField.selectionEnd;
119                 myField.value = myField.value.substring(0, startPos)
120                 + myValue
121                 + myField.value.substring(endPos, myField.value.length);
122         } else {
123                 myField.value += myValue;
124         }
125 }
126
127 /*
128  * This function inserts variables into a TinyMCE instance
129  */
130 function insert_variable_html(text) {
131         var inst = tinyMCE.getInstanceById("body_text");
132         if (inst)
133                     inst.getWin().focus();
134         //var html = inst.getContent(true);
135         //inst.setContent(html + text);
136         inst.execCommand('mceInsertRawHTML', false, text);
137 }
138
139 function insert_variable_html_link(text) {
140
141         the_label = document.getElementById('url_text').value;
142         if(typeof(the_label) =='undefined'){
143                 the_label = label;      
144         }
145
146         //remove surounding parenthesis around the label
147         if(the_label[0] == '{' && the_label[the_label.length-1] == '}'){
148                 the_label = the_label.substring(1,the_label.length-1);
149         }
150         
151         var thelink = "<a href='" + text + "' > "+the_label+" </a>";
152         insert_variable_html(thelink);
153 }       
154 /*
155  * this function will check to see if text only flag has been checked.
156  * If so, the it will call the text insert function, if not, then it
157  * will call the html (tinyMCE eidtor) insert function
158 */
159 function insert_variable(text) {
160         //if text only flag is checked, then insert into text field
161         if(document.getElementById('toggle_textonly').checked == true){
162                 //use text version insert 
163                 insert_variable_text(document.getElementById('body_text_plain'), text) ;
164         }else{
165                 //use html version insert 
166                 insert_variable_html(text) ;
167         }
168 }                       
169