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 ********************************************************************************/
38 Event = YAHOO.util.Event,
39 Connect = YAHOO.util.Connect,
43 ///////////////////////////////////////////////////////////////////////////////
46 _contactCache : new Array(), // cache of contacts
47 _dd : new Array(), // filtered list, same format as _contactCache
48 _ddLists : new Array(), // list of Lists
49 _dd_mlUsed : new Array(), // contacts in mailing list edit view column1
50 _dd_mlAvailable : new Array(), // contacts in mailing list edit view column2
51 clickBubble : true, // hack to get around onclick event bubbling
56 itemSpacing : 'white-space:nowrap; padding:2px;',
62 * YUI bug fix 2527707. Causes nested datatable's in <tables> to cause 404 errors whens earching.
64 initFixForDatatableSort: function () {
65 //Workaround for YUI bug 2527707: http://yuilibrary.com/projects/yui2/ticket/913efafad48ce433199f3e72e4847b18, should be removed when YUI 2.8+ is used
66 YAHOO.widget.DataTable.prototype.getColumn = function(column) {
67 var oColumn = this._oColumnSet.getColumn(column);
70 // Validate TD element
71 var elCell = column.nodeName.toLowerCase() != "th" ? this.getTdEl(column) : false;
73 oColumn = this._oColumnSet.getColumn(elCell.cellIndex);
75 // Validate TH element
77 elCell = this.getThEl(column);
80 var allColumns = this._oColumnSet.flat;
81 for(var i=0, len=allColumns.length; i<len; i++) {
82 if(allColumns[i].getThEl().id === elCell.id) {
83 oColumn = allColumns[i];
94 cancelEdit : function() {
95 if(this.editContactDialog)
96 this.editContactDialog.hide();
97 if(this.editMailingListDialog)
98 this.editMailingListDialog.hide();
105 var t = document.getElementById('contactsFilter');
111 * handle context-menu Compose-to call
112 * @param string type 'contacts' or 'lists'
114 composeTo : function(type, waited) {
115 var activePanel = SUGAR.email2.innerLayout.get("activeTab").get("id")
116 if (activePanel.substring(0, 10) != "composeTab") {
117 SE.composeLayout.c0_composeNewEmail();
118 setTimeout("SE.addressBook.composeTo('" + type + "', true);");
119 SE.contextMenus.contactsContextMenu.hide();
122 var idx = activePanel.substring(10);
125 // determine if we have a selection to work with
126 if(type == 'contacts') {
127 var ids = SE.contactView.getSelectedRows();
129 rows[i] = SE.contactView.getRecord(ids[i]);
131 removeHiddenNodes(rows, SE.contactView);
135 if(rows.length > 0) {
136 SE.composeLayout.handleDrop(
137 (type == 'contacts') ? SE.contactView : SE.emailListsView,
138 null, rows, 'addressTO' + idx );
140 alert(app_strings.LBL_EMAIL_MENU_MAKE_SELECTION);
144 editContact : function() {
145 SE.contextMenus.contactsContextMenu.hide();
146 var element = SE.contactView.getSelectedNodes()[0];
148 if (element.className.indexOf('address-contact') > -1) {
149 elementId = element.id;
150 } else if (element.className.indexOf('address-exp-contact') > -1) {
151 elementId = element.id.substring(2);
157 * Filters contact entries based on user input
159 filter : function(inputEl) {
160 var ret = new Object();
161 var re = new RegExp(inputEl.value, "gi");
163 for(var i in this._contactCache) {
164 if(this._contactCache[i].name.match(re)) {
165 ret[i] = this._contactCache[i];
169 this.buildContactList(ret);
172 fullForm : function(id, module) {
173 document.location = "index.php?return_module=Emails&return_action=index&module=" + module + "&action=EditView&record=" + id;
177 * returns a formatted email address from the addressBook cache
179 getFormattedAddress : function(id) {
180 var o = this._contactCache[id];
181 var primaryEmail = '';
183 for(var i=0; i<o.email.length; i++) {
184 var currentEmail = o.email[i].email_address;
186 if(o.email[i].primary_address == 1) {
187 primaryEmail = o.email[i].email_address;
191 var finalEmail = (primaryEmail == "") ? currentEmail : primaryEmail;
192 var name = new String(o.name);
193 var finalName = name.replace(/(<([^>]+)>)/ig, "").replace(/'/gi,'\'');
194 var ret = finalName + " <" + finalEmail.replace(/'/gi,'\'') + ">";
200 * Sets up async call to query for matching contacts, users, etc.
202 searchContacts : function() {
203 var fn = document.getElementById('input_searchField').value;
204 var pe = document.getElementById('input_searchPerson').value;
206 var rb = document.getElementById('hasRelatedBean').checked;
209 var relatedBeanId = document.getElementById('data_parent_id' + idx).value;
210 var relatedBeanType = document.getElementById('data_parent_type' + idx).value;
211 this.addressBookDataModel.params['related_bean_id'] = relatedBeanId;
212 this.addressBookDataModel.params['related_bean_type'] = relatedBeanType;
214 this.addressBookDataModel.params['related_bean_id'] = '';
217 this.addressBookDataModel.params['search_field'] = fn;
218 this.addressBookDataModel.params['person'] = pe;
219 this.addressBookDataModel.params['emailUIAction'] = 'getAddressSearchResults';
220 this.grid._oDataSource = this.addressBookDataModel;
221 this.grid.getDataSource().sendRequest(SUGAR.util.paramsToUrl(this.addressBookDataModel.params), this.grid.onDataReturnInitializeTable, this.grid);
225 * Clear Search Crieteria For Addressbook
227 clearAddressBookSearch : function() {
228 document.getElementById('input_searchField').value = "";
229 document.getElementById('input_searchPerson').selectedIndex = 0;
233 * Opens modal select window to add contacts to addressbook
235 selectContactsDialogue : function(destId) {
236 if(!this.contactsDialogue) {
237 var dlg = this.contactsDialogue = new YAHOO.widget.Dialog("contactsDialogue", {
241 constraintoviewport: true,
243 buttons : [{text: app_strings.LBL_EMAIL_ADDRESS_BOOK_ADD, isDefault: true, handler: this.populateEmailAddressFieldsFromResultTable},
244 {text: app_strings.LBL_EMAIL_ADDRESS_BOOK_CLEAR, isDefault: true, handler: this.clearAllEmailAddressFieldsFromResultTable} ]
246 dlg.setHeader(app_strings.LBL_EMAIL_ADDRESS_BOOK_SELECT_TITLE);
248 var body = SUGAR.util.getAndRemove("contactsDialogueHTML");
249 dlg.setBody(body.innerHTML);
250 dlg.renderEvent.subscribe(function() {
251 var iev = YAHOO.util.Dom.get("contactsDialogueBody");
252 if (iev && !SUGAR.isIE) {
253 this.body.style.width = "950px";
258 dlg.beforeRenderEvent.subscribe(function() {
259 var dd = new YAHOO.util.DDProxy(dlg.element);
260 dd.setHandleElId(dlg.header);
261 dd.on('endDragEvent', function() {
267 var tp = new YAHOO.widget.TabView("contactsSearchTabs");
269 var tabContent = SUGAR.util.getAndRemove("searchForm");
270 tp.addTab(new YAHOO.widget.Tab({
271 label: app_strings.LBL_EMAIL_ADDRESS_BOOK_TITLE,
273 content : tabContent.innerHTML,
274 id : "addressSearchTab",
278 var addListenerFields = ['input_searchPerson','input_searchField' ]
279 YAHOO.util.Event.addListener(addListenerFields,"keydown", function(e){
280 if (e.keyCode == 13) {
281 YAHOO.util.Event.stopEvent(e);
282 SUGAR.email2.addressBook.searchContacts();
286 this.contactsDialogue.render();
289 //Quick Compose does not have an innerLayout component and will always be referenced with ix 0.
290 if (typeof(SUGAR.email2.innerLayout) == 'undefined')
294 var activePanel = SUGAR.email2.innerLayout.get("activeTab").get("id");
295 var idx = activePanel.substring(10);
297 SE.addressBook.idx = idx;
300 if ((hasRelatedBeanId = document.getElementById('data_parent_id' + idx).value) != '') {
301 document.getElementById('relatedBeanColumn').style.display = '';
302 var relatedBeanName = document.getElementById('data_parent_name' + idx).value;
303 var relatedBeanType = document.getElementById('data_parent_type' + idx).value;
304 relatedBeanId = document.getElementById('data_parent_id' + idx).value;
305 document.getElementById('relatedBeanInfo').innerHTML = ' ' + relatedBeanType + ' <b>' + relatedBeanName + '</b>';
306 SE.addressBook.relatedBeanType = relatedBeanType;
308 document.getElementById('relatedBeanColumn').style.display = 'none';
309 document.getElementById('hasRelatedBean').checked = false;
312 if (!SE.addressBook.grid)
314 if (hasRelatedBeanId) {
315 document.getElementById('hasRelatedBean').checked = true;
317 AddressSearchGridInit();
318 SE.addressBook.relatedBeanId = relatedBeanId;
322 if (typeof(relatedBeanId) != 'undefined' && relatedBeanId != SE.addressBook.relatedBeanId)
324 SE.addressBook.relatedBeanId = relatedBeanId;
325 document.getElementById('hasRelatedBean').checked = true;
327 if (document.getElementById('hasRelatedBean').checked == true)
329 SE.addressBook.addressBookDataModel.params['related_bean_id'] = relatedBeanId;
330 SE.addressBook.addressBookDataModel.params['related_bean_type'] = relatedBeanType;
332 SE.addressBook.addressBookDataModel.params['related_bean_id'] = '';
333 SE.addressBook.addressBookDataModel.params['related_bean_type'] = '';
335 SE.addressBook.addressBookDataModel.params['search_field'] = document.getElementById('input_searchField').value;;
336 SE.addressBook.addressBookDataModel.params['person'] = document.getElementById('input_searchPerson').value;
337 SE.addressBook.grid.getDataSource().sendRequest(SUGAR.util.paramsToUrl(SE.addressBook.addressBookDataModel.params), SE.addressBook.grid.onDataReturnInitializeTable, SE.addressBook.grid);
340 //Remove any lingering rows in the result set table if the module was closed.
341 SE.addressBook.gridResults.deleteRows(0, SUGAR.email2.addressBook.gridResults.getRecordSet().getLength());
343 SE.addressBook.populateResulstTableEmailAddresses();
345 this.contactsDialogue.show();
348 * Clear all email addresses from result table.
351 clearAllEmailAddressFieldsFromResultTable: function () {
352 SUGAR.email2.addressBook.gridResults.deleteRows(0, SUGAR.email2.addressBook.gridResults.getRecordSet().getLength());
353 //Unhighlight any rows currently selected if the emails were cleared.
354 SUGAR.email2.addressBook.grid.toggleSelectAll(false);
355 SUGAR.email2.addressBook.grid.reSelectRowsOnRender();
358 * Take all email address listed in the compose tab To|Cc|Bcc fields and re-populates the
359 * results table. This function is called when the address book is displayed.
361 populateResulstTableEmailAddresses: function () {
363 var idx = SE.addressBook.idx;
364 var emailFields = ['to','cc','bcc'];
366 for(var k=0;k<emailFields.length;k++)
368 var elKey = 'address' + emailFields[k].toUpperCase() + idx;
369 var allEmails = document.getElementById(elKey).value;
373 var formatedEmails = SE.composeLayout._getEmailArrayFromString(allEmails);
375 for (var i=0; i<formatedEmails.length; i++)
377 var t_name = formatedEmails[i].name;
378 var t_emailAddr = formatedEmails[i].email_address;
379 var displayEmail = t_name + ' <' + t_emailAddr + '>';
381 t_name = displayEmail = t_emailAddr;
383 var addressType = SE.addressBook.translateAddresType(emailFields[k],true);
384 SUGAR.email2.addressBook.gridResults.addRow({'type':addressType,'name':t_name,'email_address': t_emailAddr,
385 'display_email_address': displayEmail,'bean_id': -1,'idx' : SE.addressBook.idx});
391 * Checks all entries in the result table against a particular email address, returning true
392 * if the email address is found, false otherwise.
394 doesEmailAdddressExistInResultTable: function(emailAddress)
396 if(trim(emailAddress) == '')
399 var emailAddressFound = false;
400 var contacts = SE.addressBook.gridResults.getRecordSet().getRecords();
401 for (var i=0; i < contacts.length; i++)
403 var data = SE.addressBook.gridResults.getRecord(contacts[i]).getData();
404 //If we are adding to cc or bcc fields, make them visible.
405 if(data.email_address == emailAddress)
407 emailAddressFound = true;
412 return emailAddressFound;
415 * Takes all email addresses that the users wishes to add from the address book and populates the To
416 * fields on the compose tab.
418 populateEmailAddressFieldsFromResultTable: function()
420 //Clear the fields first, all email addresses are stored in the address book
421 var idx = SE.addressBook.idx;
422 var emailFields = ['to','cc','bcc'];
423 for(var k=0;k<emailFields.length;k++)
425 var elKey = 'address' + emailFields[k].toUpperCase() + idx;
426 document.getElementById(elKey).value = "";
429 var contacts = SE.addressBook.gridResults.getRecordSet().getRecords();
430 for (var i=0; i < contacts.length; i++)
432 var data = SE.addressBook.gridResults.getRecord(contacts[i]).getData();
434 var addressTypeKey = SE.addressBook.translateAddresType(data.type,false);
435 //If we are adding to cc or bcc fields, make them visible.
436 if(addressTypeKey =='cc' || addressTypeKey =='bcc')
437 SE.composeLayout.showHiddenAddress(addressTypeKey,data.idx);
438 //Construct the target id
439 var target_id = 'address' + addressTypeKey.toUpperCase() + data.idx
441 var target = document.getElementById(target_id);
442 target.value = SE.addressBook.smartAddEmailAddressToComposeField(target.value, data.display_email_address);
445 //Delete all rows from the result set table
446 SUGAR.email2.addressBook.gridResults.deleteRows(0, SUGAR.email2.addressBook.gridResults.getRecordSet().getLength());
449 SE.addressBook.contactsDialogue.hide()
452 * Insert contacts into the result table.
454 insertContactToResultTable : function(event,address_type) {
456 var contactsDialogue = SE.addressBook.contactsDialogue;
457 var contacts = SE.addressBook.grid.getSelectedRows();
459 var rows = SUGAR.email2.addressBook.grid.getRecordSet().getRecords();
460 for (var i = 0; i < rows.length; i++)
462 if (typeof(rows[i]) != "undefined" && rows[i].getData().checked )
464 var recId = SE.addressBook.grid.getRecord(rows[i]).getId();
465 SE.addressBook.insertContactRowToResultTable(recId,address_type);
466 SUGAR.email2.addressBook.grid.selectRow(rows[i]);
467 rows[i].setData("selected",true);
470 var checkBoxes = SUGAR.email2.addressBook.grid.get("element").getElementsByTagName('input');
471 for (var i = 0; i < checkBoxes.length; i++) {
472 checkBoxes[i].checked = false;
478 insertContactRowToResultTable : function(rowId, addressType) {
479 var data = SE.addressBook.grid.getRecord(rowId).getData();
480 if(SE.addressBook.doesGridResultsEntryExist(data.email) )
482 var name = data.name.replace(/'/gi,'\'').replace(/"/gi,'"');
483 var ea = name + ' <' + data.email.replace(/'/gi,'\'') + '>';
484 if(addressType == null)
485 addressType = app_strings.LBL_EMAIL_ADDRESS_BOOK_ADD_TO.replace(/:$/,''); //Default to To when using the plus icon.
486 SUGAR.email2.addressBook.gridResults.addRow({'type':addressType,'name':name,'email_address': data.email,'display_email_address': ea,'bean_id': data.bean_id,'idx' : SE.addressBook.idx});
489 * Remove a row from the gridsResult table.
491 removeRowFromGridResults : function(rowId,emailAddress)
493 var contacts = SE.addressBook.gridResults.getRecordSet().getRecords();
494 for (var i=0; i < contacts.length; i++)
496 var rec = SE.addressBook.gridResults.getRecord(contacts[i]);
497 var data = rec.getData();
498 if(data.email_address == emailAddress)
500 SUGAR.email2.addressBook.gridResults.deleteRow(rec.getId());
505 SUGAR.email2.addressBook.toggleSearchRowIcon(rowId,true);
508 * Translates between the addressType To|Cc|Bcc labels/keys.
510 translateAddresType: function(addressType,fromKey)
512 var displayTo = app_strings.LBL_EMAIL_ADDRESS_BOOK_ADD_TO.replace(/:$/,'');
513 var displayCc = app_strings.LBL_EMAIL_ADDRESS_BOOK_ADD_CC.replace(/:$/,'');
514 var displayBcc = app_strings.LBL_EMAIL_ADDRESS_BOOK_ADD_BCC.replace(/:$/,'');
515 var mappingObject = {};
518 mappingObject = {'to':displayTo, 'cc':displayCc, 'bcc':displayBcc};
521 mappingObject[displayTo] = 'to'; //Cant use object literal with variable variable.
522 mappingObject[displayCc] = 'cc';
523 mappingObject[displayBcc] = 'bcc';
526 return typeof(mappingObject[addressType]) != 'undefined' ? mappingObject[addressType] : '';
532 toggleSearchRowIcon : function(rowId,show)
536 var idToShow = rowId + '_add_img';
537 var idToHide = rowId + '_rm_img';
541 var idToShow = rowId + '_rm_img';
542 var idToHide = rowId + '_add_img';
546 Dom.addClass(idToHide, "yui-hidden");
547 Dom.removeClass(idToShow, "yui-hidden");
550 * Determine if an entry has already been added to the grid results table to prevent duplicates.
552 doesGridResultsEntryExist: function(emailAddrs)
555 var contactExists = false;
556 var contacts = SE.addressBook.gridResults.getRecordSet().getRecords();
557 for (var i=0; i < contacts.length; i++)
559 var data = SE.addressBook.gridResults.getRecord(contacts[i]).getData();
560 if(data.email_address == emailAddrs)
562 contactExists = true;
566 return contactExists;
570 * adds an email address to a string, but first checks if it exists
571 * @param string concat The string we are appending email addresses to
572 * @param string addr Email address to add
575 smartAddEmailAddressToComposeField : function(concat, addr) {
576 var re = new RegExp(addr);
578 if(!concat.match(re)) {
580 concat += "; " + addr;
589 //// END ADDRESS BOOK
590 ///////////////////////////////////////////////////////////////////////////////
594 ///////////////////////////////////////////////////////////////////////////////
597 * Auto-complete object
601 delimChar : [";", ","],
605 prehighlightClassName : "yui-ac-prehighlight",
608 instances : new Array(),
611 * Parses an addressBook entry looking for primary address. If not found, it will return the last found address.
612 * @param object Contact from AddressBook
615 getPrimaryAddress : function(contact) {
616 var address = app_strings.LBL_EMAIL_ADDRESS_BOOK_NOT_FOUND;
618 for(var eIndex in contact.email) {
619 address = contact.email[eIndex].email_address;
620 if(contact.email[eIndex].primary_address == 1) {
621 return contact.email[eIndex].email_address;
629 * initializes autocomplete widgets for a given compose view
632 init : function(idx) {
633 var ds = new YAHOO.widget.DS_JSArray(this.returnDataSource(SE.addressBook._contactCache), {
634 "queryMatchContains" : false,
635 "queryMatchSubset" : true
638 this.instances[idx] = {
645 // instantiate the autoComplete widgets
646 this.instances[idx]['to'] = new YAHOO.widget.AutoComplete('addressTO'+idx, "addressToAC"+idx, ds, this.config);
647 this.instances[idx]['cc'] = new YAHOO.widget.AutoComplete('addressCC'+idx, "addressCcAC"+idx, ds, this.config);
648 this.instances[idx]['bcc'] = new YAHOO.widget.AutoComplete('addressBCC'+idx, "addressBccAC"+idx, ds, this.config);
650 // enable hiding of interfering textareas
651 this.instances[idx]['to'].containerExpandEvent.subscribe(SE.autoComplete.toggleTextareaHide);
652 this.instances[idx]['cc'].containerExpandEvent.subscribe(SE.autoComplete.toggleTextareaHide);
653 this.instances[idx]['bcc'].containerExpandEvent.subscribe(SE.autoComplete.toggleTextareaHide);
655 // enable reshowing of hidden textareas
656 this.instances[idx]['to'].containerCollapseEvent.subscribe(SE.autoComplete.toggleTextareaShow);
657 this.instances[idx]['cc'].containerCollapseEvent.subscribe(SE.autoComplete.toggleTextareaShow);
658 this.instances[idx]['bcc'].containerCollapseEvent.subscribe(SE.autoComplete.toggleTextareaShow);
660 // enable refreshes of contact lists
661 this.instances[idx]['to'].textboxFocusEvent.subscribe(SE.autoComplete.refreshDataSource);
662 this.instances[idx]['cc'].textboxFocusEvent.subscribe(SE.autoComplete.refreshDataSource);
663 this.instances[idx]['bcc'].textboxFocusEvent.subscribe(SE.autoComplete.refreshDataSource);
666 refreshDataSource : function(sType, aArgs) {
667 var textBoxId = aArgs[0].getInputEl().id; // "addressTo0"
669 var refresh = SE.autoComplete.returnDataSource(SE.addressBook._contactCache);
671 if(textBoxId.indexOf("addressTO") > -1 || textBoxId.indexOf("addressCC") > -1) {
672 idx = textBoxId.substr(9);
674 idx = textBoxId.substr(10);
677 SE.autoComplete.instances[idx]['to'].dataSource.data = refresh;
678 SE.autoComplete.instances[idx]['cc'].dataSource.data = refresh;
679 SE.autoComplete.instances[idx]['bcc'].dataSource.data = refresh;
683 * Parses AddressBook entries to return an appropriate DataSource array for YUI.autoComplete
685 returnDataSource : function(contacts) {
686 var ret = new Array();
687 for(var id in contacts) {
688 if (contacts[id].name) {
689 var primary = this.getPrimaryAddress(contacts[id]);
691 ret[ret.length] = contacts[id].name.replace(/<[\/]*b>/gi, '') + " <" + primary + ">";
692 //ret[ret.length] = contacts[id].name + " <" + primary + ">";
694 for(var emailIndex in contacts[id].email) {
695 ret[ret.length] = contacts[id].email[emailIndex].email_address;
704 * Hides address textareas to prevent autocomplete dropdown from being obscured
706 toggleTextareaHide : function(sType, aArgs) {
707 var textBoxId = aArgs[0]._oTextbox.id; // "addressTo0"
711 if(textBoxId.indexOf("addressTO") > -1) {
713 } else if(textBoxId.indexOf("addressCC") > -1) {
716 idx = textBoxId.substr(9);
718 // follow through if not BCC
720 var cc = document.getElementById("addressCC" + idx);
721 var bcc = document.getElementById("addressBCC" + idx);
725 cc.style.visibility = 'hidden';
727 bcc.style.visibility = 'hidden';
734 * Redisplays the textareas after an address is commited
736 toggleTextareaShow : function(sType, aArgs) {
737 var textBoxId = aArgs[0]._oTextbox.id; // "addressTo0"
741 if(textBoxId.indexOf("addressTO") > -1) {
743 } else if(textBoxId.indexOf("addressCC") > -1) {
746 idx = textBoxId.substr(9);
748 // follow through if not BCC
750 document.getElementById("addressCC" + idx).style.visibility = 'visible';
751 document.getElementById("addressBCC" + idx).style.visibility = 'visible';
756 //// END AUTOCOMPLETE
757 ///////////////////////////////////////////////////////////////////////////////
759 ///////////////////////////////////////////////////////////////////////////////
762 * expands the options sidebar
765 currentInstanceId : 0,
768 outboundAccountErrors : null,
769 loadedTinyInstances : {}, //Tracks which tinyMCE editors have initalized with html content.
771 showAddressDetails : function(e) {
772 var linkElement = document.getElementById("More"+e.id);
773 var spanElement = document.getElementById("Detail"+e.id);
774 var emailAddressList = e.value;
775 if(e.value.length > 96)
777 var resultArray = SE.composeLayout._getEmailArrayFromString(emailAddressList);
778 var displayArray = [];
779 for (var i=0; i<resultArray.length; i++)
781 var t_name = resultArray[i].name;
782 var t_emailAddr = resultArray[i].email_address;
784 displayArray.push('<br/><' + t_emailAddr + '>');
786 displayArray.push(t_name + '<br/><' + t_emailAddr + '>');
789 var result = displayArray.join('<br/>');
791 linkElement.style.display = "inline";
792 linkElement.style.height="10px";
793 linkElement.style.overflow="visible";
794 spanElement.innerHTML = result;
797 linkElement.style.display = "none";
802 * Given a string of email address, return an array containing the name portion (if available)
805 _getEmailArrayFromString : function (emailAddressList){
808 while ((results = reg.exec(emailAddressList)) != null)
810 orignial = results[0];
811 parsedResult = results[0].replace(';', ':::::');
812 emailAddressList = emailAddressList.replace (orignial, parsedResult);
816 while ((results = reg.exec(emailAddressList)) != null)
818 orignial = results[0];
819 parsedResult = results[0].replace(',', ':::::');
820 emailAddressList = emailAddressList.replace (orignial, parsedResult);
822 //Administrator <johndoe@som.com> ;1@somwhe.com;2@somwherecomplex.com,3@somwherecomplex.com;4@somwherecomplex.com,5@somwherecomplex.com,
823 var emailArr = emailAddressList.split(":::::");
824 var resultsArray = [];
826 for (var i=0; i<emailArr.length; i++)
828 var rposition = emailArr[i].indexOf('<');
829 var lposition = emailArr[i].indexOf('>');
831 if(trim(emailArr[i]) != '')
833 if(rposition != -1 && lposition != -1)
835 var t_name = emailArr[i].substr(0, rposition-1);
836 var t_emailAddr = emailArr[i].substr(rposition+1, (lposition-1 - rposition) );
837 resultsArray.push({'name':t_name, 'email_address': t_emailAddr});
841 resultsArray.push({'name':'', 'email_address': emailArr[i]});
847 ///////////////////////////////////////////////////////////////////////////
850 * Prepare bucket DIV and yui-ext tab panels
852 _0_yui : function() {
853 var idx = this.currentInstanceId;
855 var composeTab = new YAHOO.SUGAR.ClosableTab({
856 label: mod_strings.LNK_NEW_SEND_EMAIL,
858 content : "<div id='htmleditordiv" + idx + "'/>",
859 id : "composeTab" + idx,
860 closeMsg: app_strings.LBL_EMAIL_CONFIRM_CLOSE,
863 SE.innerLayout.addTab(composeTab);
865 // get template engine with template
866 if (!SE.composeLayout.composeTemplate) {
867 SE.composeLayout.composeTemplate = new YAHOO.SUGAR.Template(SE.templates['compose']);
870 // create Tab inner layout
871 var composePanel = this.getComposeLayout();
872 composePanel.getUnitByPosition("right").collapse();
873 composePanel.autoSize();
877 * Generate the quick compose layout
878 * @method getQuickComposeLayout
879 * @param {Pannel} parentPanel Parent pannel
880 * @param {Object} o Options
883 getQuickComposeLayout : function (parentPanel,o) {
884 var idx = SE.composeLayout.currentInstanceId;
886 //Before rendering the parent pannel we need to initalize the grid layout
887 parentPanel.beforeRenderEvent.subscribe(function() {
889 YAHOO.util.Event.onAvailable('htmleditordiv' + idx, function() {
890 SE.composeLayout._createComposeLayout(idx);
891 SE.composeLayout[idx].set('height', 350);
892 SE.composeLayout[idx].render();
896 //Wait until the Compose Layout has rendered, then add the
897 //options tab and perform the tiny initialization.
898 parentPanel.renderEvent.subscribe(function() {
900 YAHOO.util.Event.onAvailable('htmleditordiv' + idx, function() {
901 SE.composeLayout._initComposeOptionTabs(idx);
902 SE.composeLayout[idx].getUnitByPosition("right").collapse();
904 if (!SUGAR.util.isTouchScreen())
905 SE.composeLayout._1_tiny(false);
906 //Init templates and address book
907 SE.composeLayout._2_final();
909 SE.composeLayout.quickCreateComposePackage(o);
914 //Check if we have the div override for the shortcut bar
915 if(typeof o.menu_id != 'undefined') {
916 parentPanel.render(o.menu_id);
918 parentPanel.render(document.body);
921 return SE.composeLayout[idx];
924 * Fill in all fields into the quick compose layout.
925 * @method quickCreateComposePackage
926 * @param {Object} o Options
929 quickCreateComposePackage: function(o)
931 //If we have a compose package fill in defaults.
932 if (typeof(o.composePackage) != 'undefined')
934 composePackage = o.composePackage; //Set the compose data object
935 //Hijack this method called by composePackage as it's not need for quick creates.
936 SE.composeLayout.c0_composeNewEmail = function(){};
937 SE.composeLayout.composePackage(); //Fill in defaults.
940 getComposeLayout : function() {
941 var idx = SE.composeLayout.currentInstanceId;
943 this._createComposeLayout(idx);
944 SE.composeLayout[idx].render();
945 this._initComposeOptionTabs(idx);
947 return SE.composeLayout[idx];
951 * Create the layout manager for the compose window.
953 _createComposeLayout : function(idx)
955 SE.composeLayout[idx] = new YAHOO.widget.Layout('htmleditordiv' + idx, {
956 parent: SE.complexLayout,
966 SE.composeLayout.composeTemplate.exec({
967 'app_strings':app_strings,
968 'mod_strings':mod_strings,
970 'linkbeans_options' : linkBeans,
971 'idx' : SE.composeLayout.currentInstanceId
982 body: "<div class='composeRightTabs' id='composeRightTabs" + idx + "'/>",
985 header: app_strings.LBL_EMAIL_OPTIONS
991 * Create compose tab which will populate the 'right' container in the compose window.
993 _initComposeOptionTabs : function(idx)
995 var cTabs = new YAHOO.widget.TabView("composeRightTabs" + idx);
996 var tab = new YAHOO.widget.Tab({
997 label: app_strings.LBL_EMAIL_ATTACHMENT,
999 content : SUGAR.util.getAndRemove("divAttachments" + idx).innerHTML,
1000 id : "divAttachments" + idx,
1004 tab.layout = SE.composeLayout[idx];
1006 tab.on("activeChange", function(o){
1008 this.layout.getUnitByPosition("right").set("header", app_strings.LBL_EMAIL_ATTACHMENT);
1014 tab = new YAHOO.widget.Tab({
1015 label: app_strings.LBL_EMAIL_OPTIONS,
1017 content : SUGAR.util.getAndRemove("divOptions" + idx).innerHTML,
1018 id : "divOptions" + idx,
1022 tab.layout = SE.composeLayout[idx];
1023 tab.on("activeChange", function(o){
1025 this.layout.getUnitByPosition("right").set("header", app_strings.LBL_EMAIL_OPTIONS);
1030 SE.composeLayout[idx].autoSize = function() {
1031 var pEl = this.get("element").parentNode.parentNode.parentNode;
1032 this.set("height", pEl.clientHeight-30);
1036 SE.composeLayout[idx].rightTabs = cTabs;
1038 isParentTypeValid : function(idx) {
1039 var parentTypeValue = document.getElementById('data_parent_type' + idx).value;
1040 var parentNameValue = document.getElementById('data_parent_name' + idx).value;
1041 if (trim(parentTypeValue) == ""){
1042 alert(mod_strings.LBL_ERROR_SELECT_MODULE);
1048 isParentTypeAndNameValid : function(idx) {
1049 var parentTypeValue = document.getElementById('data_parent_type' + idx).value;
1050 var parentNameValue = document.getElementById('data_parent_name' + idx).value;
1051 var parentIdValue = document.getElementById('data_parent_id' + idx).value;
1052 if ((trim(parentTypeValue) != "" && trim(parentNameValue) == "") ||
1053 (trim(parentTypeValue) != "" && trim(parentNameValue) != "" && parentIdValue == "")){
1054 alert(mod_strings.LBL_ERROR_SELECT_MODULE_SELECT);
1060 callopenpopupForEmail2 : function(idx,options) {
1062 var formName = 'emailCompose' + idx;
1064 if(typeof(options) != 'undefined' && typeof(options.form_name) != 'undefined')
1065 formName = options.form_name;
1067 var parentTypeValue = document.getElementById('data_parent_type' + idx).value;
1068 var parentNameValue = document.getElementById('data_parent_name' + idx).value;
1069 if (!SE.composeLayout.isParentTypeValid(idx)) {
1072 open_popup(document.getElementById('data_parent_type' + idx).value,600,400,'&tree=ProductsProd',true,false,
1074 call_back_function:"SE.composeLayout.popupAddEmail",
1076 field_to_name_array:{
1077 id:'data_parent_id' + idx,
1078 name:'data_parent_name' + idx,
1083 popupAddEmail : function(o)
1085 var nameKey = "data_parent_name" + SE.composeLayout.currentInstanceId;
1086 var data = o.name_to_value_array;
1087 if (typeof (data[nameKey]) != "undefined" && data[nameKey] != ""
1088 && typeof (data["email1"]) != "undefined" && data["email1"] != "" && data["email1"] != "undefined")
1090 var target = Dom.get("addressTO" + SE.composeLayout.currentInstanceId);
1091 target.value = SE.addressBook.smartAddEmailAddressToComposeField(target.value, data[nameKey] + "<" + data.email1 + ">");
1098 _1_tiny : function(isReplyForward) {
1099 var idx = SE.composeLayout.currentInstanceId;
1100 var elId = SE.tinyInstances.currentHtmleditor = 'htmleditor' + idx;
1101 SE.tinyInstances[elId] = { };
1102 SE.tinyInstances[elId].ready = false;
1103 var t = tinyMCE.getInstanceById(elId);
1105 if(typeof(t) == 'undefined') {
1106 tinyMCE.execCommand('mceAddControl', false, elId);
1107 YAHOO.util.Event.onAvailable(elId + "_parent", function() {
1108 SE.composeLayout.resizeEditorSetSignature(idx,!isReplyForward);
1113 resizeEditorSetSignature : function(idx,setSignature)
1115 var instance = SE.util.getTiny(SE.tinyInstances.currentHtmleditor);
1117 if(typeof(instance) == 'undefined' || (typeof(SE.composeLayout.loadedTinyInstances[idx]) != 'undefined' && SE.composeLayout.loadedTinyInstances[idx] == false)) {
1118 setTimeout("SE.composeLayout.resizeEditorSetSignature(" + idx + ",'"+isReplyForward+"');",500);
1122 SE.composeLayout.resizeEditor(idx);
1124 setTimeout("SUGAR.email2.composeLayout.setSignature("+idx+");",250);
1129 resizeEditor : function(idx)
1131 var cof = Dom.get('composeOverFrame' + idx);
1132 var head = Dom.get('composeHeaderTable' + idx);
1133 var targetHeight = cof.clientHeight - head.clientHeight;
1134 var instance = SE.util.getTiny('htmleditor' + idx);
1137 var parentEl = Dom.get(instance.editorId + '_parent');
1138 var toolbar = Dom.getElementsByClassName("mceFirst", "tr", parentEl)[0];
1139 var contentEl = instance.contentAreaContainer;
1140 var iFrame = contentEl.firstChild;
1141 var tinMceToolbarOffset = 18;
1142 iFrame.style.height = (targetHeight - toolbar.offsetHeight - tinMceToolbarOffset) + "px";
1145 setTimeout("SE.composeLayout.resizeEditor("+idx+");",1000);
1150 * Initializes d&d, auto-complete, email templates
1152 _2_final : function() {
1153 var idx = SE.composeLayout.currentInstanceId;
1155 if(this.emailTemplates) {
1156 this.setComposeOptions(idx);
1158 //populate email template cache
1159 AjaxObject.target = '';
1160 AjaxObject.startRequest(callbackComposeCache, urlStandard + "&emailUIAction=fillComposeCache");
1163 // handle drop targets for addressBook
1164 var to = new YAHOO.util.DDTarget('addressTO' +idx, 'addressBookDD', {notifyDrop:this.handleDrop});
1165 var cc = new YAHOO.util.DDTarget('addressCC' +idx, 'addressBookDD', {notifyDrop:this.handleDrop});
1166 var bcc = new YAHOO.util.DDTarget('addressBCC'+idx, 'addressBookDD', {notifyDrop:this.handleDrop});
1167 to.notifyDrop = cc.notifyDrop = bcc.notifyDrop = this.handleDrop;
1169 // auto-complete setup
1170 SE.autoComplete.init(idx);
1173 document.getElementById("addressTO" + idx).focus();
1177 * hide tinyMCE tool bar if send email as plaintext is checked
1179 renderTinyMCEToolBar : function (idx, hide) {
1181 document.getElementById('htmleditor' + idx + '_toolbar1').style.display = 'none';
1183 document.getElementById('htmleditor' + idx + '_toolbar1').style.display = '';
1187 c1_composeEmail : function(isReplyForward, retry) {
1191 if (typeof(tinyMCE) == 'undefined' || typeof(tinyMCE.settings) == 'undefined'){
1192 setTimeout("SE.composeLayout.c1_composeEmail(" + isReplyForward + ", true);", 500);
1194 this._1_tiny(isReplyForward);
1197 if(isReplyForward) {
1198 this.replyForwardEmailStage2();
1204 * takes draft info and prepopulates
1206 c0_composeDraft : function() {
1207 this.getNewInstanceId();
1209 document.getElementById('_blank').innerHTML = '';
1210 var idx = SE.composeLayout.currentInstanceId;
1211 SE.composeLayout.draftObject = new Object();
1212 SE.composeLayout.draftObject.id = idx;
1213 SE.composeLayout.draftObject.isDraft = true;
1214 SE.composeLayout.currentInstanceId = idx;
1215 SE.tinyInstances.currentHtmleditor = 'htmleditor' + SE.composeLayout.currentInstanceId;
1216 SE.tinyInstances[SE.tinyInstances.currentHtmleditor] = new Object();
1217 SE.tinyInstances[SE.tinyInstances.currentHtmleditor].ready = false;
1219 SE.composeLayout._0_yui();
1220 SE.composeLayout._1_tiny(true);
1223 SE.composeLayout._2_final();
1225 /* Draft-specific final processing. Need a delay to allow Tiny to render before calling setText() */
1226 setTimeout("AjaxObject.handleReplyForwardForDraft(SE.o);", 1000);
1230 * Strip & Prep editor hidden fields
1232 c0_composeNewEmail : function() {
1233 this.getNewInstanceId();
1234 this.c1_composeEmail(false);
1238 * Sends async request to get the compose view.
1239 * Requests come from "reply" or "forwards"
1241 c0_replyForwardEmail : function(ieId, uid, mbox, type) {
1242 SE.composeLayout.replyForwardObj = new Object();
1243 SE.composeLayout.replyForwardObj.ieId = ieId;
1244 SE.composeLayout.replyForwardObj.uid = uid;
1245 SE.composeLayout.replyForwardObj.mbox = mbox;
1246 SE.composeLayout.replyForwardObj.type = type;
1248 if(mbox == 'sugar::Emails') {
1249 SE.composeLayout.replyForwardObj.sugarEmail = true;
1252 SE.composeLayout.getNewInstanceId();
1253 SE.composeLayout.c1_composeEmail(true);
1255 //// END COMPOSE FLOW
1256 ///////////////////////////////////////////////////////////////////////////
1259 * Called when a contact, email, or mailinglist is dropped
1260 * into one of the compose fields.
1262 handleDrop : function (source, event, data, target) {
1265 target = event.getTarget();
1267 data.nodes = [data.nodes];
1271 target = document.getElementById(target);
1275 if (target.id.indexOf('address') > -1) {
1276 // dropped onto email to/cc/bcc field
1277 for(var i in nodes) {
1278 var node = nodes[i].getData();
1280 if (node[1].indexOf('contact') > -1) {
1281 email = SE.addressBook.getFormattedAddress(node[0]);
1282 } else if (node[1].indexOf('address-email') > -1){
1283 email = node[3].replace(/ /gi, '');
1284 email = email.replace('<', '<').replace('>', '>');
1285 var tr = source.getTrEl(nodes[i]);
1286 while (tr && !Dom.hasClass(tr, "address-contact")) {
1287 tr = source.getPreviousTrEl(tr);
1289 var CID = source.getRecord(tr).getData()[0];
1290 var o = SE.addressBook._contactCache[CID];
1291 var name = new String(o.name);
1292 var finalName = name.replace(/(<([^>]+)>)/ig, "");
1293 email = finalName + email;
1295 target.value = SE.addressBook.smartAddEmailAddressToComposeField(target.value, email);
1301 /*/////////////////////////////////////////////////////////////////////////////
1302 /// EMAIL TEMPLATE CODE
1304 applyEmailTemplate : function (idx, id) {
1307 var box_title = mod_strings.LBL_EMAILTEMPLATE_MESSAGE_SHOW_TITLE;
1308 var box_msg = mod_strings.LBL_EMAILTEMPLATE_MESSAGE_SHOW_MSG;
1309 var box_none_msg = mod_strings.LBL_EMAILTEMPLATE_MESSAGE_CLEAR_MSG;
1312 var to_addr = document.getElementById('addressTO'+idx);
1313 if (to_addr.value.search(/[^;,]{6,}[;,][^;,]{6,}/) != -1)
1315 box_title = mod_strings.LBL_EMAILTEMPLATE_MESSAGE_WARNING_TITLE;
1316 box_msg = mod_strings.LBL_EMAILTEMPLATE_MESSAGE_MULTIPLE_RECIPIENTS + '<br /><br />' + box_msg;
1319 // id is selected index of email template drop-down
1320 if(id == '' || id == "0") {
1321 YAHOO.SUGAR.MessageBox.show({
1326 if(btn=='no'){return;};
1327 SUGAR.email2.composeLayout.processNoneResult(idx, id);},
1334 YAHOO.SUGAR.MessageBox.show({
1339 if(btn=='no'){return;};
1340 SUGAR.email2.composeLayout.processResult(idx, id);},
1346 processNoneResult : function(idx, id) {
1347 var tiny = SE.util.getTiny('htmleditor' + idx);
1348 var tinyHTML = tiny.getContent();
1349 var openTag = '<div><span><span>';
1350 var htmllow = tinyHTML.toLowerCase();
1351 var start = htmllow.indexOf(openTag);
1353 tinyHTML = tinyHTML.substr(start);
1354 tiny.setContent(tinyHTML);
1356 tiny.setContent('');
1360 processResult : function(idx , id){
1361 call_json_method('EmailTemplates','retrieve','record='+id,'email_template_object', this.appendEmailTemplateJSON);
1363 // get attachments if any
1364 AjaxObject.target = '';
1365 AjaxObject.startRequest(callbackLoadAttachments, urlStandard + "&emailUIAction=getTemplateAttachments&parent_id=" + id);
1368 appendEmailTemplateJSON : function() {
1369 var idx = SE.composeLayout.currentInstanceId; // post increment
1371 // query based on template, contact_id0,related_to
1372 //jchi 09/10/2008 refix #7743
1373 if(json_objects['email_template_object']['fields']['subject'] != '' ) { // cn: bug 7743, don't stomp populated Subject Line
1374 document.getElementById('emailSubject' + idx).value = decodeURI(encodeURI(json_objects['email_template_object']['fields']['subject']));
1377 var text = decodeURI(encodeURI(json_objects['email_template_object']['fields']['body_html'])).replace(/<BR>/ig, '\n').replace(/<br>/gi, "\n").replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"');
1379 // cn: bug 14361 - text-only templates don't fill compose screen
1381 text = decodeURI(encodeURI(json_objects['email_template_object']['fields']['body'])).replace(/<BR>/ig, '\n').replace(/<br>/gi, "\n").replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"').replace(/\r\n/gi,"<br/>");
1384 var tiny = SE.util.getTiny('htmleditor' + idx);
1385 var tinyHTML = tiny.getContent();
1386 var openTag = '<div><span><span>';
1387 var closeTag = '</span></span></div>';
1388 var htmllow = tinyHTML.toLowerCase();
1389 var start = htmllow.indexOf(openTag);
1391 var htmlPart2 = tinyHTML.substr(start);
1392 tinyHTML = text + htmlPart2;
1393 tiny.setContent(tinyHTML);
1395 tiny.setContent(text);
1400 * Writes out the signature in the email editor
1402 setSignature : function(idx) {
1405 var hide = document.getElementById('setEditor' + idx).checked;
1406 SE.composeLayout.renderTinyMCEToolBar(idx,hide);
1407 //wait for signatures to load before trying to set them
1408 if (!SE.composeLayout.signatures) {
1409 setTimeout("SE.composeLayout.setSignature(" + idx + ");", 1000);
1414 var sel = document.getElementById('signatures' + idx);
1416 var sel = document.getElementById('signature_id');
1417 idx = SE.tinyInstances.currentHtmleditor;
1420 //Ensure that the tinyMCE html has been rendered.
1421 if(typeof(SE.composeLayout.loadedTinyInstances[idx]) != 'undefined' && SE.composeLayout.loadedTinyInstances[idx] == false) {
1422 setTimeout("SE.composeLayout.setSignature(" + idx + ");",1000);
1429 signature = sel.options[sel.selectedIndex].value;
1434 var openTag = '<div><span><span>';
1435 var closeTag = '</span></span></div>';
1436 var t = tinyMCE.getInstanceById('htmleditor' + idx);
1438 if(typeof(t) != 'undefined')
1440 t.contentDocument = t.contentWindow.document;
1441 var html = t.getContent();
1448 var htmllow = html.toLowerCase();
1449 var start = htmllow.indexOf(openTag);
1450 var end = htmllow.indexOf(closeTag) + closeTag.length;
1452 // selected "none" - remove signature from email
1453 if(signature == '') {
1455 var htmlPart1 = html.substr(0, start);
1456 var htmlPart2 = html.substr(end, html.length);
1458 html = htmlPart1 + htmlPart2;
1461 SE.signatures.lastAttemptedLoad = '';
1465 if(!SE.signatures.lastAttemptedLoad) // lazy load place holder
1466 SE.signatures.lastAttemptedLoad = '';
1468 SE.signatures.lastAttemptedLoad = signature;
1470 if(typeof(SE.signatures[signature]) == 'undefined') {
1472 SE.signatures.lastAttemptedLoad = ''; // reset this flag for recursion
1473 SE.signatures.targetInstance = (idx) ? idx : "";
1474 AjaxObject.target = '';
1475 AjaxObject.startRequest(callbackLoadSignature, urlStandard + "&emailUIAction=getSignature&id="+signature);
1477 var newSignature = this.prepareSignature(SE.signatures[signature]);
1479 // clear out old signature
1480 if(SE.signatures.lastAttemptedLoad && start > -1) {
1481 var htmlPart1 = html.substr(0, start);
1482 var htmlPart2 = html.substr(end, html.length);
1484 html = htmlPart1 + htmlPart2;
1488 start = html.indexOf('<div><hr></div>');
1489 if(SE.userPrefs.signatures.signature_prepend == 'true' && start > -1) {
1490 var htmlPart1 = html.substr(0, start);
1491 var htmlPart2 = html.substr(start, html.length);
1492 var newHtml = htmlPart1 + openTag + newSignature + closeTag + htmlPart2;
1493 } else if(SUGAR.email2.userPrefs.signatures.signature_prepend == 'true') {
1494 var newHtml = '<br/>' + openTag + newSignature + closeTag + html;
1496 var newHtml = html + openTag + newSignature + closeTag;
1498 //tinyMCE.setContent(newHtml);
1499 t.setContent(newHtml);
1503 prepareSignature : function(str) {
1504 var signature = new String(str);
1506 signature = signature.replace(/</gi, '<');
1507 signature = signature.replace(/>/gi, '>');
1513 showAttachmentPanel : function(idx) {
1514 var east = SE.composeLayout[idx].getUnitByPosition("right");
1515 var tabs = SE.composeLayout[idx].rightTabs;
1517 tabs.set("activeTab", tabs.getTab(0));
1521 * expands sidebar and displays options panel
1523 showOptionsPanel : function(idx) {
1524 var east = SE.composeLayout[idx].getUnitByPosition("right");
1525 var tabs = SE.composeLayout[idx].rightTabs;
1527 tabs.set("activeTab", tabs.getTab(1));
1531 * Selects the Contacts tab
1533 showContactsPanel : function() {
1534 SE.complexLayout.regions.west.showPanel("contactsTab");
1538 * Generates fields for Select Document
1540 addDocumentField : function(idx) {
1541 var basket = document.getElementById('addedDocuments' + idx);
1543 var index = (basket.childNodes.length / 7) - 1;
1550 var test = document.getElementById('documentId' + idx + index);
1552 while(test != null) {
1554 test = document.getElementById('documentId' + idx + index);
1557 var documentCup = document.createElement("div");
1558 documentCup.id = 'documentCup' + idx + index;
1559 documentCup.innerHTML = "<input type='hidden' name='document" + idx + index + "' id='document" + idx + index + "' />" +
1560 // document id field
1561 "<input type='hidden' name='documentId" + idx + index + "' id='documentId" + idx + index + "' />" +
1562 // document name field
1563 "<input value='' size='15' disabled='true' type='text' name='documentName" + idx + index + "' id='documentName" + idx + index + "' />" +
1565 "<button class='button firstChild' type='button' name='documentSelect" + idx + index + "' id='documentSelect" + idx + index + "'" +
1566 "onclick='SE.composeLayout.selectDocument(\"" + index + "\");' value='" + app_strings.LBL_EMAIL_SELECT + "'>" +
1567 "<img src='index.php?entryPoint=getImage&themeName=" + SUGAR.themes.theme_name + "&imageName=id-ff-select.png' ></button>" +
1569 "<button class='button lastChild' type='button' name='documentRemove" + idx + index + "' id='documentRemove" + idx + index + "'" +
1570 "onclick='SE.composeLayout.deleteDocumentField(\"documentCup" + idx + index + "\");' value='" + app_strings.LBL_EMAIL_REMOVE + "'>" +
1571 "<img src='index.php?entryPoint=getImage&themeName=" + SUGAR.themes.theme_name + "&imageName=id-ff-clear.png' ></button>" +
1574 basket.appendChild(documentCup);
1575 //basket.innerHTML += out;
1580 * Makes async call to save a draft of the email
1581 * @param int Instance index
1583 saveDraft : function(tinyInstance) {
1584 this.sendEmail(tinyInstance, true);
1587 selectDocument : function(target) {
1588 URL="index.php?module=Emails&action=PopupDocuments&to_pdf=true&target=" + target;
1589 windowName = 'selectDocument';
1590 windowFeatures = 'width=800' + ',height=600' + ',resizable=1,scrollbars=1';
1592 win = SUGAR.util.openWindow(URL, windowName, windowFeatures);
1594 // put the focus on the popup if the browser supports the focus() method
1600 * Modal popup for file attachment dialogue
1602 addFileField : function() {
1603 if(!SE.addFileDialog){ // lazy initialize the dialog and only create it once
1604 SE.addFileDialog = new YAHOO.widget.Dialog("addFileDialog", {
1608 constraintoviewport: true,
1610 keylisteners : new YAHOO.util.KeyListener(document, { keys:27 }, {
1611 fn:function(){SE.addFileDialog.hide();}
1614 SE.addFileDialog.setHeader(app_strings.LBL_EMAIL_ATTACHMENTS);
1615 SE.addFileDialog.render();
1616 // SE.addFileDialog.addKeyListener(27, , SE.addFileDialog);
1618 Dom.removeClass("addFileDialog", "yui-hidden");
1620 SE.addFileDialog.show();
1624 * Async upload of file to temp dir
1626 uploadAttachment : function() {
1627 if(document.getElementById('email_attachment').value != "") {
1628 var formObject = document.getElementById('uploadAttachment');
1629 YAHOO.util.Connect.setForm(formObject, true, true);
1630 AjaxObject.target = '';
1631 AjaxObject.startRequest(callbackUploadAttachment, null);
1633 alert(app_strings.LBL_EMAIL_ERROR_NO_FILE);
1638 * Adds a SugarDocument to an outbound email. Action occurs in a popup window displaying a ListView from the Documents module
1639 * @param string target in focus compose layout
1641 setDocument : function(idx, target, documentId, documentName, docRevId) {
1642 // fields are named/id'd [fieldName][instanceId][index]
1643 var addedDocs = document.getElementById("addedDocuments" + idx);
1644 var docId = document.getElementById('documentId' + idx + target);
1645 var docName = document.getElementById('documentName' + idx + target);
1646 var docRevisionId = document.getElementById('document' + idx + target);
1647 docId.value = documentId;
1648 docName.value = documentName;
1649 docRevisionId.value = docRevId;
1653 * Removes the bucket div containing the document input fields
1655 deleteDocumentField : function(documentCup) {
1656 var f0 = document.getElementById(documentCup);
1657 f0.parentNode.removeChild(f0);
1661 * Removes a Template Attachment field
1665 deleteTemplateAttachmentField : function(idx, index) {
1666 // create not-in-array values for removal filtering
1667 var r = document.getElementById("templateAttachmentsRemove" + idx).value;
1673 r += document.getElementById('templateAttachmentId' + idx + index).value;
1674 document.getElementById("templateAttachmentsRemove" + idx).value = r;
1676 var target = 'templateAttachmentCup' + idx + index;
1677 d = document.getElementById(target);
1678 d.parentNode.removeChild(d);
1682 * Async removal of uploaded temp file
1683 * @param string index Should be a concatenation of idx and index
1686 deleteUploadAttachment : function(index, file) {
1687 var d = document.getElementById('email_attachment_bucket' + index);
1688 d.parentNode.removeChild(d);
1690 // make async call to delete cached file
1691 AjaxObject.target = '';
1692 AjaxObject.startRequest('', urlStandard + "&emailUIAction=removeUploadedAttachment&file="+file);
1696 * Attaches files coming from Email Templates
1698 addTemplateAttachmentField : function(idx) {
1700 document.getElementById('templateAttachmentsTitle' + idx).style.display = 'block';
1702 var basket = document.getElementById('addedTemplateAttachments' + idx);
1705 var index = basket.childNodes.length;
1712 var out = "<div id='templateAttachmentCup" + idx + index + "'>" +
1714 "<img src='index.php?entryPoint=getImage&themeName=" + SUGAR.themes.theme_name + "&imageName=minus.gif' " +
1715 "style='cursor:pointer' align='absmiddle' onclick='SUGAR.email2.composeLayout.deleteTemplateAttachmentField(\"" +
1716 idx + "\",\"" + index + "\");'/>" +
1718 "<img src='index.php?entryPoint=getImage&themeName=" + SUGAR.themes.theme_name + "&imageName=attachment.gif' " + "align='absmiddle' />" +
1719 // templateAttachment field
1720 "<input type='hidden' value='" + "' name='templateAttachment" + idx + index + "' id='templateAttachment" + idx + index + "' />" +
1722 "<input type='hidden' value='" + "' name='templateAttachmentId" + idx + index + "' id='templateAttachmentId" + idx + index + "' />" +
1724 "<span id='templateAttachmentName" + idx + index + "'" + "> </span>" +
1725 "<br id='br" + index + "></br>" +
1726 "<br id='brdoc" + index + "></br>" +
1728 basket.innerHTML = basket.innerHTML + out;
1734 * Sends one email via async call
1735 * @param int idx Editor instance ID
1736 * @param bool isDraft
1738 sendEmail : function(idx, isDraft) {
1740 //If the outbound account has an error message associate with it, alert the user and refuse to continue.
1741 var obAccountID = document.getElementById('addressFrom' + idx).value;
1743 if( typeof(SUGAR.email2.composeLayout.outboundAccountErrors[obAccountID]) != 'undefined' )
1745 overlay(app_strings.LBL_EMAIL_ERROR_DESC, SUGAR.email2.composeLayout.outboundAccountErrors[obAccountID], 'alert');
1750 var form = document.getElementById('emailCompose' + idx);
1751 var composeOptionsFormName = "composeOptionsForm" + idx;
1752 var t = SE.util.getTiny(SE.tinyInstances.currentHtmleditor);
1753 var html = t.getContent();
1754 var subj = document.getElementById('emailSubject' + idx).value;
1755 var to = trim(document.getElementById('addressTO' + idx).value);
1756 var cc = trim(document.getElementById('addressCC' + idx).value);
1757 var bcc = trim(document.getElementById('addressBCC' + idx).value);
1758 var email_id = document.getElementById('email_id' + idx).value;
1759 var composeType = document.getElementById('composeType').value;
1760 var parent_type = document.getElementById("parent_type").value;
1761 var parent_id = document.getElementById("parent_id").value;
1763 var el_uid = document.getElementById("uid");
1764 var uid = (el_uid == null) ? '' : el_uid.value;
1766 var el_ieId = document.getElementById("ieId");
1767 var ieId = (el_ieId == null) ? '' : el_ieId.value;
1769 var el_mbox = document.getElementById("mbox");
1770 var mbox = (el_mbox == null) ? '' : el_mbox.value;
1772 if (!isValidEmail(to) || !isValidEmail(cc) || !isValidEmail(bcc)) {
1773 alert(app_strings.LBL_EMAIL_COMPOSE_INVALID_ADDRESS);
1777 if (!SE.composeLayout.isParentTypeAndNameValid(idx)) {
1780 var parentTypeValue = document.getElementById('data_parent_type' + idx).value;
1781 var parentIdValue = document.getElementById('data_parent_id' + idx).value;
1782 parent_id = parentIdValue;
1783 parent_type = parentTypeValue;
1785 var in_draft = (document.getElementById('type' + idx).value == 'draft') ? true : false;
1786 // baseline viability check
1788 if(to == "" && cc == '' && bcc == '' && !isDraft) {
1789 alert(app_strings.LBL_EMAIL_COMPOSE_ERR_NO_RECIPIENTS);
1791 } else if(subj == '' && !isDraft) {
1792 if(!confirm(app_strings.LBL_EMAIL_COMPOSE_NO_SUBJECT)) {
1795 subj = app_strings.LBL_EMAIL_COMPOSE_NO_SUBJECT_LITERAL;
1797 } else if(html == '' && !isDraft) {
1798 if(!confirm(app_strings.LBL_EMAIL_COMPOSE_NO_BODY)) {
1803 SE.util.clearHiddenFieldValues('emailCompose' + idx);
1804 document.getElementById('data_parent_id' + idx).value = parentIdValue;
1805 var title = (isDraft) ? app_strings.LBL_EMAIL_SAVE_DRAFT : app_strings.LBL_EMAIL_SENDING_EMAIL;
1806 overlay(title, app_strings.LBL_EMAIL_ONE_MOMENT);
1807 html = html.replace(/</ig, "sugarLessThan");
1808 html = html.replace(/>/ig, "sugarGreaterThan");
1810 form.sendDescription.value = html;
1811 form.sendSubject.value = subj;
1812 form.sendTo.value = to;
1813 form.sendCc.value = cc;
1814 form.sendBcc.value = bcc;
1815 form.email_id.value = email_id;
1816 form.composeType.value = composeType;
1817 form.composeLayoutId.value = 'composeLayout' + idx;
1818 form.setEditor.value = (document.getElementById('setEditor' + idx).checked == false) ? 1 : 0;
1819 form.saveToSugar.value = 1;
1820 form.fromAccount.value = document.getElementById('addressFrom' + idx).value;
1821 form.parent_type.value = parent_type;
1822 form.parent_id.value = parent_id;
1823 form.uid.value = uid;
1824 form.ieId.value = ieId;
1825 form.mbox.value = mbox;
1827 // email attachments
1828 var addedFiles = document.getElementById('addedFiles' + idx);
1830 for(i=0; i<addedFiles.childNodes.length; i++) {
1831 var bucket = addedFiles.childNodes[i];
1833 for(j=0; j<bucket.childNodes.length; j++) {
1834 var node = bucket.childNodes[j];
1835 var nName = new String(node.name);
1837 if(node.type == 'hidden' && nName.match(/email_attachment/)) {
1838 if(form.attachments.value != '') {
1839 form.attachments.value += "::";
1841 form.attachments.value += node.value;
1848 var addedDocs = document.getElementById('addedDocuments' + idx);
1850 for(i=0; i<addedDocs.childNodes.length; i++) {
1851 var cNode = addedDocs.childNodes[i];
1852 for(j=0; j<cNode.childNodes.length; j++) {
1853 var node = cNode.childNodes[j];
1854 var nName = new String(node.name);
1855 if(node.type == 'hidden' && nName.match(/documentId/)) {
1856 if(form.documents.value != '') {
1857 form.documents.value += "::";
1859 form.documents.value += node.value;
1865 // template attachments
1866 var addedTemplateAttachments = document.getElementById('addedTemplateAttachments' + idx);
1867 if(addedTemplateAttachments) {
1868 for(i=0; i<addedTemplateAttachments.childNodes.length; i++) {
1869 var cNode = addedTemplateAttachments.childNodes[i];
1870 for(j=0; j<cNode.childNodes.length; j++) {
1871 var node = cNode.childNodes[j];
1872 var nName = new String(node.name);
1873 if(node.type == 'hidden' && nName.match(/templateAttachmentId/)) {
1874 if(form.templateAttachments.value != "") {
1875 form.templateAttachments.value += "::";
1877 form.templateAttachments.value += node.value;
1883 // remove attachments
1884 form.templateAttachmentsRemove.value = document.getElementById("templateAttachmentsRemove" + idx).value;
1886 YAHOO.util.Connect.setForm(form);
1888 AjaxObject.target = 'frameFlex';
1890 // sending a draft email
1891 if(!isDraft && in_draft) {
1893 SE.listView.removeRowByUid(email_id);
1896 var sendCallback = (isDraft) ? AjaxObject.composeLayout.callback.saveDraft : callbackSendEmail;
1897 var emailUiAction = (isDraft) ? "&emailUIAction=sendEmail&saveDraft=true" : "&emailUIAction=sendEmail";
1899 AjaxObject.startRequest(sendCallback, urlStandard + emailUiAction);
1903 * Handles clicking the email address link from a given view
1905 composePackage : function() {
1906 if(composePackage != null) {
1907 SE.composeLayout.c0_composeNewEmail();
1910 if(composePackage.to_email_addrs) {
1911 document.getElementById("addressTO" + SE.composeLayout.currentInstanceId).value = composePackage.to_email_addrs;
1913 if (composePackage.subject != null && composePackage.subject.length > 0) {
1914 document.getElementById("emailSubject" + SE.composeLayout.currentInstanceId).value = composePackage.subject;
1917 //If no parent fields are set in the composePackage, ensure they are cleared.
1918 var parentFields = ['parent_type','parent_name','parent_id'];
1919 for(var i=0;i<parentFields.length;i++)
1921 if ( typeof(composePackage[parentFields[i]]) == 'undefined' )
1922 composePackage[parentFields[i]] = "";
1925 document.getElementById("parent_type").value = composePackage.parent_type;
1926 document.getElementById('data_parent_type' + SE.composeLayout.currentInstanceId).value = composePackage.parent_type;
1927 document.getElementById("parent_id").value = composePackage.parent_id;
1928 document.getElementById('data_parent_id' + SE.composeLayout.currentInstanceId).value = composePackage.parent_id;
1929 document.getElementById('data_parent_name' + SE.composeLayout.currentInstanceId).value = composePackage.parent_name;
1931 if(composePackage.email_id != null && composePackage.email_id.length > 0) {
1932 document.getElementById("email_id" + SE.composeLayout.currentInstanceId).value = composePackage.email_id;
1934 if (composePackage.body != null && composePackage.body.length > 0) {
1935 var tiny = SE.util.getTiny('htmleditor' + SE.composeLayout.currentInstanceId);
1936 SE.composeLayout.loadedTinyInstances[SE.composeLayout.currentInstanceId] = false;
1937 setTimeout("SE.composeLayout.setContentOnThisTiny();", 3000);
1939 if (composePackage.attachments != null) {
1940 SE.composeLayout.loadAttachments(composePackage.attachments);
1943 if (composePackage.fromAccounts != null && composePackage.fromAccounts.status) {
1944 var addressFrom = document.getElementById('addressFrom' + SE.composeLayout.currentInstanceId);
1945 SE.util.emptySelectOptions(addressFrom);
1946 var fromAccountOpts = composePackage.fromAccounts.data;
1947 for(i=0; i<fromAccountOpts.length; i++) {
1948 var key = fromAccountOpts[i].value;
1949 var display = fromAccountOpts[i].text;
1950 var opt = new Option(display, key);
1951 if (fromAccountOpts[i].selected) {
1952 opt.selected = true;
1954 addressFrom.options.add(opt);
1961 setContentOnThisTiny : function() {
1962 var tiny = SE.util.getTiny('htmleditor' + SE.composeLayout.currentInstanceId);
1963 var tinyHTML = tiny.getContent();
1964 composePackage.body = decodeURI(encodeURI(composePackage.body));
1965 // cn: bug 14361 - text-only templates don't fill compose screen
1966 if(composePackage.body == '') {
1967 composePackage.body = decodeURI(encodeURI(composePackage.body)).replace(/<BR>/ig, '\n').replace(/<br>/gi, "\n").replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"');
1969 //Flag determines if we should clear the tiny contents or just append
1970 if (typeof(composePackage.clearBody) != 'undefined' && composePackage.clearBody)
1971 SE.composeLayout.tinyHTML = '';
1973 SE.composeLayout.tinyHTML = tinyHTML + composePackage.body;
1975 tiny.setContent(SE.composeLayout.tinyHTML);
1976 //Indicate that the contents has been loaded successfully.
1977 SE.composeLayout.loadedTinyInstances[SE.composeLayout.currentInstanceId] = true;
1980 * Confirms closure of a compose screen if "x" is clicked
1982 confirmClose : function(panel) {
1983 if(confirm(app_strings.LBL_EMAIL_CONFIRM_CLOSE)) {
1984 SE.composeLayout.closeCompose(panel.id);
1992 * forces close of a compose screen
1994 forceCloseCompose : function(id) {
1995 SE.composeLayout.closeCompose(id);
1997 // handle flow back to originating view
1998 if(composePackage) {
1999 // check if it's a module we need to return to
2000 if(composePackage.return_module && composePackage.return_action && composePackage.return_id) {
2001 if(confirm(app_strings.LBL_EMAIL_RETURN_TO_VIEW)) {
2002 var url = "index.php?module=" + composePackage.return_module + "&action=" + composePackage.return_action + "&record=" + composePackage.return_id;
2003 window.location = url;
2010 * closes the editor that just sent email
2011 * @param string id ID of composeLayout tab
2013 closeCompose : function(id) {
2014 // destroy tinyMCE instance
2015 var idx = id.substr(13, id.length);
2016 var instanceId = "htmleditor" + idx;
2017 tinyMCE.execCommand('mceRemoveControl', false, instanceId);
2019 // nullify DOM and namespace values.
2021 SE.composeLayout[idx] = null;
2022 SE.tinyInstances[instanceId] = null;
2023 var tabsArray = SE.innerLayout.get("tabs");
2024 for (i = 0 ; i < tabsArray.length ; i++) {
2025 if (tabsArray[i].get("id") == ('composeTab' + idx)) {
2026 tabsArray[i].close();
2030 //SE.innerLayout.getTab(idx).close();
2034 * Enable the quick search for the compose relate field or search tab
2036 enableQuickSearchRelate: function(idx,overides){
2038 if(typeof overides != 'undefined')
2040 var newModuleID = overides['moduleSelectField']; //data_parent_type_search
2041 var newModule = document.getElementById(newModuleID).value;
2042 var formName = overides['formName'];
2043 var fieldName = overides['fieldName'];
2044 var fieldId = overides['fieldId'];
2045 var fullName = formName + "_" + fieldName;
2046 var postBlurFunction = null;
2050 var newModule = document.getElementById('data_parent_type'+idx).value;
2051 var formName = 'emailCompose'+idx;
2052 var fieldName = 'data_parent_name'+idx;
2053 var fieldId = 'data_parent_id'+idx;
2054 var fullName = formName + "_" + fieldName;
2055 var postBlurFunction = "SE.composeLayout.qsAddAddress";
2058 if(typeof sqs_objects == 'undefined')
2059 window['sqs_objects'] = new Array;
2061 window['sqs_objects'][fullName] = {
2064 modules:[newModule],
2066 field_list:["name","id", "email1"],populate_list:[fieldName,fieldId],required_list:[fieldId],
2067 conditions:[{name:"name",op:"like_custom",end:"%",value:""}],
2068 post_onblur_function: postBlurFunction,
2069 order:"name","limit":"30","no_match_text":"No Match"};
2072 if(typeof QSProcessedFieldsArray != 'undefined')
2073 QSProcessedFieldsArray[fullName] = false;
2074 if (typeof(QSFieldsArray) != 'undefined' && typeof(QSFieldsArray[fullName]) != 'undefined') {
2075 QSFieldsArray[fullName].destroy();
2076 delete QSFieldsArray[fullName];
2078 if (Dom.get(fullName + "_results")) {
2079 Dom.get(fullName + "_results").parentNode.removeChild(Dom.get(fullName + "_results"));
2085 qsAddAddress : function(o) {
2086 if (o.name != "" && o.email1 != "")
2088 var target = Dom.get("addressTO" + SE.composeLayout.currentInstanceId);
2089 target.value = SE.addressBook.smartAddEmailAddressToComposeField(target.value, o.name + "<" + o.email1 + ">");
2093 * Returns a new instance ID, 0-index
2095 getNewInstanceId : function() {
2096 this.currentInstanceId = this.currentInstanceId + 1;
2097 return this.currentInstanceId;
2101 * Takes an array of objects that contain the filename and GUID of a Note (attachment or Sugar Document) and applies the values to the compose screen. Valid use-cases are applying an EmailTemplate or resuming a Draft Email.
2103 loadAttachments : function(result) {
2104 var idx = SE.composeLayout.currentInstanceId;
2106 if(typeof(result) == 'object') {
2107 //jchi #20680. Clean the former template attachments;
2108 var basket = document.getElementById('addedTemplateAttachments' + idx);
2109 if(basket.innerHTML != ''){
2110 confirm(mod_strings.LBL_CHECK_ATTACHMENTS, mod_strings.LBL_HAS_ATTACHMENTS, function(btn){
2112 basket.innerHTML = '';
2117 if(typeof result[i] == 'object') {
2118 var index = SE.composeLayout.addTemplateAttachmentField(idx);
2119 var bean = result[i];
2120 document.getElementById('templateAttachmentId' + idx + index).value = bean['id'];
2121 document.getElementById('templateAttachmentName' + idx + index).innerHTML += bean['filename'];
2128 * fills drop-down values for email templates and signatures
2130 setComposeOptions : function(idx) {
2131 // send from accounts
2132 var addressFrom = document.getElementById('addressFrom' + idx);
2134 if (addressFrom.options.length <= 0) {
2135 SE.util.emptySelectOptions(addressFrom);
2136 var fromAccountOpts = SE.composeLayout.fromAccounts;
2137 for (id = 0 ; id < fromAccountOpts.length ; id++) {
2138 var key = fromAccountOpts[id].value;
2139 var display = fromAccountOpts[id].text;
2140 var is_default = false;
2141 if(key == SUGAR.default_inbound_accnt_id)
2143 var opt = new Option(display, key);
2144 addressFrom.options.add(opt);
2145 addressFrom.options[id].selected = is_default; //Safari bug new Option(x,y,true) does not work.
2150 var et = document.getElementById('email_template' + idx);
2151 SE.util.emptySelectOptions(et);
2153 for(var key in this.emailTemplates) { // iterate through assoc array
2154 var display = this.emailTemplates[key];
2155 var opt = new Option(display, key);
2156 et.options.add(opt);
2160 var sigs = document.getElementById('signatures' + idx);
2161 SE.util.emptySelectOptions(sigs);
2163 for(var key in this.signatures) { // iterate through assoc array
2164 var display = this.signatures[key];
2165 var opt = new Option(display, key);
2167 if(key == SE.userPrefs.signatures.signature_default) {
2168 opt.selected = true;
2171 sigs.options.add(opt);
2174 // html/plain email?
2175 var htmlEmail = document.getElementById('setEditor' + idx);
2176 if(SE.userPrefs.emailSettings.sendPlainText == 1) {
2177 htmlEmail.checked = true;
2179 htmlEmail.checked = false;
2182 SE.tinyInstances[SE.tinyInstances.currentHtmleditor].ready = true;
2186 * After compose screen is rendered, async call to get email body from Sugar
2188 replyForwardEmailStage2 : function() {
2189 SE.util.clearHiddenFieldValues('emailUIForm');
2190 overlay(app_strings.LBL_EMAIL_RETRIEVING_MESSAGE, app_strings.LBL_EMAIL_ONE_MOMENT);
2192 var ieId = SE.composeLayout.replyForwardObj.ieId;
2193 var uid = SE.composeLayout.replyForwardObj.uid;
2194 var mbox = SE.composeLayout.replyForwardObj.mbox;
2195 var type = SE.composeLayout.replyForwardObj.type;
2196 var idx = SE.composeLayout.currentInstanceId;
2198 var sugarEmail = (SE.composeLayout.replyForwardObj.sugarEmail) ? '&sugarEmail=true' : "";
2200 document.getElementById('emailSubject' + idx).value = type;
2201 document.getElementById('emailUIAction').value = 'composeEmail';
2202 document.getElementById('composeType').value = type;
2203 document.getElementById('ieId').value = ieId;
2204 document.getElementById('uid').value = uid;
2205 document.getElementById('mbox').value = mbox;
2206 document.getElementById('setEditor' + idx).checked = SE.userPrefs.emailSettings.sendPlainText == 1 ? true : false;
2207 var formObject = document.getElementById('emailUIForm');
2208 YAHOO.util.Connect.setForm(formObject);
2210 var sendType = type;
2211 AjaxObject.startRequest(callbackReplyForward, urlStandard + "&composeType=" + type + sugarEmail);
2215 * Show the hidden cc or bcc fields
2217 showHiddenAddress: function(addrType,idx){
2219 Dom.removeClass(addrType+"_tr"+idx, "yui-hidden");
2220 Dom.addClass(addrType+"_span"+idx, "yui-hidden");
2221 Dom.addClass("bcc_cc_sep"+idx, "yui-hidden");
2222 this[addrType+'Hidden'+idx] = false;
2224 //After bcc or cc is added, move options below last addr field
2225 Dom.insertAfter("add_addr_options_tr"+idx, 'bcc_tr'+idx);
2227 //If both cc and bcc hidden, remove the empty row containing text.
2228 if( ( typeof(this['ccHidden'+idx]) != 'undefined' && typeof(this['bccHidden'+idx]) != 'undefined')
2229 && ( this['ccHidden'+idx] == false && this['bccHidden'+idx] == false) )
2230 Dom.addClass("add_addr_options_tr"+idx, "yui-hidden");
2232 // SE.composeLayout.resizeEditor(idx);
2235 * Hide the cc and bcc fields if they were shown.
2237 hideHiddenAddresses: function(idx){
2239 var addrTypes = ['cc','bcc'];
2240 for(var i = 0;i<addrTypes.length;i++)
2242 Dom.addClass(addrTypes[i] + "_tr"+idx, "yui-hidden");
2243 Dom.removeClass(addrTypes[i] + "_span"+idx, "yui-hidden");
2244 this[addrTypes[i] + 'Hidden'+idx] = true
2247 Dom.removeClass("bcc_cc_sep"+idx, "yui-hidden");
2248 Dom.removeClass("add_addr_options_tr"+idx, "yui-hidden");
2249 Dom.insertBefore("add_addr_options_tr"+idx, 'bcc_tr'+idx);
2253 //// END SE.composeLayout
2254 ///////////////////////////////////////////////////////////////////////////////
2255 ///////////////////////////////////////////////////////////////////////////////
2259 * Cleans serialized UID lists of duplicates
2263 cleanUids : function(str) {
2264 var seen = new Object();
2266 var arr = new String(str).split(",");
2268 for(var i=0; i<arr.length; i++) {
2273 clean += (clean != "") ? "," : "";
2275 seen[arr[i]] = true;
2282 * Clears hidden field values
2283 * @param string id ID of form element to clear
2285 clearHiddenFieldValues : function(id) {
2286 var form = document.getElementById(id);
2288 for(i=0; i<form.elements.length; i++) {
2289 if(form.elements[i].type == 'hidden') {
2290 var e = form.elements[i];
2291 if(e.name != 'action' && e.name != 'module' && e.name != 'to_pdf') {
2299 * Reduces a SELECT drop-down to 0 items to prepare for new ones
2301 emptySelectOptions : function(el) {
2303 for(i=el.childNodes.length - 1; i >= 0; i--) {
2304 if(el.childNodes[i]) {
2305 el.removeChild(el.childNodes[i]);
2312 * Returns the MBOX path in the manner php_imap expects:
2313 * ie: INBOX.DEBUG.test
2314 * @param string str Current serialized value, Home.personal.test.INBOX.DEBUG.test
2316 generateMboxPath : function(str) {
2317 var ex = str.split("::");
2319 /* we have a serialized MBOX path */
2323 for(var i=0; i<ex.length; i++) {
2324 if(ex[i] == 'INBOX') {
2336 /* we have a Sugar folder GUID - do nothing */
2344 * returns a SUGAR GUID by navigating the DOM tree a few moves backwards
2345 * @param HTMLElement el
2346 * @return string GUID of found element or empty on failure
2348 getGuidFromElement : function(el) {
2354 for(var i=0; i<iterations; i++) {
2356 if(el.id.match(SE.reGUID)) {
2368 * Returns the ID value for the current in-focus, active panel (in the innerLayout, not complexLayout)
2371 getPanelId : function() {
2372 return SE.innerLayout.get("activeTab").id ? SE.innerLayout.get("activeTab").id : "Preview";
2376 * wrapper to handle weirdness with IE
2377 * @param string instanceId
2378 * @return tinyMCE Controller object
2380 getTiny : function(instanceId) {
2381 if(instanceId == '') {
2385 var t = tinyMCE.getInstanceById(instanceId);
2389 YAHOO.util.Event.onContentReady(instanceId, function(t) { return t; });
2395 * Simple check for MSIE browser
2399 var nav = new String(navigator.appVersion);
2400 if(nav.match(/MSIE/)) {
2407 * Recursively removes an element from the DOM
2408 * @param HTMLElement
2410 removeElementRecursive : function(el) {
2411 this.emptySelectOptions(el);
2418 sleep : function(secs) {
2419 setTimeout("void(0);", secs);
2423 * Converts a <select> element to an Ext.form.combobox
2425 convertSelect : function(select) {
2426 alert('in convertSelect');
2427 if (typeof(select) == "string") {
2428 select = document.getElementById(select);
2432 findChildNode : function (parent, property, value) {
2433 for (i in parent.children) {
2434 var child = parent.children[i];
2435 if (child.data[property] && child.data[property] == value || child[property] && child[property] == value)
2437 var searchChild = SE.util.findChildNode(child, property, value);
2444 cascadeNodes : function (parent, fn, scope, args) {
2445 for (i in parent.children) {
2446 var child = parent.children[i];
2447 var s = scope ? scope : child;
2448 var a = args ? args : child;
2450 SE.util.cascadeNodes(child, fn, scope, args);
2457 ///////////////////////////////////////////////////////////////////////////////
2460 })();//End namespace