<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>

<!-- Page Body -->
<div class="card">
	<!-- 입력 영역 -->
	<form id="frmEdit--${pageName}" name="frmEdit">
		<!-- hidden -->
		<input type="hidden" id="crdnId--${pageName}" name="crdnId" data-map="CRDN_ID" />
		<input type="hidden" id="sggCd--${pageName}" name="sggCd" data-map="SGG_CD" />
		<input type="hidden" id="taskSeCd--${pageName}" name="taskSeCd" data-map="TASK_SE_CD" />
		<input type="hidden" id="cvlcptDscsnId--${pageName}" name="cvlcptDscsnId" data-map="CVLCPT_DSCSN_ID" />
		<input type="hidden" id="vhrno--${pageName}" name="vhrno" data-map="VHRNO" />
		<input type="hidden" id="rtpyrNo--${pageName}" name="rtpyrNo" data-map="RTPYR_NO" />

		<div class="row g-1">
			<!-- 민원 접수 구분 코드 -->
			<div class="col-md-12">
				<label for="cvlcptRcptSeCd--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">접수구분</label>
				<select class="form-select" id="cvlcptRcptSeCd--${pageName}" name="cvlcptRcptSeCd" data-map="CVLCPT_RCPT_SE_CD" required>
					<option value="">선택하세요</option>
					<c:forEach items="${FIM065List}" var="item">
						<option value="${item.code}">${item.value}</option>
					</c:forEach>
				</select>
			</div>
			<!-- 상담 내용 -->
			<div class="col-md-12">
				<label for="dscsnCn--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">상담 내용</label>
				<textarea type="text" class="form-control w-80" id="dscsnCn--${pageName}" name="dscsnCn" data-map="DSCSN_CN" rows="5" data-maxlengthb="4000">
				</textarea>
			</div>
		</div>
	</form> <!-- /입력 영역 -->
</div>
<!-- <div class="card"> -->

<!-- 업무 버튼 표시 -->
<div>
	<span class="container-page-btn">
		<span class="container-window-btn-right">
			<!-- 업무 버튼 -->
			<button type="button" class="btn btn-primary" id="btnSave--${pageName}" title="저장" onclick="fnSave${pageName}()">저장</button>
		</span>
	</span>
</div>
<!-- / 업무 버튼 표시 -->

<script>
	/**************************************************************************
	 * Global Variable
	 **************************************************************************/
	// URL
	var ${pageName}PrefixUrl = "/sprt/sprt04";
	// FormFields
 	var ${pageName}Fields = new FormFields("#frmEdit--${pageName}");

	/**************************************************************************
	 * DatasetControl
	 **************************************************************************/
	var ${pageName}Control = new DatasetControl({
		  prefix : "cvlcptDscsnCn"
		, prefixName : "민원상담내용"
		, keymapper : info => info ? info.CVLCPT_DSCSN_ID : ""
		, dataGetter : obj => obj.cvlcptDscsnCn
		, urls : {
			  create : wctx.url(${pageName}PrefixUrl + "/020/create.do")		// 등록
			, update : wctx.url(${pageName}PrefixUrl + "/020/update.do")		// 수정
		}
	});

	${pageName}Control.onCurrentChange = item => {
		${pageName}Fields.set(item);
	}

	/**************************************************************************
	 *
	 **************************************************************************/
	// 저장 callback
	${pageName}Control.onSave = (resp) => {
  		let dialogTitle = $("#" + ${pageName}Control.prefix + "Dialog").find("h5.modal-title").html();
  		let showMessage = resp.retMessage.replace(/[S]|[F]/g, dialogTitle);

		dialog.alert(showMessage);

		if (resp.saved) {
			dialog.close(${pageName}Control.prefix + "Dialog");
		}
	}

	// 저장
	${pageName}Control.save = (info) => {
		if (!info) return;

  		let create = isEmpty(info.cvlcptDscsnId);

		ajax.post({
  			  url : !create ? ${pageName}Control.urls.update : ${pageName}Control.urls.create
  			, data : info
  			, success : resp => ${pageName}Control.onSave(resp)
  		});
	}

	/**************************************************************************
	 * 초기 셋팅
	 **************************************************************************/
	// 검색조건 초기값 셋팅
	initForm${pageName} = () => {
		let initDataset = ${cvlcptDscsnCn};

		$("#cvlcptRcptSeCd--${pageName}").prop("disabled", true);

		if (initDataset.CVLCPT_DSCSN_ID == undefined || initDataset.CVLCPT_DSCSN_ID == null) {
			$("#cvlcptRcptSeCd--${pageName}").prop("disabled", false);
		}
	}

	// 이벤트 설정
	setEvent${pageName} = () => {

	}

	/**************************************************************************
	 * function
	 **************************************************************************/
	// 저장
	fnSave${pageName} = () => {
		// validate 확인
		if (!customValidate($("#frmEdit--${pageName}").find("input, select, textarea"))) return;

		dialog.alert({
			  content : "현재 " + ${pageName}Control.prefixName + " 정보를 저장하시겠습니까?"
			, onOK : () => {
				${pageName}Control.save(${pageName}Fields.get());
			}
		});
	}

	/**************************************************************************
	 * script 진입
	 **************************************************************************/
	$(document).ready(function() {
		// 이벤트 설정
		setEvent${pageName}();

		// 화면 초기 설정
		initForm${pageName}();

		// Data 셋팅
		${pageName}Control.setData([${cvlcptDscsnCn}]);
	});

// #sourceURL=sprt04020-info.jsp
</script>
