<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : PlanListPopupForm.html
 * @desc    : 기획전 조회 팝업 화면 Page
 *============================================================================
 * SISUN
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.02.15   sowon     최초 작성
 *******************************************************************************
 -->

<div class="modalPopup" data-width="1200" id="popupPlan">

	<div class="panelStyle" style="height: 750px;">
		<div class="panelTitle">
			<strong>기획전 조회</strong>
			<button type="button" class="close"
				onclick="uifnPopupClose('popupPlan')">
				<i class="fa fa-times"></i>
			</button>
		</div>

		<div class="panelContent">
			<form id="popupPlanSearchForm" name="popupPlanSearchForm" action="#"
				th:action="@{'/marketing/planning/list/detail/popup'}"
				onsubmit="$('#btnPlanPopupSearch').trigger('click'); return false;">
				<table class="frmStyle">
					<colgroup>
						<col style="width: 5%;" />
						<col style="width: 20%;" />
						<col style="width: 5%;" />
						<col style="width: 20%;" />
						<col style="width: 5%;" />
						<col style="width: 10%;" />
						<col style="width: 5%;" />
						<col style="width: 10%;" />
						<col />
					</colgroup>
					<tbody>
						<tr>
							<th>사이트</th>
							<td><select name="siteCd">
									<th:block th:if="${siteList}"
										th:each="oneData, status : ${siteList}">
										<option th:value="${oneData.cd}"
											th:text="${oneData.cdNm}"></option>
									</th:block>
							</select></td>

							<th>기획전명</th>
							<td><input type="text" name="planNm" id="planNm" /></td>

							<th>기획전번호</th>
							<td colspan="3"><input type="text" name="planSq" id="planSq" />
							</td>

						</tr>
						<tr>
							<th>웹/모바일구분</th>
							<td><select name="frontGb">
									<option value="">ALL</option>
									<option value="P">웹</option>
									<option value="M">모바일</option>
									<option value="A">앱</option>
							</select></td>

							<th>기획전구분</th>
							<td><select name="planGb">
									<option value="">전체</option>
									<option value="P">기획전</option>
									<option value="E">이벤트</option>
									<option value="C">출석체크</option>
									<option value="S">총알배송</option>
							</select></td>
							
							<th>오픈여부</th>
							<td><select name="openYn">
									<option value="">전체</option>
									<option th:if="${useYnList}"
										th:each="oneData, status : ${useYnList}"
										th:value="${oneData.cd}"
										th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select></td>
						</tr>

						<tr>
							<th>진행기간</th>
							<td colspan="5" id="popupPlanTerms"></td>
<!-- 
							<th>등록자</th>
							<td><input type="text" name="regId" id="regId" />
							</td> -->
						</tr>
					</tbody>
				</table>
				<ul class="panelBar">
					<li class="center">
						<input type="button" value="초기화" class="btn btn-gray btn-lg" id="btnInitPop"/>
						<input type="button" value="조회" class="btn btn-base btn-lg"	 id="btnPlanPopupSearch" />
					</li>
				</ul>
			</form>
		</div>
		<!-- 리스트 영역 -->
		<div class="panelContent">
			<div id="gridListPop" style="width: 100%; height: 400px;" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->

		<!-- 버튼 배치 영역 -->
		<ul class="panelBar">
			<li class="right">
				<button type="button" class="btn btn-info btn-lg"
					id="btnPlanPopupApply">적용</button>
			</li>
		</ul>

	</div>
