/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (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.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Community System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.servlets.format;

import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;

public class JoinKeyDialog extends ContentDialog
{
  /*--------------------------------------------------------------------------------
   * Constructors
   *--------------------------------------------------------------------------------
   */

  public JoinKeyDialog()
  {
    super("Join Key Required",null,"joinkeyform","sigops");
    setHiddenField("cmd","J");
    setHiddenField("sig","");
    setInstructions("You must specify a join key before you can join this community.  You might have received "
 		    + "the join key from the community's host, or via an invitation e-mail message. Please "
		    + "enter it in the box below.");
    addFormField(new CDTextFormField("key","Join key",null,false,32,64));
    addCommandButton(new CDImageButton("join","bn_join_now.gif","Join Now",80,24));
    addCommandButton(new CDImageButton("cancel","bn_cancel.gif","Cancel",80,24));

  } // end constructor

  protected JoinKeyDialog(JoinKeyDialog other)
  {
    super(other);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Overrides from class ContentDialog
   *--------------------------------------------------------------------------------
   */

  protected void validateWholeForm() throws ValidationException
  {
    if (StringUtil.isStringEmpty(getFieldValue("key")))
      throw new ValidationException("No join key specified.");

  } // end validateWholeForm

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  public void setupDialog(CommunityContext comm)
  {
    setHiddenField("sig",String.valueOf(comm.getCommunityID()));

  } // end setupDialog

  public void doDialog(CommunityContext comm) throws ValidationException, DataException, AccessError
  {
    validate();
    comm.join(getFieldValue("key"));

  } // end doDialog

  public void resetOnError(String message)
  {
    setErrorMessage(message);
    setFieldValue("key",null);

  } // end resetOnError

  public Object clone()
  {
    return new JoinKeyDialog(this);

  } // end clone

} // end class JoinKeyDialog

