<%@ 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">
		<form name="frmEdit">

			<div class="card my-2">
				<div class="card-header">
					<h5>파일 레이아웃</h5>
				</div>
				<div class="card-body">
					<input type="hidden" name="fileLayoutId" data-map="FILE_LAYOUT_ID" />
					<input type="hidden" name="sggCd" data-map="SGG_CD" />
					<input type="hidden" name="taskSeCd" data-map="TASK_SE_CD" />
					<input type="hidden" name="instCd" data-map="INST_CD" />
					<input type="hidden" name="deptCd" data-map="DEPT_CD" />

					<div class="row g-1">
						<div class="col-md-4">
							<label is="name-label" for="fileGroup"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
								자료 파일 구분
							</label>
							<select is="id-select" name="fileGroup" data-map="DATA_FILE_SE"
								class="form-select" required>
								<option value="">선택</option>
								<option value="TXT">텍스트파일 포함</option>
								<option value="JPG">텍스트파일 미포함</option>
								<option value="BIN">단일 바이너리 파일</option>
							</select>
						</div>
						<div class="col-md-4">
							<label is="name-label" for="fileNameLength"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								파일명 길이
							</label>
							<input type="text" is="id-input" name="fileNameLength" data-map="FILE_NM_SZ"
							class="form-control w-px-70" maxlength="4" data-maxlengthb="4" />
						</div>
						<div class="col-md-4">
							<label is="name-label" for="enterpriseName"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								업체명
							</label>
							<input type="text" is="id-input" name="enterpriseName" data-map="ENT_NM"
							class="form-control" maxlength="100" data-maxlengthb="100" />
						</div>
						<div class="col-md-2">
							<label is="name-label" for="fileNameSeperator"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								파일명 구분 유형
							</label>
							<select is="id-select" name="fileNameSeperator" data-map="FILE_NM_SE_TYPE"
								class="form-select">
								<option value=""></option>
								<option value="_">언더바</option>
							</select>
						</div>
						<div class="col-md-10">
							<label is="name-label" for="fileNameItmes"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								파일명 형식
							</label>
							<input type="text" is="id-input" name="fileNameItmes" data-map="FILE_NM_LAYOUT"
							class="form-control w-100" maxlength="500" data-maxlengthb="500" />
						</div>
						<div class="col-md-2">
							<label is="name-label" for="contentSeperator"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								자료 구분 유형1
							</label>
							<select is="id-select" name="contentSeperator" data-map="DATA_SE_TYPE1"
								class="form-select">
								<option value=""></option>
								<option value=",">콤마</option>
								<option value="byte">바이트</option>
							</select>
						</div>
						<div class="col-md-10">
							<label is="name-label" for="contentItems"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								자료 형식1
							</label>
							<input type="text" is="id-input" name="contentItems" data-map="DATA_LAYOUT1"
							class="form-control w-100" maxlength="500" data-maxlengthb="500" />
						</div>
						<div class="col-md-2">
							<label is="name-label" for="contentSecondSeperator"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								자료 구분 유형2
							</label>
							<select is="id-select" name="contentSecondSeperator" data-map="DATA_SE_TYPE2"
								class="form-select">
								<option value=""></option>
								<option value=",">콤마</option>
								<option value="LineBreak">줄바꿈문자</option>
							</select>
						</div>
						<div class="col-md-10">
							<label is="name-label" for="secondSeperatorStarterItems"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								자료 형식2
							</label>
							<input type="text" is="id-input" name="secondSeperatorStarterItems" data-map="DATA_LAYOUT2"
							class="form-control w-100" maxlength="500" data-maxlengthb="500" />
						</div>
						<div class="col-md-2">
							<label is="name-label" for="countPerFileGroup"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								파일 총 건수
							</label>
							<input type="text" is="id-input" name="countPerFileGroup" data-map="FILE_TNOCS"
							class="form-control w-50" maxlength="2" data-maxlengthb="2" />
						</div>
						<div class="col-md-10">
							<label is="name-label" for="linkFileLocation"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								연계 파일 경로
							</label>
							<input type="text" is="id-input" name="linkFileLocation" data-map="LINK_FILE_PATH"
							class="form-control w-100" maxlength="200" data-maxlengthb="200" />
						</div>
						<div class="col-md-9">
							<label is="name-label" for="sameItemsInFileGroup"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								동일 항목
							</label>
							<input type="text" is="id-input" name="sameItemsInFileGroup" data-map="SAME_ITEMS"
							class="form-control w-px-600" maxlength="300" data-maxlengthb="300" />
						</div>
						<div class="col-md-9">
							<label is="name-label" for="increaseItemInFileGroup"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								증가 항목
							</label>
							<input type="text" is="id-input" name="increaseItemInFileGroup" data-map="INCREASE_ITEM"
							class="form-control w-px-600" maxlength="300" data-maxlengthb="300" />
						</div>
						<div class="col-md-3">
							<label is="name-label" for="increaseTypeInFileGroup"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								증가 형식
							</label>
							<select is="id-select" name="increaseTypeInFileGroup" data-map="INCREASE_TYPE"
								class="form-select">
								<option value=""></option>
								<option value="number">숫자</option>
								<option value="alphabet">영문자</option>
							</select>
						</div>

					</div>
				</div>
			</div>

			<div class="card my-2">
				<div class="card-header">
					<h5>파일전송 연계 정보</h5>
				</div>
				<div class="card-body">
					<div class="row g-1">
						<div class="col-md-4">
							<label is="name-label" for="linkEnterpriseName"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								업체명(연계)
							</label>
							<input type="text" is="id-input" name="linkEnterpriseName" data-map="LINK_ENT_NM"
							class="form-control" maxlength="100" data-maxlengthb="100" />
						</div>

						<div class="col-md-4">
							<label is="name-label" for="ip"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								아이피
							</label>
							<input type="text" is="id-input" name="ip" data-map="REMOTE_IP"
							class="form-control" maxlength="100" data-maxlengthb="100" />
						</div>

						<div class="col-md-4">
							<label is="name-label" for="port"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								포트
							</label>
							<input type="number" is="id-input" name="port" data-map="REMOTE_PORT"
							class="form-control" min="1" max="65535" />
						</div>

						<div class="col-md-6">
							<label is="name-label" for="id"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								아이디
							</label>
							<input type="text" is="id-input" name="id" data-map="REMOTE_ID"
							class="form-control" maxlength="100" data-maxlengthb="100" />
						</div>
						<div class="col-md-6">
							<label is="name-label" for="pw"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
								패스워드
							</label>
							<input type="text" is="id-input" name="pw" data-map="REMOTE_PASSWORD"
							class="form-control" maxlength="100" data-maxlengthb="100" />
						</div>

						<div class="col-md-2">
							<label is="name-label" for="osType"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								운영체제
							</label>
							<select is="id-select" name="osType" data-map="REMOTE_OS"
								class="form-select w-100">
								<option value=""></option>
								<option value="linux">리눅스</option>
								<option value="windows">윈도우</option>
							</select>
						</div>

						<div class="col-md-10">
							<label is="name-label" for="workPath"
							class="w-px-130 bg-lighter pe-2 ps-2 col-form-label text-sm-start">
								파일경로
							</label>
							<input type="text" is="id-input" name="workPath" data-map="REMOTE_WORK_PATH"
							class="form-control w-100" maxlength="100" data-maxlengthb="100" />
						</div>

					</div>
				</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="btnDelete" class="btn btn-primary">삭제</button>
					</span>
				</div>
			</div>

		</form>
	</div>
</div>

<script>
LoadScript("crdn01020Script",wctx.url("/resources/js/fims/crdn/crdn01020.js?ver=${ver}"));

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 = newCrdn01020Control($P, { taskSeCd : currentTask() });

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

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

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

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

		var create = ctrl.dataset.empty;

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

	$P.fnRemove = () => {

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

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

	}

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

	/**************************************************************************
	* 초기화
	**************************************************************************/
	var layoutInfo = ${layoutInfo};
	if (layoutInfo){
		ctrl.dataset.setData([layoutInfo]);
	} else {
		ctrl.dataset.setData([]);

		$P.$findn("sggCd").val(MY_INFO.info.sggCd);
		$P.$findn("instCd").val(MY_INFO.info.instCd);
		$P.$findn("deptCd").val(MY_INFO.info.deptCd);
		$P.$findn("taskSeCd").val("${taskSeCd}");
		$P.$findn("btnDelete").attr("hidden","hidden");
	}

});
</script>