<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
	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"/>
<style type="text/css">
.img_pointer { cursor:pointer; }
.ui-common-table { width: 100% !important; }
.ui-jqgrid .ui-jqgrid-hbox { padding-right: 0px !important; }
</style>
<script type="text/javascript">

$(document).ready(function() {
	$('#grid').jqGrid({
		datatype : "json",
		mtype : 'POST',
		colNames : [ '파일명', '자원설명', '버전', '반입일시', 'SRCID'],
		colModel : [ 
			{ name: 'FILENM'	, align: 'left'		},
			{ name: 'DESC'		, align: 'left' 	, width: '400' },
			{ name: 'VERSION'	, align: 'center'	, width: '50' },
			{ name: 'MODIFYDT'	, align: 'center' 	, width: '80' },
			{ name: 'SRCID'		, hidden: 'true' }],
		jsonReader : {
	    	root : "cmList",
			repeatitems : false
		},
		height : "200",
		autowidth: true,
		multiselect: true,
		multiboxonly: true,
		loadComplete: function(data) {
			$('#hRepKey').val(data.repKey);
			$('#hGroupCoCd').val(data.groupCoCd);
		},
		loadError: function(xhr,status,error){
			if (xhr.responseText != null) {
				try {
					alert(JSON.parse(xhr.responseText).errorMsg);
				} catch (e) {}
			}
	    }
	});
	// ComboBox 세팅
	initSelBzwkDstcd();
	$('#btn_operate').click(onclickOperate);
	$('#btn_search').click(onclickBtnSearch);
	$("#btn_close").click(function(){
		window.close();
	});
});

function initSelBzwkDstcd() {
	$.ajax({  
		type: "POST",
		dataType:"json",
		url: '<c:url value="/onl/admin/rule/layoutMan.json"/>',
		data: { 'cmd': 'LIST_CODE' },
		success:function(json){
			if (json.codeList == null || json.codeList.length == 0) {
				return;
			}
			for (var i=0; i<json.codeList.length; i++) {
				var item = json.codeList[i];
				$('#selBzwkDstcd').append('<option value="'+ jQuery.trim(item.EAIBZWKDSTCD) +'">'+ item.EAIBZWKDSTCD + ' - '+ item.BZWKDSTICNAME +'</option>');
			}
		},
		error:function(xhr){
			if (xhr.responseText != null) {
				try {
					alert(JSON.parse(xhr.responseText).errorMsg);
				} catch (e) {
					alert(xhr.responseText);
				}
			}
		}
	});
}

function onclickBtnSearch() {
	if ($('#selBzwkDstcd').val() == '') {
		alert('업무구분코드를 선택해 주세요.');
		return;
	}
	var params = {};
	params['cmd'] = 'LIST_SRC';
	params['eaiBzwkDstCd'] = $('#selBzwkDstcd').val();
	params['repType'] = $('#selRepType').val();
	params['schType'] = $('#selSchType').val();
	params['desc'] = $('#txtDesc').val();
	$("#grid").setGridParam({ 
		'postData': params,
		'url': '<c:url value="/onl/admin/rule/layoutMan.json"/>'
	}).trigger("reloadGrid");
}

function onclickOperate() {
	if ($('#selBzwkDstcd').val() == '') {
		alert('업무구분코드를 선택해 주세요.');
		return;
	}
	var sel = $('#grid').jqGrid('getGridParam', 'selarrrow');
	if (sel.length == 0) {
		alert('하나의 자료를 선택 해주세요.');
		return;
	}
	var arrSrcId = [];
	var arrVersion = [];
	var arrFileName = [];
	$(sel).each(function(index, i) {
		arrSrcId.push($('#grid').getCell(i, 'SRCID'));
		arrVersion.push($('#grid').getCell(i, 'VERSION'));
		arrFileName.push($('#grid').getCell(i, 'FILENM'));
	});
	var params = new Object();
	params['cmd'] = 'TRANSACTION_CMDOWN';
	params['eaiBzwkDstCd'] = $('#selBzwkDstcd').val();
	params['srcIds'] = arrSrcId.join(',');
	params['versions'] = arrVersion.join(',');
	params['fileNames'] = arrFileName.join(',');
	$.ajax({  
		type: "POST",
		dataType:"json",
		url: '<c:url value="/onl/admin/rule/layoutMan.json"/>',
		data: params,
		success:function(json){
			if (json.fileList == null || json.fileList.length == 0) {
				return;
			}
			var value = {
				'ExcelNames': json.fileList.join(',')	
			};
			window.returnValue = value;
			window.close();
		},
		error:function(xhr){
			if (xhr.responseText != null) {
				try {
					alert(JSON.parse(xhr.responseText).errorMsg);
				} catch (e) {
					alert(xhr.responseText);
				}
			}
		}
	});
}

</script>
</head>
	<body>
		<div class="popup_box">
			<div class="search_wrap">
				<img src="<c:url value="/img/btn_operate.png"/>" alt="" id="btn_operate" level="R" status="DETAIL,NEW" />
				<img src="<c:url value="/img/btn_close.png"/>" alt="" id="btn_close" level="R" status="DETAIL,NEW"/>	
			</div>
			<div class="title">형상연동 입출력항목(송수신항목)설계서 선택</div>
			<form id="ajaxForm">
				<input type="hidden" id="hRepKey" name="hRepKey" />
				<input type="hidden" id="hGroupCoCd" name="hGroupCoCd" />
				<table class="table_row" cellspacing="0">
					<tbody>
						<tr>
							<th style="width:20%;">업무구분코드</th>
							<td colspan="3">
								<select id="selBzwkDstcd">
									<option value="">선택하지 않음</option>
								</select>
							</td>
						</tr>
						<tr>
							<th>형상저장소</th>
							<td>
								<select id="selRepType">
									<option value="M">유지보수</option>
									<option value="D">개발</option>
								</select>
							</td>
							<th>조회조건</th>
							<td>
								<select id="selSchType">
									<option value="N">자료명</option>
									<option value="T">태그명</option>
								</select>
							</td>
						</tr>
						<tr>
							<th>검색명</th>
							<td colspan="3">
								<div>
									<input type="text" id="txtDesc" name="txtDesc" style="width:386px;" />&nbsp;
									<img id="btn_search" src="<c:url value="/images/bt/bt_search.gif"/>" alt="검색" class="img_pointer">
								</div>
							</td>
						</tr>
					</tbody>
				</table>
				<table id="grid"></table>
			</form>
		</div>
	</body>
</html>