1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2010, 2011, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2010, 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates a dialog for showing debug log messages. 26 * @class 27 * This class represents a dialog for showing debug log messages. 28 * 29 * @param {DwtControl} shell the parent 30 * 31 * @extends DwtDialog 32 */ 33 ZmDebugLogDialog = function(parent) { 34 35 var title = ZmMsg.debugLog; 36 var emailButton = new DwtDialog_ButtonDescriptor(ZmDebugLogDialog.EMAIL_BUTTON, ZmMsg.sendAsEmail, DwtDialog.ALIGN_LEFT); 37 var clearButton = new DwtDialog_ButtonDescriptor(ZmDebugLogDialog.CLEAR_BUTTON, ZmMsg.clear, DwtDialog.ALIGN_LEFT); 38 DwtDialog.call(this, {parent:parent, title:title, standardButtons:[DwtDialog.OK_BUTTON], 39 extraButtons: [emailButton, clearButton]}); 40 41 this.setButtonListener(ZmDebugLogDialog.EMAIL_BUTTON, new AjxListener(this, this._handleEmailButton)); 42 this.setButtonListener(ZmDebugLogDialog.CLEAR_BUTTON, new AjxListener(this, this._handleClearButton)); 43 44 this._setAllowSelection(); 45 this.setContent(this._contentHtml()); 46 }; 47 48 ZmDebugLogDialog.prototype = new DwtDialog; 49 ZmDebugLogDialog.prototype.constructor = ZmDebugLogDialog; 50 51 ZmDebugLogDialog.EMAIL_BUTTON = "EMAIL"; 52 ZmDebugLogDialog.CLEAR_BUTTON = "CLEAR"; 53 54 // Public methods 55 56 /** 57 * Pops-up the dialog. 58 * 59 * @param {string} content text to display 60 * @param {constant} type logging type (see AjxDebug) 61 */ 62 ZmDebugLogDialog.prototype.popup = 63 function(content, type) { 64 65 this._logType = type; 66 this.setTitle(AjxMessageFormat.format(ZmMsg.debugLog, [type])); 67 var div = document.getElementById(this._descDivId); 68 if (div) { 69 var size = AjxDebug.BUFFER_MAX[type]; 70 div.innerHTML = AjxMessageFormat.format(ZmMsg.debugLogDesc, [size, type]); 71 } 72 div = document.getElementById(this._contentDivId); 73 if (div) { 74 div.innerHTML = content; 75 } 76 77 DwtDialog.prototype.popup.call(this); 78 }; 79 80 // Protected methods 81 82 ZmDebugLogDialog.prototype._contentHtml = 83 function() { 84 85 this._descDivId = this._htmlElId + "_desc"; 86 this._contentDivId = this._htmlElId + "_log"; 87 88 return AjxTemplate.expand("share.Widgets#ZmDebugLogDialog", {id:this._htmlElId}); 89 }; 90 91 ZmDebugLogDialog.prototype._handleEmailButton = 92 function(event) { 93 this.popdown(); 94 var div = document.getElementById(this._contentDivId); 95 var text = AjxStringUtil.convertHtml2Text(div); 96 var params = {action:ZmOperation.NEW_MESSAGE, subjOverride:ZmMsg.debugLogEmailSubject, 97 composeMode: Dwt.TEXT, extraBodyText:text}; 98 appCtxt.getApp(ZmApp.MAIL).compose(params); 99 }; 100 101 ZmDebugLogDialog.prototype._handleClearButton = 102 function(event) { 103 AjxDebug.BUFFER[this._logType] = []; 104 var div = document.getElementById(this._contentDivId); 105 div.innerHTML = ""; 106 }; 107