/*
 * $Id: SignOutPanel.java,v 1.1.1.1 2005/06/14 22:08:43 jm Exp $ $Revision:
 * 1.11 $ $Date: 2005/06/14 22:08:43 $
 * 
 * ==================================================================== Licensed
 * under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the
 * License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.jatak.webtools.web.gui.components.panel;

import wicket.PageParameters;
import wicket.RequestCycle;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.Form;
import wicket.markup.html.panel.Panel;

public abstract class SignOutPanel extends Panel {

	/**
	 * @see wicket.Component#Component(String)
	 */
	public SignOutPanel(String componentName, String userName) {
		super(componentName);
		
		// Add sign-in form to page, passing feedback panel as
		// validation error handler
		add(new SignOutForm("signOutForm", userName));
	}

	/**
	 * Sign out user
	 */
	public abstract void signOut();

	/**
	 * Sign in form.
	 */
	public final class SignOutForm extends Form {
		/** Serial Version ID. */
		private static final long serialVersionUID = 303695648327317416L;

		/**
		 * Constructor.
		 * 
		 * @param componentName
		 *            Name of the form component
		 * @param feedback
		 *            The feedback panel to update
		 */
		public SignOutForm(final String componentName, String userName) {
			super(componentName);
			add(new Label("email", userName));
		}

		/**
		 * @see wicket.markup.html.form.Form#handleSubmit()
		 */
		public final void onSubmit() {
			// Sign the user out
			signOut();
			
			// Get active request cycle
			final RequestCycle cycle = getRequestCycle();

			setResponsePage(getApplicationSettings()
					.getDefaultPageFactory().newPage(
							getApplicationPages().getHomePage(),
							(PageParameters) null));
		}
	}
}
