<%@ 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 wrapper-list">

		    <div class="container-page-btn">
		        <button type="button" name="btnReset"
		        class="btn btn-outline-dark w-px-120" title="초기화">초기화</button>
		        <span class="container-window-btn-right">
					<button type="button" name="btnSearch"
					class="btn btn-search w-px-120" title="검색">검색</button>
		        </span>
		    </div>

		    <form name="frmSearch">
		        <div class="container-search">
                    <div class="row g-1">
                    	<jsp:include page="/WEB-INF/jsp/include/sgg-tasklist.jsp"><jsp:param name="col" value="col-6" /></jsp:include>
                        <div class="col-6">
                            <label is="name-label" for="regDt" class="form-label fw-bold form-search-title w-px-120 text-end">등록일자</label>
							<input type="text" is="id-input" name="regDt"
							class="form-control form-date" data-fmt-type="day"
							title="금일" disabled="disabled" />
                        </div>
                    </div>
		        </div>
		    </form>
			<div>
				<span class="container-page-btn">
					<div class="d-flex flex-row justify-content-between">
						<span is="paging-info" name="crdnPagingInfo" class="dataTables_info"></span>
		                <ul name="crdnPaging" class="pagination pagination-primary"></ul>
					</div>
					<span class="container-window-btn-right">
						<button type="button" name="btnInsertByFile" class="btn btn-primary"
						title="단속 파일 등록">단속 파일 등록</button>
			         	<button type="button" name="btnInsertByHand" class="btn btn-primary"
			         	title="단속 수기 등록">단속 수기 등록</button>
					</span>
			     </span>
			</div>
			<div class="card-datatable text-nowrap">
		        <div class="dataTables_wrapper dt-bootstrap5 no-footer">
					<div name="table-responsive" class="table-responsive ox-scroll oy-scroll h-px-600">
						<table name="crdnTable" class="table-layout-fixed datatables-ajax table table-bordered dataTable no-footer">
							<thead class="sticky-thead">
								<tr name="crdnTheadTr">
									<th style="width: 80px;">No.</th>
									<th style="width: 200px;">등록구분</th>
									<th style="width: 200px;">자료출처</th>
									<th style="width: 200px;">위반일시</th>
									<th style="width: 200px;">차량번호</th>
									<th style="width: 400px;">단속장소</th>
									<th style="width: 200px;">위반내용</th>
									<th class="dummy-th"></th>
								</tr>
		                    </thead>
		                    <tbody name="crdnTbody"></tbody>
							<template is="curly-brackets" name="crdnRow">
	                    		<tr data-index="DATA-INDEX">
	                    			<td onclick ondblclick class="text-end">ROW_NUM</td>
	                    			<td onclick ondblclick class="text-center">CRDN_REG_SE_NM</td>
	                    			<td onclick ondblclick class="text-center">CRDN_INPT_SE_NM</td>
		                    		<td onclick ondblclick class="text-center">CRDN_YMD_TM</td>
		                    		<td onclick ondblclick class="text-center">VHRNO</td>
		                    		<td onclick ondblclick class="text-start">CRDN_PLC</td>
		                    		<td onclick ondblclick class="text-start">VLTN_ARTCL</td>
		                    		<td class="dummy-td"></td>
		                    	</tr>
	                    	</template>
	                    	<template name="crdnNotFound">
	                    		<tr>
	                    			<td valign="top" colspan="8" class="dataTables_empty text-center">
	                    			단속 정보를 찾지 못했습니다.
	                    			</td>
	                    		</tr>
	                    	</template>
						</table>
					</div>
				</div>
		    </div>

		</div>
	</div>



  	<div class="content-backdrop fade"></div>
</div>
<script>
LoadScript("crdn05010Script",wctx.url("/resources/js/fims/crdn/crdn05010.js?ver=${ver}"));

/**************************************************************************
 * Global Variable
 **************************************************************************/
var FIM003 = new CommonCodes(${FIM003});
var FIM026 = new CommonCodes(${FIM026});

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


