<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : ItemkindPopupForm.html
 * @desc    : 품복 팝업 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.07.16   eskim       최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="600" id="popupItemkindList">
	<div class="panelStyle"  style="max-height:700px;">
		<!-- TITLE -->
		<div class="panelTitle">
			<strong>품목 목록</strong>
			<button type="button" class="close" onclick="uifnPopupClose('popupItemkindList');"><em class="fa fa-times"></em></button>
		</div>
		<!-- //TITLE -->
		<!-- 검색 조건 -->
		<div class="panelContent">
			<form id="searchItemkindListForm" name="searchItemkindListForm" action="#" th:action="@{'/goods/itemkind/base/list'}" onsubmit="$('#btnSearchItemkindList').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:15%;"/>
						<col style="width:35%;"/>
						<col style="width:15%;"/>
						<col/>
					</colgroup>
					<tbody>
						<tr>
							<th>품목코드</th>
							<td>
								<textarea class="textareaR2" name="searchItemkindCd" id="searchItemkindCd"></textarea>
							</td>
							<th>품목명</th>
							<td>
								<textarea class="textareaR2" name="searchItemkindNm" id="searchItemkindNm"></textarea>
							</td>
						</tr>
					</tbody>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearchItemkindList">조회</button>
					</li>
				</ul>
			</form>
			<!-- 리스트 영역 -->
			<div class="panelContent">
				<div id="gridItemkindList" style="width: 100%; height: 380px" class="ag-theme-balham"></div>
			</div>
			<!-- //리스트 영역 -->
			
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-info btn-lg" id="btnConfirmItemkind">확인</button>
				</li>
			</ul>
		</div>
		<!-- //검색 조건 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let headerSelection = false;
	if([[${params.multiGb}]] == "M") headerSelection = true;
	let columnDefsMdList = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: headerSelection, checkboxSelection: true, filter: false},
		{headerName: "품목코드", field: "itemkindCd", width: 150, cellClass: 'text-center'},
		{headerName: "품목명", field: "itemkindNm", width: 370, cellClass: 'text-left',
			cellRenderer: function(params) {
				return params.value.replaceAll("&gt;", ">");
			}
		}
	];

	let gridOptionsItemkindList = gagaAgGrid.getGridOptions(columnDefsMdList);
	if(headerSelection) {	gridOptionsItemkindList.rowSelection = "multiple";	}

	// Row double click
	gridOptionsItemkindList.onRowDoubleClicked = function(event) {
		$('#btnConfirmItemkind').trigger('click');
	}

	// 조회
	$('#btnSearchItemkindList').on('click', function() {
		// Fetch data
		gagaAgGrid.fetch($('#searchItemkindListForm').prop('action'), gridOptionsItemkindList, '#searchItemkindListForm');
	});
	
	// 확인
	$('#btnConfirmItemkind').on('click', function() {
		var selectedData = gagaAgGrid.selectedRowData(gridOptionsItemkindList);
		
		if (selectedData.length == 0) {
			mcxDialog.alert('선택된 품목이 없습니다.');
			return false;
		}
		
		var callbackFn = [[${params.callbackFn}]];

		var jsonData = JSON.stringify(selectedData);

		if (typeof callbackFn != 'undefined' && callbackFn) {
			if (typeof callbackFn == 'function') {
				callbackFn(jsonData);
			} else {
				if (callbackFn) {
					if (callbackFn.indexOf("(") == -1) {
						(new Function(callbackFn + "(" + jsonData + ");"))();
					} else {
						(new Function(callbackFn(jsonData)))();
					}
				}
			}
			uifnPopupClose('popupItemkindList');
		}
	});
	
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridItemkindList', gridOptionsItemkindList);
		
		//$('#btnSearchItemkindList').trigger('click');
	});
/*]]>*/
</script>

</div>

</html>
