<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
	<!--
 *******************************************************************************
 * @source  : AnswerPhaseForm.html
 * @desc    : 답변문구관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.10.29   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="@{'/envset/answer/phase/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>사이트</th>
						<td>
							<select name="siteCd">
								<option value="">[전체]</option>
								<option th:if="${siteList}" th:each="oneData, status : ${siteList}"th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>답변종류</th>
						<td>
							<select name="ansClsf">
								<option value="">[전체]</option>
								<option th:if="${ansClsfList}" th:each="oneData, status : ${ansClsfList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>답변제목</th>
						<td>
							<input type="text" name="ansTitle" class="w200"/>
						</td>
						<th>사용여부</th>
						<td>
							<select name="useYn">
								<option value="">[전체]</option>
								<option value="Y">[Y] Yes</option>
								<option value="N">[N] No</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 class="right">
					<button type="button" class="btn btn-default btn-lg" id="btnExcel">엑셀다운로드</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 470px" class="ag-theme-balham"></div>
		</div>
		
		<!-- 등록/수정 -->
		<div class="panelStyle">
			<form id="detailForm" name="detailForm" action="#" th:action="@{'/envset/answer/phase/save'}">
				<input type="hidden" name="ansSq" value=""/>
				<table class="frmStyle" aria-describedby="등록폼">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>사이트<em class="required" title="필수"></em></th>
						<td>
							<select name="siteCd" required="required" data-valid-name="사이트">
								<option>[전체]</option>
								<option th:if="${siteList}" th:each="oneData, status : ${siteList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>답변종류<em class="required" title="필수"></em></th>
						<td>
							<select name="ansClsf" required="required" data-valid-name="답변종류">
								<option value="">[선택]</option>
								<option th:if="${ansClsfList}" th:each="oneData, status : ${ansClsfList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>사용여부</th>
						<td>
							<input type="hidden" name="useYn" value="Y"/>
							<label class="chkBox"><input type="checkbox" name="chkUseYn" checked="checked"/>사용</label>
						</td>
					</tr>
					<tr>
						<th>답변제목<em class="required" title="필수"></em></th>
						<td colspan="5">
							<input type="text" name="ansTitle" required="required" data-valid-name="답변제목"/>
						</td>
						
					</tr>
					<tr>
						<th>답변내용<em class="required" title="필수"></em></th>
						<td colspan="5">
							<textarea name="ansContent" class="textareaR3" required="required"  data-valid-name="답변내용"></textarea>
						</td>
					</tr>
				</table>
			</form>
			
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-info btn-lg" id="btnNew">신규</button>
					<button type="button" class="btn btn-success btn-lg" id="btnSave">저장</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
		</div>
		<!-- 등록/수정 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	var siteList = gagajf.convertToArray([[${siteList}]]);
	var ansClsfList = gagajf.convertToArray([[${ansClsfList}]]);

	var columnDefs = [
		{headerName: "답변번호", field: "ansSq", width: 100, cellClass: 'text-center'},
		{
			headerName: "사이트", field: "siteCd", width: 150, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(siteList, params.data.siteCd); }
		},
		{
			headerName: "답변종류", field: "ansClsf", width: 150, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(ansClsfList, params.data.ansClsf); }
		},
		{
			headerName: "답변제목", field: "ansTitle", width: 350,
			cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.value + '</a>'; }
		},
		{headerName: "사용여부", field: "useYn", width: 80, cellClass: 'text-center'},
		{headerName: "등록자", field: "regNm", width: 150, cellClass: 'text-center'},
		{
			headerName: "등록일시", field: "regDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		},
		{headerName: "수정자", field: "updNm", width: 100, cellClass: 'text-center'},
		{
			headerName: "수정일시", field: "updDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) { return gagaAgGrid.toDateTimeFormat(params.value); }
		}
	];

	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// 셀 클릭 이벤트
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'ansTitle')
			return;
		
		$('#detailForm input[name=ansSq]').val(event.data.ansSq); // 답변일련번호
		$('#detailForm select[name=siteCd]').val(event.data.siteCd); // 사이트
		$('#detailForm select[name=ansClsf]').val(event.data.ansClsf); // 답변종류

		if (event.data.useYn == 'Y') {
			$("#detailForm input:checkbox[name=chkUseYn]").prop('checked', true);
		} else {
			$("#detailForm input:checkbox[name=chkUseYn]").prop('checked', false);
		}
		
		$('#detailForm input[name=ansTitle]').val(event.data.ansTitle.replaceAll('&gt;','>')); // 답변제목
		$('#detailForm textarea[name=ansContent]').val(event.data.ansContent); // 답변내용
	}

	// 검색
	$('#btnSearch').on('click', function() {
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 신규
	$('#btnNew').on('click', function() {
		$('#detailForm')[0].reset();
		$('#detailForm input[name=ansSq]').val('');
		$('#detailForm input[name=ansTitle]').focus();
	});

	// 저장/수정
	$("#btnSave").on("click", function() {
		// 필수값 체크
		if (!gagajf.validation('#detailForm'))
			return false;

		mcxDialog.confirm('저장하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				$('#detailForm input[name=useYn]').val($('#detailForm input:checkbox[name=chkUseYn]').is(':checked') ? 'Y' : 'N');
				
				gagajf.ajaxFormSubmit($('#detailForm').prop('action'), '#detailForm', function() {
					$('btnNew').click();
					$('#btnSearch').trigger('click');
				});
				
				gagajf.ajaxJsonSubmit($(formId).prop("action"), jsonData, fnSaveCallback);
			}
		});
	});

	// 엑셀다운로드
	$('#btnExcel').on('click', function() {
		gagaAgGrid.exportToExcel('답변문구 목록', gridOptions);
	});
	
	$(document).ready(function() {
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>