/********************************************************************************* * SugarCRM is a customer relationship management program developed by * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License version 3 as published by the * Free Software Foundation with the addition of the following permission added * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ (function() { var sw = YAHOO.SUGAR, Event = YAHOO.util.Event, Connect = YAHOO.util.Connect, Dom = YAHOO.util.Dom SE = SUGAR.email2; /////////////////////////////////////////////////////////////////////////////// //// EMAIL ACCOUNTS SE.accounts = { outboundDialog : null, inboundAccountEditDialog : null, inboundAccountsSettingsTable : null, outboundAccountsSettingsTable : null, testOutboundDialog : null, errorStyle : 'input-error', normalStyle : '', newAddedOutboundId : '', /** * makes async call to retrieve an outbound instance for editting */ //EXT111 editOutbound : function(obi) { AjaxObject.startRequest(AjaxObject.accounts.callbackEditOutbound, urlStandard + "&emailUIAction=editOutbound&outbound_email=" + obi); }, deleteOutbound : function(obi) { if(obi.match(/^(add|line|sendmail)+/)) { alert('Invalid Operation'); } else { overlay(app_strings.LBL_EMAIL_DELETING_OUTBOUND, app_strings.LBL_EMAIL_ONE_MOMENT); AjaxObject.startRequest(AjaxObject.accounts.callbackDeleteOutbound, urlStandard + "&emailUIAction=deleteOutbound&outbound_email=" + obi); } }, //EXT111 getReplyAddress : function() { var primary = ''; for(var i=0; i'; } }; this.showBoolean = function(el, oRecord, oColumn, oData) { var is_group = oRecord.getData("is_group"); var bChecked = oData; bChecked = (bChecked) ? " checked" : ""; if(!is_group) { el.innerHTML = ""; } }; YAHOO.widget.DataTable.Formatter.customImage = this.customImageFormatter; YAHOO.widget.DataTable.Formatter.showBoolean = this.showBoolean; var typeHoverHelp = ' 
'+ '' + '
' + mod_strings.LBL_EMAIL_INBOUND_TYPE_HELP + '
'; this.ieColumnDefs = [{key:'name',label:app_strings.LBL_EMAIL_SETTINGS_NAME }, {key:'server_url',label:ie_mod_strings.LBL_SERVER_URL}, {key:'is_active',label:ie_mod_strings.LBL_STATUS_ACTIVE,formatter:"checkbox",className:'yui-cstm-cntrd-liner'}, {key:'is_default',label:app_strings.LBL_EMAIL_ACCOUNTS_SMTPDEFAULT,formatter:"showBoolean",className:'yui-cstm-cntrd-liner'}, {key:'type',label:mod_strings.LBL_LIST_TYPE + typeHoverHelp }, {key:'edit',label:mod_strings.LBL_BUTTON_EDIT,formatter:"customImage",className:'yui-cstm-cntrd-liner'}, {key:'delete',label:app_strings.LBL_EMAIL_DELETE,formatter:"customImage",className:'yui-cstm-cntrd-liner'}]; var query = "index.php?module=Emails&action=EmailUIAjax&to_pdf=true&emailUIAction=rebuildShowAccount"; this.ieDataSource = new YAHOO.util.DataSource(query); this.ieDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; this.ieDataSource.responseSchema = { resultsList: "account_list", fields: [{key:'id'},{key:'name'},'is_active',{key:'server_url'},'is_group','group_id','is_default','has_groupfolder','type'] }; this.inboundAccountsSettingsTable = new YAHOO.widget.DataTable("inboundAccountsTable", this.ieColumnDefs, this.ieDataSource); this.inboundAccountsSettingsTable.subscribe("checkboxClickEvent", function(oArgs){ var elCheckbox = oArgs.target; var oColumn = this.getColumn(elCheckbox); if(oColumn.key == 'is_active') { var oRecord = this.getRecord(elCheckbox); oRecord.setData("is_active",elCheckbox.checked); var t_id = oRecord.getData('id'); var isGroupFolder = oRecord.getData('has_groupfolder'); if(isGroupFolder) SUGAR.email2.folders.updateSubscriptions(); else SUGAR.email2.folders.setFolderSelection(); } }); var lastDefaultSelectedId = ""; this.inboundAccountsSettingsTable.subscribe("radioClickEvent", function(oArgs){ var elRadio = oArgs.target; var oColumn = this.getColumn(elRadio); if(oColumn.key == 'is_default') { var oRecord = this.getRecord(elRadio); var t_id = oRecord.getData('id'); var t_isGroup = oRecord.getData('is_group'); if(t_id != lastDefaultSelectedId && !t_isGroup) { SUGAR.default_inbound_accnt_id = t_id; //Set in the global space for access during compose lastDefaultSelectedId = t_id; AjaxObject.startRequest(callbackDefaultOutboundSave, urlStandard + "&emailUIAction=saveDefaultOutbound&id="+ t_id); } else if(t_isGroup) YAHOO.util.Event.preventDefault(oArgs.event); //Do not allow users to select group mailboxes as a default. } }); this.inboundAccountsSettingsTable.subscribe("rowMouseoverEvent", this.inboundAccountsSettingsTable.onEventHighlightRow); this.inboundAccountsSettingsTable.subscribe("rowMouseoutEvent", this.inboundAccountsSettingsTable.onEventUnhighlightRow); } }, _setupOutboundAccountTable: function() { if(!this.outboundAccountsSettingsTable) { this.obImageFormatter = function(elLiner, oRecord, oColumn, oData) { var clckEvent = oColumn.key; var imgSrc = ""; var isEditable = oRecord.getData("is_editable"); var type = oRecord.getData("type"); if(isEditable) { if(oColumn.key == 'edit') { clckEvent = "SUGAR.email2.accounts.editOutbound('"+ oRecord.getData('id') +"')"; imgSrc = 'index.php?entryPoint=getImage&themeName=Sugar&imageName='+oColumn.key+'_inline.gif'; } else if(oColumn.key == 'delete' && type == 'user') { clckEvent = "SUGAR.email2.accounts.deleteOutbound('"+ oRecord.getData('id')+"')"; imgSrc = 'index.php?entryPoint=getImage&themeName=Sugar&imageName='+oColumn.key+'_inline.gif'; } if(imgSrc != '') elLiner.innerHTML = ''; } }; //Custom formatter to display any error messages. this.messageDisplay = function(elLiner, oRecord, oColumn, oData) { if(SUGAR.email2.composeLayout.outboundAccountErrors == null) SUGAR.email2.composeLayout.outboundAccountErrors = {}; var id = oRecord.getData('id'); var message = oRecord.getData("errors"); if(message != '') { elLiner.innerHTML = '' + message + ''; //Add the id and message for all outbound accounts. SUGAR.email2.composeLayout.outboundAccountErrors[id] = message; } else { if(typeof(SUGAR.email2.composeLayout.outboundAccountErrors[id]) != 'undefined' ) delete SUGAR.email2.composeLayout.outboundAccountErrors[id]; } }; YAHOO.widget.DataTable.Formatter.actionsImage = this.obImageFormatter; YAHOO.widget.DataTable.Formatter.messageDisplay = this.messageDisplay; this.obAccntsColumnDefs = [{key:'name',label:app_strings.LBL_EMAIL_ACCOUNTS_NAME }, {key:'mail_smtpserver',label:app_strings.LBL_EMAIL_ACCOUNTS_SMTPSERVER}, {key:'edit',label:mod_strings.LBL_BUTTON_EDIT,formatter:"actionsImage",className:'yui-cstm-cntrd-liner'}, {key:'delete', label:app_strings.LBL_EMAIL_DELETE,formatter:"actionsImage",className:'yui-cstm-cntrd-liner'}, {key:'messages',label:'', formatter:"messageDisplay",className:'yui-cstm-cntrd-liner'}]; var query = "index.php?module=Emails&action=EmailUIAjax&to_pdf=true&emailUIAction=retrieveAllOutbound"; this.obDataSource = new YAHOO.util.DataSource(query); this.obDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; this.obDataSource.responseSchema = { resultsList: "outbound_account_list", fields: ['id','name','is_editable','mail_smtpserver','type','errors'] }; this.outboundAccountsSettingsTable = new YAHOO.widget.DataTable("outboundAccountsTable", this.obAccntsColumnDefs, this.obDataSource); this.outboundAccountsSettingsTable.subscribe("rowMouseoverEvent", this.outboundAccountsSettingsTable.onEventHighlightRow); this.outboundAccountsSettingsTable.subscribe("rowMouseoutEvent", this.outboundAccountsSettingsTable.onEventUnhighlightRow); this.outboundAccountsSettingsTable.subscribe("postRenderEvent",this.rebuildMailerOptions); } }, /** * Displays a modal diaglogue to edit outbound account settings */ showEditInboundAccountDialogue : function(clear) { if(!this.inboundAccountEditDialog) { var EAD = this.inboundAccountEditDialog = new YAHOO.widget.Dialog("editAccountDialogue", { modal:true, visible:true, fixedcenter:true, constraintoviewport: true, width : "600px", shadow : true }); EAD.showEvent.subscribe(function() { var el = this.element; var viewH = YAHOO.util.Dom.getViewportHeight(); if (this.header && el && viewH - 50 < el.clientHeight) { var body = this.header.nextElementSibling; body.style.overflow = "hidden"; body.style.height = "100%"; } }, EAD); EAD.setHeader(mod_strings.LBL_EMAIL_ACCOUNTS_INBOUND); Dom.removeClass("editAccountDialogue", "yui-hidden"); } // end lazy load if(clear == undefined || clear == true) { SE.accounts.clearInboundAccountEditScreen(); //Set default protocol to IMAP when creating new records document.forms['ieAccount'].elements['protocol'].value = "imap"; SE.accounts.setPortDefault(); } //Check if we should display username/password fields for outbound account if errors were detected. this.checkOutBoundSelection(); this.inboundAccountEditDialog.render(); this.inboundAccountEditDialog.show(); }, /** * Set all fields on the outbound edit form to either enabled/disabled * except for the username/password. * */ toggleOutboundAccountDisabledFields: function(disable) { var fields = ['mail_name', 'mail_smtpserver','mail_smtpport','mail_smtpauth_req']; for(var i=0;iAccounts */ fillIeAccount:function(jsonstr) { var o = JSON.parse(jsonstr); document.getElementById('ie_id').value = o.id; document.getElementById('ie_name').value = o.name; if (o.stored_options != null) { document.getElementById('ie_from_name').value = o.stored_options.from_name == 'undefined' ? '' : o.stored_options.from_name; document.getElementById('ie_from_addr').value = o.stored_options.from_addr == 'undefined' ? '' : o.stored_options.from_addr; document.getElementById('reply_to_addr').value = typeof(o.stored_options.reply_to_addr) == 'undefined' ? '' : o.stored_options.reply_to_addr; if (o.stored_options.trashFolder != null) { document.getElementById('trashFolder').value = o.stored_options.trashFolder; } if (o.stored_options.sentFolder != null) { document.getElementById('sentFolder').value = o.stored_options.sentFolder; } } document.getElementById('server_url').value = o.server_url; document.getElementById('email_user').value = o.email_user; document.getElementById('port').value = o.port; document.getElementById('group_id').value = o.group_id; document.getElementById('mailbox').value = o.mailbox; var i = 0; // handle SSL if(typeof(o.service[2]) != 'undefined') { document.getElementById('ssl').checked = true; } // handle protocol if(document.getElementById('protocol').value != o.protocol) { var prot = document.getElementById('protocol'); for(i=0; i"; } if(trim(smtpServer) == '') { isError = true; errorMessage += app_strings.LBL_EMAIL_ACCOUNTS_SMTPSERVER + "
"; } if(trim(smtpPort) == '') { isError = true; errorMessage += app_strings.LBL_EMAIL_ACCOUNTS_SMTPPORT + "
"; } if(mailsmtpauthreq.checked) { if(trim(document.getElementById('mail_smtpuser').value) == '') { isError = true; errorMessage += app_strings.LBL_EMAIL_ACCOUNTS_SMTPUSER + "
"; } } } if(isError) { overlay(mod_strings.ERR_MISSING_REQUIRED_FIELDS, errorMessage, 'alert'); return false; } else { return true; } }, testOutboundSettings: function() { var errorMessage = ''; var isError = false; var fromAddress = document.getElementById("outboundtest_from_address").value; if (trim(fromAddress) == "") { errorMessage += app_strings.LBL_EMAIL_SETTINGS_FROM_TO_EMAIL_ADDR + "
"; overlay(mod_strings.ERR_MISSING_REQUIRED_FIELDS, errorMessage, 'alert'); return false; } else if (!isValidEmail(fromAddress)) { errorMessage += app_strings.LBL_EMAIL_SETTINGS_FROM_TO_EMAIL_ADDR + "
"; overlay(mod_strings.ERR_INVALID_REQUIRED_FIELDS, errorMessage, 'alert'); return false; } //Hide the dialogue and show an in progress indicator. SE.accounts.testOutboundDialog.hide(); overlay(app_strings.LBL_EMAIL_PERFORMING_TASK, app_strings.LBL_EMAIL_ONE_MOMENT, 'plain'); //If the outbound mail type is a system override we need to re-enable the post fields otherwise //nothing is sent in the request. var outboundType = document.forms['outboundEmailForm'].elements['type'].value; SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(false); YAHOO.util.Connect.setForm(document.getElementById("outboundEmailForm")); if(outboundType == 'system-override') SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(true); var data = "&emailUIAction=testOutbound&outboundtest_from_address=" + fromAddress; AjaxObject.startRequest(callbackOutboundTest, urlStandard + data); }, testOutboundSettingsDialog: function() { //Ensure that all settings are correct before proceeding to send test email. if(!SE.accounts.checkOutboundSettings()) return; // lazy load dialogue if(!SE.accounts.testOutboundDialog) { SE.accounts.testOutboundDialog = new YAHOO.widget.Dialog("testOutboundDialog", { modal:true, visible:true, fixedcenter:true, constraintoviewport: true, width : 600, shadow : true }); SE.accounts.testOutboundDialog.setHeader(app_strings.LBL_EMAIL_TEST_OUTBOUND_SETTINGS); Dom.removeClass("testOutboundDialog", "yui-hidden"); } // end lazy load SE.accounts.testOutboundDialog.render(); SE.accounts.testOutboundDialog.show(); }, /** * Saves Outbound email settings */ saveOutboundSettings : function() { if(SE.accounts.checkOutboundSettings()) { //Enable the form fields for the post. SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(false); YAHOO.util.Connect.setForm(document.getElementById("outboundEmailForm")); AjaxObject.startRequest(callbackOutboundSave, urlStandard + "&emailUIAction=saveOutbound"); } else { return false; } }, saveIeAccount : function() { //Before saving check if there are any error messages associated with the outbound account. var outboundID = document.getElementById('outbound_email').value; if( SE.accounts.checkIeCreds({'valiateTrash': true,'validateFromAddr': true,'validateOutbound' :true, 'validateSMTPCreds':true}) ) { document.getElementById('saveButton').disabled = true; overlay(app_strings.LBL_EMAIL_IE_SAVE, app_strings.LBL_EMAIL_ONE_MOMENT); var formObject = document.getElementById('ieAccount'); YAHOO.util.Connect.setForm(formObject); AjaxObject._reset(); AjaxObject.target = 'frameFlex'; AjaxObject.startRequest(callbackAccount, urlStandard + '&emailUIAction=saveIeAccount'); } }, testSettings : function() { form = document.getElementById('ieAccount'); if(SE.accounts.checkIeCreds()) { ie_test_open_popup_with_submit("InboundEmail", "Popup", "Popup", 400, 300, trim(form.server_url.value), form.protocol.value, trim(form.port.value), trim(form.email_user.value), Rot13.write(form.email_password.value), trim(form.mailbox.value), form.ssl.checked, true, "ieAccount"); } }, getFoldersListForInboundAccountForEmail2 : function() { form = document.getElementById('ieAccount'); if(SE.accounts.checkIeCreds()) { var mailBoxValue = form.mailbox.value; if (form.searchField.value.length > 0) { mailBoxValue = ""; } // if getFoldersListForInboundAccount("InboundEmail", "ShowInboundFoldersList", "Popup", 400, 300, form.server_url.value, form.protocol.value, form.port.value, form.email_user.value, Rot13.write(form.email_password.value), mailBoxValue, form.ssl.checked, true, form.searchField.value ); } // if }, checkIeCreds : function(validateRules) { if(typeof(validateRules) == 'undefined') validateRules = {}; var errors = new Array(); var out = new String(); var ie_name = Dom.get('ie_name').value; var fromAddress = Dom.get('ie_from_addr').value; var server_url = Dom.get('server_url').value; var email_user = Dom.get('email_user').value; var email_password = Dom.get('email_password').value; var protocol = Dom.get('protocol').value; var port = Dom.get('port').value; var oe = Dom.get('outbound_email'); var oe_value = typeof(oe.options[oe.selectedIndex]) == 'undefined' ? "" : oe.options[oe.selectedIndex].value; var outboundUserName = Dom.get('inbound_mail_smtpuser').value; var outboundPass = Dom.get('inbound_mail_smtppass').value; //If the username and password were provided then ignore the error messge var outboundCredentialsFound = false; if(outboundUserName != "" && outboundPass != "") outboundCredentialsFound = true; var validateSMTPCreds = (typeof(validateRules.validateSMTPCreds) != 'undefined' && validateRules.validateSMTPCreds); if ( SE.composeLayout.outboundAccountErrors != null && SE.composeLayout.outboundAccountErrors[oe_value] != null && validateSMTPCreds) { if(trim(outboundUserName) == "") { errors.push(app_strings.LBL_EMAIL_ACCOUNTS_SMTPUSER); } if(trim(outboundPass) == "") { errors.push(app_strings.LBL_EMAIL_ACCOUNTS_SMTPPASS); } } if(trim(ie_name) == "") { errors.push(app_strings.LBL_EMAIL_ERROR_NAME); } if ( typeof(validateRules.validateFromAddr) != 'undefined' && validateRules.validateFromAddr) { if(trim(fromAddress) == "" || !isValidEmail(fromAddress) ) { errors.push(app_strings.LBL_EMAIL_ERROR_FROM_ADDRESS); } } if( (typeof(validateRules.validateOutbound) != 'undefined' && validateRules.validateOutbound) && ( trim(oe_value) == "" || trim(oe_value) == "SYSTEM_ADD") ) { errors.push(app_strings.LBL_EMAIL_ERROR_NO_OUTBOUND); } if(trim(server_url) == "") { errors.push(app_strings.LBL_EMAIL_ERROR_SERVER); } if(trim(email_user) == "") { errors.push(app_strings.LBL_EMAIL_ERROR_USER); } if(protocol == "") { errors.push(app_strings.LBL_EMAIL_ERROR_PROTOCOL); } if (protocol == 'imap') { var mailbox = document.getElementById('mailbox').value; if (trim(mailbox) == "") { errors.push(app_strings.LBL_EMAIL_ERROR_MONITORED_FOLDER); } // if if (typeof(validateRules.valiateTrash) != 'undefined' && validateRules.valiateTrash) { var trashFolder = document.getElementById('trashFolder').value; if (trim(trashFolder) == "") { errors.push(app_strings.LBL_EMAIL_ERROR_TRASH_FOLDER); } // if } // if } if(port == "") { errors.push(app_strings.LBL_EMAIL_ERROR_PORT); } if(errors.length > 0) { out = app_strings.LBL_EMAIL_ERROR_DESC; for(i=0; i 0) { node.setUpLabel('' + node.data.origText + '(' + node.data.unseen + ')'); } else { node.setUpLabel(node.data.origText); } } else { node.setUpLabel('' + node.data.origText + ''); } SE.accounts.setupDDTarget(node); }, setupDDTarget : function(node) { if (node.ddTarget) { node.ddTarget.removeFromGroup(); delete node.ddTarget; } var id = node.getElId(); var num = id.substring(4); if (node.data.origText != SUGAR.language.get("Emails", "LNK_MY_INBOX") && node.data.origText != SUGAR.language.get("Emails", "LNK_MY_DRAFTS") && node.data.origText != SUGAR.language.get("Emails", "LNK_SENT_EMAIL_LIST")) { node.ddTarget = new SUGAR.email2.folders.folderDD("ygtvcontentel" + num); } else if (node.data.origText == SUGAR.language.get("Emails", "LNK_MY_INBOX")){ node.ddTarget = new YAHOO.util.DDTarget("ygtvcontentel" + num); } }, /** * Async call to rebuild the folder list. After a folder delete or account delete */ rebuildFolderList : function() { overlay(app_strings.LBL_EMAIL_REBUILDING_FOLDERS, app_strings.LBL_EMAIL_ONE_MOMENT); AjaxObject.startRequest(callbackFolders, urlStandard + '&emailUIAction=rebuildFolders'); }, /** * Returns the number of remote accounts the user has active. */ getAccountCount : function() { var tree = SE.tree; var count = 0; for(i=0; i 25) { tabLabel = tabLabel.substring(0, 25) + "..."; } // if targetDiv.set("label", tabLabel); targetDiv.set("content", out); var displayEmailFrameDiv = document.getElementById('displayEmailFrameDiv' + targetDiv.id); if (SUGAR.email2.util.isIe()) { displayEmailFrameDiv.style.height = "390px"; } else { displayEmailFrameDiv.style.height = "410px"; } var displayFrame = document.getElementById('displayEmailFrame' + targetDiv.id); displayFrame.contentWindow.document.write(email.description); displayFrame.contentWindow.document.close(); // hide archive links if(ret.meta.is_sugarEmail) { document.getElementById("archiveEmail" + targetDiv.id).style.display = "none"; document.getElementById("btnEmailView" + targetDiv.id).style.display = "none"; } else { if (document.getElementById("showDeialViewForEmail" + targetDiv.id)) document.getElementById("showDeialViewForEmail" + targetDiv.id).style.display = "none"; } // else }, consumeMetaPreview : function(ret) { // cache contents browser-side SE._setDetailCache(ret); var currrow = SE.grid.getLastSelectedRecord(); currrow = SE.grid.getRecord(currrow); if (!currrow) { document.getElementById('_blank').innerHTML = ''; return; } // handling if the Email drafts if(ret.type == 'draft'){ if (currrow.getData().uid == ret.uid) { SE.composeLayout.c0_composeDraft(); } return; } if (currrow.getData().uid != ret.meta.uid) { return; } // remove loading sprite document.getElementById('_blank').innerHTML = '