/********************************************************************************* * SugarCRM Community Edition 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". ********************************************************************************/ if (typeof console == "undefined") console = { log: function(o) {alert(o)} }; var AjaxObject = { ret : '', currentRequestObject : null, //timeout : 30000, // 30 second timeout default timeout : 9999999999, // 30 second timeout default forceAbort : false, trail : new Array(), /** */ _reset : function() { this.timeout = 30000; this.forceAbort = false; }, folderRenameCleanup : function() { SUGAR.email2.folders.setSugarFolders(); }, fullSyncCleanup : function(o) { this.folders.checkMailCleanup(o); SUGAR.email2.settings.settingsDialog.hide(); }, /** */ composeCache : function(o) { var idx = SUGAR.email2.composeLayout.currentInstanceId; // post instance increment // get email templates and user signatures var ret = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.composeLayout.emailTemplates = ret.emailTemplates; SUGAR.email2.composeLayout.signatures = ret.signatures; SUGAR.email2.composeLayout.fromAccounts = ret.fromAccounts; SUGAR.email2.composeLayout.setComposeOptions(idx); //Set the error array so we can notify the user when they try to hit send if any errors //are present. We will also notify them now (after hitting compose button). SUGAR.email2.composeLayout.outboundAccountErrors = ret.errorArray; //if error element is returning an array, then check the length to make sure we have error messages if (typeof(ret.errorArray)=='object' && ret.errorArray instanceof Array && ret.errorArray.length > 0){ //add error messages for display for(i in ret.errorArray) overlay(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorArray[i], 'alert'); }else if (typeof(ret.errorArray)=='object' && ret.errorArray!=null && ret.errorArray!='' ) { //if error element is returning an object, and the object value is not empty or null, then display error message for(i in ret.errorArray) overlay(app_strings.LBL_EMAIL_ERROR_DESC, ret.errorArray[i], 'alert'); } //YUI bug with IE6 - Wont restore visibility property for nested select elements. if(SUGAR.isIE) { var overlayPanel = YAHOO.SUGAR.MessageBox.panel; if(overlayPanel) { overlayPanel.subscribe('hide',function() { YAHOO.util.Dom.setStyle('addressFrom' + idx,'visibility','');}); } } }, handleDeleteSignature : function(o) { hideOverlay(); var ret = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.composeLayout.signatures = ret.signatures; var field = document.getElementById('signature_id'); SUGAR.email2.util.emptySelectOptions(field); for(var i in ret.signatures) { // iterate through assoc array var opt = new Option(ret.signatures[i], i); field.options.add(opt); } setSigEditButtonVisibility(); }, /** */ handleDeleteReturn : function(o) { // force refresh ListView hideOverlay(); if(document.getElementById('focusEmailMbox')) { YAHOO.namespace('frameFolders').selectednode = SUGAR.email2.folders.getNodeFromMboxPath(document.getElementById('focusEmailMbox').innerHTML); } // need to display success message before calling next async call? document.getElementById(this.target).innerHTML = o.responseText; }, /** */ handleFailure : function(o) { // Failure handler overlay('Exception occurred...', o.statusText, 'alert'); if(document.getElementById('saveButton')) { document.getElementById('saveButton').disabled = false; } }, handleReplyForward : function(o) { var a = YAHOO.lang.JSON.parse(o.responseText); globalA = a; var idx = SUGAR.email2.composeLayout.currentInstanceId; document.getElementById('email_id' + idx).value = a.uid; document.getElementById('emailSubject' + idx).value = a.name; document.getElementById('addressTO' + idx).value = a.from; document.getElementById('uid' + idx).value = a.uid; if(a.cc) { document.getElementById('addressCC' + idx).value = a.cc; SE.composeLayout.showHiddenAddress('cc', idx); } if(a.type) { document.getElementById('type' + idx).value = a.type; } // apply attachment values SUGAR.email2.composeLayout.loadAttachments(a.attachments); setTimeout("callbackReplyForward.finish(globalA);", 500); }, handleReplyForwardForDraft : function(o) { var a = YAHOO.lang.JSON.parse(o.responseText); globalA = a; var idx = SUGAR.email2.composeLayout.currentInstanceId; document.getElementById('email_id' + idx).value = a.uid; document.getElementById('emailSubject' + idx).value = a.name; document.getElementById('addressTO' + idx).value = a.to; if(a.cc) { document.getElementById('addressCC' + idx).value = a.cc; SUGAR.email2.composeLayout.showHiddenAddress('cc',idx); } if(a.bcc) { document.getElementById('addressBCC' + idx).value = a.bcc; SUGAR.email2.composeLayout.showHiddenAddress('bcc',idx); } if(a.type) { document.getElementById('type' + idx).value = a.type; } // apply attachment values SUGAR.email2.composeLayout.loadAttachments(a.attachments); setTimeout("callbackReplyForward.finish(globalA);", 500); }, /** */ handleSuccess : function(o) { document.getElementById(this.target).innerHTML = o.responseText; hideOverlay(); }, /** */ ieDeleteSuccess : function(o) { hideOverlay(); SUGAR.email2.accounts.refreshInboundAccountTable(); alert(app_strings.LBL_EMAIL_IE_DELETE_SUCCESSFUL); SUGAR.email2.accounts.rebuildFolderList(); }, /** */ ieSaveSuccess : function(o) { document.getElementById('saveButton').disabled = false; var a = YAHOO.lang.JSON.parse(o.responseText); if (a) { if(a.error) { overlay(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_CHECK_IE_SETTINGS, 'alert'); SUGAR.email2.accounts.ieAccountError(SUGAR.email2.accounts.errorStyle); } else { resp = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.accounts.refreshInboundAccountTable(); SUGAR.email2.accounts.refreshOuboundAccountTable(); SUGAR.email2.folders.startEmailCheckOneAccount(resp.id, true); SUGAR.email2.accounts.inboundAccountEditDialog.hide(); } } else { hideOverlay(); overlay(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_SAVE_ACCOUNT, 'alert'); } }, /** */ loadAttachments : function(o) { var result = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.composeLayout.loadAttachments(result); }, /** */ loadSignature : function(o) { var ret = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.signatures[ret.id] = ret.signature_html; SUGAR.email2.composeLayout.setSignature(SUGAR.email2.signatures.targetInstance); }, /** * Follow up to mark email read|unread|flagged */ markEmailCleanup : function(o) { var ret = YAHOO.lang.JSON.parse(o.responseText); if (!ret['status']) { hideOverlay(); overlay(app_strings.LBL_EMAIL_ERROR_DESC, ret['message'], 'alert'); } else { SUGAR.email2.contextMenus.markEmailCleanup(); } // else }, /** */ rebuildShowFolders : function(o) { var t = YAHOO.lang.JSON.parse(o.responseText); var show = document.getElementById('ieAccountListShow'); SUGAR.email2.util.emptySelectOptions(show); for(i=0; i" + // remove button "" + // file icon "" + // hidden id field "" + // file name ((ret.nameForDisplay != null) ? ret.nameForDisplay + " " : ret.name + " ") + "
" + ""; overall.innerHTML += out; if(SUGAR.email2.util.isIe()) { document.getElementById('addedFiles' + idx).innerHTML = document.getElementById('addedFiles' + idx).innerHTML; } // hide popup SUGAR.email2.addFileDialog.hide(); // focus attachments SUGAR.email2.composeLayout.showAttachmentPanel(idx); } }; /////////////////////////////////////////////////////////////////////////// //// PER MODULE CALLBACK OBJECTS AjaxObject.accounts = { saveOutboundCleanup : function(o) { SUGAR.email2.accounts.refreshOuboundAccountTable(); SUGAR.email2.accounts.outboundDialog.hide(); var id = o.responseText; SUGAR.email2.accounts.newAddedOutboundId = id; }, saveDefaultOutboundCleanup: function(o){ }, callbackEditOutbound : { success : function(o) { var ret = YAHOO.lang.JSON.parse(o.responseText); // show overlay SUGAR.email2.accounts.showAddSmtp(); // fill values document.getElementById("mail_id").value = ret.id; document.getElementById("type").value = ret.type; document.getElementById("mail_sendtype").value = ret.mail_sendtype; document.getElementById("mail_name").value = ret.name; document.getElementById("mail_smtpserver").value = ret.mail_smtpserver; document.getElementById("outboundEmailForm").mail_smtptype.value = ret.mail_smtptype; document.getElementById("mail_smtpport").value = ret.mail_smtpport; document.getElementById("mail_smtpuser").value = ret.mail_smtpuser; document.getElementById("mail_smtpauth_req").checked = (ret.mail_smtpauth_req == 1) ? true : false; SUGAR.email2.accounts.smtp_authenticate_field_display(); document.getElementById("mail_smtpssl").options[ret.mail_smtpssl].selected = true; if(ret.type == 'system-override') { SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(true); SUGAR.email2.accounts.changeEmailScreenDisplay(ret.mail_smtptype,true); } else { SUGAR.email2.accounts.toggleOutboundAccountDisabledFields(false); SUGAR.email2.accounts.changeEmailScreenDisplay(ret.mail_smtptype,false); } SUGAR.util.setEmailPasswordDisplay('mail_smtppass', ret.has_password); }, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject }, callbackDeleteOutbound : { success : function(o) { var ret = YAHOO.lang.JSON.parse(o.responseText); if(ret.is_error) { if(confirm(ret.error_message)) { overlay(app_strings.LBL_EMAIL_IE_DELETE, app_strings.LBL_EMAIL_ONE_MOMENT); AjaxObject.startRequest(AjaxObject.accounts.callbackDeleteOutbound, urlStandard + "&emailUIAction=deleteOutbound&confirm=true&outbound_email=" + ret.outbound_email); } else hideOverlay(); } else { hideOverlay(); SUGAR.email2.accounts.refreshOuboundAccountTable(); } }, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject }, callbackCheckMailProgress : { success : function(o) { if (typeof(SUGAR.email2.accounts.totalMsgCount) == "undefined") { SUGAR.email2.accounts.totalMsgCount = -1; } //Check for server timeout / errors var ret = YAHOO.lang.JSON.parse(o.responseText); var done = false; if (typeof(o.responseText) == 'undefined' || o.responseText == "" || ret == false) { hideOverlay(); overlay(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_TIMEOUT, 'alert'); SUGAR.email2.accounts.totalMsgCount = -1; //SUGAR.email2.folders.rebuildFolders(); done = true; } var currIeId = ret['ieid']; var serverCount = ret.count; if (ret['status'] == 'done') { for(i=0; i < SUGAR.email2.accounts.ieIds.length; i++) { if (i == SUGAR.email2.accounts.ieIds.length - 1) { //We are all done done = true; break; } else if (SUGAR.email2.accounts.ieIds[i] == currIeId) { //Go to next account currIeId = SUGAR.email2.accounts.ieIds[i+1]; ret.count = 0; SUGAR.email2.accounts.totalMsgCount = -1; break; } } } else if (ret.mbox && ret.totalcount && ret.count) { SUGAR.email2.accounts.totalMsgCount = ret.totalcount; if (ret.count >= ret.totalcount) { serverCount = 0; } } else if (SUGAR.email2.accounts.totalMsgCount < 0 && ret.totalcount) { SUGAR.email2.accounts.totalMsgCount = ret.totalcount; } else { hideOverlay(); overlay(app_strings.LBL_EMAIL_ERROR_DESC, app_strings.LBL_EMAIL_ERROR_TIMEOUT, 'alert'); SUGAR.email2.accounts.totalMsgCount = -1; done = true; } if (done) { SUGAR.email2.accounts.totalMsgCount = -1; hideOverlay(); SUGAR.email2.folders.rebuildFolders(); SE.listView.refreshGrid(); } else if (SUGAR.email2.accounts.totalMsgCount < 0) { YAHOO.SUGAR.MessageBox.updateProgress(0, mod_strings.LBL_CHECKING_ACCOUNT + ' '+ (i + 2) + ' '+ mod_strings.LBL_OF + ' ' + SUGAR.email2.accounts.ieIds.length); AjaxObject.startRequest(AjaxObject.accounts.callbackCheckMailProgress, urlStandard + '&emailUIAction=checkEmailProgress&ieId=' + currIeId + "¤tCount=0&synch=" + ret.synch); } else { YAHOO.SUGAR.MessageBox.updateProgress((ret.count / SUGAR.email2.accounts.totalMsgCount) * 100, app_strings.LBL_EMAIL_DOWNLOAD_STATUS.replace(/\[\[count\]\]/, ret.count).replace(/\[\[total\]\]/, SUGAR.email2.accounts.totalMsgCount)); AjaxObject.startRequest(AjaxObject.accounts.callbackCheckMailProgress, urlStandard + '&emailUIAction=checkEmailProgress&ieId=' + currIeId + "¤tCount=" + serverCount + '&mbox=' + ret.mbox + '&synch=' + ret.synch + '&totalcount=' + SUGAR.email2.accounts.totalMsgCount); } }, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject } }; /////////////////////////////////////////////////////////////////////////////// //// COMPOSE LAYOUT AjaxObject.composeLayout = { /** * Populates the record id */ saveDraftCleanup : function(o) { var ret; hideOverlay(); try { ret = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.composeLayout.forceCloseCompose(ret.composeLayoutId); } catch(err) { if (o.responseText) { overlay(mod_strings.LBL_ERROR_SAVING_DRAFT, o.responseText, 'alert'); } } } }; AjaxObject.composeLayout.callback = { saveDraft : { success : AjaxObject.composeLayout.saveDraftCleanup, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject } }; AjaxObject.detailView = { /** * Pops-up a printable view of an email */ displayPrintable : function(o) { var ret = YAHOO.lang.JSON.parse(o.responseText); var displayTemplate = new YAHOO.SUGAR.Template(SUGAR.email2.templates['viewPrintable']); // 2 below must be in global context meta = ret.meta; meta['panelId'] = SUGAR.email2.util.getPanelId(); email = ret.meta.email; if (typeof(email.cc) == 'undefined') { email.cc = ""; } var out = displayTemplate.exec({ 'app_strings' : app_strings, 'theme' : theme, 'idx' : 'Preview', 'meta' : meta, 'email' : meta.email }); // open popup window var popup = window.open('modules/Emails/templates/_blank.html', 'printwin' , 'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'); popup.document.write(out); popup.document.close(); }, /** * Takes formatted response and creates a modal pop-over containing a title and content */ displayView : function(o) { var SED = SUGAR.email2.detailView; var ret = YAHOO.lang.JSON.parse(o.responseText); if(!SED.viewDialog) { SED.viewDialog = new YAHOO.widget.Dialog("viewDialog", { modal:true, visible:true, fixedcenter:true, constraintoviewport: true, shadow : true }); SED.viewDialog.renderEvent.subscribe(function() { var content = this.body.firstChild; var viewH = YAHOO.util.Dom.getViewportHeight(); if (content) { this.body.style.overflow = "auto"; this.body.style.width = "800px"; this.body.style.height = (viewH - 75 > content.clientHeight ? (content.clientHeight) : (viewH - 75)) + "px"; } }, SED.viewDialog); } // end lazy load SED.viewDialog.setHeader(ret.title); SED.viewDialog.setBody(ret.html); SED.viewDialog.render(); SED.viewDialog.show(); }, /** * Generates a modal popup to populate with the contents of bean's full EditView */ showQuickCreateForm : function(o) { var SED = SUGAR.email2.detailView; var ret = YAHOO.lang.JSON.parse(o.responseText); if(!SED.quickCreateDialog) { SED.quickCreateDialog = new YAHOO.widget.Dialog("quickCreate", { modal:true, visible:true, fixedcenter:true, constraintoviewport: true, shadow : true }); SED.quickCreateDialog.renderEvent.subscribe(function() { var viewH = YAHOO.util.Dom.getViewportHeight(); var contH = 0; for (var i in this.body.childNodes) { if (this.body.childNodes[i].clientHeight) { contH += this.body.childNodes[i].clientHeight; } else if (this.body.childNodes[i].offsetHeight) { contH += this.body.childNodes[i].offsetHeight; } // if } this.body.style.width = "800px"; this.body.style.height = (viewH - 75 > contH ? (contH + 10) : (viewH - 75)) + "px"; this.body.style.overflow = "auto"; }, SED.quickCreateDialog); SED.quickCreateDialog.hideEvent.subscribe(function(){ var qsFields = YAHOO.util.Dom.getElementsByClassName('.sqsEnabled', null, this.body); /*for(var qsField in qsFields){ if (typeof QSFieldsArray[qsFields[qsField].id] != 'undefined') Ext.getCmp('combobox_'+qsFields[qsField].id).destroy(); }*/ }); SED.quickCreateDialog.setHeader(app_strings.LBL_EMAIL_QUICK_CREATE); } // end lazy load if (ret.html) { ret.html = ret.html.replace('', ""); } SED.quickCreateDialog.setBody(ret.html ? ret.html : " "); SED.quickCreateDialog.render(); SUGAR.util.evalScript(ret.html + ''); SED.quickCreateDialog.ieId = ret.ieId; SED.quickCreateDialog.uid = ret.uid; SED.quickCreateDialog.mbox = ret.mbox; SED.quickCreateDialog.qcmodule = ret.module; SED.quickCreateDialog.show(); var editForm = document.getElementById('form_EmailQCView_' + ret.module); if (editForm) { editForm.module.value = 'Emails'; var count = SUGAR.EmailAddressWidget.count[ret.module] ? SUGAR.EmailAddressWidget.count[ret.module] : 0; var tableId = YAHOO.util.Dom.getElementsByClassName('emailaddresses', 'table', editForm)[0].id; var instId = ret.module + count; SED.quickCreateEmailsToAdd = ret.emailAddress; SED.quickCreateEmailCallback = function(instId, tableId) { var eaw = SUGAR.EmailAddressWidget.instances[instId]; if (typeof(eaw) == "undefined") window.setTimeout("SUGAR.email2.detailView.quickCreateEmailCallback('" + instId + "','" + tableId + "');", 100); eaw.prefillEmailAddresses(tableId, SUGAR.email2.detailView.quickCreateEmailsToAdd); } window.setTimeout("SUGAR.email2.detailView.quickCreateEmailCallback('" + instId + "','" + tableId + "');", 100); } }, saveQuickCreateForm : function(o) { hideOverlay(); SUGAR.email2.detailView.quickCreateDialog.hide(); validate['EditView'] = [ ]; }, saveQuickCreateFormAndReply : function(o) { hideOverlay(); var ret = YAHOO.lang.JSON.parse(o.responseText); SUGAR.email2.detailView.quickCreateDialog.hide(); var qcd = SUGAR.email2.detailView.quickCreateDialog; var type = (qcd.qcmodule == 'Cases') ? 'replyCase' : 'reply'; if (ret) { var emailID = ret.id; SUGAR.email2.composeLayout.c0_replyForwardEmail(null, ret.id, 'sugar::Emails', type); } else { SUGAR.email2.composeLayout.c0_replyForwardEmail(qcd.ieId, qcd.uid, qcd.mbox, type); } //Cean the validate cache to prevent errors on the next call validate['EditView'] = [ ]; }, saveQuickCreateFormAndAddToAddressBook : function(o) { hideOverlay(); SUGAR.email2.detailView.quickCreateDialog.hide(); SUGAR.email2.complexLayout.findPanel('contactsTab').show(); validate['EditView'] = [ ]; }, handleAssignmentDialogAssignAction : function() { var assign_user_id = window.document.forms['Distribute'].elements['assigned_user_id'].value; var dist = 'direct'; var users = false; var rules = false; var get = ""; var found_teams = false; var warning_message = mod_strings.LBL_WARN_NO_USERS; if(!found_teams && assign_user_id == '' ) { alert(warning_message); return; } var emailUids = SUGAR.email2.listView.getUidsFromSelection(); var uids = ""; for(i=0; i'; } overlay(SUGAR.language.get('Emails','LBL_IMPORT_STATUS_TITLE'), statusString, 'alert'); } SE.listView.refreshGrid(); }, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject }; var callbackComposeCache = { success : AjaxObject.composeCache, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject }; var callbackDelete = { success : AjaxObject.handleDeleteReturn, failure : AjaxObject.handleFailure, timeout : AjaxObject.timeout, scope : AjaxObject }; var callbackEmailDetailMultiple = { success : function(o) { hideOverlay(); var retMulti = YAHOO.lang.JSON.parse(o.responseText); var ret = new Object(); for(var i=0; i 0) { for (i = 0 ; i < tabArray.length ; i++) { var tabObject = tabArray[i]; if (tabObject.get("id") == ("composeTab" + idx)) { var tabLabel = a.name; if (tabLabel != null && tabLabel.length > 25) { tabLabel = tabLabel.substring(0, 25) + "..."; } // if tabObject.get("labelEl").firstChild.data = tabLabel; break; } } } //SUGAR.email2.innerLayout.regions.center.getPanel('composeLayout' + idx).setTitle(a.name); if (a.parent_name != null && a.parent_name != "") { document.getElementById('data_parent_name' + idx).value = a.parent_name; } if (a.parent_type != null && a.parent_type != "") { document.getElementById('data_parent_type' + idx).value = a.parent_type; } if (a.parent_id != null && a.parent_id != "") { document.getElementById('data_parent_id' + idx).value = a.parent_id; } if (a.fromAccounts.status) { var addressFrom = document.getElementById('addressFrom' + idx); SUGAR.email2.util.emptySelectOptions(addressFrom); var fromAccountOpts = a.fromAccounts.data; for(i=0; i