<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : CouponPopupForm.html
 * @desc    : 쿠폰 등록 팝업 화면
 *============================================================================
 * ISTYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.12.23   xyzp1539       최초 작성
 *******************************************************************************
 -->
<!-- 선착순 쿠폰 설정 -->
<span class="limitedTimeCpnSpan">
	<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddLimitedTimeCpnRow">행추가</button>
	<button type="button" class="btn btnRight btn-success btn-lg" id="btnDelLimitedTimeCpnRow">행삭제</button>
</span>
<br/>
<div id="limitedTimeCpnList" style="width: 100%; height: 500px" class="ag-theme-balham"></div>
<!-- //선착순 쿠폰 설정 -->

<!-- //제휴채널 설정 -->
<script th:inline="javascript">
let limitedTimeCpnList 	= [[${limitedTimeCpnList}]];

//선착순 쿠폰 리스트
var limitedTimeCpnDefs = [
	{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
	{ headerName: "쿠폰시퀀스", field: "cpnId", width: 150, cellClass: 'text-center'},	//, hide: true
	{ headerName: "선착순쿠폰명" , field: "limitCpnNm" , width: 200, cellClass: 'text-center'
		,cellEditorParams: { maxlength: 20}
	} ,
	{ headerName: "시작일" , field: "downStDate" , width: 200, cellClass: 'text-center'
		,cellEditor: 'datePicker'
		,cellEditorParams: { maxlength: 10, required: true }
	},
	{ headerName: "시작시간" , field: "downStTime" , width: 200, cellClass: 'text-center'
		,cellEditor: 'dateTimer'
		,cellEditorParams: { maxlength: 8, required: true }
	},
	{ headerName: "종료일"  , field: "downEdDate" , width: 200 , cellClass: 'text-center'
		,cellEditor: 'datePicker'
		,cellEditorParams: { maxlength: 10, required: true }
	} ,
	{ headerName: "종료시간"  , field: "downEdTime" , width: 200 , cellClass: 'text-center'
		,cellEditor: 'dateTimer'
		,cellEditorParams: { maxlength: 8, required: true }
	} ,
	{ headerName: "다운로드가능수량"  , field: "downLimitQty" , width: 150 , cellClass: 'text-center'
		,cellEditorParams: { maxlength: 4, validType: 'numeric'}
	},
	{ headerName: "선착순시퀀스", field: "limitCpnId", width: 150, cellClass: 'text-center' , hide: true}
	,{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	,{headerName: "시작일시", field: "downStdt", width: 150, cellClass: 'text-center' , hide:true}
	,{headerName: "종료일시", field: "downEddt", width: 150, cellClass: 'text-center' , hide:true}
];

var limitedTimeCpnGridOptions = gagaAgGrid.getGridOptions(limitedTimeCpnDefs);
limitedTimeCpnGridOptions.defaultColDef.editable = true;
limitedTimeCpnGridOptions.rowSelection = "multiple";

var limitedTimeInfoInit = function() {
	
	gagaAgGrid.createGrid('limitedTimeCpnList'	, limitedTimeCpnGridOptions);
	
	if (limitedTimeCpnList != null) {
		limitedTimeCpnGridOptions.api.setRowData(limitedTimeCpnList);
	}
	
	// 선착순 쿠폰 종료시간 초 59로 변경
	limitedTimeCpnGridOptions.onCellValueChanged = function (event){
		if (event.colDef.field == "downEdTime"){
			var temp 	= event.data.downEdTime.replaceAll(":","");
			var hh 		= temp.substr(0,2);
			var mm 		= temp.substr(2,2);
			
			event.data.downEdTime = hh+':'+mm+':'+'59';
			limitedTimeCpnGridOptions.api.updateRowData({update: [event.data]});
			
			return;
		}
	}
	
	// 선착순 쿠폰 행추가
	$('#btnAddLimitedTimeCpnRow').on('click', function() {
		var data = { cpnId: 1 ,limitCpnNm: null, downStDate: _today, downStTime: '00:00:00', downEdDate: _today, downEdTime: '23:59:59', downLimitQty: null, limitCpnId: null, delYn: 'N' };
		gagaAgGrid.addRowData(limitedTimeCpnGridOptions, data, "limitCpnNm");
	});
	
	// 선착순 쿠폰 행삭제
	$('#btnDelLimitedTimeCpnRow').on('click', function() {
		limitedTimeCpnGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(limitedTimeCpnGridOptions)});
	});
	
	// 비활성화처리 대기상태가아닐때 동작
	if (cpnDetail.cpnStat != 'G232_10' || issueCnt > 0) {
		$('#btnAddLimitedTimeCpnRow').hide();
		$('#btnDelLimitedTimeCpnRow').hide();
		limitedTimeCpnGridOptions.defaultColDef.editable = false;
	}
	
	
}
</script>
</html>