<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : LmsPopupForm.html
 * @desc    : 메시지발송팝업 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.21   jsshin     최초 작성
 *******************************************************************************
 -->

	<div class="modelessPopup draggable" data-width="800">
		<div class="panelStyle">
			<!-- TITLE -->
			<div class="panelTitle">
				<strong>LMS 발송</strong>
				<button type="button" class="close" onclick="uifnPopupClose('popupLmsForm')"><em class="fa fa-times"></em></button>
			</div>
			<!-- //TITLE -->
			<!-- CONTENT -->
			<div class="panelContent">
				<form id="lmsForm" name="lmsForm">
					<table class="frmStyle">
						<colgroup>
							<col style="width:1%"/>
							<col style="width:40%"/>
						</colgroup>
						<tbody>
						<tr >
							<th>수신자번호<em class="required" title="필수"></em></th>
							<td th:if="${maskingCellPhnno == ''}">
								<input type="text" class="w150" name="cellPhnno" data-valid-name="수신번호"  required="required"  maxlength="13" readonly="readonly"/>
							</td>
							<td th:unless="${maskingCellPhnno == ''}">
								<input type="hidden" name="cellPhnno"/>
								<input type="text" class="w150" name="maskingCellPhnno" readonly="readonly"/>
							</td>
						</tr>
						<tr>
							<th>발신자번호<em class="required" title="필수"></em></th>
							<td>
								<input type="text" class="w150" name="callBack" th:value="${callBack}" maxlength="11" readonly="readonly"/>
							</td>
						</tr>
						<tr>
							<th>메시지<em class="required" title="필수"></em></th>
							<td>
								<textarea class="textareaR4"  style="resize: none;" name ="content" ></textarea>
								<span name="count">0</span> / 2000 byte
							</td>
						</tr>
						</tbody>
					</table>
				</form>
			</div>
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-success btn-lg" id="btnSendSms">발송</button>
					<button type="button" class="btn btn-gray btn-lg" onclick="uifnPopupClose('popupLmsForm')">취소</button>
				</li>
			</ul>
			<!-- //CONTENT -->
		</div>
	</div>

<script th:inline="javascript">
	/*<![CDATA[*/
	const elementCellPhnno = [[${elementCellPhnno}]];
	const elementCustNo = [[${elementCustNo}]];
	const maskingCellPhnno = [[${maskingCellPhnno}]];
	const pageGb = [[${pageGb}]];

	// 메시지 전송
	$("#btnSendSms").on("click",function() {
		let formId = '#lmsForm';
		let custNo = gagajf.isNull(pageGb) ? $(elementCustNo).val() : elementCustNo;
		const $content = $(formId+' textarea[name=content]');

		if(gagajf.isNull($content.val())) {
			mcxDialog.alertC("보낼 메시지를 입력해 주세요.", {
				sureBtnText: "확인",
				sureBtnClick: function() {
					$content.focus();
				}
			});
			return;
		}

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

		mcxDialog.confirm("저장하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				let params = $(formId).serializeObject();
				params.custNo = custNo;
				let jsonData = JSON.stringify(params);
				gagajf.ajaxJsonSubmit('/customer/message/send', jsonData, uifnPopupClose('popupLmsForm'));
			}
		});

	});

	// LMS 글자수 변경 이벤트
	$("#lmsForm textarea[name=content]").bind('focus focusout input keyup keydown paste change', function () {
		cfnGetTextLength($(this), 2000, $('#lmsForm span[name=count]'));
	});

	var fnInitDataSet = function () {
		let cellPhnno = gagajf.isNull(pageGb) ? $(elementCellPhnno).val() : elementCellPhnno;
		if (gagajf.isNull(maskingCellPhnno)) {
			$('#lmsForm input[name=cellPhnno]').val(cellPhnno);
		} else {
			let mkCellPhno = gagajf.isNull(pageGb) ? $(maskingCellPhnno).val() : maskingCellPhnno;
			$('#lmsForm input[name=cellPhnno]').val(cellPhnno);
			$('#lmsForm input[name=maskingCellPhnno]').val(mkCellPhno);
		}
	}

	$(document).ready(function() {
		fnInitDataSet();
	
		cfnGetTextLength("#lmsForm textarea[name=content]", 2000, $('#lmsForm span[name=count]'));
	
		$('#popupLmsForm .modelessPopup').draggable({'cancel':'.panelContent'});
	});
	/*]]>*/
</script>
</html>
