<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : LookbookListForm.html
 * @desc    : 룩북관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.3.4     bin2107     최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<form id="searchForm" name="searchForm" action="#" th:action="@{'/display/lookbook/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
			<div class="panelStyle">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:40%;"/>
					</colgroup>
					<tr>
						<th>사이트</th>
						<td>
							<select name="siteCd">
								<option th:if="${siteCdList}" th:each="oneData, status : ${siteCdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>브랜드</th>
						<td>
							<input type="text" class="w100" name="brandCd" value="" />
							<button type="button" class="btn btnRight btn-success btn-lg" onclick="fnSearchLbBrandGroup();">브랜드조회</button>
						</td>
						<!--<td>
							<select name="brandCd">
								<option value="">[선택]</option>
								<option th:if="${brandGroupList}" th:each="oneData, status : ${brandGroupList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>-->
						<th>전시기간</th>
						<td colspan="5" id="sellTerms">
							<span class="nowrap">
								<input name="dispStdt" id="schStDate" type="text" class="w80 schDate" maxlength="10" required="required" data-valid-name="노출기간 시작일" />
								<select id="schStTimeHour" required="required" data-valid-name="노출기간 시작시간">
									<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
									<option  th:value="${#numbers.formatInteger(num,2)}" th:text="|${#numbers.formatInteger(num,2)}시|" >시간</option>
									</th:block>
								</select>
								<select id="schStTimeMin" required="required" data-valid-name="노출기간 시작시간">
									<th:block th:each="num: ${#numbers.sequence(0,59)}">
									<option  th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" >분</option>
									</th:block>
								</select>
								<input name="dispStTime" id="schStTime" type="hidden" data-valid-name="노출기간 시작시간" value='000000' />
								~
								<input name="dispEddt" id="schEdDate" type="text" class="w80 schDate" maxlength="10" required="required" data-valid-name="노출기간 종료일" />
								<select id="schEdTimeHour" required="required" data-valid-name="노출기간 종료시간">
									<th:block th:each="num: ${#numbers.sequence(0,23)}">
									<option  th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="${#numbers.formatInteger(num,2)}==23 ? 'true'">시간</option>
									</th:block>
								</select>
								<select id="schEdTimeMin" required="required" data-valid-name="노출기간 종료시간">
									<th:block th:each="num: ${#numbers.sequence(0,59)}">
									<option  th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="${#numbers.formatInteger(num,2)}==59 ? 'true'">분</option>
									</th:block>
								</select>
								<input name="dispEdTime" id="schEdTime" type="hidden" data-valid-name="노출기간 종료시간" value='235959' />
							</span>
						</td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-default btn-lg" id="btnInit">초기화</button>
						<button type="button" class="btn btn-base btn-lg" id="btnSearch">조회</button>
					</li>
				</ul>
			</div>
		<!-- 검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<!-- 상단영역 START -->
			<ul class="panelBar">
				<li class="left">
					<span class="btnLeft">
						<button type="button" class="btn btn-danger btn-lg" id="btnDel">노출안함</button>
					</span>
				</li>
				<li class="right">
					<span class="btnRight">
						<button type="button" class="btn btn-success btn-lg" id="btnReg">등록</button>
					</span>
					검색결과 : <strong><span id="gridRowTotalCount">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
					<select id="pageSize" name="pageSize">
						<option value="50" selected="selected">50개씩 보기</option>
						<option value="100">100개씩 보기</option>
						<option value="500">500개씩 보기</option>
						<option value="1000">1000개씩 보기</option>
					</select>
					<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
				</li>
			</ul>
			<!-- 상단영역 END -->
			<div id="gridList" style="width: 100%; height: 470px" class="ag-theme-balham"></div>

			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="lookbookListPagination"></div>
				</li>
			</ul>
		</div>
		<!-- //리스트 영역 -->
		</form>
	</div>

