<%@ 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="content-wrapper" data-doctx="${pageName}">
	<div class="container-xxl flex-grow-1 px-0">

		<div class="card">
			<form name="frmEdit">
				<input type="text" name="schdlId" data-map="SCHDL_ID" hidden />

				<div class="row g-1">

					<div class="col-md-6">
						<label is="name-label" for="schdlBgngYmd"
						class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">
						시작일
						</label>
						<input type="text" is="id-input" name="schdlBgngYmd" data-map="SCHDL_BGNG_YMD"
						class="form-control form-date" required
						data-fmt-type="day" title="시작 날짜 선택" />
						<button type="button" class="bx bx-lg bx-calendar bg-white"></button>
					</div>
					<div class="col-md-6">
						<label is="name-label" for="schdlEndYmd"
						class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">
						종료일
						</label>
						<input type="text" is="id-input" name="schdlEndYmd" data-map="SCHDL_END_YMD"
						class="form-control form-date" required
						data-fmt-type="day" title="종료 날짜 선택" />
                           <button type="button" class="bx bx-lg bx-calendar bg-white"></button>
					</div>
					<div class="col-md-12">
						<label is="name-label" for="schdlCn"
						class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end align-top required">
						내용
						</label>
						<input type="text" is="id-input" name="schdlCn" data-map="SCHDL_CN"
						class="form-control w-px-500" required />
					</div>

				</div>

				<div class="row m-3">
					<div class="col-md-12">
						<span class="float-end">
							<button type="button" name="btnSave" class="btn btn-primary">저장</button>
							<button type="button" name="btnRemove" class="btn btn-primary">삭제</button>
						</span>
					</div>
				</div>
			</form>


		</div>

	</div>
</div>
<script>
LoadScript("mngt02020Script",wctx.url("/resources/js/fims/mngt/mngt02020.js?ver=${ver}"));

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

pageObject.childReq = [];
pageObject.childReq.push({
	refresh : function(){ },
});

$(document).ready(function(){

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

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

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

	var ctrl = newMngt02020Control($P);

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

	/**************************************************************************
	* pageObject.function
	**************************************************************************/
	$P.fnSave = () => {

		if(!AppSupport.customValidate($P.$findn("frmEdit").find("input"))) return;

		var info = $P.formFields.get();

		if(info.schdlBgngYmd > info.schdlEndYmd){
			alert("시작일자가 종료일자 보다 큽니다.");
			return;
		}

		var create = ($P.$findn("schdlId").val() == "");
		if(create){
			ajax.post({
				url : ctrl.urls.create,
				data : info,
				success : (resp) => {
					if(resp.saved){
						dialog.close($P.selfDlgId());
						dialog.alert({
							content:"저장되었습니다.",
							init : function() {
								AppSupport.setDialogZindex();
								AppSupport.focusClose();
							},
							onClose : () => {
								info.schdlId = resp.schdlId;
								$P.provided.refresh("add", info);
							}
						});
					}
				}
			});
		} else {
			ajax.post({
				url : ctrl.urls.update,
				data : info,
				success : (resp) => {
					if(resp.saved){
						dialog.close($P.selfDlgId());
						dialog.alert({
							content:"저장되었습니다.",
							init : function() {
								AppSupport.setDialogZindex();
								AppSupport.focusClose();
							},
							onClose : () => {
								$P.provided.refresh("modify", info);
							}
						});
					}
				}
			});
		}

	}

	$P.fnRemove = () => {

		var info = $P.formFields.get();

		ajax.post({
			url : ctrl.urls.remove,
			data : info,
			success : (resp) => {
				if(resp.saved){
					dialog.close($P.selfDlgId());
					dialog.alert({
						content:"삭제되었습니다.",
						init : function() {
							AppSupport.setDialogZindex();
							AppSupport.focusClose();
						},
						onClose : () => {
							$P.provided.refresh("del", { schdlId : info.schdlId });
						}
					});
				}
			}
		});
	}

	/**************************************************************************
	* element.on
	**************************************************************************/
	$P.$findn("btnSave").on('click', () => $P.fnSave());
	$P.$findn("btnRemove").on('click', () => $P.fnRemove());

	/**************************************************************************
	* 초기화
	**************************************************************************/
	AppSupport.initDatepicker($P.findn("frmEdit")); //달력 초기화

	var schdlInfo = ${schdlInfo};
	if(schdlInfo != null){
		ctrl.dataset.setData([schdlInfo]);
	} else {

		ctrl.dataset.setData([{ SCHDL_BGNG_YMD : "${schdlBgngYmd}", SCHDL_END_YMD : "${schdlEndYmd}" }]);

		$P.$findn("btnRemove").attr("hidden","hidden");
	}

});
</script>