/*
 * 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.workflow.vo;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospException;

import jp.mosp.workflow.dto.AmRouteDto;

public class ApprovalRouteCardVo extends ApprovalMenuVo {

	private static final long serialVersionUID = -8505387639842276947L;

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

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

	// 定数
	public static final int MODE_INSERT		= 0;
	public static final int MODE_UPDATE		= 1;
	public static final int MODE_IMPOSSIBLE	= 2;

	// パラメータ名
	public static final String PRM_TXT_ROUTE_CODE		= "txtRouteCode";
	public static final String PRM_PLT_LAYER1			= "pltLayer1";
	public static final String PRM_PLT_LAYER2			= "pltLayer2";
	public static final String PRM_PLT_LAYER3			= "pltLayer3";
	public static final String PRM_PLT_LAYER4			= "pltLayer4";
	public static final String PRM_PLT_LAYER5			= "pltLayer5";
	public static final String PRM_PLT_LAST_LAYER  	= "pltLastLayer";
	public static final String PRM_PLT_DELETE			= "pltDelete";

	// フィールド
	private String txtRouteCode;
	private String pltLayer1;
	private String pltLayer2;
	private String pltLayer3;
	private String pltLayer4;
	private String pltLayer5;
	private String pltLastLayer;
	private String pltDelete;

	// プルダウンリスト
	public String[][] aryPltUnit;

	// フィールド名及び制限
	public static final String NAM_ROUTE_CODE	= CommonConst.NAM_APPROVAL_ROUTE + CommonConst.NAM_COMMON_CODE;
	public static final String NAM_CODE		= CommonConst.NAM_COMMON_CODE;
	public static final String NAM_LAYER1		= CommonConst.NAM_1ST_APPROVED;
	public static final String NAM_LAYER2		= CommonConst.NAM_2ND_APPROVED;
	public static final String NAM_LAYER3		= CommonConst.NAM_3RD_APPROVED;
	public static final String NAM_LAYER4		= CommonConst.NAM_4TH_APPROVED;
	public static final String NAM_LAYER5		= CommonConst.NAM_5TH_APPROVED;
	public static final String NAM_LAST_LAYER	= CommonConst.NAM_LAST_APPROVED;
	public static final String NAM_DELETE		= CommonConst.NAM_DELETE_FLAG;

	public static final int    LEN_CODE = 10;

	public static final String REG_DELETE  = CommonConst.REG_DELETE;

	/**
	 * コンストラクタ
	 */
	public ApprovalRouteCardVo() {
		super();
		mode = MODE_INSERT;
		setExtraCss(EXTRA_CSS);
		addExtraJs(EXTRA_JS);
		setRetUrl(RETURN_URL);
	}

	/**
	 * 初期値設定
	 */	
	public void setDefaultValues(){
		setTxtRouteCode("");
		setPltLayer1("");
		setPltLayer2("");
		setPltLayer3("");
		setPltLayer4("");
		setPltLayer5("");
		setPltLastLayer("");
		setPltDelete(String.valueOf(MospConst.DELETE_FLAG_OFF));
	}

	/**
	 * パラメータ設定
	 */
	public void setParams(HttpServletRequest request) {
		txtRouteCode	= request.getParameter(PRM_TXT_ROUTE_CODE);
		pltLayer1		= request.getParameter(PRM_PLT_LAYER1);
		pltLayer2		= request.getParameter(PRM_PLT_LAYER2);
		pltLayer3		= request.getParameter(PRM_PLT_LAYER3);
		pltLayer4		= request.getParameter(PRM_PLT_LAYER4);
		pltLayer5		= request.getParameter(PRM_PLT_LAYER5);
		pltLastLayer	= request.getParameter(PRM_PLT_LAST_LAYER);
		pltDelete		= request.getParameter(PRM_PLT_DELETE);
	}

	/**
	 * フィールド設定
	 * @param dto 対象DTO
	 */
	public void setFields(AmRouteDto dto) {
		txtRouteCode	= dto.getRtCode();
		pltLayer1		= dto.getLayer1();
		pltLayer2		= dto.getLayer2();
		pltLayer3		= dto.getLayer3();
		pltLayer4		= dto.getLayer4();
		pltLayer5		= dto.getLayer5();
		pltLastLayer	= dto.getLastLayer();
		pltDelete 		= String.valueOf(dto.getDeleteFlag());
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFields(AmRouteDto dto) {
		dto.setRtCode(txtRouteCode);
		dto.setLayer1(pltLayer1);
		dto.setLayer2(pltLayer2);
		dto.setLayer3(pltLayer3);
		dto.setLayer4(pltLayer4);
		dto.setLayer5(pltLayer5);
		dto.setLastLayer(pltLastLayer);
		dto.setDeleteFlag(Integer.parseInt(pltDelete));
	}

	/**
	 * フィールドの妥当性確認
	 * @throws MospException
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 必須確認
		checkRequired(txtRouteCode	, NAM_ROUTE_CODE	, PRM_TXT_ROUTE_CODE);
		// 文字列長確認
		checkLength(txtRouteCode	, LEN_CODE	, NAM_ROUTE_CODE	, PRM_TXT_ROUTE_CODE);
		// 妥当性確認終了時処理
		endValidation();
	}

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

	// アクセサメソッド
	public String getTxtRouteCode() 	{ return txtRouteCode	; }
	public String getPltLayer1() 		{ return pltLayer1		; }
	public String getPltLayer2() 		{ return pltLayer2		; }
	public String getPltLayer3() 		{ return pltLayer3		; }
	public String getPltLayer4() 		{ return pltLayer4		; }
	public String getPltLayer5() 		{ return pltLayer5		; }
	public String getPltLastLayer() 	{ return pltLastLayer	; }
	public String getPltDelete() 		{ return pltDelete		; }

	public String getEscTxtRouteCode() 	{ return escapeHTML(txtRouteCode)	; }

	public void setTxtRouteCode	(String txtRouteCode) 	{ this.txtRouteCode	= txtRouteCode	; }
	public void setPltLayer1		(String pltLayer1	) 	{ this.pltLayer1 	= pltLayer1		; }
	public void setPltLayer2		(String pltLayer2	) 	{ this.pltLayer2 	= pltLayer2		; }
	public void setPltLayer3		(String pltLayer3	) 	{ this.pltLayer3 	= pltLayer3		; }
	public void setPltLayer4		(String pltLayer4	) 	{ this.pltLayer4 	= pltLayer4		; }
	public void setPltLayer5		(String pltLayer5	) 	{ this.pltLayer5	= pltLayer5		; }
	public void setPltLastLayer	(String pltLastLayer) 	{ this.pltLastLayer	= pltLastLayer	; }
	public void setPltDelete		(String pltDelete	) 	{ this.pltDelete 	= pltDelete		; }

}
