<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : ClauseDetailForm.html
 * @desc    :  약관관리상세 Page
 *=============================================================
 * SISUN
 * Copyright(C) 2019 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2020.03.09   Daehyoung     최초 작성
 *******************************************************************************
 -->
	<ul class="popup modal" id="popupClauseDetail" data-width="1200" data-height="800">
		<li class="mdPopTitle">
			<strong>약관상세</strong>
 			<button type="button" id="closeBtn" class="close" onclick="uifnPopClose('popupClauseDetail')"><i class="fa fa-times" aria-hidden="true"></i></button>
		</li>
		<li class="mdPopContent">
			<form id="clauseDetailForm" name="clauseDetailForm" action="#" >
				<div class="cardArea" style="height: 620px;">
					<table class="frmStyle" aria-describedby="상세">
					<colgroup>
						<col style="width:15%;"/>
						<col style="width:25%;"/>
						<col style="width:15%;"/>
						<col style="width:45%;"/>
					</colgroup>
					<tbody>
						<tr>
							<th>약관일련번호</th>
							<td>
								<input type="text" name="clauseSq" id="clauseSq" maxlength="20" readonly="readonly"/>
							</td>
							<th>사이트</th>
							<td>
								<select name="siteCd" id="siteCd">
									<option th:if="${siteList}" th:each="oneData, status : ${siteList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
								</select>
							</td>
						</tr>
						<tr>
							<th>약관유형</th>
							<td>
								<select name="clauseType" id="clauseType">
									<option th:if="${clauseTypeList}" th:each="oneData, status : ${clauseTypeList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
								</select>
							</td>
							<th>표시여부</th>
							<td>
								<label><input type="checkbox" name="chkYn" value="Y"/>표시</label>
								<span class="cBlue" style="font-size:11px;"><i class="fa fa-info-circle" aria-hidden="true"></i> 표시여부를 체크 할 경우, 현재  약관으로 노출됩니다.</span>
								<input type="hidden" name="dispYn" id="dispYn"/>
							</td>
						</tr>
						<tr id="dateTableRow">
							<th>등록일시</th>
							<td>
								<input type="text" class="" name="regDt" id="regDt" placeholder="" maxlength="20" readonly="readonly"/>
							</td>
							<th>수정일시</th>
							<td>
								<input type="text" class="" name="updDt" id="updDt" placeholder="" maxlength="20" readonly="readonly"/>
							</td>
						</tr>
						<tr>
							<th>약관 제목<i class="star" aria-hidden="true"></i></th>
							<td colspan="3">
								<input type="text" name="clauseTitle" id="clauseTitle" placeholder="" maxlength="20"/>
							</td>
						</tr>
						<tr>
							<th>약관 내용<i class="star" aria-hidden="true"></i></th>
							<td colspan="3">
								<textarea class="textareaR4" name="clauseContent" id="clauseContent" style="height:350px;"></textarea>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</form>
		</li>
		<li class="mdPopBtnB btnRight">
			<button type="button" class="btn btn-success btn-lg" id="btnSave">저장</button>
		</li>
	</ul>
	
<script type="text/javascript" src="/smartEditor/js/HuskyEZCreator.js?v=2019122801" charset="utf-8"></script>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.smarteditor.js?v=2019122801"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	
	var mode = [[${mode}]];	
	var clauseInfo;
	
	$('#btnSave').on('click', function() {
		if(mode == "N"){
			fnRegist();
		} else {
			fnUpdate();
		}
	});
	
	// 약관 등록
	var fnRegist = function() {
		gagaSe.getContents('clauseContent');
		
		var clauseTitle = $('#clauseTitle').val();
		var clauseContent = $('#clauseContent').val();
		
		if (gagajf.isNull(clauseTitle)) {
			mcxDialog.alert("약관 제목을 입력해주세요.");
			return;
		}
		if (gagajf.isNull(clauseContent)) {
			mcxDialog.alert("약관 내용을 입력해주세요.");
			return;
		}
		$('#clauseDetailForm input[name=dispYn]').val($('#clauseDetailForm input:checkbox[name=chkYn]').is(":checked") ? 'Y' : 'N');
		
		mcxDialog.confirm("등록하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify($('#clauseDetailForm').serializeObject());
				gagajf.ajaxJsonSubmit('/system/clause/detail/create', jsonData, saveCallback);
			}
		});
	}
	
	// 약관 수정
	var fnUpdate = function() {
		gagaSe.getContents('clauseContent');
		
		var clauseTitle = $('#clauseTitle').val();
		var clauseContent = $('#clauseContent').val();
		
		if (gagajf.isNull(clauseTitle)) {
			mcxDialog.alert("약관 제목을 입력해주세요.");
			return;
		}
		if (gagajf.isNull(clauseContent)) {
			mcxDialog.alert("약관 내용을 입력해주세요.");
			return;
		}
		$('#clauseDetailForm input[name=dispYn]').val($('#clauseDetailForm input:checkbox[name=chkYn]').is(":checked") ? 'Y' : 'N');
		
		mcxDialog.confirm("수정하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify($('#clauseDetailForm').serializeObject());
				gagajf.ajaxJsonSubmit('/system/clause/detail/update', jsonData, saveCallback);
			}
		});
	}
	
	// 저장 콜백
	var saveCallback = function() {
		$('#closeBtn').trigger('click');
		fnSearch();
	}	
	
	var seOptions = gagaSe.getEditorOptions();
	// 초기세팅
	var fnInit = function(mode){
		gagaSe.createSmartEditor(seOptions, 'clauseContent');
		if(mode == "N"){
			// 등록
			$('#clauseSq').val('자동생성');
			$('#dateTableRow').remove();
			
		} else {
			// 수정
			clauseInfo = [[${admClause}]];
			
			$('#clauseSq').val(clauseInfo.clauseSq);
			$('#siteCd').val(clauseInfo.siteCd);
			$('#clauseType').val(clauseInfo.clauseType);
			
			$('#regDt').val(clauseInfo.regDt.toDate("YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss"));
			$('#updDt').val(clauseInfo.updDt.toDate("YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss"));
			
			$('#clauseTitle').val(clauseInfo.clauseTitle);
			
			if(clauseInfo.dispYn == 'Y'){
				$('input[type=checkbox]').attr('checked', true);
			} else {
				
			}
			gagaSe.setContents('clauseContent', clauseInfo.clauseContent); //공지내용
			
		}
	}
	
	$(document).ready(function() {
		fnInit(mode);
	});
	
/*]]>*/
</script>

</html>
