<%@ 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="card" data-doctx="${pageName}" style="padding: .25rem;">
	<form name="frmEdit">
		<input type="hidden" name="eqplcCd" data-map="EQPLC_CD" />

		<div class="row g-1">
			<div class="col-md-12">
				<label is="name-label" for="eqpCd" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">장비코드</label>
				<input type="text" is="id-input" name="eqpCd" data-map="EQP_CD"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="3"/>
			</div>		
			<div class="col-md-12">
				<label is="name-label" for="plcNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">단속장소명</label>
				<input type="text" is="id-input" name="plcNm" data-map="PLC_NM"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="100"/>
			</div>	
			<div class="col-md-12">
				<label is="name-label" for="stdgNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">법정동</label>
				<input type="text" is="id-input" name="stdgNm" data-map="STDG_NM"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="30"/>
			</div>	
			<div class="col-md-12">
				<label is="name-label" for="roadNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">도로명</label>
				<input type="text" is="id-input" name="roadNm" data-map="ROAD_NM"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="50"/>
			</div>	
			<div class="col-md-12">
				<label is="name-label" for="plc" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">단속장소</label>
				<input type="text" is="id-input" name="plc" data-map="PLC"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="100"/>
			</div>	
			<div class="col-md-12">
				<label is="name-label" for="laneNo" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">차선번호</label>
				<input type="text" is="id-input" name="laneNo" data-map="LANE_NO"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="2"/>
			</div>	
			<div class="col-md-12">
				<label is="name-label" for="drctn" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end me-3">차선방향</label>
				<label class="form-label me-3">
					<input type="radio" name="drctn" value="0" class="form-check-input" checked> 상행
				</label>
				<label class="form-label">
					<input type="radio" name="drctn" value="1" class="form-check-input"> 하행
				</label>
			</div>	
			<div class="col-md-12">
				<label is="name-label" for="etcInfo" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">비고</label>
				<input type="text" is="id-input" name="etcInfo" data-map="ETC_INFO"
					class="form-control w-px-300" data-maxlengthb="1000" maxlength="60"/>
			</div>	
		</div>
		<div class="row mt-4 justify-content-end mb-3">
			<div class="row justify-content-end">
				<div class="col-sm-3">
					<button type="button" name="btnSave" class="btn btn-primary">저장</button>
				</div>
			</div>
		</div>
	</form>
</div>

<script>
LoadScript("eqplcScript",wctx.url("/resources/js/fims/eqplc/eqplc.js?${ver}"));

/**************************************************************************
* Global Variable
**************************************************************************/

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

pageObject.childReq = [];
pageObject.childReq.push({
	refreshList : 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 = newEqplcControl($P);

	/**************************************************************************
	* pageObject.function
	**************************************************************************/
	$P.setInfo = (item) => {
		$P.formFields.set(ctrl, item);
	}

	$P.fnSave = async() => {
		if(!AppSupport.customValidate($P.$findn("frmEdit").find("input"))) return;

		if(await confirm2("단속장비장소 정보를 저장하시겠습니까?")){
			var info = $P.formFields.get();

			if (!info) {
				return;
			}

			var insert = isEmpty(info.eqplcCd);

			ajax.post({
				url : !insert ? ctrl.urls.update : ctrl.urls.insert,
				data : info,
				success : (resp) => {
					$P.saveCallback(resp);
				}
			});
		}
	};

	$P.saveCallback = (resp) => {
		if (resp.saved) {
			dialog.alert({
				content : "저장됐습니다.",
				init : function() {
					AppSupport.setDialogZindex();
					AppSupport.focusClose();
				}
			});
			dialog.close($P.selfDlgId());
			$P.provided.refreshList();
		}
	};

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

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

	$P.$findn("frmEdit").find(".form-date").each(function(){
		$(this).on("input",function(){
			var value = this.value.replaceAll("-","");

			if(value.length > 7){
				this.value = value.substring(0,4)+"-"+value.substring(4,6)+"-"+value.substring(6);
			} else if(value.length > 5){
				this.value = value.substring(0,4)+"-"+value.substring(4);
			}

		});
	});

	//보안모드
    fn_securityModeToggle($("#securityMode--top").is(":checked"));

    var eqplcInfo = ${eqplcInfo};
	$P.setInfo(eqplcInfo);

});
</script>