$(document).ready(function(){

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

	/**************************************************************************
	* DatasetControl, DatasetSupport, FormFields
	**************************************************************************/
	var ctrl = newCrdn05010Control($P);

	ctrl.defaultFetchSize = FETCH_XS;
	ctrl.query = { pageNum : 1, fetchSize : ctrl.defaultFetchSize };

	ctrl.urls.newInfoByFile = "";
	ctrl.urls.newInfoByHand = "";

	ctrl.dataset.onDatasetChange = (obj, option) => {
		var t = $P.getGridTemplate();
		var trs = Apply.fromDataset.getTbody(ctrl.dataset, t.found, t.notFound, t.replacer);
		$P.renderCrdnList(obj?.Paging?.totalSize, ctrl.dataset.length, trs, option);

		$P.pagingSupport.setPagingInfo(obj);
	};

	ctrl.dataset.onCurrentChange = (dataItem) => {
		Apply.fromDataset.currentRow(ctrl.dataset, dataItem, $P.findn("crdnTbody"));
	}

	$P.pagingSupport = new FimsPagingSupport({
		doq: $P,
        linkContainer: "[name='crdnPaging']"
	});

	/**************************************************************************
	* pageObject.function
	**************************************************************************/
	$P.fnReset = () => {
		$P.$findn("regDt").datepicker('setDate', TODAY());
		ctrl.dataset.setData([]);
	}

	$P.fnResetAndChangeBiz = (taskSeCd) => {
		$P.fnReset();
		ctrl.urls.load = wctx.url("/crdn/crdn05/010/list.do");
		ctrl.urls.newInfoByFile = wctx.url("/crdn/crdn05/020/info.do");
		ctrl.urls.newInfoByHand = wctx.url("/crdn/crdn05/030/info.do");

		switch(taskSeCd){
			case "PVS" :
			case "RVS" :
			case "BPV" :
			case "DPV" :
			case "ECA" :
			case "DVS" :
				$P.$findn("btnInsertByFile").show();
				break;
			case "PES" :
			default :
				$P.$findn("btnInsertByFile").hide();
				break;
		}
	}

	$P.getParams = () => {
		var formFields = new FimsFormFields($P.selectorn("frmSearch"));
		var data = formFields.get();
		data.taskSeCd = currentTask();
		data.fetchSize = ctrl.defaultFetchSize;
		return data;
	}

	$P.searchCrdnList = () => {
		ctrl.query = $P.getParams();
	    ctrl.load(1);
	}

	$P.scrollCrdnList = () => {
		ctrl.load(ctrl.query.pageNum + 1);
	}

	$P.refreshCrdnList = () => {
        ctrl.reload({all : true});
    }


	$P.getGridTemplate = () => {
		var notFound = [$P.findn("crdnNotFound").innerHTML];
		var found = $P.findn("crdnRow").innerHTML;
		var replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickCrdnList('{DATA-INDEX}');")
        	.replace(/{ondblclick}/gi, "");

		return {
			found : found,
			notFound : notFound,
			replacer : replacer
		};
	}

	$P.renderCrdnList = (total, listLength, trs, option) => {

		let noMore = (listLength >= total);
		var initScroll = (ctrl.query.pageNum < 2);
		if(option != null && option.reloaded){
			initScroll = false;
		}

		$P.findn("table-responsive").changeContent(trs, initScroll, noMore);

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

	}

	$P.clickCrdnList = (dataIndex) => {
		if(dataIndex == ""){
			return;
		}
		$P.$findn("crdnTbody").setCurrentRow(dataIndex);


		Apply.toDataset.current(ctrl.dataset, dataIndex);
	}

	$P.newInfo = (type) => {
		var url = "";
		if(type == "file") url = ctrl.urls.newInfoByFile;
		if(type == "hand") url = ctrl.urls.newInfoByHand;

		let dialogName = "";
		if(type == "file") dialogName = "fileDialog";
		if(type == "hand") dialogName = "manualDialog";

		var title = "";
		if(type == "file") title = "단속파일 등록";
		if(type == "hand") title = "단속자료 수기 등록";

		ajax.get({
			url : url,
			data : {taskSeCd: currentTask()},
			success : (resp) => {
				let dialogId = dialogName+"-"+uuid();

				dialog.open({
					id: dialogId,
					title: title,
					content:resp,
					size: "xxl",
					init:() => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");
					}
				});
			}
		});
	};

	/**************************************************************************
	* element.on
	**************************************************************************/
	$P.$findn("btnReset").on('click', () => $P.fnReset());
	$P.$findn("btnSearch").on("click", () => $P.searchCrdnList());
	$P.$findn("btnInsertByFile").on('click', () => { $P.newInfo("file"); });
	$P.$findn("btnInsertByHand").on('click', () => { $P.newInfo("hand"); });

	Componentization.fnMakeResizableTable($P.findn("table-responsive"));
	Componentization.fnMakeScrollableTable($P.findn("table-responsive"), $P.scrollCrdnList);

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

    var defaultBizValue = $("#layout-navbar input[name='taskSeCd']:checked").val();
    $P.$findn("frmSearch").find("input[name='taskSeCd'][value='" + defaultBizValue + "']").prop("checked",true);
	$P.fnResetAndChangeBiz(defaultBizValue);
	//보안모드
    fn_securityModeToggle($("#securityMode--top").is(":checked"));

    $P.$findn("frmSearch").find("input[name='taskSeCd']").each(function(i) {
		$(this).prop("disabled", "true");
	});
});

</script>