1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
36 var focus_obj = false;
37 var label = SUGAR.language.get('app_strings', 'LBL_DEFAULT_LINK_TEXT');
39 function remember_place(obj) {
43 function showVariable() {
44 document.EditView.variable_text.value =
45 document.EditView.variable_name.options[document.EditView.variable_name.selectedIndex].value;
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);
58 function toggle_text_only(firstRun) {
59 if (typeof(firstRun) == 'undefined')
61 var text_only = document.getElementById('text_only');
62 //Initialization of TinyMCE
64 setTimeout("tinyMCE.execCommand('mceAddControl', false, 'body_text');", 500);
65 var tiny = tinyMCE.getInstanceById('body_text');
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';
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';
82 update_textarea_button();
85 function update_textarea_button()
87 if(document.getElementById('text_div').style.display == 'none') {
88 document.getElementById('toggle_textarea_elem').value = toggle_textarea_elem_values[0];
90 document.getElementById('toggle_textarea_elem').value = toggle_textarea_elem_values[1];
94 function toggle_textarea_edit(obj)
96 if(document.getElementById('text_div').style.display == 'none')
98 document.getElementById('text_div').style.display = 'block';
100 document.getElementById('text_div').style.display = 'none';
102 update_textarea_button();
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');
111 if (tiny.getContent() != null) {
112 tiny.setContent(text)
114 setTimeout(setTinyHTML(text), 1000);
118 function stripTags(str) {
119 var theText = new String(str);
121 if(theText != 'undefined') {
122 return theText.replace(/<\/?[^>]+>/gi, '');
126 * this function will insert variables into text area
128 function insert_variable_text(myField, myValue) {
130 if (document.selection) {
132 sel = document.selection.createRange();
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)
141 + myField.value.substring(endPos, myField.value.length);
143 myField.value += myValue;
148 * This function inserts variables into a TinyMCE instance
150 function insert_variable_html(text) {
151 var inst = tinyMCE.getInstanceById("body_text");
153 inst.getWin().focus();
154 //var html = inst.getContent(true);
155 //inst.setContent(html + text);
156 inst.execCommand('mceInsertRawHTML', false, text);
159 function insert_variable_html_link(text) {
161 the_label = document.getElementById('url_text').value;
162 if(typeof(the_label) =='undefined'){
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);
171 var thelink = "<a href='" + text + "' > "+the_label+" </a>";
172 insert_variable_html(thelink);
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
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) ;
185 //use html version insert
186 insert_variable_html(text) ;