<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<!-- inner page html -->
<div class="content-wrapper" id="wrapper--${pageName}">
	<div class="container-xxl flex-grow-1 px-0">
		<c:set var="pageKorName" scope="request">민원신고 답변 문구 관리</c:set>
		<div class="card">
			<div class="wrapper-list">
				<div>
				    <form id="frmSearch--${pageName}" name="frmSearch">
				        <div class="container-search">
		                    <div class="row g-1">
		                        <div class="col-12">
		                            <label class="form-label fw-bold form-search-title">업무구분</label>
		                            <span class="form-search-linebox">
										<c:forEach items="${FIM054List}" var="item">
											<label>
												<input name="taskSeCd" type="radio" value="${item.code}"
												class="form-check-input" alt="업무구분"
												onchange="pageObject['${pageName}'].fnResetAndChangeBiz(this.value);">
												${item.value}
											</label>
										</c:forEach>
		                            </span>
		                        </div>
		                    </div>
				        </div>
				    </form>
				    
					<div class="container-page-btn mt-3">
				        <button type="button" id="btnReset--${pageName}" class="btn btn-outline-dark" 
				        title="초기화">초기화</button>
				        <button type="button" id="btnAnsBasicTab--${pageName}" class="btn btn-blue btn-tab" 
				        title="머리말/꼬리말">머리말/꼬리말</button>
				        <button type="button" id="btnLevyAnsBodyTab--${pageName}" class="btn btn-blue btn-tab" 
				        title="부과건 답변내용">부과건 답변내용</button>
				        <button type="button" id="btnWarningAnsBodyTab--${pageName}" class="btn btn-blue btn-tab" 
				        title="계도건 답변내용">계도건 답변내용</button>
				        <button type="button" id="btnNonlevyAnsBodyTab--${pageName}" class="btn btn-blue btn-tab" 
				        title="미부과처리건 답변내용">미부과처리건 답변내용</button>
				        <span class="container-window-btn-right"></span>
				    </div>
				    
				    <div class="h-px-500 mt-4">
				    
				    	<!-- 머리말,꼬리말 영역 -->
				    	<span class="area-answerbasic">
				    		<div class="d-flex flex-row justify-content-center" style="height:100%">
								<div class="card p-4 justify-content-center align-items-center w-px-1300">
									<form id="frmEditAnsBasic--${pageName}">
										<div class="w-px-900">
											<div class="row">
												<div class="col-12">
													<label for="headerCn--${pageName}"
													class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end align-top"
													>머리말</label>
													<textarea id="headerCn--${pageName}" name="headerCn" 
													rows="5" cols="80%" class="form-control" required
													placeholder="머리말이 없습니다."
													></textarea>
												</div>
											</div>
											<div class="row">
												<div class="col-12">
													<label for="footerCn--${pageName}"
													class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end align-top"
													>꼬리말</label>
													<textarea id="footerCn--${pageName}" name="footerCn"
													rows="5" cols="80%" class="form-control" required
													placeholder="꼬리말이 없습니다."
													></textarea>
												</div>
											</div>
											<div class="row justify-content-end">
												<div class="col-12">
													<button type="button" id="btnSaveAnsBasic--${pageName}" 
										        	class="btn btn-primary float-end" title="적용">적용</button>
												</div>
											</div>
										</div>
									</form>
								</div>
							</div>
				    	</span>
				    	
				    	<!-- 본문처리 영역 -->
				    	<span class="area-answerbody area-answerbody-common">
				    		<div class="d-flex flex-row justify-content-center" style="height:100%">
								<div class="card p-4 d-flex flex-row w-px-1300">
									<!-- 그리드 영역 -->
									<div class="card-datatable text-nowrap d-inline-flex" 
										style="border: #D9DEE3 1px solid;">
										<div class="dataTables_wrapper dt-bootstrap5 no-footer">
											<!-- 부과건 그리드 -->
											<span class="area-answerbody area-levy">
												<div id="table-responsive-levy--${pageName}"
													class="table-responsive"
													style="height:100%;width:470px;overflow-y: auto;">
													<table class="datatables-ajax table table-bordered dataTable no-footer">
														<thead>
															<tr>
																<th style="width:50px;"></th>
																<th style="min-width: 300px;">위반내용</th>
															</tr>
														</thead>
									                    <tbody id="vltnTbody--${pageName}"></tbody>
														<template id="vltnRow--${pageName}">
															<tr data-key="{VLTN_CASE_ID}">
																<td class="text-center" style="min-width:50px;max-width: 50px;">
																	<input type="radio" name="levyRadio" value="{VLTN_CASE_ID}"
																	onchange="{onchange}" />
																</td>
									                    		<td onclick="{onclick}" class="text-center">{VLTN_CASE_NM}</td>
									                    	</tr>
														</template>
														<template id="vltnNotFound--${pageName}">
															<tr>
																<td valign="top" colspan="2" 
																class="dataTables_empty text-center">정보를 찾지 못했습니다.</td>
															</tr>
														</template>
													</table>
												</div>
											</span>
											<!-- 계도건 그리드 -->
											<span class="area-answerbody area-warning">
												<div id="table-responsive-warning--${pageName}"
													class="table-responsive"
													style="height:100%;width:470px;overflow-y: auto;">
													<table class="datatables-ajax table table-bordered dataTable no-footer">
														<thead>
															<tr>
																<th style="width:50px;"></th>
																<th style="min-width: 300px;">계도내용</th>
															</tr>
														</thead>
									                    <tbody id="warningTbody--${pageName}"></tbody>
														<template id="warningRow--${pageName}">
															<tr data-key="{LEVY_EXCL_RSN_CD}">
																<td class="text-center" style="min-width:50px;max-width: 50px;">
																	<input type="radio" name="warningRadio" value="{LEVY_EXCL_RSN_CD}"
																	onchange="{onchange}" />
																</td>
									                    		<td onclick="{onclick}" class="text-center">{LEVY_EXCL_RSN_NM}</td>
									                    	</tr>
														</template>
														<template id="warningNotFound--${pageName}">
															<tr>
																<td valign="top" colspan="2" 
																class="dataTables_empty text-center">정보를 찾지 못했습니다.</td>
															</tr>
														</template>
													</table>
												</div>
											</span>
											<!-- 미부과처리건 그리드 -->
											<span class="area-answerbody area-nonlevy">
												<div id="table-responsive-nonlevy--${pageName}"
													class="table-responsive"
													style="height:100%;width:470px;overflow-y: auto;">
													<table class="datatables-ajax table table-bordered dataTable no-footer">
														<thead>
															<tr>
																<th style="width:50px;"></th>
																<th style="min-width: 300px;">미부과사유</th>
																<th style="min-width: 100px;">답변여부</th>
															</tr>
														</thead>
									                    <tbody id="nonlevyTbody--${pageName}"></tbody>
														<template id="nonlevyRow--${pageName}">
															<tr data-key="{LEVY_EXCL_RSN_CD}">
																<td class="text-center" style="min-width:50px;max-width: 50px;">
																	<input type="radio" name="nonlevyRadio" value="{LEVY_EXCL_RSN_CD}"
																	onchange="{onchange}" />
																</td>
																<td onclick="{onclick}" class="text-center">{LEVY_EXCL_RSN_NM}</td>
									                    		<td onclick="{onclick}" class="text-center">{USE_YN}</td>
									                    	</tr>
														</template>
														<template id="nonlevyNotFound--${pageName}">
															<tr>
																<td valign="top" colspan="3" 
																class="dataTables_empty text-center">정보를 찾지 못했습니다.</td>
															</tr>
														</template>
													</table>
												</div>
											</span>
										</div>
								    </div>
	
							    	<!-- 답변내용 표시영역 -->
								    <div class="w-px-800 d-inline-flex">
							    		<div class="container-md"
							    			style="display: flex;justify-content: space-between;flex-flow: column;">
									    	<div class="row g-1 h-px-400" 
									    		style="overflow-y:auto;border-bottom:#D9DEE3 1px solid">
										    	<div class="col-12">
										    		<form id="frmEditAnsBody--${pageName}">
										    			<input type="hidden" id="ansRsnCd--${pageName}" name="ansRsnCd" />
										    			<input type="hidden" id="dstrbncYn--${pageName}" name="dstrbncYn" />
										    			<input type="hidden" id="ansWordsId--${pageName}" name="ansWordsId" />
										    			<label for="prcsRsltCn--${pageName}"
										    			class="w-px-130 bg-lighter pe-2 col-form-label text-sm-center">답변내용</label>
										    			<br/>
										    			<textarea id="prcsRsltCn--${pageName}" name="prcsRsltCn" 
										    			class="form-control" required
										    			style="width:100%;" rows="15"
										    			></textarea>
										    		</form>
										    	</div>
									    	</div>
									    	<div class="row g-1 py-2">
									    		<div class="col-12">
									    			<div class="btns float-start">
									    				<button type="button" id="btnRemove--${pageName}" 
										            		class="btn btn-primary area-answerbody area-nonlevy" 
										            		title="답변대상 제외">답변대상 제외</button>
									    			</div>
									    			<div class="btns float-end">
									    				<button type="button" id="btnOpenPreviewPop--${pageName}" 
										            		class="btn btn-primary" title="미리보기">미리보기</button>
										            	<button type="button" id="btnSaveAnsBody--${pageName}" 
										            		class="btn btn-primary" title="적용">적용</button>
									    			</div>
								    			</div>
							            	</div>
						            	</div>
									</div>
							    </div>
							</div>
				    	</span>
				    </div>

					
				    <!-- 매크로 삽입 버튼 영역 -->
				    <div class="mt-4 d-flex flex-row justify-content-center align-items-center">
						<div class="card ps-3 py-3 w-px-1300">
							<div class="row">
								<div class="col-12 btns">
									<strong>[매크로 문자 삽입]</strong>
									<label id="macroTarget--${pageName}" for="" hidden></label>
									
									<button type="button" id="btnInsertMacro1--${pageName}" 
					            		class="btn btn-primary" title="일련번호 삽입">일련번호</button>
					            	<button type="button" id="btnInsertMacro2--${pageName}" 
					            		class="btn btn-primary" title="사용자 전화번호 삽입">사용자 전화번호</button>
					            	<button type="button" id="btnInsertMacro3--${pageName}" 
					            		class="btn btn-primary" title="사용자 성명 삽입">사용자 성명</button>
								</div>
			            	</div>
						</div>
					</div>
				</div>

				<div class="toast-container position-fixed bottom-0 end-0 p-3">
				  <div id="divToast--${pageName}" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
				    <div class="toast-body bg-black text-white">
				      저장 되었습니다.
				    </div>
				  </div>
				</div>
			</div>
		</div>
	</div>

	<jsp:include page="/WEB-INF/jsp/include/bottom.jsp" />

  	<div class="content-backdrop fade"></div>