<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=2019072202"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	var brandGroupList = [[${brandGroupList}]];

	let columnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "룩북일련번호", field: "lookbookSq", width: 100, cellClass: 'text-center'
			,cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{headerName: "타이틀", field: "title", width: 200, cellClass: 'text-center'},
		{headerName: "브랜드", field: "brandCd", width: 80, cellClass: 'text-center'},
		{headerName: "브랜드명", field: "brandNm", width: 80, cellClass: 'text-center'},
		{headerName: "메인룩북", field: "mainDispYn", width: 80, cellClass: 'text-center'},
		{headerName: "노출여부", field: "dispYn", width: 80, cellClass: 'text-center'},
		{headerName: "노출시작일", field: "dispStdt", width: 150, cellClass: 'text-center'},
		{headerName: "노출종료일", field: "dispEddt", width: 150, cellClass: 'text-center'},
		{headerName: "등록자", field: "regNm", width: 80, cellClass: 'text-center'},
		{headerName: "등록일자", field: "regDt", width: 150, cellClass: 'text-center'},
		{headerName: "수정자", field: "updNm", width: 80, cellClass: 'text-center'},
		{headerName: "수정일자", field: "updDt", width: 150, cellClass: 'text-center'}
	];

	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	gridOptions.rowSelection = "multiple";

	// 셀 클릭 이벤트
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field == 'lookbookSq') {
			// 룩북 상세
			cfnOpenLookbookBannerPopup('U',event.data.lookbookSq);
		}
	}

	// 등록 팝업
	$("#btnReg").on('click', function(){
		cfnOpenLookbookBannerPopup('N');
	});

	// 초기화 버튼
	$("#btnInit").on('click', function (){
		$("#searchForm")[0].reset();
		gagajf.setDate('schStDate', 'schEdDate', 't');
	});

	// 조회
	$("#btnSearch").on('click', function(){
		var fromDate = '';
		var toDate = '';
		if(!gagajf.isNull($("#searchForm input[name=dispStdt]").val())){
			$("#searchForm input[name=dispStTime]").val($('#searchForm #schStTimeHour').val()+$('#searchForm #schStTimeMin').val()+'00');
			fromDate = $("#searchForm input[name=dispStdt]").val().replaceAll('-','')+$("#searchForm input[name=dispStTime]").val();
		}
		if(!gagajf.isNull($("#searchForm input[name=dispEddt]").val())){
			$("#searchForm input[name=dispEdTime]").val($('#searchForm #schEdTimeHour').val()+$('#searchForm #schEdTimeMin').val()+'59');
			toDate = $("#searchForm input[name=dispEddt]").val().replaceAll('-','')+$("#searchForm input[name=dispEdTime]").val();
		}

		if (!gagajf.isNull(fromDate) || !gagajf.isNull(toDate)) {
			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#searchForm input[name=dispStTime]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alertC("시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#searchForm input[name=dispEdTime]').focus();
					}
				});
				return false;
			}
		}

		fnSearch();
	});

	var fnSearch = function(){
		gagaPaging.init('searchForm', fnSearchCallBack, 'lookbookListPagination', $('#searchForm').find('#pageSize').val());
		gagaPaging.load(1);
	};

	//페이징
	$('#searchForm select[name=pageSize]').on('change', function() {
		$("#searchForm input[name=pageNo]").val('1');
		gagaPaging.init('searchForm', fnSearchCallBack, 'lookbookListPagination', $('#searchForm').find('#pageSize').val());
		gagaPaging.load(1);
	});

	var fnSearchCallBack = function(result){
		$('#searchForm').find('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
		$('#searchForm').find('#pageNo').val(result.pageing.pageable.pageNo.addComma());
		$('#searchForm').find('#pgNo').html(result.pageing.pageable.pageNo.addComma());
		$('#searchForm').find('#endPgNo').html(result.pageing.pageable.totalPage.addComma());
		gridOptions.api.setRowData(result.lookbookList);
		gagaPaging.createPagination(result.pageing.pageable);
	}

	// 노출안함
	$("#btnDel").on('click', function (){
		var selectRowData = gagaAgGrid.selectedRowData(gridOptions);
		if (selectRowData.length > 0) {
			mcxDialog.confirm('변경하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					var selectDataArr = [];
					$.each(selectRowData, function(idx, item) {
						selectDataArr.push(item.lookbookSq);
					});

					var data = {
						selectDataArr : selectDataArr
					};

					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/display/lookbook/delete', jsonData, fnSaveCollback);
				}
			});
		}else{
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}
	});

	var fnSaveCollback = function (){
		$("#btnInit").click();
		$('#btnSearch').trigger('click');
	}

	var fnSearchLbBrandGroup = function (){
		cfnOpenBrandGroupListPopup("fnCallBackLbBrandGroup", "S", "S");
	}

	var fnCallBackLbBrandGroup = function (result){
		$("#searchForm").find("input[name=brandCd]").val(result[0].brandGroupNo);
	}

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

</html>
