<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : EmailPopupForm.html
 * @desc    : 메일발송팝업 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.21   jsshin     최초 작성
 *******************************************************************************
 -->
<div class="modelessPopup" data-width="800">
	<div class="panelStyle">
		<!-- TITLE -->
		<div class="panelTitle">
			<strong >메일 발송</strong>
			<button type="button" class="close" onclick="uifnPopupClose('popupEmailForm')"><em class="fa fa-times"></em></button>
		</div>
		<!-- //TITLE -->
		<!-- CONTENT -->
		<div class="panelContent">
			<form id="emailForm" name="emailForm">
				<input type="hidden" name="sendEmail" th:value="${sendEmail}"/>
				<input type="hidden" name="email"/>
				<table class="frmStyle">
					<colgroup>
						<col style="width:1%"/>
						<col style="width:40%"/>
					</colgroup>
					<tbody>
					<tr >
						<th>보내는사람</th>
						<td>
							<span name="sendEmail" th:text="${sendEmail}"></span>
						</td>
					</tr>
					<tr>
						<th>받는사람</th>
						<td>
							<span name="email"></span>
						</td>
					</tr>
					<tr>
						<th>제목<em class="star"></em></th>
						<td>
							<input type="text" class="w300" name="title" value="" required="required" data-valid-name="제목"/>
						</td>
					</tr>
					<tr>
						<th>내용<em class="star"></em></th>
						<td>
							<textarea class="textareaR4" style="resize: none;" name ="content" ></textarea>
						</td>
					</tr>
					</tbody>
				</table>
			</form>
		</div>
		<ul class="panelBar">
			<li class="right">
				<button type="button" class="btn btn-success btn-lg" id="btnSendEmail">발송</button>
				<button type="button" class="btn btn-gray btn-lg" onclick="uifnPopupClose('popupEmailForm')">취소</button>
			</li>
		</ul>
		<!-- //CONTENT -->
	</div>
</div>
<script th:inline="javascript">
	/*<![CDATA[*/
	const elementEmail = [[${elementEmail}]];
	const elementCustNo = [[${elementCustNo}]];
	const elementMaskingEmail = [[${elementMaskingEmail}]];

	// 메시지 전송
	$("#btnSendEmail").on("click",function() {
		let formId = '#emailForm';
		let $content = $(formId+' textarea[name=content]');
		let $email = $(formId+' input[name=email]');


		if(gagajf.isNull($content.val())) {
			mcxDialog.alertC("내용을 입력해 주세요.", {
				sureBtnText: "확인",
				sureBtnClick: function() {
					$content.focus();
				}
			});
			return;
		}

		if(gagajf.isNull($email.val())) {
			mcxDialog.alertC("수신메일을 입력해 주세요.", {
				sureBtnText: "확인",
				sureBtnClick: function() {
					$email.focus();
				}
			});
			return;
		}

		if(!gagajf.validation(formId)){
			return;
		}

		mcxDialog.confirm("메일을 발송하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				let params = $(formId).serializeObject();
				params.custNo = $(elementCustNo).val();
				let jsonData = JSON.stringify(params);
				gagajf.ajaxJsonSubmit('/customer/email/send', jsonData, uifnPopupClose('popupEmailForm'));
			}
		});

	});

	// 데이터 셋팅
	var fnInitDataSet = function () {
		let email = $(elementEmail).val();
		if (gagajf.isNull(elementMaskingEmail)) {
			$('#emailForm input[name=email]').val(email);
			$('#emailForm span[name=email]').text(email);
		} else {
			let mkEmail = $(elementMaskingEmail).val();
			$('#emailForm input[name=email]').val(email);
			$('#emailForm span[name=email]').text(mkEmail);
		}
	}

	$(document).ready(function() {
		fnInitDataSet();
	});

	/*]]>*/
</script>
</html>
