1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
39 var uploads_arr=new Array();
40 var uploads_count_map=new Object();
41 var uploads_count = -1;
42 var current_uploads_id = -1;
43 var append = false; // Ed has method InsertHTML which inserts at cursor point - plain does not
44 //following varaibles store references to input fields grouped with the clicked email selection button (select).
45 var current_contact = '';
46 var current_contact_id = '';
47 var current_contact_email = '';
48 var current_contact_name = '';
50 var select_image = SUGAR.language.get('app_strings', 'LBL_ONLY_IMAGE_ATTACHMENT');
51 var lbl_remove = SUGAR.language.get('app_strings', 'LBL_REMOVE');
52 var lbl_email_attachments_file = SUGAR.language.get('app_strings', 'LBL_EMAIL_ATTACHMENTS_FILE');
53 var lbl_email_attachments_document = SUGAR.language.get('app_strings', 'LBL_EMAIL_ATTACHMENTS_DOCUMENT');
54 var lbl_email_attachments_embeded = SUGAR.language.get('app_strings', 'LBL_EMAIL_ATTACHMENTS_EMBEDED');
57 function toggleRawEmail() {
58 var raw = document.getElementById('rawEmail');
59 var button = document.getElementById('rawButton');
61 if(raw.style.display == '') {
62 raw.style.display = 'none';
63 button.value = showRaw;
65 raw.style.display = '';
66 button.value = hideRaw;
70 ///////////////////////////////////////////////////////////////////////////////
71 //// DOCUMENT HANDLING HELPERS
73 function deletePriorAttachment(id) {
74 var rem = document.getElementById('removeAttachment');
81 document.getElementById('noteDiv'+id).style.display = 'none';
84 function setDocument(target, documentId, documentName, docRevId) {
85 if(window.opener.SUGAR.email2) {
86 var idx = window.opener.SUGAR.email2.composeLayout.currentInstanceId;
87 window.opener.SUGAR.email2.composeLayout.setDocument(idx, target, documentId, documentName, docRevId);
89 var docId = window.opener.document.getElementById('documentId' + target);
90 var docName = window.opener.document.getElementById('documentName' + target);
91 var docRevisionId = window.opener.document.getElementById('document' + target);
92 docId.value = documentId;
93 docName.value = documentName;
94 docRevisionId.value = docRevId;
99 function setDocumentToCampaignTemplate(target, documentId, documentName,docRevId, documentType) {
100 // var docId = eval("window.opener.document.forms.EditView.documentId" + target);
101 var docId = window.opener.document.getElementById('documentId' + target);
102 //var docName = eval("window.opener.document.EditView.documentName" + target);
103 var docName = window.opener.document.getElementById('documentName' + target);
104 var docType = window.opener.document.getElementById('documentType' + target);
106 var docId = window.opener.document.getElementById('documentId');
107 var docName = window.opener.document.getElementById('documentName');
108 var docRevisionId = window.opener.document.getElementById('docRevId');
109 var docType = window.opener.document.getElementById('documentType');
111 docId.value = documentId;
112 //docId.onchange('docUpload(); form_reset_doc();');
113 docName.value = documentName;
114 docRevisionId.value = docRevId;
115 docType.value = documentType;
116 docName.onchange('docUpload(); form_reset_doc();');
117 //alert(docName.onchange);
121 function selectDocument(target) {
122 URL="index.php?module=Emails&action=PopupDocuments&to_pdf=true&target=" + target;
123 windowName = 'selectDocument';
124 windowFeatures = 'width=800' + ',height=600' + ',resizable=1,scrollbars=1';
126 win = SUGAR.util.openWindow(URL, windowName, windowFeatures);
128 // put the focus on the popup if the browser supports the focus() method
133 function addDocument() {
134 for(var i=0;i<10;i++) {
135 var elem = document.getElementById('document'+i);
136 if(elem.style.display == 'none') {
137 elem.style.display='block';
143 function deleteDocument(index) {
144 var elem = document.getElementById('document'+index);
145 document.getElementById('documentId'+index).value = "";
146 document.getElementById('documentName'+index).value = "";
147 elem.style.display='none';
150 // attachment functions below
151 function deleteFile(index) {
153 var elem = document.getElementById('file'+index);
155 var ea_input = document.getElementById('email_attachment'+index);
157 //get the parent node
158 var Parent = ea_input.parentNode;
159 //create replacement node
160 var ea = document.createElement('input');
161 ea.setAttribute('id', 'email_attachment' + index);
162 ea.setAttribute('name', 'email_attachment' + index);
163 ea.setAttribute('tabindex', '120');
164 ea.setAttribute('size', '40');
165 ea.setAttribute('type', 'file');
167 //replace the old node with the new one
168 Parent.replaceChild(ea, ea_input);
170 //hide the div element
171 elem.style.display='none';
176 for(var i=0;i<10;i++) {
177 var elem = document.getElementById('file'+i);
178 if(elem.style.display == 'none') {
179 elem.style.display='block';
184 //// END DOCUMENT HANDLING HELPERS
185 ///////////////////////////////////////////////////////////////////////////////
187 ///// New file upload code
189 function multiFiles( list_target){
190 // Where to write the list
191 this.list_target = list_target;
192 //this.list_target = document.getElementById(list_target);
193 // How many elements?
197 * Add a new file input element
199 this.addElement = function( element ){
200 // Make sure it's a file input element
201 if( element.tagName == 'INPUT' && element.type == 'file' ){
202 var currCount =this.id++;
203 element.name = 'email_attachment' + currCount;
204 element.id = 'email_attachment' + currCount;
206 // Add reference to this object
207 element.multi_selector = this;
208 // What to do when a file is selected
209 element.onchange = function() {
210 var url = 'index.php?to_pdf=1&module=EmailTemplates&action=AttachFiles',
214 YAHOO.util.Connect.setForm(document.getElementById("upload_form"), true, true);
215 YAHOO.util.Connect.asyncRequest('POST', url, {upload: function() {}}, null);
219 new_element = document.createElement('input');
220 new_element.type = 'file';
221 // new_element.name = 'email_attachment' +up++;
224 this.parentNode.insertBefore(new_element, this);
225 // Apply 'update' to element
226 this.multi_selector.addElement(new_element);
228 this.multi_selector.addListRow(this);
229 // Hide this: we can't use display:none because Safari doesn't like it
230 //this.style.display='none';
231 //display none works fine for FF and IE
232 this.style.display = 'none';
233 //later for Safari add following
234 //this.style.position = 'absolute';
235 //this.style.left = '-5000px';
237 // File element counter
239 // Most recent element
240 this.current_element = element;
243 // This can only be applied to file input elements!
244 alert( 'Error: not a file input element' );
249 * Add a new row to the list of files
251 this.addListRow = function( element ){
253 var new_row = document.createElement( 'div' );
256 var new_row_button_remove = document.createElement( 'input' );
257 new_row_button_remove.type = 'button';
258 new_row_button_remove.value = lbl_remove;
260 var new_row_file_name = document.createElement( 'input' );
261 new_row_file_name.type = 'text';
262 new_row_file_name.size = '40';
263 new_row_file_name.disabled=true;
265 var new_row_chk_box = document.createElement( 'input' );
266 new_row_chk_box.setAttribute('id','checkBoxFile[]');
267 new_row_chk_box.setAttribute('name','checkBoxFile[]');
268 new_row_chk_box.type = 'checkbox';
269 new_row_chk_box.checked =false;
270 new_row_chk_box.disabled =true;
272 var new_row_attach_file = document.createElement( 'input' );
273 new_row_attach_file.type = 'image';
274 new_row_attach_file.value ='/index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=company_logo.png';
275 new_row_attach_file.disabled ='true';
277 var imgElement = document.createElement("img");
278 imgElement.setAttribute("src", "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Accounts.gif");
279 imgElement.setAttribute("align","absmiddle");
280 imgElement.setAttribute("alt",lbl_email_attachments_file);
281 imgElement.setAttribute("border","0");
282 imgElement.setAttribute("height","16");
283 imgElement.setAttribute("width","16");
285 var new_row_button_embed = document.createElement("img");
286 new_row_button_embed.setAttribute("src", "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=attachment.gif");
287 new_row_button_embed.setAttribute("align","absmiddle");
288 new_row_button_embed.setAttribute("alt",lbl_email_attachments_embeded);
289 new_row_button_embed.setAttribute("border","0");
290 new_row_button_embed.setAttribute("height","16");
291 new_row_button_embed.setAttribute("width","16");
294 new_row.element = element;
298 new_row_button_remove.onclick = function() {
299 var filePathComponents = this.parentNode.element.value.split("\\"),
300 fileName = (filePathComponents[filePathComponents.length - 1]),
303 tiny = tinyMCE.getInstanceById('body_text'),
304 currValTiny = tiny.getContent();
306 // Remove row element from form
307 this.parentNode.element.parentNode.removeChild(this.parentNode.element);
309 // find instances of the file and set it to ''
310 while (currValTiny.indexOf(fileName) !== -1) {
311 currValTiny = currValTiny.replace(fileName, 'QW%%^%%WQ');
312 currValTiny = currValTiny.replace(/<img[^<]*QW%%\^%%WQ[^>]*>?/, '');
315 tiny.setContent(currValTiny);
317 // Remove this row from the list
318 this.parentNode.parentNode.removeChild(this.parentNode);
321 this.parentNode.element.multi_selector.count--;
322 // Re-enable input element (if it's disabled)
323 this.parentNode.element.multi_selector.current_element.disabled = false;
326 // without it Safari wants to reload the browser window
327 // which nixes your already queued uploads
332 // Embed image into the email body template
333 new_row_button_embed.onclick = function() {
334 var filePathComponents = element.value.split("\\"),
335 fileName = filePathComponents[filePathComponents.length - 1],
338 allowedTypes = ['gif', 'bmp', 'png', 'jpg', 'jpeg'],
339 imglocation = 'cache/images/';
341 //check if filetype is valid
342 if (SUGAR.util.validateFileExt(fileName, allowedTypes)) {
343 cid = 'cid:' + fileName;
344 embedImage = '<img src="' + imglocation + encodeURI(fileName) + '">';
345 insert_variable(embedImage);
347 this.parentNode.childNodes[2].checked = 'true';
355 var oas = new ActiveXObject("Scripting.FileSystemObject");
356 var d = document.a.b.value;
357 var e = oas.getFile(d);
362 //new_row_file_name.value =element.value;
363 new_row_file_name_tab = element.value.split("\\");
364 //alert(new_row_file_name_tab);
365 nbr_elements = new_row_file_name_tab.length;
366 new_row_file_name.value = new_row_file_name_tab[nbr_elements-1];
368 //new_row.innerHTML = element.value;
369 //add all the elements
370 //new_row.appendChild(new_row_attach_file);
371 new_row.appendChild(imgElement);
372 new_row.appendChild(new_row_button_embed);
373 new_row.appendChild(new_row_chk_box);
374 new_row.appendChild( new_row_file_name);
376 new_row.appendChild( new_row_button_remove);
377 // Add it to the list
378 this.list_target.appendChild( new_row );
379 //document.getElementById(list_target).appendChild(new_row);
384 function docUpload() {
386 //var theForm = document.getElementById('EditView');
387 //var theForm = document.getElementById('upload_form');
391 upload: function(r) {
392 rets = YAHOO.lang.JSON.parse(r.responseText);
396 var url ='index.php?module=EmailTemplates&action=AttachDocuments';
397 YAHOO.util.Connect.asyncRequest('POST', url, callback,null);
400 var element = document.getElementById('documentName');
401 var element1 = document.getElementById('documentId');
402 var element2 = document.getElementById('docRevId');
403 var element3 = document.getElementById('documentType');
404 var elm = document.createElement('div');
405 elm.setAttribute('id','file'+uploadIndex);
407 var sugarDoc = document.createElement('input');
408 sugarDoc.setAttribute('type', 'label');
409 sugarDoc.setAttribute('disabled', 'true');
410 sugarDoc.setAttribute('font', 'bold');
411 sugarDoc.setAttribute('value',"Sugar Document");
414 var new_row_button_embed_doc = document.createElement( 'input' );
415 new_row_button_embed_doc.type = 'button';
416 new_row_button_embed_doc.value = 'Embed';
418 var new_row_chk_box = document.createElement( 'input' );
419 new_row_chk_box.setAttribute('id','checkBoxDoc'+uploadIndex);
420 new_row_chk_box.setAttribute('name','checkBoxDoc'+uploadIndex);
421 new_row_chk_box.type = 'checkbox';
422 new_row_chk_box.checked =false;
423 new_row_chk_box.disabled='true';
426 var eah = document.createElement('input');
427 eah.setAttribute('id', 'documentId'+uploadIndex);
428 eah.setAttribute('name', 'documentId'+uploadIndex);
429 eah.setAttribute('tabindex', '120');
430 eah.setAttribute('type', 'hidden');
431 eah.setAttribute('value',element1.value);
434 var attId = document.createElement('input');
435 attId.setAttribute('id', 'docRevId'+uploadIndex);
436 attId.setAttribute('name', 'docRevId'+uploadIndex);
437 attId.setAttribute('tabindex', '120');
438 attId.setAttribute('type', 'hidden');
439 attId.setAttribute('value',element2.value);
442 var attType = document.createElement('input');
443 attType.setAttribute('id', 'documentType'+uploadIndex);
444 attType.setAttribute('name', 'documentType'+uploadIndex);
445 attType.setAttribute('tabindex', '120');
446 attType.setAttribute('type', 'hidden');
447 attType.setAttribute('value',element3.value);
450 var ea = document.createElement('input');
451 ea.setAttribute('id', 'document[]');
452 ea.setAttribute('name', 'document[]');
453 ea.setAttribute('tabindex', '120');
454 ea.setAttribute('size', '40');
455 ea.setAttribute('type', 'text');
456 ea.setAttribute('disabled',true);
457 ea.setAttribute('value',element.value);
459 var eai = document.createElement('input');
460 eai.setAttribute('type', 'button');
461 //eai.setAttribute('onclick', 'deleteFile('+uploadIndex+');');
462 eai.setAttribute('value', lbl_remove);
463 eai.onclick=function(){
464 var filename = this.parentNode.childNodes[4].value;
466 var tiny = tinyMCE.getInstanceById('body_text');
467 var currValTiny = tiny.getContent();
468 while(currValTiny.indexOf(unescape(filename)) != -1){
469 currValTiny = currValTiny.replace(unescape(filename),'QW%%^%%WQ');
470 currValTiny = currValTiny.replace(/<img[^<]*QW%%\^%%WQ[^>]*>?/,' ');
472 tiny.setContent(currValTiny);
474 this.parentNode.parentNode.removeChild(this.parentNode);
478 var new_row_button_embed = document.createElement("img");
479 new_row_button_embed.setAttribute("src", "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=attachment.gif");
480 new_row_button_embed.setAttribute("align","absmiddle");
481 new_row_button_embed.setAttribute("alt",lbl_email_attachments_embeded);
482 new_row_button_embed.setAttribute("border","0");
483 new_row_button_embed.setAttribute("height","16");
484 new_row_button_embed.setAttribute("width","16");
485 new_row_button_embed.onclick= function(){
486 //retrieve the documentid
487 this.parentNode.childNodes[2].checked='true';
488 var documentRevisionId = this.parentNode.childNodes[4].value;
489 var mime_type = this.parentNode.childNodes[5].value;
490 if(mime_type == "image/gif" || mime_type == "image/bmp" || mime_type == "image/png" || mime_type == "image/x-png" || mime_type == "image/jpg" || mime_type == "image/jpeg")
492 embedImage='<img src="index.php?entryPoint=download&type=Documents&id='+documentRevisionId+'">';
493 insert_variable(embedImage);
496 new_row_chk_box.checked =false;
501 var SugarDoc = document.createElement("img");
502 SugarDoc.setAttribute("src", "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=sugar_document.png");
503 SugarDoc.setAttribute("align","absmiddle");
504 SugarDoc.setAttribute("alt",lbl_email_attachments_document);
505 SugarDoc.setAttribute("border","0");
506 SugarDoc.setAttribute("height","16");
507 SugarDoc.setAttribute("width","16");
510 //elm.appendChild(eah);
511 elm.appendChild(SugarDoc);
512 elm.appendChild(new_row_button_embed);
513 elm.appendChild(new_row_chk_box);
514 elm.appendChild(eah);
515 elm.appendChild(attId);
516 elm.appendChild(attType);
518 elm.appendChild(eai);
519 elm.style.display = 'block';
521 var rN= document.getElementById('attachments_div');
526 function addUploadFiles(form_name) {
527 var chForm = document.getElementById('upload_div');
528 var theForm = document.getElementById(form_name);
529 var elems = chForm.getElementsByTagName("input");
530 //get the count of all the email_attachment file elements
532 //Use the count to add the documents
533 count=this.multi_selector.id;
534 for (var i=0; i<count-1; i++) {
535 // find out all the email_attachments and append to the EditView form
536 var el = document.getElementsByName('email_attachment'+i);
538 theForm.appendChild(el[0]);
541 var chForm = document.getElementById("upload_form");
542 var elems = chForm.getElementsByTagName("input");
544 for (var i=0; i<elems.length; i++) {
545 //find out all the email_attachments and append to the EditView form
547 //var el = document.getElementsByName('checkBoxFile[]');
548 if(el.id == 'checkBoxFile[]'){
549 var eah = document.createElement('input');
550 eah.setAttribute('id', 'embedded'+num);
551 eah.setAttribute('name', 'embedded'+num);
552 eah.setAttribute('tabindex', '120');
553 eah.setAttribute('type', 'hidden');
554 eah.setAttribute('value',el.checked);
556 theForm.appendChild(eah);
561 function addUploadDocs(form_name) {
562 var chForm = document.getElementById("upload_form");
563 var theForm = document.getElementById(form_name);
564 var attDiv = document.getElementById("attachments_div");
565 var elems = chForm.getElementsByTagName("input");
566 var elems1 = attDiv.getElementsByTagName("input");
567 for (var i=0; i<elems1.length; i++) {
568 //if (elems[i].type == "file") {
570 if(el.id=='document[]') {
571 theForm.appendChild(el);
574 for (var i=0; i<elems.length; i++) {
575 //if (elems[i].type == "file") {
578 if(el.id=='document[]') {
579 theForm.appendChild(el);
581 if(el.id.indexOf('documentId')>=0 || el.id=='document[]') {
582 theForm.appendChild(el);
587 function form_reset_doc() {
588 // var theForm = document.getElementById('upload_form');
589 var theForm = document.getElementById('upload_div');
590 var elems = theForm.getElementsByTagName("input");
591 for (var i=0; i<elems.length; i++) {
592 if (elems[i].type == "text" || "hidden" ) {
594 if(el.id == 'documentName') {
595 var new_el =document.createElement('input');
596 new_el.type = 'hidden';
597 new_el.name = el.name;
599 new_el.onchange = el.onchange;
600 //new_el.disabled=true;
601 //new_el.style.visibility="hidden";
603 el.parentNode.replaceChild(new_el, el);
604 // el.parentNode.insertBefore(new_el, el);
605 // el.parentNode.removeChild(el);
607 if(el.id == 'documentId') {
608 var new_el =document.createElement('input');
609 new_el.type = 'hidden';
610 new_el.name = el.name;
612 //new_el.onchange = el.onchange;
613 //new_el.DISABLED='true';
614 el.parentNode.replaceChild(new_el, el);
615 // el.parentNode.insertBefore(new_el, el);
616 // el.parentNode.removeChild(el);
623 function selectDoc() {
624 URL="index.php?module=EmailTemplates&action=PopupDocumentsCampaignTemplate&to_pdf=true&target=" ;
625 windowName = 'selectDocument';
626 windowFeatures = 'width=800' + ',height=600' + ',resizable=1,scrollbars=1';
628 win = SUGAR.util.openWindow(URL, windowName, windowFeatures);
630 // put the focus on the popup if the browser supports the focus() method
634 ///////////////////////////////////////////////////////////////////////////////
635 //// HTML/PLAIN EDITOR FUNCTIONS
636 function setEditor() {
637 if(document.getElementById('setEditor').checked == true) {
642 // cn: bug 9690 - unchecked "Send HTML" - we hose the html_div contents
643 function prepSave() {
644 if(document.getElementById('setEditor').checked == true) {
645 document.getElementById('html_div').innerHTML = '';
650 function toggle_textonly() {
651 var altText = document.getElementById('alt_text_div');
652 var plain = document.getElementById('text_div');
653 var html = document.getElementById('html_div');
655 var desc = document.getElementById('description');
656 var tiny = tinyMCE.getInstanceById('description_html');
658 // toggling INTO HTML editting
659 if(html.style.display == 'none') {
660 html.style.display = 'block';
661 if(document.getElementById('toggle_textarea_elem').checked == false) {
662 plain.style.display = 'none';
664 altText.style.display = 'block';
666 var plainText = new String(desc.value);
667 plainText = plainText.replace(/\n/gi, '<br />');
668 tiny.setContent(plainText);
670 // toggling into Plain Text ONLY
671 html.style.display = 'none';
672 plain.style.display = 'block';
673 altText.style.display = 'none';
675 if(tiny.getContent()) {
676 var htmlText = new String(tiny.getContent());
677 htmlText = htmlText.replace(/<br \/>/gi, "\n");
678 htmlText = htmlText.replace(/>/gi, ">");
679 htmlText = htmlText.replace(/</gi, "<");
680 htmlText = htmlText.replace(/ /gi, " ");
681 desc.value = stripTags(htmlText);
686 function stripTags(str) {
687 var theText = new String(str);
689 if(theText != 'undefined') {
690 return theText.replace(/<\/?[^>]+>/gi, '');
694 function toggle_textarea() {
695 var checkbox = document.getElementById('toggle_textarea_elem');
696 var plain = document.getElementById('text_div');
698 if (checkbox.checked == false) {
699 plain.style.display = 'none';
701 plain.style.display = 'block';
704 //// END HTML/PLAIN EDITOR FUNCTIONS
705 ///////////////////////////////////////////////////////////////////////////////
710 ///////////////////////////////////////////////////////////////////////////////
711 //// EMAIL TEMPLATE CODE
712 function appendEmailTemplateJSON() {
713 // query based on template, contact_id0,related_to
714 if(document.EditView.name.value == '') { // cn: bug 7743, don't stomp populated Subject Line
715 document.EditView.name.value = decodeURI(encodeURI(json_objects['email_template_object']['fields']['subject']));
718 document.EditView.description.value += decodeURI(encodeURI(json_objects['email_template_object']['fields']['body'])).replace(/<BR>/ig, '\n');
719 var tiny = tinyMCE.getInstanceById("description_html");
720 var tinyHtml = tiny.getContent(true);
722 // cn: bug 10985 - IE6/7 will show inline image at top of screen if we set this with no valid target
723 if(document.getElementById('setEditor').checked == false) {
724 var descHtml = decodeURI(encodeURI(json_objects['email_template_object']['fields']['body_html'])).replace(/</gi,'<').replace(/>/gi,'>').replace(/<BR>/ig, '\n').replace(/'/gi,'\'').replace(/"/gi,'"');
726 // cn: bug 13376 - leave & to last to preserve certain HTML-entities for TinyMCE editor
727 descHtml = descHtml.replace(/&/gi,'&');
729 tiny.setContent(tinyHtml + descHtml);
732 var htmlDiv = document.getElementById('html_div');
734 // hide the HTML editor if this is Plain-text only
735 if((tinyHtml == '' || tinyHtml == '<br>') && htmlDiv.style.display == '') {
736 var desc = document.getElementById('description');
737 var plainText = new String(desc.value);
738 plainText = plainText.replace(/\n/gi, '<br />');
739 tiny.setContent(plainText);
742 // if the template is plain-text, then uncheck "Send HTML Email"
743 document.getElementById('setEditor').checked = true;
748 if(typeof SugarClass == "object") {
749 SugarClass.inherit("EmailJsonObj","SugarClass");
751 function EmailJsonObj() {
753 EmailJsonObj.prototype.display = function(result) {
755 var block = document.getElementById('template_attachments');
756 var target = block.innerHTML;
760 if(typeof result[i] == 'object') {
762 full_file_path = file_path + bean['id']+bean['filename'];
763 target += '\n<input type="hidden" name="template_attachment[]" value="' + bean['id'] + '">';
764 target += '\n<input type="checkbox" name="temp_remove_attachment[]" value="' + bean['id'] + '"> '+ lnk_remove + ' ';
765 target += '<a href="' + full_file_path + '"target="_blank">' + bean['filename'] + '</a><br>';
768 block.innerHTML = target;
771 ejo = new EmailJsonObj();
772 //// END EMAIL TEMPLATE CODE
773 ///////////////////////////////////////////////////////////////////////////////
776 function fill_form(type, error_text) {
777 if(document.getElementById('subjectfield').value == '') {
778 var sendAnyways = confirm(lbl_send_anyways);
779 if(sendAnyways == false) { return false; }
782 if(type == 'out' && document.EditView.to_addrs.value == '' &&
783 document.EditView.cc_addrs.value == '' &&
784 document.EditView.bcc_addrs.value == '') {
790 var the_form = document.EditView;
791 var inputs = the_form.getElementsByTagName('input');
793 // this detects if browser needs the following hack or not..
794 if(inputs.length > 0) {
795 // no need to appendChild to EditView to get file uploads to work
796 return check_form('EditView');
799 if(! check_form('EditView')) {
805 function setLabels(uploads_arr) {
810 //this function appends the selected email address to the aggregated email address fields.
811 function set_current_parent(id,email,name,value) {
812 current_contact_id.value += id+";";
813 current_contact_email.value += email+";";
814 current_contact_name.value += name+";";
816 if(current_contact.value != '') {
817 current_contact.value += "; ";
820 current_contact.value += name + " <" + email + ">";
821 // current_contact.value += value;
824 function set_email_return(popup_reply_data) {
825 var form_name = popup_reply_data.form_name;
826 var name_to_value_array = popup_reply_data.name_to_value_array;
827 if (typeof name_to_value_array == "object" ) {
828 update_email_addresses(form_name,name_to_value_array);
830 for(var i in name_to_value_array) {
831 update_email_addresses(form_name,name_to_value_array[i]);
836 function update_email_addresses(form_name,name_to_value) {
837 for(var the_key in name_to_value) {
838 if(the_key == 'toJSON') {
841 var displayValue = name_to_value[the_key];
842 displayValue=displayValue.replace(''',"'"); //restore escaped single quote.
843 displayValue=displayValue.replace('&',"&"); //restore escaped &.
844 displayValue=displayValue.replace('>',">"); //restore escaped >.
845 displayValue=displayValue.replace('<',"<"); //restore escaped <.
846 displayValue=displayValue.replace('" ',"\""); //restore escaped ".
848 window.document.forms[form_name].elements[the_key].value += displayValue + '; ';
853 //create references to input fields associated with the select email address button.
854 //Clicked button is passed as the parameter to the function.
855 function button_change_onclick(obj) {
857 if(obj.name.match(/^cc_/i)) {
859 } else if(obj.name.match(/^bcc_/i)) {
863 for(var i = 0; i < obj.form.length;i++) {
865 if(child.name.indexOf(prefix) != 0) {
869 if(child.name.match(/addrs_emails$/i)) {
870 current_contact_email = child;
871 } else if(child.name.match(/addrs_ids$/i)) {
872 current_contact_id = child;
873 } else if(child.name.match(/addrs_names$/i)) {
874 current_contact_name = child;
875 } else if(child.name.match(/addrs$/i)) {
876 current_contact = child;
883 if(document.EditView.parent_type.value == 'Accounts' && typeof(document.EditView.parent_name.value) != 'undefined' && document.EditView.parent_name.value != '') {
884 filter = "&form_submit=false&query=true&html=Email_picker&account_name=" + escape(document.EditView.parent_name.value);
885 acct_name = document.EditView.parent_name.value;
888 var popup_request_data =
890 "call_back_function" : "set_email_return",
891 "form_name" : "EditView",
892 "field_to_name_array" :
894 "id" : prefix + "addrs_ids",
895 "email1" : prefix + "addrs_emails",
896 "name" : prefix + "addrs_names",
897 "email_and_name1" : prefix + "addrs_field"
901 return open_popup("Contacts", 600, 400, filter, true, false, popup_request_data, 'MultiSelect', false, 'popupdefsEmail');
904 //this function clear the value stored in the aggregated email address fields(nodes).
905 //it relies on the references set by the button_change_onclick method
906 function clear_email_addresses() {
908 if(current_contact != '') {
909 current_contact.value = '';
911 if(current_contact_id != '') {
912 current_contact_id.value = '';
914 if(current_contact_email != '') {
915 current_contact_email.value = '';
917 if(current_contact_name != '') {
918 current_contact_name.value = '';
922 function quick_create_overlib(id, theme) {
923 return overlib('<a style=\'width: 150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,"yes");\' onmouseout=\'unhiliteItem(this);\' href=\'index.php?module=Cases&action=EditView&inbound_email_id=' + id + '\'>' +
924 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Cases.gif' style='margin-right:5px'>" + SUGAR.language.get('Emails', 'LBL_LIST_CASE') + '</a>' +
925 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Leads&action=EditView&inbound_email_id=" + id + "'>" +
926 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Leads.gif' style='margin-right:5px'>"
927 + SUGAR.language.get('Emails', 'LBL_LIST_LEAD') + "</a>" +
928 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Contacts&action=EditView&inbound_email_id=" + id + "'>" +
929 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Contacts.gif' style='margin-right:5px'>"
930 + SUGAR.language.get('Emails', 'LBL_LIST_CONTACT') + "</a>" +
931 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Bugs&action=EditView&inbound_email_id=" + id + "'>"+
932 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Bugs.gif' style='margin-right:5px'>"
933 + SUGAR.language.get('Emails', 'LBL_LIST_BUG') + "</a>" +
934 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Tasks&action=EditView&inbound_email_id=" + id + "'>" +
935 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Tasks.gif' style='margin-right:5px'>"
936 + SUGAR.language.get('Emails', 'LBL_LIST_TASK') + "</a>"
937 , CAPTION, SUGAR.language.get('Emails', 'LBL_QUICK_CREATE')
938 , STICKY, MOUSEOFF, 3000, CLOSETEXT, '<img border=0 style="margin-left:2px; margin-right: 2px;" src="index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=close.gif">', WIDTH, 150, CLOSETITLE, SUGAR.language.get('app_strings', 'LBL_ADDITIONAL_DETAILS_CLOSE_TITLE'), CLOSECLICK, FGCLASS, 'olOptionsFgClass',
939 CGCLASS, 'olOptionsCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olOptionsCapFontClass', CLOSEFONTCLASS, 'olOptionsCloseFontClass');