1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 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) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * Creates a confirmation dialog.
 26  * @class
 27  * This class represents a confirmation dialog.
 28  * 
 29  * @param {DwtComposite}	parent  the parent widget (the shell)
 30  * @param {string}		className  the CSS class
 31  * 
 32  * @extends		DwtDialog
 33  */
 34 DwtConfirmDialog = function(parent, className, id, buttons, extraButtons) {
 35 	if (arguments.length == 0) return;
 36 
 37     if(!buttons){
 38 	buttons = [ DwtDialog.YES_BUTTON, DwtDialog.NO_BUTTON, DwtDialog.CANCEL_BUTTON ];
 39     }
 40 	DwtDialog.call(this, {parent:parent, className:className || "DwtConfirmDialog", title:AjxMsg.confirmTitle, standardButtons:buttons, id:id, extraButtons:extraButtons});
 41 	
 42 	this._questionDiv = document.createElement("DIV");
 43 	this._questionDiv.className = "DwtConfirmDialogQuestion";
 44 	this._getContentDiv().appendChild(this._questionDiv);
 45 	
 46 	this.registerCallback(DwtDialog.YES_BUTTON, this._handleYesButton, this);
 47 	this.registerCallback(DwtDialog.NO_BUTTON, this._handleNoButton, this);
 48 	this.registerCallback(DwtDialog.CANCEL_BUTTON, this._handleCancelButton, this);
 49 }
 50 DwtConfirmDialog.prototype = new DwtDialog;
 51 DwtConfirmDialog.prototype.constructor = DwtConfirmDialog;
 52 
 53 DwtConfirmDialog.prototype.toString =
 54 function() {
 55 	return "DwtConfirmDialog";
 56 };
 57 
 58 
 59 // Public methods
 60 
 61 /**
 62  * Pops up the confirmation dialog. The caller passes in the confirmation
 63  * question and callbacks for the Yes, No, and Cancel buttons.
 64  * <p>
 65  * <strong>Note:</strong>
 66  * If the callback for the No button is not specified, the confirmation
 67  * dialog assumes that the caller is only concerned with a Yes response
 68  * and hides the (presumably) extraneous Cancel button.
 69  * 
 70  * @param	{string}	questionHtml		the question HTML
 71  * @param	{AjxCallback}	yesCallback		the "yes" button callback
 72  * @param	{AjxCallback}	noCallback		the "no" button callback
 73  * @param	{AjxCallback}	cancelCallback		the "cancel" button callback
 74  * @param	{DwtPoint}	loc			the location
 75  */
 76 DwtConfirmDialog.prototype.popup = 
 77 function(questionHtml, yesCallback, noCallback, cancelCallback, loc) {
 78 	this._questionDiv.innerHTML = questionHtml || "";
 79 	
 80 	this._yesCallback = yesCallback;
 81 	this._noCallback = noCallback;
 82 	this._cancelCallback = cancelCallback;
 83 	
 84 	this.setButtonVisible(DwtDialog.CANCEL_BUTTON, Boolean(noCallback));
 85 	
 86 	DwtDialog.prototype.popup.call(this, loc);
 87 };
 88 
 89 DwtConfirmDialog.prototype.popdown =
 90 function() {
 91 	this._yesCallback = this._noCallback = this._cancelCallback = null;
 92 	DwtDialog.prototype.popdown.call(this);
 93 };
 94 
 95 // Protected methods
 96 
 97 DwtConfirmDialog.prototype._handleYesButton =
 98 function(ev) {
 99 	if (this._yesCallback) this._yesCallback.run(ev);
100 	this.popdown();
101 };
102 
103 DwtConfirmDialog.prototype._handleNoButton =
104 function(ev) {
105 	if (this._noCallback) this._noCallback.run(ev);
106 	this.popdown();
107 };
108 
109 DwtConfirmDialog.prototype._handleCancelButton =
110 function(ev) {
111 	if (this._cancelCallback) this._cancelCallback.run(ev);
112 	this.popdown();
113 };
114 
115 DwtConfirmDialog.prototype._getSeparatorTemplate =
116 function() {
117 	return "";
118 };
119