1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2005, 2006, 2007, 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) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * 
 26  * 
 27  * @private
 28  */
 29 DwtXFormDialog = function(xformDef, xmodelDef, parent, className, title, standardButtons, extraButtons, zIndex, mode, loc) {
 30 	if (arguments.length == 0) return;
 31 	className = className || "DwtXFormDialog";
 32 	DwtDialog.call(this, parent, className, title, standardButtons, extraButtons, zIndex, mode, loc);
 33 	 
 34 	this._xform = new XForm(xformDef, new XModel(xmodelDef), null, this);
 35 	this._xform.addListener(DwtEvent.XFORMS_FORM_DIRTY_CHANGE, new AjxListener(this, this._handleXFormDirty));
 36 	
 37 	this.setView(this._xform);
 38 
 39 	if (this._button[DwtDialog.OK_BUTTON]) {	
 40 		this.setButtonListener(DwtDialog.OK_BUTTON, new AjxListener(this, this._handleOkButton));
 41 	}
 42 	if (this._button[DwtDialog.CANCEL_BUTTON]) {	
 43 		this.setButtonListener(DwtDialog.CANCEL_BUTTON, new AjxListener(this, this._handleCancelButton));
 44 	}
 45 	if (this._button[DwtDialog.YES_BUTTON]) {	
 46 		this.setButtonListener(DwtDialog.YES_BUTTON, new AjxListener(this, this._handleYesButton));
 47 	}
 48 	if (this._button[DwtDialog.NO_BUTTON]) {	
 49 		this.setButtonListener(DwtDialog.NO_BUTTON, new AjxListener(this, this._handleNoButton));
 50 	}
 51 }
 52 DwtXFormDialog.prototype = new DwtDialog;
 53 DwtXFormDialog.prototype.constructor = DwtXFormDialog;
 54 
 55 // Data
 56 
 57 DwtXFormDialog.prototype._xform;
 58 DwtXFormDialog.prototype._xformInitialized = false;
 59 
 60 // Public methods
 61 
 62 DwtXFormDialog.prototype.setInstance = function(instance) { 
 63 	this._xform.setInstance(instance);
 64 }
 65 DwtXFormDialog.prototype.getInstance = function() {
 66 	return this._xform.getInstance();
 67 }
 68 
 69 DwtXFormDialog.prototype.popup = function(loc) {
 70 	this._initDialog();
 71 	
 72 	// make sure that form represents current data and show
 73 	this._xform.setIsDirty(true);
 74 	this._xform.refresh();
 75 	if (this._button[DwtDialog.OK_BUTTON]) {
 76 		this.setButtonEnabled(DwtDialog.OK_BUTTON, false);
 77 	}
 78 	if (this._button[DwtDialog.YES_BUTTON]) {
 79 		this.setButtonEnabled(DwtDialog.YES_BUTTON, false);
 80 	}
 81 	DwtDialog.prototype.popup.call(this, loc);
 82 }
 83 
 84 // Protected methods
 85 
 86 DwtXFormDialog.prototype._initDialog = function() {
 87 	// initialize form
 88 	if (!this._xformInitialized) {
 89 		this._xform.draw();
 90 		this._xformInitialized = true;
 91 	}
 92 }
 93 
 94 DwtXFormDialog.prototype._handleXFormDirty = function(event) {
 95 	if (this._button[DwtDialog.OK_BUTTON]) {
 96 		this.setButtonEnabled(DwtDialog.OK_BUTTON, true);
 97 	}
 98 	if (this._button[DwtDialog.YES_BUTTON]) {
 99 		this.setButtonEnabled(DwtDialog.YES_BUTTON, true);
100 	}
101 }
102 
103 DwtXFormDialog.prototype._handleOkButton = function(event) {
104 	this.popdown();
105 	this.setInstance(null);
106 }
107 DwtXFormDialog.prototype._handleCancelButton = DwtXFormDialog.prototype._handleOkButton;
108 
109 DwtXFormDialog.prototype._handleYesButton = DwtXFormDialog.prototype._handleOkButton;
110 DwtXFormDialog.prototype._handleNoButton = DwtXFormDialog.prototype._handleOkButton;
111