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 = sugar_cache_dir + '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")
492 var imglocation = unescape(document.location.pathname.substr(1));
493 imglocation = imglocation.substring(0,imglocation.lastIndexOf('/')+1);
494 imglocation='/'+imglocation+sugar_upload_dir;
495 embedImage='<img src='+imglocation+documentRevisionId+'>';
496 embedImage1='<img src=cid:'+documentRevisionId+' width="1" height="1" >';
497 insert_variable(embedImage);
500 new_row_chk_box.checked =false;
505 var SugarDoc = document.createElement("img");
506 SugarDoc.setAttribute("src", "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=sugar_document.png");
507 SugarDoc.setAttribute("align","absmiddle");
508 SugarDoc.setAttribute("alt",lbl_email_attachments_document);
509 SugarDoc.setAttribute("border","0");
510 SugarDoc.setAttribute("height","16");
511 SugarDoc.setAttribute("width","16");
514 //elm.appendChild(eah);
515 elm.appendChild(SugarDoc);
516 elm.appendChild(new_row_button_embed);
517 elm.appendChild(new_row_chk_box);
518 elm.appendChild(eah);
519 elm.appendChild(attId);
520 elm.appendChild(attType);
522 elm.appendChild(eai);
523 elm.style.display = 'block';
525 var rN= document.getElementById('attachments_div');
530 function addUploadFiles(form_name) {
531 var chForm = document.getElementById('upload_div');
532 var theForm = document.getElementById(form_name);
533 var elems = chForm.getElementsByTagName("input");
534 //get the count of all the email_attachment file elements
536 //Use the count to add the documents
537 count=this.multi_selector.id;
538 for (var i=0; i<count-1; i++) {
539 // find out all the email_attachments and append to the EditView form
540 var el = document.getElementsByName('email_attachment'+i);
542 theForm.appendChild(el[0]);
545 var chForm = document.getElementById("upload_form");
546 var elems = chForm.getElementsByTagName("input");
548 for (var i=0; i<elems.length; i++) {
549 //find out all the email_attachments and append to the EditView form
551 //var el = document.getElementsByName('checkBoxFile[]');
552 if(el.id == 'checkBoxFile[]'){
553 var eah = document.createElement('input');
554 eah.setAttribute('id', 'embedded'+num);
555 eah.setAttribute('name', 'embedded'+num);
556 eah.setAttribute('tabindex', '120');
557 eah.setAttribute('type', 'hidden');
558 eah.setAttribute('value',el.checked);
560 theForm.appendChild(eah);
565 function addUploadDocs(form_name) {
566 var chForm = document.getElementById("upload_form");
567 var theForm = document.getElementById(form_name);
568 var attDiv = document.getElementById("attachments_div");
569 var elems = chForm.getElementsByTagName("input");
570 var elems1 = attDiv.getElementsByTagName("input");
571 for (var i=0; i<elems1.length; i++) {
572 //if (elems[i].type == "file") {
574 if(el.id=='document[]') {
575 theForm.appendChild(el);
578 for (var i=0; i<elems.length; i++) {
579 //if (elems[i].type == "file") {
582 if(el.id=='document[]') {
583 theForm.appendChild(el);
585 if(el.id.indexOf('documentId')>=0 || el.id=='document[]') {
586 theForm.appendChild(el);
591 function form_reset_doc() {
592 // var theForm = document.getElementById('upload_form');
593 var theForm = document.getElementById('upload_div');
594 var elems = theForm.getElementsByTagName("input");
595 for (var i=0; i<elems.length; i++) {
596 if (elems[i].type == "text" || "hidden" ) {
598 if(el.id == 'documentName') {
599 var new_el =document.createElement('input');
600 new_el.type = 'hidden';
601 new_el.name = el.name;
603 new_el.onchange = el.onchange;
604 //new_el.disabled=true;
605 //new_el.style.visibility="hidden";
607 el.parentNode.replaceChild(new_el, el);
608 // el.parentNode.insertBefore(new_el, el);
609 // el.parentNode.removeChild(el);
611 if(el.id == 'documentId') {
612 var new_el =document.createElement('input');
613 new_el.type = 'hidden';
614 new_el.name = el.name;
616 //new_el.onchange = el.onchange;
617 //new_el.DISABLED='true';
618 el.parentNode.replaceChild(new_el, el);
619 // el.parentNode.insertBefore(new_el, el);
620 // el.parentNode.removeChild(el);
627 function selectDoc() {
628 URL="index.php?module=EmailTemplates&action=PopupDocumentsCampaignTemplate&to_pdf=true&target=" ;
629 windowName = 'selectDocument';
630 windowFeatures = 'width=800' + ',height=600' + ',resizable=1,scrollbars=1';
632 win = SUGAR.util.openWindow(URL, windowName, windowFeatures);
634 // put the focus on the popup if the browser supports the focus() method
638 ///////////////////////////////////////////////////////////////////////////////
639 //// HTML/PLAIN EDITOR FUNCTIONS
640 function setEditor() {
641 if(document.getElementById('setEditor').checked == true) {
646 // cn: bug 9690 - unchecked "Send HTML" - we hose the html_div contents
647 function prepSave() {
648 if(document.getElementById('setEditor').checked == true) {
649 document.getElementById('html_div').innerHTML = '';
654 function toggle_textonly() {
655 var altText = document.getElementById('alt_text_div');
656 var plain = document.getElementById('text_div');
657 var html = document.getElementById('html_div');
659 var desc = document.getElementById('description');
660 var tiny = tinyMCE.getInstanceById('description_html');
662 // toggling INTO HTML editting
663 if(html.style.display == 'none') {
664 html.style.display = 'block';
665 if(document.getElementById('toggle_textarea_elem').checked == false) {
666 plain.style.display = 'none';
668 altText.style.display = 'block';
670 var plainText = new String(desc.value);
671 plainText = plainText.replace(/\n/gi, '<br />');
672 tiny.setContent(plainText);
674 // toggling into Plain Text ONLY
675 html.style.display = 'none';
676 plain.style.display = 'block';
677 altText.style.display = 'none';
679 if(tiny.getContent()) {
680 var htmlText = new String(tiny.getContent());
681 htmlText = htmlText.replace(/<br \/>/gi, "\n");
682 htmlText = htmlText.replace(/>/gi, ">");
683 htmlText = htmlText.replace(/</gi, "<");
684 htmlText = htmlText.replace(/ /gi, " ");
685 desc.value = stripTags(htmlText);
690 function stripTags(str) {
691 var theText = new String(str);
693 if(theText != 'undefined') {
694 return theText.replace(/<\/?[^>]+>/gi, '');
698 function toggle_textarea() {
699 var checkbox = document.getElementById('toggle_textarea_elem');
700 var plain = document.getElementById('text_div');
702 if (checkbox.checked == false) {
703 plain.style.display = 'none';
705 plain.style.display = 'block';
708 //// END HTML/PLAIN EDITOR FUNCTIONS
709 ///////////////////////////////////////////////////////////////////////////////
714 ///////////////////////////////////////////////////////////////////////////////
715 //// EMAIL TEMPLATE CODE
716 function appendEmailTemplateJSON() {
717 // query based on template, contact_id0,related_to
718 if(document.EditView.name.value == '') { // cn: bug 7743, don't stomp populated Subject Line
719 document.EditView.name.value = decodeURI(encodeURI(json_objects['email_template_object']['fields']['subject']));
722 document.EditView.description.value += decodeURI(encodeURI(json_objects['email_template_object']['fields']['body'])).replace(/<BR>/ig, '\n');
723 var tiny = tinyMCE.getInstanceById("description_html");
724 var tinyHtml = tiny.getContent(true);
726 // cn: bug 10985 - IE6/7 will show inline image at top of screen if we set this with no valid target
727 if(document.getElementById('setEditor').checked == false) {
728 var descHtml = decodeURI(encodeURI(json_objects['email_template_object']['fields']['body_html'])).replace(/</gi,'<').replace(/>/gi,'>').replace(/<BR>/ig, '\n').replace(/'/gi,'\'').replace(/"/gi,'"');
730 // cn: bug 13376 - leave & to last to preserve certain HTML-entities for TinyMCE editor
731 descHtml = descHtml.replace(/&/gi,'&');
733 tiny.setContent(tinyHtml + descHtml);
736 var htmlDiv = document.getElementById('html_div');
738 // hide the HTML editor if this is Plain-text only
739 if((tinyHtml == '' || tinyHtml == '<br>') && htmlDiv.style.display == '') {
740 var desc = document.getElementById('description');
741 var plainText = new String(desc.value);
742 plainText = plainText.replace(/\n/gi, '<br />');
743 tiny.setContent(plainText);
746 // if the template is plain-text, then uncheck "Send HTML Email"
747 document.getElementById('setEditor').checked = true;
752 if(typeof SugarClass == "object") {
753 SugarClass.inherit("EmailJsonObj","SugarClass");
755 function EmailJsonObj() {
757 EmailJsonObj.prototype.display = function(result) {
759 var block = document.getElementById('template_attachments');
760 var target = block.innerHTML;
764 if(typeof result[i] == 'object') {
766 full_file_path = file_path + bean['id']+bean['filename'];
767 target += '\n<input type="hidden" name="template_attachment[]" value="' + bean['id'] + '">';
768 target += '\n<input type="checkbox" name="temp_remove_attachment[]" value="' + bean['id'] + '"> '+ lnk_remove + ' ';
769 target += '<a href="' + full_file_path + '"target="_blank">' + bean['filename'] + '</a><br>';
772 block.innerHTML = target;
775 ejo = new EmailJsonObj();
776 //// END EMAIL TEMPLATE CODE
777 ///////////////////////////////////////////////////////////////////////////////
780 function fill_form(type, error_text) {
781 if(document.getElementById('subjectfield').value == '') {
782 var sendAnyways = confirm(lbl_send_anyways);
783 if(sendAnyways == false) { return false; }
786 if(type == 'out' && document.EditView.to_addrs.value == '' &&
787 document.EditView.cc_addrs.value == '' &&
788 document.EditView.bcc_addrs.value == '') {
794 var the_form = document.EditView;
795 var inputs = the_form.getElementsByTagName('input');
797 // this detects if browser needs the following hack or not..
798 if(inputs.length > 0) {
799 // no need to appendChild to EditView to get file uploads to work
800 return check_form('EditView');
803 if(! check_form('EditView')) {
809 function setLabels(uploads_arr) {
814 //this function appends the selected email address to the aggregated email address fields.
815 function set_current_parent(id,email,name,value) {
816 current_contact_id.value += id+";";
817 current_contact_email.value += email+";";
818 current_contact_name.value += name+";";
820 if(current_contact.value != '') {
821 current_contact.value += "; ";
824 current_contact.value += name + " <" + email + ">";
825 // current_contact.value += value;
828 function set_email_return(popup_reply_data) {
829 var form_name = popup_reply_data.form_name;
830 var name_to_value_array = popup_reply_data.name_to_value_array;
831 if (typeof name_to_value_array == "object" ) {
832 update_email_addresses(form_name,name_to_value_array);
834 for(var i in name_to_value_array) {
835 update_email_addresses(form_name,name_to_value_array[i]);
840 function update_email_addresses(form_name,name_to_value) {
841 for(var the_key in name_to_value) {
842 if(the_key == 'toJSON') {
845 var displayValue = name_to_value[the_key];
846 displayValue=displayValue.replace(''',"'"); //restore escaped single quote.
847 displayValue=displayValue.replace('&',"&"); //restore escaped &.
848 displayValue=displayValue.replace('>',">"); //restore escaped >.
849 displayValue=displayValue.replace('<',"<"); //restore escaped <.
850 displayValue=displayValue.replace('" ',"\""); //restore escaped ".
852 window.document.forms[form_name].elements[the_key].value += displayValue + '; ';
857 //create references to input fields associated with the select email address button.
858 //Clicked button is passed as the parameter to the function.
859 function button_change_onclick(obj) {
861 if(obj.name.match(/^cc_/i)) {
863 } else if(obj.name.match(/^bcc_/i)) {
867 for(var i = 0; i < obj.form.length;i++) {
869 if(child.name.indexOf(prefix) != 0) {
873 if(child.name.match(/addrs_emails$/i)) {
874 current_contact_email = child;
875 } else if(child.name.match(/addrs_ids$/i)) {
876 current_contact_id = child;
877 } else if(child.name.match(/addrs_names$/i)) {
878 current_contact_name = child;
879 } else if(child.name.match(/addrs$/i)) {
880 current_contact = child;
887 if(document.EditView.parent_type.value == 'Accounts' && typeof(document.EditView.parent_name.value) != 'undefined' && document.EditView.parent_name.value != '') {
888 filter = "&form_submit=false&query=true&html=Email_picker&account_name=" + escape(document.EditView.parent_name.value);
889 acct_name = document.EditView.parent_name.value;
892 var popup_request_data =
894 "call_back_function" : "set_email_return",
895 "form_name" : "EditView",
896 "field_to_name_array" :
898 "id" : prefix + "addrs_ids",
899 "email1" : prefix + "addrs_emails",
900 "name" : prefix + "addrs_names",
901 "email_and_name1" : prefix + "addrs_field"
905 return open_popup("Contacts", 600, 400, filter, true, false, popup_request_data, 'MultiSelect', false, 'popupdefsEmail');
908 //this function clear the value stored in the aggregated email address fields(nodes).
909 //it relies on the references set by the button_change_onclick method
910 function clear_email_addresses() {
912 if(current_contact != '') {
913 current_contact.value = '';
915 if(current_contact_id != '') {
916 current_contact_id.value = '';
918 if(current_contact_email != '') {
919 current_contact_email.value = '';
921 if(current_contact_name != '') {
922 current_contact_name.value = '';
926 function quick_create_overlib(id, theme) {
927 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 + '\'>' +
928 "<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>' +
929 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Leads&action=EditView&inbound_email_id=" + id + "'>" +
930 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Leads.gif' style='margin-right:5px'>"
931 + SUGAR.language.get('Emails', 'LBL_LIST_LEAD') + "</a>" +
932 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Contacts&action=EditView&inbound_email_id=" + id + "'>" +
933 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Contacts.gif' style='margin-right:5px'>"
934 + SUGAR.language.get('Emails', 'LBL_LIST_CONTACT') + "</a>" +
935 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Bugs&action=EditView&inbound_email_id=" + id + "'>"+
936 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Bugs.gif' style='margin-right:5px'>"
937 + SUGAR.language.get('Emails', 'LBL_LIST_BUG') + "</a>" +
938 "<a style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,\"yes\");' onmouseout='unhiliteItem(this);' href='index.php?module=Tasks&action=EditView&inbound_email_id=" + id + "'>" +
939 "<img border='0' src='index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=Tasks.gif' style='margin-right:5px'>"
940 + SUGAR.language.get('Emails', 'LBL_LIST_TASK') + "</a>"
941 , CAPTION, SUGAR.language.get('Emails', 'LBL_QUICK_CREATE')
942 , 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',
943 CGCLASS, 'olOptionsCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olOptionsCapFontClass', CLOSEFONTCLASS, 'olOptionsCloseFontClass');