<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>
<script language="javascript">
var rcvFileName = window.dialogArguments['rcvFileName'];
var bjobMsgDstcd = window.dialogArguments['bjobMsgDstcd'];
var isPopup = window.dialogArguments['ispop'];

function isValid() {

	if($('#skipCnt').val().trim() == "") {
		$('#skipCnt').focus();
		alert("파일 시작위치를 입력하여 주십시요.");
		return false;
	} else if($('#loopCnt').val().trim() == "") {
		$('#loopCnt').focus();
		alert("요청 건수를 입력하여 주십시요.");
		return false;
	} else if($('#loopCnt').val() > 100) {
		$('#loopCnt').focus();
		alert("요청 건수는 100건까지 가능합니다.");
		return false;
	}
	
	return true;
}

function init(url, key) {
	$("input[name=rcvFileName]").val(key).attr('readonly', true);
	$("input[name=recSize]").val('').attr('readonly', true);
	$("input[name=bjobMsgDstcd]").val(bjobMsgDstcd);
	
	if($('#skipCnt').val().trim() == "") $('#skipCnt').val("0");
	if($('#loopCnt').val().trim() == "") $('#loopCnt').val("100");
	
//	clearInputbox();
}

function clearInputbox() {
	for(let i = 0; i < 100; i++) {
		$("#dataNum" + (i + 1)).text('');
		$("#dataVal" + (i + 1)).text('');
	}
}

function setInputbox(data) {

	if(typeof data === 'undefined') return false;
	
	const s = parseInt($('#skipCnt').val());
	const l = parseInt($('#loopCnt').val());
	const e = data.length < l ? data.length : l;

	for(let i = 0; i < e; i++) {
		$("#dataNum" + (i+1)).html((i+s+1));
		$("#dataVal" + (i+1)).html(data[i].replace(/ /g, '&nbsp;'));
	}
}

$(document).ready(function() {
 	var url ='<c:url value="/bap/transaction/transactionStatusMan.json" />';
 	var key = rcvFileName;

 	init(url, key);
	
	$("#btn_close").click(function() {
		window.close();
	});

	$("#btn_search").click(function() {
		
		if (!isValid()) return false;

		var postData = $('#ajaxForm').serializeArray();
		postData.push({ name: "cmd", value:"DETAIL_FILE_DATA"});

		$.ajax({
			type: "POST",
			url: url,
			data: postData,
			success: function(json) {
				clearInputbox();
				$("input[name=recSize]").val(json.recSize);
				setInputbox(json.detail);
			},
			error:function(e) {
				alert(e.responseText);
			}
		});
	});

	$("#btn_prev").click(function() {
		var s = parseInt($('#skipCnt').val());
		var l = parseInt($('#loopCnt').val());
		if ( s >= 0 ) {
			var n = s - l < 0 ? 0 : s - l;
			$('#skipCnt').val(n);
			$("#btn_search").click();
		}
	});

	$("#btn_next").click(function() {
		var s = parseInt($('#skipCnt').val());
		var l = parseInt($('#loopCnt').val());
		if ( s >= 0 ) {
			var n = s + l;
			$('#skipCnt').val(n);
			$("#btn_search").click();
		}
	});

});


</script>
</head>
<body>
	<div class="right_box">
		<div class="content_top">
			<ul class="path">
				<li><a href="#">${rmsMenuPath}</a></li>
			</ul>
		</div><!-- end content_top -->
		<div class="content_middle" id="content_middle">
			<div class="search_wrap">
			<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />
			<img src="<c:url value="/img/btn_remove.png"/>" alt="" id="btn_prev" level="R" />
			<img src="<c:url value="/img/btn_add.png"/>" alt="" id="btn_next" level="R" />
			<img src="<c:url value="/img/btn_close.png"/>" alt="" id="btn_close" level="R" />
			</div>
			<div class="title">업무파일 내용 조회</div>
			<form id="ajaxForm">
				<input type="hidden" name="bjobMsgDstcd" />
				<table class="search_condition" cellspacing="0">
					<tr>
						<th style="width:23%">파일 시작위치</th>
						<td style="width:10%"><input type="text" id="skipCnt" name="skipCnt" onKeyup="this.value=this.value.replace(/[^0-9]/g,'');" style="text-align:center;"></td>
						<th style="width:23%">요청건수</th>
						<td style="width:10%"><input type="text" id="loopCnt" name="loopCnt" onKeyup="this.value=this.value.replace(/[^0-9]/g,'');" style="text-align:center;"></td>
						<th style="width:24%">한 레코드 길이</th>
						<td style="width:10%"><input type="text" id="recSize" name="recSize" onKeyup="this.value=this.value.replace(/[^0-9]/g,'');" style="text-align:center;"></td>
					</tr>
					<tr>
						<th style="width:23%">파일 이름</th>
						<td colspan="5"><input type="text" id="rcvFileName" name="rcvFileName"></td>
					</tr>
				</table>
			</form>
			<table class="table_row" cellspacing="0">
				<colgroup>
					<col width="10%">
					<col width="90%">
				</colgroup>
				<tr>
					<th height="28px" nowrap style="text-align:center; border-right: 1px solid #a3a9b1;">순번</th>
					<th nowrap style="text-align:center; border-right: 1px solid #a3a9b1;">데이터</th>
				</tr>
				<c:forEach var="i" begin="1" end="100">
				<tr>
					<td align="center" nowrap><span id="dataNum${i}"></span></td>
					<td align="left" nowrap><span id="dataVal${i}"></span></td>
				</tr>
				</c:forEach>
			</table>

		</div><!-- end content_middle -->
	</div><!-- end right_box -->
</body>
</html>