<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<c:set var="pageKorName" scope="request">민원 원본 보기</c:set>

<div class="d-flex flex-row justify-content-evenly" data-doctx="${pageName}">
	<div class="card">
		<form name="frmEdit">
			<input name="crdnId" type="hidden" data-map="CRDN_ID" />

			<div class="row g-1">
				<div class="col-md-4">
					<label is="name-label" for="cvlcptListNo" class="w-px-150 bg-lighter pe-2 col-form-label text-sm-end">
						목록번호
					</label>
					<input type="text" is="id-input" name="cvlcptListNo" data-map="CVLCPT_LIST_NO"
						class="form-control" readonly />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="cvlcptRcptNo"
					class="w-px-150 bg-lighter pe-2 col-form-label text-sm-end">
						접수번호
					</label>
					<input type="text" is="id-input" name="cvlcptRcptNo"
					data-map="CVLCPT_RCPT_NO" class="form-control" readonly />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="cvlcptAplcntNm"
					class="w-px-150 bg-lighter pe-2 col-form-label text-sm-end">
						신청자
					</label>
					<input type="text" is="id-input" name="cvlcptAplcntNm"
					data-map="CVLCPT_APLCNT_NM" class="form-control" readonly />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="cvlcptRcptYmd"
					class="w-px-150 bg-lighter pe-2 col-form-label text-sm-end">
						접수일자
					</label>
					<input type="text" is="id-input" name="cvlcptRcptYmd"
					data-map="CVLCPT_RCPT_YMD" class="form-control" readonly />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="cvlcptPrcsPrnmtDt"
					class="w-px-150 bg-lighter pe-2 col-form-label text-sm-end">
						처리기한
					</label>
					<input type="text" is="id-input" name="cvlcptPrcsPrnmtDt"
					data-map="CVLCPT_PRCS_PRNMNT_DT" class="form-control" readonly />
				</div>
				<div class="col-md-12">
					<label is="name-label" for="cvlcptAplyCn"
					class="w-px-150 bg-lighter pe-2 col-form-label text-sm-center">
						민원 내용
					</label>
					<span class="float-end pe-4">
						<button type="button" class="btn btn-blue" name="btnMakeHwp" title="한글파일 다운">
						한글파일 다운
						</button>
					</span>
				</div>
				<div class="col-md-12">
					<div class="px-2">
						<textarea is="id-textarea" name="cvlcptAplyCn" data-map="CVLCPT_APLY_CN"
						rows="25" class="w-100" readonly
						></textarea>
					</div>
				</div>
				<div class="col-md-6">
					<label is="name-label" for="cvlcptAplySeCd"
					class="w-px-150 bg-lighter pe-2 col-form-label text-sm-center">
						접수경로
					</label>
					<select is="id-select" name="cvlcptAplySeCd" class="form-select"
					data-map="CVLCPT_APLY_SE_CD"
					disabled="disabled">
						<option value=""></option>
						<c:forEach items="${FIM039List}" var="item">
							<option value="${item.code}">${item.value}</option>
		                </c:forEach>
					</select>
				</div>
				<div class="col-md-6" name="pageNavArea">
					<input type="text" name="countStauts"
					class="form-control w-px-150 text-center fw-bold" readonly />
					<button type="button" iname="btnPrev" class="w-px-50 btn-PageUp">◀</button>
					<button type="button" name="btnNext" class="w-px-50 btn-PageDown">▶</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script>
LoadScript("cvlc01050Script",wctx.url("/resources/js/fims/cvlc/cvlc01050.js?ver=${ver}"));

pageObject["${pageName}"] = newDoctxFinder("${pageName}");
pageObject["${pageName}"].provided = {};

pageObject.childReq = [];
pageObject.childReq.push({
	getCountStatus : function(){ return ""; },
	getNextKey : function(){ return ""; },
	getPrevKey : function(){ return ""; },
	selectRow : function(){}
});

$(document).ready(function() {

	var $P = pageObject["${pageName}"];
	$P.taskSeCd = "${taskSeCd}";

	if(pageObject.parentRes.length > 0){
		$P.provided = pageObject.parentRes.pop();
	} else {
		$P.provided = pageObject.childReq.pop();
		$P.$findn("pageNavArea").hide();
	}

	/**************************************************************************
	* DatasetControl, DatasetSupport, FormFields
	**************************************************************************/
	$P.formFields = new FimsFormFields($P.selectorn("frmEdit"));

	var ctrl = newCvlc01050Control($P);

	ctrl.dataset.onCurrentChange = (dataItem) => {
		$P.formFields.set(ctrl,dataItem);
	}

	/**************************************************************************
	* pageObject.function
	**************************************************************************/

	$P.fnPrev = () => {
		var prevKey = $P.provided.getPrevKey($P.$findn("crdnId").val());
		if(prevKey != ""){
			$P.fnGo(prevKey);
		}
	}

	$P.fnNext = () => {
		var nextKey = $P.provided.getNextKey($P.$findn("crdnId").val());
		if(nextKey != ""){
			$P.fnGo(nextKey);
		}
	}

	$P.fnGo = (crdnId) => {
		ajax.get({
			url: ctrl.urls.getInfo,
			data: { "crdnId" : crdnId },
			headers: {
			    Accept: "application/json; charset=utf-8"
			},
			success : (resp) => {
				var cvlcptInfo = resp.cvlcptInfo;
				cvlcptInfo.CVLCPT_APLY_CN = StringSupport.escapeHTMLEntity(cvlcptInfo.CVLCPT_APLY_CN);
				ctrl.dataset.setData([cvlcptInfo]);

				var cs = $P.provided.getCountStatus($P.$findn("crdnId").val());
				$P.$findn("countStauts").val(cs);
				$P.provided.selectRow(crdnId);
			}
		});
	}

	$P.fnMakeHwp = () => {
		var url = wctx.url("/cvlc/cvlc01/050/makeFileFromHwpFormat.do");
		var parameter = toQuery({ crdnId : $P.$findn("crdnId").val() });

		document.location.href = url + "?" + parameter;
	}

	/**************************************************************************
	* element.on
	**************************************************************************/
	$P.$findn("btnPrev").on("click", () => $P.fnPrev() );
	$P.$findn("btnNext").on("click", () => $P.fnNext() );
	$P.$findn("btnMakeHwp").on("click", () => $P.fnMakeHwp() );

	/**************************************************************************
	* 초기화
	**************************************************************************/
	var cvlcptInfo = ${cvlcptInfo};
	cvlcptInfo.CVLCPT_APLY_CN = StringSupport.escapeHTMLEntity(cvlcptInfo.CVLCPT_APLY_CN);
	ctrl.dataset.setData([cvlcptInfo]);
	var cs = $P.provided.getCountStatus($P.$findn("crdnId").val());
	$P.$findn("countStauts").val(cs);
});
</script>