<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : ExtmallPriceSyncForm.html
 * @desc    : 제휴몰가격연계관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.07   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="@{'/ocm/extmall/price/sync/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>제휴몰벤더</th>
						<td>
							<select name="vendorId">
								<option th:if="${vendorList}" th:each="oneData, status : ${vendorList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</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>
					<span class="infoTxt cBlue"><i class="fa fa-info-circle" aria-hidden="true"></i>"연계여부" 항목을 변경 후 저장할 수 있습니다.</span>
				</li>
				<li class="right">
					<button type="button" class="btn btn-success btn-lg" id="btnSave">저장</button>
					<button type="button" class="btn btn-default btn-lg" id="btnExcel">엑셀다운로드</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 570px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let vendorList = gagajf.convertToArray([[${vendorList}]]);
	let ynList = { "Y":"Yes", "N":"No" };

	let columnDefs = [
		{headerName: "CRUD", field: "crud", width: 75, hide: true},
		{
			headerName: "제휴몰벤더", field: "vendorId", width: 200, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(vendorList, params.data.vendorId); }
		},
		{headerName: "브랜드코드", field: "brandCd", width: 100, cellClass: 'text-center'},
		{headerName: "브랜드국문명", field: "brandKnm", width: 200, cellClass: 'text-center'},
		{headerName: "브랜드영문명", field: "brandEnm", width: 200, cellClass: 'text-center'},
		{
			headerName: "연계여부", field: "syncYn", width: 100, cellClass: 'text-center',
			editable: true, cellEditor: 'agRichSelectCellEditor',
			cellStyle: { color: '#fffff', 'background-color': '#aaaaff' },
			cellEditorParams: { values: gagaAgGrid.extractValues(ynList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(ynList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(ynList, params.newValue); }
		}
	];

	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// 검색
	$('#btnSearch').on('click', function() {
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 저장
	$('#btnSave').on('click', function() {
		// 변경된 데이터
		var changedData = gagaAgGrid.getChangedData(gridOptions);
		
		if (changedData.length == 0) {
			mcxDialog.alert('변경된 데이터가 없습니다.');
			return;
		}
		
		// Validation
		if (!gagaAgGrid.validation(gridOptions, changedData))
			return;
		
		mcxDialog.confirm("저장하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify(changedData);
				gagajf.ajaxJsonSubmit('/ocm/extmall/price/sync/save', jsonData, function() {
					$('#btnSearch').trigger('click');
				});
			}
		});
	});
	
	// 엑셀다운로드
	$('#btnExcel').on('click', function() {
		gagaAgGrid.exportToExcel('제휴몰가격연계 목록', gridOptions);
	});

	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
