<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GoodsNotiInfoForm.html
 * @desc    : 상품고시정보 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.12.08   gagamel     최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<form id="searchForm" name="searchForm" action="#" th:action="@{'/goods/noti/info/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:25%;"/>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>고시분류<em class="required" title="필수"></em></th>
						<td>
							<select name="niClsfCd" required="required" data-valid-name="고시분류">
								<option value="">[전체]</option>
								<option th:if="${niClsfCdList}" th:each="oneData, status : ${niClsfCdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>상품코드</th>
						<td>
							<textarea class="textareaR3 w70p" name="goodsCds" id="goodsCds"></textarea>
						</td>
					</tr>
				</table>
				
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearch">조회</button>
						<button type="button" class="btn btn-gray btn-lg" onclick="$('#searchForm')[0].reset();">초기화</button>
					</li>
				</ul>
			</form>
		</div>
		<!-- //검색조건 영역 -->
		
		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-default btn-lg" id="btnExcel">엑셀다운로드</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 670px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	var roleList = gagajf.convertToArray([[${roleList}]]);
	
	// specify the columns
	var columnDefs = [
		{headerName: "상품코드", field: "goodsCd", width: 120, cellClass: 'text-center'},
		{headerName: "COL1", field: "col1", width: 100},
		{headerName: "COL2", field: "col2", width: 100},
		{headerName: "COL3", field: "col3", width: 100},
		{headerName: "COL4", field: "col4", width: 100},
		{headerName: "COL5", field: "col5", width: 100},
		{headerName: "COL6", field: "col6", width: 100},
		{headerName: "COL7", field: "col7", width: 100},
		{headerName: "COL8", field: "col8", width: 100},
		{headerName: "COL9", field: "col9", width: 100},
		{headerName: "COL10", field: "col10", width: 100},
		{headerName: "COL11", field: "col11", width: 100},
		{headerName: "COL12", field: "col12", width: 100},
		{headerName: "COL13", field: "col13", width: 100}
	];
	
	// Get GridOptions
	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	
	// Grid 속성 변경
	var fnChangeGridProperty = function(colInfo) {
		var colCnt = Number(colInfo.useColsCnt);
		
		// 컬럼 이름 변경
		if (colCnt >= 1) gagaAgGrid.setColumnHeaderName(gridOptions, 'col1', colInfo.col1);
		if (colCnt >= 2) gagaAgGrid.setColumnHeaderName(gridOptions, 'col2', colInfo.col2);
		if (colCnt >= 3) gagaAgGrid.setColumnHeaderName(gridOptions, 'col3', colInfo.col3);
		if (colCnt >= 4) gagaAgGrid.setColumnHeaderName(gridOptions, 'col4', colInfo.col4);
		if (colCnt >= 5) gagaAgGrid.setColumnHeaderName(gridOptions, 'col5', colInfo.col5);
		if (colCnt >= 6) gagaAgGrid.setColumnHeaderName(gridOptions, 'col6', colInfo.col6);
		if (colCnt >= 7) gagaAgGrid.setColumnHeaderName(gridOptions, 'col7', colInfo.col7);
		if (colCnt >= 8) gagaAgGrid.setColumnHeaderName(gridOptions, 'col8', colInfo.col8);
		if (colCnt >= 9) gagaAgGrid.setColumnHeaderName(gridOptions, 'col9', colInfo.col9);
		if (colCnt >= 10) gagaAgGrid.setColumnHeaderName(gridOptions, 'col10', colInfo.col10);
		if (colCnt >= 11) gagaAgGrid.setColumnHeaderName(gridOptions, 'col11', colInfo.col11);
		if (colCnt >= 12) gagaAgGrid.setColumnHeaderName(gridOptions, 'col12', colInfo.col12);
		if (colCnt >= 13) gagaAgGrid.setColumnHeaderName(gridOptions, 'col13', colInfo.col13);
		gridOptions.columnApi.resetColumnState();

		// 컬럼 숨김 처리
		for (var k = 1; k <= 13; k++) {
			// 컬럼 숨긴걸 초기화 한다.
			gagaAgGrid.showOrHideColumn(gridOptions, 'col' + k, true);
		
			// 컬럼을 숨긴다.
			if (k > colCnt) {
				gagaAgGrid.showOrHideColumn(gridOptions, 'col' + k, false);
			}
		}
	}
	
	// 조회
	$('#btnSearch').on('click', function() {
		// 입력 값 체크
		if (!gagajf.validation($('#searchForm')))
			return false;
		
		// Fetch data
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm', function() {
			// 업로드의 칼럼정보 가져오기
			var actionUrl = '/goods/noti/info/column/' + $('#searchForm select[name=niClsfCd]').val();
			
			$.getJSON(actionUrl
					, function(result, status) {
						if (status == 'success') {
							fnChangeGridProperty(result);
						}
					}
				);
		});
	});
	
	// 엑셀다운로드
	$('#btnExcel').on('click', function() {
		gagaAgGrid.exportToExcel('상품고시정보 목록', gridOptions);
	});
	
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
