1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 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) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * Creates a dialog allowing user to choose between an Instance or Series for an appointment.
 26  * @constructor
 27  * @class
 28  *
 29  * @author Parag Shah
 30  * @param {Hash}	params			a hash of parameters
 31  * @param {DwtComposite}      params.parent			a parent widget (the shell)
 32  * @param {String}	params.title			a title of dialog
 33  * @param {String}	params.confirmMsg 	a dialog confirmation message 
 34  * @param {String}	params.choiceLabel1	a label value for choice 1
 35  * @param {String}	params.choiceLabel2	a label value for choice 2
 36  * 
 37  * @extends	DwtDialog
 38  */
 39 ZmApptDeleteNotifyDialog = function(params) {
 40 
 41     params = Dwt.getParams(arguments, ZmApptDeleteNotifyDialog.PARAMS);
 42     var buttons = [ DwtDialog.YES_BUTTON, DwtDialog.NO_BUTTON, DwtDialog.CANCEL_BUTTON ];
 43     DwtDialog.call(this, {parent: params.parent, standardButtons:buttons, id:"CONFIRM_DELETE_APPT_DIALOG"});
 44 
 45     this._choiceLabel1 = params.choiceLabel1;
 46     this._choiceLabel2 = params.choiceLabel2;
 47     this._confirmMsg   = params.confirmMsg;
 48     this._choice2WarningMsg = params.choice2WarningMsg;
 49 
 50 	this.setTitle(params.title || AjxMsg.confirmTitle);
 51 	this.setContent(this._setHtml());
 52 	this._cacheFields();
 53     this.registerCallback(DwtDialog.YES_BUTTON, new AjxCallback(this, this._handleYesButton));
 54     this.registerCallback(DwtDialog.NO_BUTTON, new AjxCallback(this, this._handleNoButton));
 55 };
 56 
 57 ZmApptDeleteNotifyDialog.PARAMS = ["parent", "title", "confirmMsg", "choiceLabel1", "choiceLabel2"];
 58 
 59 ZmApptDeleteNotifyDialog.prototype = new DwtDialog;
 60 ZmApptDeleteNotifyDialog.prototype.constructor = ZmApptDeleteNotifyDialog;
 61 
 62 // Public methods
 63 
 64 ZmApptDeleteNotifyDialog.prototype.toString =
 65 function() {
 66 	return "ZmApptDeleteNotifyDialog";
 67 };
 68 
 69 /**
 70  * Initializes the dialog.
 71  * 
 72  * @param	{ZmAppt}	appt		the appointment
 73  * @param	{String}	attId		the id
 74  */
 75 ZmApptDeleteNotifyDialog.prototype.initialize =
 76 function(appt, attId) {
 77 	this._appt = appt;
 78 	this._attId = attId;
 79 	this._defaultRadio.checked = true;
 80 };
 81 
 82 // helper method - has no use for this dialog
 83 ZmApptDeleteNotifyDialog.prototype.getAppt =
 84 function() {
 85 	return this._appt;
 86 };
 87 
 88 // helper method - has no use for this dialog
 89 ZmApptDeleteNotifyDialog.prototype.getAttId =
 90 function() {
 91 	return this._attId;
 92 };
 93 
 94 /**
 95  * Checks if the default option is checked.
 96  * 
 97  * @return	{Boolean}	<code>true</code> if the default option is checked
 98  */
 99 ZmApptDeleteNotifyDialog.prototype.isDefaultOptionChecked =
100 function() {
101 	return this._defaultRadio.checked;
102 };
103 
104 ZmApptDeleteNotifyDialog.prototype.addSelectionListener =
105 function(buttonId, listener) {
106 	this._button[buttonId].addSelectionListener(listener);
107 };
108 
109 
110 // Private / protected methods
111 
112 ZmApptDeleteNotifyDialog.prototype._setHtml =
113 function() {
114     this._confirmMessageDivId = Dwt.getNextId();
115 	this._defaultRadioId	= Dwt.getNextId();
116 	this._notifyChoiceName	= Dwt.getNextId();
117 
118 	var html = new Array();
119 	var i = 0;
120 
121 	html[i++] = "<div style='width:300px;' id='";
122     html[i++] = this._confirmMessageDivId;
123     html[i++] = "'>";
124 	html[i++] = this._confirmMsg;
125 	html[i++] = "</div><div style='margin:1em;width:300px;'>";
126 	html[i++] = "<table class='ZRadioButtonTable'>";
127 	html[i++] = "<tr><td width=1%><input checked value='1' type='radio' id='";
128 	html[i++] = this._defaultRadioId;
129 	html[i++] = "' name='";
130 	html[i++] = this._notifyChoiceName;
131 	html[i++] = "'></td><td>";
132 	html[i++] = "<label for='" + this._defaultRadioId + "'>";
133 	html[i++] = this._choiceLabel1;
134 	html[i++] = "</label>";
135 	html[i++] = "</td></tr>";
136 	html[i++] = "<tr><td width=1%><input value='2' type='radio' id='";
137 	html[i++] = this._defaultRadioId + this._notifyChoiceName;
138 	html[i++] = "' name='";
139 	html[i++] = this._notifyChoiceName;
140 	html[i++] = "'></td><td>";
141 	html[i++] = "<label for='" + this._defaultRadioId + this._notifyChoiceName + "'>"
142 	html[i++] = this._choiceLabel2;
143 	html[i++] = "</label>";
144 	html[i++] = "</td></tr>";
145     if (this._choice2WarningMsg) {
146         html[i++] = "<tr><td></td><td style='font-style:italic'>" + this._choice2WarningMsg + "</td></tr>";
147     }
148 	html[i++] = "</table></div>";
149 
150 	return html.join("");
151 };
152 
153 ZmApptDeleteNotifyDialog.prototype._cacheFields =
154 function() {
155 	this._defaultRadio = document.getElementById(this._defaultRadioId); 		delete this._defaultRadioId;	
156 };
157 
158 ZmApptDeleteNotifyDialog.prototype.popup = 
159 function(yesCallback, noCallback) {
160 
161 	this._yesCallback = yesCallback;
162 	this._noCallback = noCallback;
163 
164 	this.setButtonVisible(DwtDialog.CANCEL_BUTTON, Boolean(noCallback));
165 
166 	DwtDialog.prototype.popup.call(this);
167 };
168 
169 ZmApptDeleteNotifyDialog.prototype._handleYesButton =
170 function(ev) {
171 	if (this._yesCallback) this._yesCallback.run(ev);
172 	this.popdown();
173 };
174 
175 ZmApptDeleteNotifyDialog.prototype._handleNoButton =
176 function(ev) {
177 	if (this._noCallback) this._noCallback.run(ev);
178 	this.popdown();
179 };
180