1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2008, 2009, 2010, 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) 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 */ 27 28 /** 29 * Creates a prompt dialog. 30 * @class 31 * This class represents a prompt dialog. 32 * 33 * @param {Hash} args a hash of arguments 34 * @param {Array} args.buttons an array of buttons (default is [{@link DwtDialog.OK_BUTTON}, {@link DwtDialog.CANCEL_BUTTON}]) 35 * @param {String} args.password the password 36 * 37 * @extends ZmDialog 38 * 39 * @see ZmPromptDialog.getInstance 40 * @see ZmPromptDialog.getPasswordInstance 41 */ 42 ZmPromptDialog = function(args) { 43 args.buttons = args.buttons || [DwtDialog.OK_BUTTON, DwtDialog.CANCEL_BUTTON]; 44 this._password = args.password; 45 ZmDialog.call(this, args); 46 47 this._labelFieldId = this._htmlElId + "_label"; 48 this._nameFieldId = this._htmlElId + "_name"; 49 this._setNameField(this._nameFieldId); 50 }; 51 52 ZmPromptDialog.prototype = new ZmDialog; 53 ZmPromptDialog.prototype.constructor = ZmPromptDialog; 54 55 ZmPromptDialog.prototype.toString = 56 function() { 57 return "ZmPromptDialog"; 58 }; 59 60 /** 61 * Gets an instance of the prompt dialog. 62 * 63 * @return {ZmPromptDialog} the dialog 64 */ 65 ZmPromptDialog.getInstance = 66 function() { 67 if (!ZmPromptDialog._INSTANCE) { 68 ZmPromptDialog._INSTANCE = new ZmPromptDialog({ parent:appCtxt.getShell() }); 69 } 70 return ZmPromptDialog._INSTANCE; 71 }; 72 73 /** 74 * Gets an instance of the prompt dialog. 75 * 76 * @return {ZmPromptDialog} the dialog 77 */ 78 ZmPromptDialog.getPasswordInstance = 79 function() { 80 if (!ZmPromptDialog._PASSWORD_INSTANCE) { 81 ZmPromptDialog._PASSWORD_INSTANCE = new ZmPromptDialog({ parent:appCtxt.getShell(), password: true }); 82 } 83 return ZmPromptDialog._PASSWORD_INSTANCE; 84 }; 85 86 /** 87 * Pops-up the dialog. 88 * 89 * @param {Hash} params a hash of parameters 90 * @param {String} params.title the dialog box title 91 * @param {String} params.label the label next to the dialog's input field 92 * @param {String} params.value the initial value of input field 93 * @param {AjxCallback} params.callback the callback to run when ok button is pressed 94 */ 95 ZmPromptDialog.prototype.popup = 96 function(params) { 97 this.setTitle(params.title); 98 Dwt.byId(this._labelFieldId).innerHTML = params.label; 99 var nameElement = Dwt.byId(this._nameFieldId); 100 nameElement.innerHTML = params.value || ""; 101 this._resetCallbacks(); 102 this.registerCallback(DwtDialog.OK_BUTTON, params.callback); 103 DwtDialog.prototype.popup.call(this); 104 if (nameElement.focus) { 105 nameElement.focus(); 106 } 107 }; 108 109 ZmPromptDialog.prototype._contentHtml = 110 function() { 111 return AjxTemplate.expand("share.Dialogs#ZmPromptDialog", { id: this._htmlElId, type: this._password ? "password" : "text" }); 112 }; 113 114 ZmPromptDialog.prototype._okButtonListener = 115 function(ev) { 116 var results = this._getPromptData(); 117 if (results) 118 DwtDialog.prototype._buttonListener.call(this, ev, results); 119 }; 120 121 ZmPromptDialog.prototype._getPromptData = 122 function() { 123 return { 124 value: AjxStringUtil.trim(this._nameField.value), 125 dialog: this 126 }; 127 }; 128 129 ZmPromptDialog.prototype._enterListener = 130 function(ev) { 131 var results = this._getPromptData(); 132 if (results) 133 this._runEnterCallback(results); 134 }; 135 136 ZmPromptDialog.prototype._getTabGroupMembers = 137 function() { 138 return [this._nameField, this._colorButton]; 139 }; 140 141