<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GoodsSizeInfoForm.html
 * @desc    : 사이즈정보관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.26   eskim       최초 작성
  *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<div class="panelContent">
			<form id="searchForm" name="searchForm" action="#" th:action="@{'/goods/size/info/list'}">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>구분<em class="required" title="필수"></em></th>
						<td>
							<label class="rdoBtn"><input type="radio" name="sizeGb"  value="1"  checked/>표준사이즈</label>
							<label class="rdoBtn"><input type="radio" name="sizeGb"  value="2"/>측정가이드</label>
						</td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-success btn-lg" id="btnSearch">조회</button>
					</li>
				</ul>
			</form>
			</div>
		</div>
		<!-- //검색조건 영역 -->
		
		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<div id="gridList" style="width: 100%; height: 300px;" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
		<!-- 등록/수정 -->
		<form id="sizeInfoForm" name="sizeInfoForm" action="#" th:action="@{'/goods/size/info/save'}">
		<input type="hidden" name="sizeCate1Cd" />
		<!-- 등록/수정 -->
		<div class="panelStyle" >
			<ul>
				<li>
					<table class="w100p">
						<colgroup>
							<col style="width:35%;"/>
							<col style="width:1%;"/>
							<col/>
						</colgroup>
						<tr>
							<td  class="vaT">
								<table class="frmStyle" aria-describedby="등록/수정 폼">
									<colgroup>
										<col style="width:10%;"/>
										<col/>
									</colgroup>
									<tr>
										<th>구분<em class="required" title="필수"></em></th>
										<td>
											<label class="rdoBtn"><input type="radio" name="sizeGb"  value="1"  checked/>표준사이즈</label>
											<label class="rdoBtn"><input type="radio" name="sizeGb"  value="2"/>측정가이드</label>
										</td>
									</tr>
									<tr id="brandArea">	
										<th>브랜드<em class="required" title="필수"></em></th>
										<td>
											<label class="rdoBtn"><input type="radio" name="selfYn"  value="N"  checked/>공통</label>
											<label class="rdoBtn"><input type="radio" name="selfYn"  value="Y"/>자사브랜드</label>
											<select name="brandCd" id="brandCd">
												<option value="" >[선택]</option>
												<option th:if="${selfBrandList}" th:each="oneData, status : ${selfBrandList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}" th:attr="brandNm=${oneData.cdNm}"></option>
											</select>
										</td>
									</tr>
									<tr>
										<th>사이즈카테명</th>
										<td>
											<input type="text" class="w200" name="sizeCate2Nm" maxlength="10" data-valid-name="사이즈카테명" />
											<input type="hidden" name="sizeCate2Cd" />
										</td>
									</tr>
									<tr>
										<th>노출순서<em class="required" title="필수"></em></th>
										<td>
											<input type="text" class="aR w100" name="dispOrd" maxlength="5" required="required" data-valid-type="integer" data-valid-name="노출순서"/>
										</td>
									</tr>
									<tr>
										<th>사용여부<em class="required" title="필수"></em></th>
										<td>
											<label class="rdoBtn"><input type="radio" name="useYn" value="Y"  checked/>Yes</label>
											<label class="rdoBtn"><input type="radio" name="useYn" value="N"/>No</label>
										</td>
									</tr>
								</table>
							</td>
							<td>&nbsp;</td>
							<td>
								<textarea class="textareaR4" name="sizeInfo" id="sizeInfo"></textarea>
							</td>
						</tr>
					</table>
				</li>
			</ul>
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-info btn-lg" id="btnNew">신규</button>
					<button type="button" class="btn btn-success btn-lg" id="btnSave">저장</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
		</div>
		<!-- 등록/수정 -->
		</form>
	</div>
