/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2008 MIND Co., Ltd.  http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jp.mosp.system.vo;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.common.MospException;
import jp.mosp.system.dto.MCodeDto;

public class LeaveReasonCardVo extends ReasonMenuVo {

	private static final long serialVersionUID = 7587659669223985261L;

	// URL、JSファイル、CSSファイル
	private static final String RETURN_URL = "/jsp/system/leaveReasonCard.jsp";
	private static final String EXTRA_JS   = "/pub/system/js/leaveReasonCard.js";
	private static final String EXTRA_CSS  = "/pub/system/css/leaveReasonCard.css";

	// 画面サブタイトル
	public final String SUB_TITLE = CommonConst.TTL_LEAVE_REASON;

	// 定数
	public static final int MODE_UPDATE = 1;

	// パラメータ名
	public static final String PRM_TXT_LEAVE_REASON = "txtLeaveReason";

	// フィールド
	private String[]	aryLeaveReason;  
	private String		txtLeaveReason;

	// モード(1：更新)
	private int mode;

	// フィールド名及び制限
	public static final String NAM_LEAVE_REASON 	= CommonConst.NAM_VACATION_LEAVE + CommonConst.NAM_REASON;

	public static final int	LEN_REASON = 15;

	/**
	 * コンストラクタ
	 */
	public LeaveReasonCardVo() {
		super();
		mode = 0;
		setExtraCss(EXTRA_CSS);
		addExtraJs(EXTRA_JS);
		setRetUrl(RETURN_URL);
		aryLeaveReason = new String[0];
	}

	/**
	 * パラメータ設定
	 */
	public void setParams(HttpServletRequest request, int i) {
		txtLeaveReason = request.getParameter(PRM_TXT_LEAVE_REASON + i);
	}

	/**
	 * フィールド設定
	 * @param listLeave		休暇理由リスト
	 */
	public void setFieldsLeaveReason(List listLeave) {
		// リストの設定
		list = listLeave;
		// データ総数の取得
		count = 10;
		// 配列の初期化
		aryLeaveReason		= new String[count];
		// データの設定
		int i = 0;
		Iterator it = listLeave.iterator();
		while (it.hasNext()) {
			MCodeDto dto = (MCodeDto)it.next();
			aryLeaveReason[i] = escapeHTML(dto.getTName());
			i++;
		}
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFieldLeaveReason(MCodeDto dto, int i) {
		dto.setTId(CommonConst.TID_LEAVE_REASON);
		dto.setTCode(String.valueOf(i));
		dto.setTName(txtLeaveReason);
		dto.setTChange("");
	}

	/**
	 * フィールドの妥当性確認
	 * @throws MospException
	 */
	public void validateLeaveReason(int i) throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 文字列長確認
		checkLength  (txtLeaveReason, LEN_REASON, NAM_LEAVE_REASON, PRM_TXT_LEAVE_REASON + i);
		// 妥当性確認終了時処理
		endValidation();
	}

	/**
	 * JavaScript設定
	 * @param cls 情報取得クラス
	 * @throws IllegalAccessException
	 */
	@Override
	public String getDirectJs(Class cls) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls));
		sb.append("var MODE = ");
		sb.append(mode);
		sb.append(";");
		return sb.toString();
	}

	// アクセサメソッド
	public String[] getEscAryLeaveReason() 	{ return aryLeaveReason.clone()	; }

	public String getTxtLeaveReason() 		{ return txtLeaveReason	; }
	public String getEscTxtLeaveReason() 	{ return escapeHTML(txtLeaveReason)	; }

	public void setTxtLeaveReason(String txtLeaveReason) { this.txtLeaveReason = txtLeaveReason; }

	public void setMode(int mode) { this.mode = mode; }
	public int getMode() { return mode; }

}