</div>

<template id="previewDialogTemplate--${pageName}">
	<form id="frmView--${pageName}">
		<div class="card">
			<textarea id="preview--${pageName}" rows="15"
			></textarea>
		</div>
		<div>
			<span class="container-page-btn">
				<span class="container-window-btn-right">
					<button type="button" class="btn btn-primary" id="btnClose--${pageName}" title="닫기">닫기</button>
				</span>
			</span>
		</div>
	</form>
</template>

<script type="module" src="<c:url value='/resources/js/fims/cvlc/answerWords.js?${ver}'/>"></script>
<script ${module}>
import {
	AnswerBodyControl,
	MACRO_STRING,
	fnMacroStringInsert,
	fnMacroWordsReplace
} from "<c:url value='/resources/js/fims/cvlc/answerWords.js?${ver}'/>";

/**************************************************************************
 * Global Variable
 **************************************************************************/
pageObject["${pageName}"] = {};

$(document).ready(function(){

	var $P = pageObject["${pageName}"];
	
	$P.toast = new bootstrap.Toast(document.getElementById('divToast--${pageName}'), {
        animation: true,
        autohide: true,
        delay: 2000
    });
	
	/**************************************************************************
	 * DatasetControl
	 **************************************************************************/
	$P.ansBodyControl = new AnswerBodyControl({
		dataGetter : obj => obj["levyCaseList"], urls : {}, formats : {},
	    keymapper : info => info ? info.VLTN_CASE_ID : ""
	},
	{
	    dataGetter : obj => obj["warningCaseList"], urls : {}, formats : {},
	    keymapper : info => info ? info.LEVY_EXCL_RSN_CD : ""
	},
	{
	    dataGetter : obj => obj["nonlevyCaseList"], urls : {}, formats : {},
	    keymapper : info => info ? info.LEVY_EXCL_RSN_CD : ""
	});
	
	/**************************************************************************
	 * pageObject.function
	 **************************************************************************/
	$P.fnResetAndChangeBiz = (taskSeCd) => {
		$P.ansBodyControl.urls = {};
		$P.ansBodyControl.urls.load = wctx.url("/"+taskSeCd+"/cvlc/cvlc05/010/info.do");
		$P.ansBodyControl.urls.update = wctx.url("/"+taskSeCd+"/cvlc/cvlc05/010/save.do");
		$P.ansBodyControl.urls.remove = wctx.url("/"+taskSeCd+"/cvlc/cvlc05/010/remove.do");
		
		$P.fnReset();
	}
	
	$P.fnReset = () => {
		$('#btnAnsBasicTab--${pageName}').trigger("click");
		$P.ansBodyControl.levy.setData([]);
		$P.ansBodyControl.warning.setData([]);
		$P.ansBodyControl.nonlevy.setData([]);
		
		$P.renderAnsBodyList(0,'levy');
	    $P.renderAnsBodyList(0,'warning');
	    $P.renderAnsBodyList(0,'nonlevy');
	    
	    $("#frmEditAnsBasic--${pageName}").find("input, textarea").val("");
	    $("#frmEditAnsBody--${pageName}").find("input, textarea").val("");
	    
	    $P.searchWordsStng();
	}

	$P.getParams = () => {
		var formFields = new FimsFormFields("#frmSearch--${pageName}");
		var data = formFields.get();
		return data;
	}
	
	$P.searchWordsStng = () => {
		var taskSeCd = $("#frmSearch--${pageName}").find("input[name='taskSeCd']:checked").val();

		ajax.get({
			url : $P.ansBodyControl.urls.load,
			data : {"taskSeCd" : taskSeCd},
			success : resp => {

				$("#headerCn--${pageName}").val(resp.headerCn);
				$("#footerCn--${pageName}").val(resp.footerCn);
				
				$P.ansBodyControl.levy.setData(resp.levyCaseList);
				$P.ansBodyControl.warning.setData(resp.warningCaseList);
				$P.ansBodyControl.nonlevy.setData(resp.nonlevyCaseList);
				
				$P.renderAnsBodyList(resp.levyCaseList.length,'levy');
			    $P.renderAnsBodyList(resp.warningCaseList.length,'warning');
			    $P.renderAnsBodyList(resp.nonlevyCaseList.length,'nonlevy');
			    
			    if(resp.levyCaseList.length > 0){
			    	var current = $P.ansBodyControl.levy.getCurrent()["VLTN_CASE_ID"];
			    	$P.clickAnsBodyList(current,'levy');
			    }
				if(resp.warningCaseList.length > 0){
					var current = $P.ansBodyControl.warning.getCurrent()["LEVY_EXCL_RSN_CD"];
			    	$P.clickAnsBodyList(current,'warning');
			    }
				if(resp.nonlevyCaseList.length > 0){
					var current = $P.ansBodyControl.nonlevy.getCurrent()["LEVY_EXCL_RSN_CD"];
			    	$P.clickAnsBodyList(current,'nonlevy');
				}
			}
		});
	}
	
	$P.renderAnsBodyList = (total, renderDataType) => {
		
		var notFoundId = "";
		var foundId = "";
		var tbodyId = "";
		if(renderDataType == "levy"){
			notFoundId = "vltnNotFound--${pageName}";
			foundId = "vltnRow--${pageName}";
			tbodyId = "vltnTbody--${pageName}";
		} else if(renderDataType == "warning"){
			notFoundId = "warningNotFound--${pageName}";
			foundId = "warningRow--${pageName}";
			tbodyId = "warningTbody--${pageName}";
		} else if(renderDataType == "nonlevy"){
			notFoundId = "nonlevyNotFound--${pageName}";
			foundId = "nonlevyRow--${pageName}";
			tbodyId = "nonlevyTbody--${pageName}";
		} else {
			return;
		}
		
		var ansBodyList = $P.ansBodyControl[renderDataType].dataset;
		var empty = ansBodyList.empty;
		var notFound = [document.getElementById(notFoundId).innerHTML];
		var found = document.getElementById(foundId).innerHTML;
		
		var replacer = () => {};
		if(renderDataType == "levy"){
			replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickAnsBodyList('" + dataItem.getValue("VLTN_CASE_ID") + "','levy');")
			.replace(/{onchange}/gi, "pageObject['${pageName}'].radioClickAnsBodyList('" + dataItem.getValue("VLTN_CASE_ID") + "','levy');");	
		} else if(renderDataType == "warning"){
			replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickAnsBodyList('" + dataItem.getValue("LEVY_EXCL_RSN_CD") + "','warning');")
			.replace(/{onchange}/gi, "pageObject['${pageName}'].radioClickAnsBodyList('" + dataItem.getValue("LEVY_EXCL_RSN_CD") + "','warning');");
		} else if(renderDataType == "nonlevy"){
			replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickAnsBodyList('" + dataItem.getValue("LEVY_EXCL_RSN_CD") + "','nonlevy');")
			.replace(/{onchange}/gi, "pageObject['${pageName}'].radioClickAnsBodyList('" + dataItem.getValue("LEVY_EXCL_RSN_CD") + "','nonlevy');");
		}

		var trs = empty ? notFound : ansBodyList.inStrings(found, replacer);
		$("#"+tbodyId).html(trs.join());
	}
	
	$P.radioClickAnsBodyList = (dataKey, gridType) => {
		
		$P.ansBodyControl[gridType].setCurrent(dataKey);
		
		var tbodyId = "";
		if(gridType == "levy"){
			tbodyId = "vltnTbody--${pageName}";
		} else if(gridType == "warning"){
			tbodyId = "warningTbody--${pageName}";
		} else if(gridType == "nonlevy"){
			tbodyId = "nonlevyTbody--${pageName}";
		} else {
			return;
		}
		$("#"+tbodyId).setCurrentRow(dataKey);

		if(gridType == "levy" && $P.currentDisplay == "levyAnsBody"){
			$P.changeAnsBodyText();
		} else if(gridType == "warning" && $P.currentDisplay == "warningAnsBody"){
			$P.changeAnsBodyText();
		} else if(gridType == "nonlevy" && $P.currentDisplay == "nonlevyAnsBody"){
			$P.changeAnsBodyText();
		}
	}
	
	$P.clickAnsBodyList = (dataKey, gridType) => {
		var radioName = "";
		if(gridType == "levy"){
			radioName = "levyRadio";
		} else if(gridType == "warning"){
			radioName = "warningRadio";
		} else if(gridType == "nonlevy"){
			radioName = "nonlevyRadio";
		} else {
			return;
		}
		
		$("#wrapper--${pageName}").find(":radio[name='"+radioName+"'][value='"+dataKey+"']").prop("checked",true);
		
		if(gridType == "levy" && $P.currentDisplay == "levyAnsBody"){
			$("#wrapper--${pageName}").find(":radio[name='"+radioName+"'][value='"+dataKey+"']").focus();
		} else if(gridType == "warning" && $P.currentDisplay == "warningAnsBody"){
			$("#wrapper--${pageName}").find(":radio[name='"+radioName+"'][value='"+dataKey+"']").focus();
		} else if(gridType == "nonlevy" && $P.currentDisplay == "nonlevyAnsBody"){
			$("#wrapper--${pageName}").find(":radio[name='"+radioName+"'][value='"+dataKey+"']").focus();
		}
		
		$P.radioClickAnsBodyList(dataKey, gridType);
	}
	
	$P.changeAnsBodyText = () => {
		var curData = null;
		var rnsRsnCd = "";
		var dstrbncYn = "";
		
		if($P.currentDisplay == "levyAnsBody"){
			curData = $P.ansBodyControl.levy.getCurrent();
		} else if($P.currentDisplay == "warningAnsBody"){
			curData = $P.ansBodyControl.warning.getCurrent();
		} else if($P.currentDisplay == "nonlevyAnsBody"){
			curData = $P.ansBodyControl.nonlevy.getCurrent();
		}
		
		if(curData == null){
			$("#ansRsnCd--${pageName}").val("");
			$("#dstrbncYn--${pageName}").val("");
			$("#ansWordsId--${pageName}").val("");
			$("#prcsRsltCn--${pageName}").val("");
			return;
		}
		
		if($P.currentDisplay == "levyAnsBody"){
			if(curData["VLTN_CASE_ID"].endsWith("D")){
				rnsRsnCd = "3" + curData["VLTN_CASE_ID"].substring(0,2);
				dstrbncYn = "Y";
			} else {
				rnsRsnCd = "3" + curData["VLTN_CASE_ID"];
				dstrbncYn = "N";
			}
		} else if($P.currentDisplay == "warningAnsBody"){
			rnsRsnCd = curData["LEVY_EXCL_RSN_CD"]
		} else if($P.currentDisplay == "nonlevyAnsBody"){
			rnsRsnCd = curData["LEVY_EXCL_RSN_CD"]
			
			if(curData["ANS_WORDS_ID"] == null){
				$("#btnRemove--${pageName}").prop("disabled",true);
			} else {
				$("#btnRemove--${pageName}").prop("disabled",false);
			}
		}

		$("#ansRsnCd--${pageName}").val(rnsRsnCd);
		$("#dstrbncYn--${pageName}").val(dstrbncYn);
		$("#ansWordsId--${pageName}").val(curData["ANS_WORDS_ID"]);
		$("#prcsRsltCn--${pageName}").val(curData["PRCS_RSLT_CN"]);
	}
	
	$P.refreshAnsWordsInfo = () => {
		var cursor1 = $P.ansBodyControl.levy.getCurrent()["VLTN_CASE_ID"];
		var cursor2 = $P.ansBodyControl.warning.getCurrent()["LEVY_EXCL_RSN_CD"];
		var cursor3 = $P.ansBodyControl.nonlevy.getCurrent()["LEVY_EXCL_RSN_CD"];
		
		var taskSeCd = $("#frmSearch--${pageName}").find("input[name='taskSeCd']:checked").val();

		ajax.get({
			url : $P.ansBodyControl.urls.load,
			data : {"taskSeCd" : taskSeCd},
			success : resp => {
				
				$("#headerCn--${pageName}").val(resp.headerCn);
				$("#footerCn--${pageName}").val(resp.footerCn);
				
				$P.ansBodyControl.levy.setData(resp.levyCaseList);
				$P.ansBodyControl.warning.setData(resp.warningCaseList);
				$P.ansBodyControl.nonlevy.setData(resp.nonlevyCaseList);
				
				$P.renderAnsBodyList(resp.levyCaseList.length,'levy');
			    $P.renderAnsBodyList(resp.warningCaseList.length,'warning');
			    $P.renderAnsBodyList(resp.nonlevyCaseList.length,'nonlevy');
			    
			    if(resp.levyCaseList.length > 0){
			    	$P.ansBodyControl.levy.setCurrent(cursor1);
			    	var current = $P.ansBodyControl.levy.getCurrent()["VLTN_CASE_ID"];
			    	$P.clickAnsBodyList(current,'levy');
			    }
				if(resp.warningCaseList.length > 0){
					$P.ansBodyControl.warning.setCurrent(cursor2);
					var current = $P.ansBodyControl.warning.getCurrent()["LEVY_EXCL_RSN_CD"];
			    	$P.clickAnsBodyList(current,'warning');
			    }
				if(resp.nonlevyCaseList.length > 0){
					$P.ansBodyControl.nonlevy.setCurrent(cursor3);
					var current = $P.ansBodyControl.nonlevy.getCurrent()["LEVY_EXCL_RSN_CD"];
			    	$P.clickAnsBodyList(current,'nonlevy');
				}
			}
		});
	}

	//적용
	$P.fnSave = (isBasicWords) => {
	
		var formId = "";
		var confirmMessage = "";
		
		if(isBasicWords){	
			confirmMessage = "머리말/꼬리말 내용을 저장하시겠습니까?";
			formId = "frmEditAnsBasic--${pageName}";
		} else {
			confirmMessage = "본문내용을 저장하시겠습니까?"
			formId = "frmEditAnsBody--${pageName}";
		}
		
		
		if(!customValidate($("#"+formId).find("input, select, textarea"))) return;
		var info = (new FimsFormFields("#"+formId)).get();
		if(isBasicWords){
			info.saveData = "basic";
		} else {
			info.saveData = "body";
		}
		info.taskSeCd = $("#frmSearch--${pageName}").find("input[name='taskSeCd']:checked").val();

		dialog.alert({
			content : confirmMessage,
			onOK: () => {
				
				ajax.get({
					url : $P.ansBodyControl.urls.update,
					data : info,
					success : resp => {
						if(resp.saved){
							$P.toast.show();	
							$P.refreshAnsWordsInfo();
						}
					}
				});
			}
		});
	}
	
	//답변대상 제외
	$P.fnRemove = () => {
		
		if(!customValidate($("#frmEditAnsBody--${pageName}").find("input, select, textarea"))) return;
		var info = (new FimsFormFields("#frmEditAnsBody--${pageName}")).get();
		
		dialog.alert({
			content : "해당 미부과사유를 답변대상에서 제외하시겠습니까?",
			onOK: () => {
				ajax.get({
					url : $P.ansBodyControl.urls.remove,
					data : info,
					success : resp => {
						if(resp.saved){
							$P.toast.show();	
							$P.refreshAnsWordsInfo();
						}
					}
				});
			}
		});
	}
	
	//미리보기 팝업 호출
	$P.fnOpenPreviewPop = () => {
		
		var result = fnMacroWordsReplace(
			$("#headerCn--${pageName}").val(),
			$("#footerCn--${pageName}").val(),
			$("#prcsRsltCn--${pageName}").val(),
			"${currentUserTelno}",
			"${currentUserName}"
		);
		
		dialog.open({
			id : "previewDialog--${pageName}",
			title : "답변 내용 미리보기",
			content : document.getElementById("previewDialogTemplate--${pageName}").innerHTML,
			size : "lg",
			init : () => {
				$("#preview--${pageName}").val(result);
				$("#btnClose--${pageName}").on("click", () => dialog.close("previewDialog--${pageName}"));
			},
			onOk : () => {},
			onClose : () => {}
		});
	}

	/**************************************************************************
	 * element.on			
	 **************************************************************************/
    $('#btnReset--${pageName}').on('click', () => $P.fnReset());
	
	//탭 버튼
    $('#btnAnsBasicTab--${pageName}').on('click', (event) => {
    	$(event.target).addClass("active");
    	$(event.target).siblings(".btn-tab").removeClass("active");
		
    	$("#wrapper--${pageName}").find(".area-answerbasic").show();
    	$("#wrapper--${pageName}").find(".area-answerbody").hide();
    	
    	$P.currentDisplay = "ansBasic";
    	
    	$("#macroTarget--${pageName}").attr("for","");
    });
    
	$('#btnLevyAnsBodyTab--${pageName}').on('click', (event) => {
		$(event.target).addClass("active");
    	$(event.target).siblings(".btn-tab").removeClass("active");
		
		$("#wrapper--${pageName}").find(".area-answerbasic").hide();
		$("#wrapper--${pageName}").find(".area-answerbody").each(function(){
			if($(this).hasClass("area-answerbody-common") || $(this).hasClass("area-levy")){
				$(this).show();
			} else {
				$(this).hide();
			}
		});
		
		$P.currentDisplay = "levyAnsBody";
		
		$("#wrapper--${pageName}").find(":radio[name='levyRadio']:checked").focus();
		
		$P.changeAnsBodyText();
		
		$("#macroTarget--${pageName}").attr("for","");
	});
	$('#btnWarningAnsBodyTab--${pageName}').on('click', (event) => {
		$(event.target).addClass("active");
    	$(event.target).siblings(".btn-tab").removeClass("active");
		
		$("#wrapper--${pageName}").find(".area-answerbasic").hide();
		$("#wrapper--${pageName}").find(".area-answerbody").each(function(){
			if($(this).hasClass("area-answerbody-common") || $(this).hasClass("area-warning")){
				$(this).show();
			} else {
				$(this).hide();
			}
		});
		
		$P.currentDisplay = "warningAnsBody";
		
		$("#wrapper--${pageName}").find(":radio[name='warningRadio']:checked").focus();
		
		$P.changeAnsBodyText();
		
		$("#macroTarget--${pageName}").attr("for","");
	});
	$('#btnNonlevyAnsBodyTab--${pageName}').on('click', (event) => {
		$(event.target).addClass("active");
    	$(event.target).siblings(".btn-tab").removeClass("active");
		
		$("#wrapper--${pageName}").find(".area-answerbasic").hide();
		$("#wrapper--${pageName}").find(".area-answerbody").each(function(){
			if($(this).hasClass("area-answerbody-common") || $(this).hasClass("area-nonlevy")){
				$(this).show();
			} else {
				$(this).hide();
			}
		});
		
		$P.currentDisplay = "nonlevyAnsBody";
		
		$("#wrapper--${pageName}").find(":radio[name='nonlevyRadio']:checked").focus();
		
		$P.changeAnsBodyText();
		
		$("#macroTarget--${pageName}").attr("for","");
	});
	
	//업무처리 버튼
    $("#btnSaveAnsBasic--${pageName}").on("click", () => $P.fnSave(true));  
    $("#btnSaveAnsBody--${pageName}").on("click", () => $P.fnSave(false));
    $("#btnRemove--${pageName}").on("click", () => $P.fnRemove());
    $("#btnOpenPreviewPop--${pageName}").on("click", () => $P.fnOpenPreviewPop());
    
    $("#headerCn--${pageName},#footerCn--${pageName},#prcsRsltCn--${pageName}").on("focus", (event) => {
    	$("#macroTarget--${pageName}").attr("for", event.target.id);
    });
    
    $("#btnInsertMacro1--${pageName}").on("click", () => {
		var macroTarget = $("#macroTarget--${pageName}").attr("for");
		if(macroTarget == ""){ return; }
		fnMacroStringInsert(macroTarget, MACRO_STRING.MACRO_SEQ);
    });
    $("#btnInsertMacro2--${pageName}").on("click", () => {
		var macroTarget = $("#macroTarget--${pageName}").attr("for");
		if(macroTarget == ""){ return; }
		fnMacroStringInsert(macroTarget, MACRO_STRING.MACRO_TELNO);
    });
    $("#btnInsertMacro3--${pageName}").on("click", () => {
		var macroTarget = $("#macroTarget--${pageName}").attr("for");
		if(macroTarget == ""){ return; }
		fnMacroStringInsert(macroTarget, MACRO_STRING.MACRO_PIC_NM);
    });
	/**************************************************************************
	 * 초기화
	 **************************************************************************/
    var defaultBizValue = $("#layout-navbar input[name='taskSeCd']:checked").val();
	$("#frmSearch--${pageName} input[name='taskSeCd'][value='" + defaultBizValue + "']").prop("checked",true);
	$P.fnResetAndChangeBiz(defaultBizValue);

});


</script>