<script type="text/javascript" src="/ux/plugins/summernote/summernote.js?v=2020103001"></script>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.summernote.js?v=2021053101"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	var sizeGbList = { "1":"표준사이즈", "2":"측정가이드" };
	var useYnList = { "Y":"Yes", "N":"No" };
	// specify the columns
	var columnDefs = [
		{headerName: 'No', width: 60, cellClass: 'text-center', valueGetter: function(params) { return params.node.rowIndex + 1 }},
		{headerName: "구분", field: "sizeGb", width: 120, cellClass: 'text-center',
			cellEditorParams: { values: gagaAgGrid.extractValues(sizeGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(sizeGbList, params.value); }
		},
		{headerName: "브랜드코드", field: "sizeCate1cd", width: 130, cellClass: 'text-center', hide: true},
		{headerName: "브랜드명", field: "sizeCate1Nm", width: 150, cellClass: 'text-center'},
		{headerName: "사이즈카테코드", field: "sizeCate2cd", width: 130, cellClass: 'text-center', hide: true},
		{headerName: "카테명", field: "sizeCate2Nm", width: 150, cellClass: 'text-center'
			,cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{headerName: "표시순서", field: "dispOrd", width: 150, cellClass: 'text-center'},
		{headerName: "사용여부", field: "useYn", width: 100, cellClass: 'text-center'},
		{headerName: "등록일자", field: "regDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss") : '';
			}
		},
		{headerName: "등록자", field: "regNm", width: 130, cellClass: 'text-center'},
		{headerName: "수정일자", field: "updDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss") : '';
			}
		},
		{headerName: "수정자", field: "updNm", width: 130, cellClass: 'text-center'},
	];
	
	// Get GridOptions
	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	
	//gridOptions.suppressRowClickSelection = true;
	//gridOptions.rowHeight = 60; //이미지가 있을경우 높이 지정해야함.
	
	//  클릭
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field == "sizeCate2Nm"){
			
			$('#btnNew').click();
			
			$("#sizeInfoForm input:radio[name=sizeGb]:input[value=" + event.data.sizeGb + "]").click();
			if ("1" == event.data.sizeGb){
				$('#brandArea').removeClass('off').addClass('on');
				if (event.data.sizeCate1Cd == "00") {
					$("#sizeInfoForm input:radio[name=selfYn]:input[value=N]").click();
				}else{
					$("#sizeInfoForm input:radio[name=selfYn]:input[value=Y]").click();
					$("#sizeInfoForm select[name=brandCd]").val(event.data.sizeCate1Cd);
				}
				$('#sizeInfoForm input[name=selfYn]').prop('readonly', true);
				$('#sizeInfoForm input[name=selfYn]').addClass("formControl");
				$('#sizeInfoForm select[name=brandCd]').prop('disabled', true);
				$('#sizeInfoForm select[name=brandCd]').addClass("formControl");
			}
			$("#sizeInfoForm input[name=sizeCate1Cd]").val(event.data.sizeCate1Cd);
			$("#sizeInfoForm input[name=sizeCate2Nm]").val(event.data.sizeCate2Nm);
			$("#sizeInfoForm input[name=sizeCate2Cd]").val(event.data.sizeCate2Cd);
			$("#sizeInfoForm input[name=dispOrd]").val(event.data.dispOrd);
			gagaSn.setContents('#sizeInfo', event.data.sizeInfo); 
				
			$('#sizeInfoForm input[name=sizeGb]').prop('readonly', true);
			$('#sizeInfoForm input[name=sizeGb]').addClass("formControl");
			
		}
	}

	// 조회
	$('#btnSearch').on('click', function() {
		// Fetch data
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 신규버튼 초기화
	$('#btnNew').on('click', function() {
		$("#sizeInfoForm")[0].reset();
		$('#sizeInfoForm input[name=sizeCate1Cd]').val(''); 
		$('#sizeInfoForm input[name=sizeCate2Cd]').val('');
		$('#brandArea').removeClass('off').addClass('on');
		$('#sizeInfoForm input[name=sizeGb]').prop('readonly', false);
		$('#sizeInfoForm input[name=sizeGb]').removeClass("formControl");
		$('#sizeInfoForm input[name=selfYn]').prop('readonly', false);
		$('#sizeInfoForm input[name=selfYn]').removeClass("formControl");
		$('#sizeInfoForm select[name=brandCd]').prop('disabled', false);
		$('#sizeInfoForm select[name=brandCd]').removeClass("formControl");
		$("#sizeInfoForm input:radio[name=sizeGb]:input[value=1]").click();
		$("#sizeInfoForm input:radio[name=selfYn]:input[value=N]").click();
		gagaSn.setContents('#sizeInfo', ''); 
	});
	
	// 자사/입점 변경여부
	$("#sizeInfoForm input[name=sizeGb]").bind('change', function () {
		var sizeGb = $(this).val();
		if (sizeGb == "1"){
			$('#brandArea').removeClass('off').addClass('on');
		}else{
			$('#brandArea').removeClass('on').addClass('off');
		}
		
	});
	
	// 브랜드 변경
	$("#sizeInfoForm select[name=brandCd]").bind('change', function () {
		$("#sizeInfoForm input[name=sizeCate2Nm]").val($("#sizeInfoForm select[name=brandCd] option:selected").attr("brandNm"));
	});
	
	// 사이즈정보 저장
	$("#btnSave").on('click', function() {
		
		// 표준사이즈, 자사브랜드일 경우
		if("1" == $('#sizeInfoForm input[name=sizeGb]').val() && "Y" == $('#sizeInfoForm input[name=selfYn]').val() 
			&& gagajf.isNull($('#sizeInfoForm input[name=brandCd]').val())){
			mcxDialog.alert("자사브랜드를 선택하세요.");
			return false;
		}
		
		// validation
		if (!gagajf.validation('#sizeInfoForm'))
			return false;
		
		if (gagajf.isNull($('#sizeInfoForm input[name=sizeCate2Nm]').val())){
			if ("1" == $('#sizeInfoForm input[name=sizeGb]').val() && "Y" == $('#sizeInfoForm input[name=selfYn]:checked').val() ){
				
			}else{
				mcxDialog.alertC("사이즈카테명을 입력해주세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$("#sizeInfoForm select[name=sizeCate2Nm]").focus();
					}
				});
				return false;
			}	
		}
		
		if (gagajf.isNull($('#sizeInfoForm textarea[name=sizeInfo]').val())){
			mcxDialog.alert("html 내용을 입력하세요.");
			return false;
		}
		
		mcxDialog.confirm('저장하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				gagajf.ajaxFormSubmit($('#sizeInfoForm').prop('action'), '#sizeInfoForm', function() {
					$('#btnNew').click();
					$('#btnSearch').click();
				});
			}
		});
	});
	
	$(document).ready(function() {
		
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
		
		// Create a summernote
		var snOptions = gagaSn.getToolbarOptions('media');
		gagaSn.createSummernote(snOptions, '#sizeInfo');
	});
	
/*]]>*/
</script>

</html>