</div>
<script th:inline="javascript">
/*<![CDATA[*/

	var siteCdList = gagajf.convertToArray([[${siteList}]]);
	var wmGbList = {"A":"ALL", "P":"웹", "M":"모바일"};
	var templateTypeList = {"H":"HTML", "T":"TEXT"};
	var planGbList = {"P":"기획전", "E":"이벤트"};
	var planList = ([[${planList}]]);
	
	// 초기화 클릭시
	$('#btnInitPop').on('click', function() {
		fnInit();
	});
	
	var fnInit = function(){
		$('#popupPlanSearchForm')[0].reset();
	}

	var columnDefs =  [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "미리보기"		, field:'plan'		, width:100, cellClass: 'text-center',
			cellRenderer: function(params) { return '<a href="javascript:void(0);" onclick="fnPreview(\'' + params.data.planSq + '\');">' + '미리보기' + '</a>'; }
		},
		{headerName: "기획전구분"		, field:'planGb'	, width:100, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(planGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(planGbList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(planGbList, params.newValue); }
		},
		{headerName: "사이트"			, field:'siteCd'	, width:100, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(siteCdList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(siteCdList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(siteCdList, params.newValue); }
		},
		{headerName: "프론트구분"	, field:'frontGb'	, width:120, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(wmGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(wmGbList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(wmGbList, params.newValue); }
		},
		{headerName: "오픈여부"		, field:'openYn'	, width:80 , cellClass: 'text-center'},
		{headerName: "기획전번호"		, field:'planSq'	, width:100, cellClass: 'text-center',
			cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.value + '</a>'; }
		},
		{headerName: "기획전명"		, field:'planNm'	, width:300, cellClass: 'text-left',
			cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.value + '</a>'; }
		},
		{headerName: "서브제목"		, field:'dtlTitle1'	, width:300 , cellClass: 'text-center'},
		{headerName: "기획전템플릿유형"	, field:'templateType'	, width:100, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(templateTypeList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(templateTypeList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(templateTypeList, params.newValue); }
		},
		{headerName: "pc이미지"		, field:'mainPimg'	, width:100, cellClass: 'text-right' , hide: true},
		{headerName: "mobile이미지"		, field:'mainMimg'	, width:100, cellClass: 'text-right' , hide: true},
		{headerName: "전시순서"		, field:'dispOrd'	, width:100, cellClass: 'text-right' },
		{headerName: "진행시작일시"		, field:'dispStdt'	, width:150, cellClass: 'text-center'},
		{headerName: "진행종료일시"		, field:'dispEddt'	, width:150, cellClass: 'text-center'},
		{headerName: "등록자"			, field:'regNm'		, width:100, cellClass: 'text-center'},
		{headerName: "등록일"			, field:'regDt'		, width:150, cellClass: 'text-center'}
	];

	var gridOptionsPopupPlan = gagaAgGrid.getGridOptions(columnDefs);
	gridOptionsPopupPlan.rowSelection = 'single';
	
	// 셀 클릭 이벤트
	gridOptionsPopupPlan.onCellClicked = function(event) {
		var field = event.colDef.field;
		if (field != 'planSq' && field != 'planNm')
			return;
		
	}
	
	// 미리보기
	var fnPreview = function(planSq) {
		var _wmall = [[${@environment.getProperty('domain.pastel')}]];
		window.open(_wmall + '/planning/detail/form?planSq=' + planSq + '&adminPreview=Y', '_blank');
 		//document.location.href = _PAGE_CUSTOMER_INFO;
	}
	
	// 조회 버튼 클릭 시
	$('#btnPlanPopupSearch').on('click', function() {
		var formId = '#popupPlanSearchForm';
		gagaAgGrid.fetch($(formId).prop('action'), gridOptionsPopupPlan, formId);
	});
		
	// 적용 버튼 클릭 시
	$('#btnPlanPopupApply').on('click', function() {
		
		var selectedData = gagaAgGrid.selectedRowData(gridOptionsPopupPlan);
		
		if (selectedData.length < 1) {
			mcxDialog.alert('선택 된 기획전이 없습니다.');
			return
		}
		
		var callback = [[${params.callBackFun}]];
		
		var jsonData = JSON.stringify(selectedData);

		if ( typeof callback != 'undefined' && callback) {

			if (typeof callback == 'function') {
				callback(jsonData);
			} else {
				if (callback) {
					if ( callback.indexOf("(") == -1 ) eval( callback +"(" + jsonData+")");
					else eval( callback(jsonData) );
				}
			}
			
			uifnPopupClose('popupPlan');
		}
	});
	
	$(document).ready(function() {
		gagaAgGrid.createGrid('gridListPop', gridOptionsPopupPlan);
		cfnCreateCalendar('#popupPlanTerms', 'popupDispStdt', 'popupDispEddt', false);
		gagajf.setDate('popupDispStdt', 'popupDispEddt', '7d');
	});
	
	
	// 기획전 리스트 팝업============================================================================
	/* var fnPlanSearch = function(sub){
		if (sub == "View"){
			cfnOpenPlanPopup('fnSetPlanSqView');
		}else{
			cfnOpenPlanPopup('fnSetPlanSq');
		}
	}

	// 팝업 등록 기획전
	var fnSetPlanSq = function(result) {
		$('#planListSearchForm input[name=planSq]').val(result[0].planSq);
	}

	//미리보기 기획전
	var fnSetPlanSqView = function(result) {
		$('#planSqView').val(result[0].planSq);
	}
 */
	
	//=========================================================================================
/*]]>*/
</script>

</html>