<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : UserMenuForm.html
 * @desc    : 사용자메뉴 팝업 Page
 *============================================================================
 * Wivismall
 * Copyright(C) 2019 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2019.12.06   gagamel     최초 작성
 *******************************************************************************
 -->
<ul class="popup modeless ui-widget-content" data-width="600" data-height="670">
	<li class="mdPopTitle">
		<strong>사용자 메뉴</strong>
		<button type="button" class="close" onclick="uifnPopClose('popupUserMenu');"><em class="fa fa-times"></em></button>
	</li>
	
	<li class="mdPopContent">
		<div class="yScroll" style="height: 500px;">
			<form id="userMenuForm" name="userMenuForm" action="#" th:action="@{'/system/user/menu/list/save'}" th:method="post">
				<table class="frmStyle" aria-describedby="사용자 메뉴 목록">
					<colgroup>
						<col style="width: 20%"/>
						<col style="width: 20%"/>
						<col/>
						<col style="width: 20%"/>
					</colgroup>
					<thead>
						<tr>
							<th><input type="button" class="chkBox" name="allCheck" onclick="fnAllCheck(this);"/></th>
							<th>메뉴ID</th>
							<th>메뉴명</th>
							<th>메뉴구분</th>
						</tr>
					</thead>
					<tbody id="tbodyUserMenu">
						<tr th:unless="${userMenuList}">
							<td colspan="4">조회 결과가 없습니다.</td>
						</tr>
						<tr th:each="oneData : ${userMenuList}">
							<input type="hidden" name="userNo" th:value="${oneData.userNo}"/>
							<input type="hidden" name="menuId" th:value="${oneData.menuId}"/>
							<td><label class="chkBox"><input type="checkbox" name="chkUseYn" th:checked="${oneData.useYn == 'Y'}" th:readonly="${oneData.menuGb == 'M'}"/></label></td>
							<td style="text-align: left" th:text="${(oneData.menuLvl == 1 ? '&nbsp;&nbsp;&nbsp;' : oneData.menuLvl == 2 ? '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' : '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;') + oneData.menuLvl + '. ' + oneData.menuId}">A</td>
							<td style="text-align: left" th:text="${oneData.menuNm}">상품</td>
							<td th:text="${oneData.menuGb == 'M' ? '메뉴' : '프로그램'}">메뉴</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</li>
	
	<li class="mdPopBtnB">
		<ul class="lrStyle">
			<li class="aL">
				<button type="button" class="btn btn-info btn-lg" onclick="fnSaveUserMenu();">저장</button>
				<button type="button" class="btn btn-gray btn-lg" onclick="$('#userMenuForm')[0].reset();">초기화</button>
			</li>
		</ul>
	</li>
</ul>

<script th:inline="javascript">
/*<![CDATA[*/
	// 전체 체크
	var fnAllCheck = function(obj) {
		var $el = $("#userMenuForm input:checkbox[name=chkUseYn]");
		
		$.each($el, function(idx, item) {
			if (gagajf.isNull($(this).attr('readonly'))) {
				if ($(obj).hasClass('checked')) {
					$(this).prop('checked', false);
					$(this).parent('label').removeClass('checked');
				} else {
					$(this).prop('checked', true);
					$(this).parent('label').addClass('checked');
				}
			}
		});
		
		if ($(obj).hasClass('checked')) {
			$(obj).removeClass('checked');
		} else {
			$(obj).addClass('checked');
		}
	}
	
	// 저장
	var fnSaveUserMenu = function() {
		var changedData = [];
		
		$('#tbodyUserMenu tr').each(function(idx) {
			if ($(this).find('input:checkbox[name=chkUseYn]').is(':checked')) {
				var params = new Object();
				params.userNo = $(this).find('input[name=userNo]').val();
				params.menuId = $(this).find('input[name=menuId]').val();
				params.useYn = 'Y';
				changedData.push(params);
			}
		});
		
		if (changedData.length == 0) {
			mcxDialog.alert('저장할 데이터가 없습니다.');
			return;
		}
		
		mcxDialog.confirm("저장하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify(changedData);
				gagajf.ajaxJsonSubmit($('#userMenuForm').prop('action'), jsonData, function() {
					uifnPopClose('popupUserMenu');
				});
			}
		});
	}
	
	$(document).ready(function() {
		
	});
/*]]>*/
</script>

</html>
