<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GoodsVideoForm.html
 * @desc    : 상품동영상관리 Page
 *============================================================================
 * Pastelmall
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.16   eskim       최초 작성
  *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<!-- TITLE -->
			<div class="panelTitle">
				<h3><i class="fa fa-info-circle"></i>아래 검색조건 중 하나를 꼭 입력해 주세요.</h3>
			</div>
			<!-- //TITLE -->
			<div class="panelContent">
			
			<form id="searchForm" name="searchForm" action="#" th:action="@{'/goods/video/list'}">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:40%;"/>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>키워드</th>
						<td>
							<select name="keyWord">
								<option value="goodsCd">상품코드</option>
								<option value="goodsNm">상품명</option>
								<option value="goodsNum">품번</option>
								<option value="supplyGoodsCd">업체상품코드</option>
							</select>
							<input type="text" class="w100" maxlength="20" name="searchTxt" placeholder=""/>
							<input type="text" class="off" name="goodsCd" id="goodsCd"/>
							<input type="text" class="off" name="goodsNm" id="goodsNm"/>
							<input type="text" class="off" name="goodsNum" id="goodsNum"/>
							<input type="text" class="off" name="supplyGoodsCd" id="supplyGoodsCd"/>
						</td>
						<th>브랜드명</th>
						<td>
							<input type="text" class="w200" name="brandEnm" placeholder="" maxlength="50"/>
						</td>
					</tr>
					<tr>
						<th>등록일</th>
						<td colspan="3" id="sellTerms">
						</td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-default btn-lg" id="btnInit">초기화</button>
						<button type="button" class="btn btn-success btn-lg" id="btnSearch">조회</button>
					</li>
				</ul>
			</form>
			</div>
		</div>
		<!-- //검색조건 영역 -->
		
		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<ul class="panelBar">
				<li class="left">
					<button type="button" class="btn btn-danger btn-lg" id="btnNotUse">노출안함</button>
				</li>
				<li  class="right">
					<button type="button" class="btn btn-default btn-lg" onclick="cfnDownloadSampleFile('SF002');">상품동영상등록 양식다운로드</button>
					<button type="button" class="btn btn-info btn-lg" id="btnExcReg">엑셀등록</button>
				</li>
			</ul>
			<div id="gridList" style="width: 100%; height: 450px;" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
		<!-- 등록/수정 -->
		<div class="panelStyle">
			<form id="detailForm" name="detailForm" action="#" th:action="@{'/display/brand/save'}">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col style="width:10%;"/>
						<col style="width:20%;"/>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<td colspan='6'>동영상등록(상세)</td>
					</tr>
					<tr>
						<th>상품코드<em class="required" title="필수"></em></th>
						<td>
							<input name="videoSq"  data-valid-name="상품동영상일련번호" type="hidden"/>
							<input type="text" class="w150" name="goodsCd" maxlength="20" required="required" data-valid-name="상품코드"/>
						</td>
						<th>동영상구분<em class="required" title="필수"></em></th>
						<td>
							<select name="videoGb" id="videoGb" required="required" data-valid-name="동영상구분" onchange="">
								<option value="">[선택]</option>
								<option value="Y">[Y] 유투브</option>
								<option value="M">[M] MP4</option>
							</select>
						</td>
						<th>노출여부<em class="required" title="필수"></em></th>
						<td>
							<label class="rdoBtn"><input type="radio" name="dispYn" id="dispYn" value="Y" checked="checked">Y</label>
							<label class="rdoBtn"><input type="radio" name="dispYn" id="dispYn" value="N">N</label>
						</td>
					</tr>
					<tr>
						<th>동영상URL<em class="required" title="필수"></em></th>
						<td class="infoTxt" colspan="5">
							<em><i class="fa fa-info-circle"></i>유투브의 경우 빨간색 표시로 되어있는 값만 넣으세요.</em><br/>
							예시 : https://www.youtube.com/embed/<em><strong>5YqYG71bQ3s</strong></em>?showinfo=0&amp;rel=0&amp;vp=hd1080&amp;fs=0&amp;wmode=opaque&amp;enablejsapi=1
							<br/>
							<input type="text" class="w400" id="videoVal" name="videoVal" maxlength="100" required="required" data-valid-name="동영상URL">
							<button type="button" class="btn btn-dark btn-lg" onclick="cfnOpenGoodsVideoPopup('filmVideoView','videoVal', '#detailForm', $('#videoGb').val());">미리보기</button>
						</td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<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>
			</form>
		</div>
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	var videoGbList = {'Y':'유투브', 'M':'MP4'};
	// specify the columns
	var columnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: 'No', width: 60, cellClass: 'text-center', valueGetter: function(params) { return params.node.rowIndex + 1 }},
		{headerName: "브랜드명", field: "brandEnm", width: 120, cellClass: 'text-center'},
		{headerName: "상품동영상일련번호", field: "goodsVideoSq", width: 120, cellClass: 'text-center', hide: true},
		{headerName: "상품코드", field: "goodsCd", width: 120, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}	
		},
 		{headerName: "동영상구분", field: "videoGb", width: 100, cellClass: 'text-center',
			cellRenderer: function (params) { return !gagajf.isNull(params.value) ? "["+params.value+"] "+gagaAgGrid.lookupValue(videoGbList, params.value) : '';}
		},
		{headerName: "동영상정보", field: "videoVal", width: 300, cellClass: 'text-center'},
		{headerName: "노출여부", field: "dispYn", width: 80, 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: "regNo", width: 150, 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: "updNo", width: 150, cellClass: 'text-center'},
	];
	
	// Get GridOptions
	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	
	gridOptions.rowSelection = 'multiple';
	gridOptions.suppressRowClickSelection = true;
	
	// 상품코드 셀 클릭
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field == "goodsCd"){
			var formId = '#detailForm';
			$(formId + " input[name=videoSq]").val(event.data.videoSq);
			$(formId + " input[name=goodsCd]").val(event.data.goodsCd);
			$(formId + " select[name=videoGb]").val(event.data.videoGb);
			$(formId + " input[name=videoVal]").val(event.data.videoVal);
			$(formId + " input:radio[name=dispYn]:input[value="+event.data.dispYn+"]").click();
			$(formId + " input[name=goodsCd]").prop("disabled", true);
			$(formId).closest("div").show();
		}
	}
	
	// 신규 버튼 클릭
	$("#btnNew").on('click', function() {
		$("#detailForm")[0].reset();
		$("#detailForm input[name=videoSq]").val('');
		$("#detailForm input[name=goodsCd]").prop("disabled", false);
	});

	// 엑셀등록
	$("#btnExcReg").on('click', function() {
		cfnExcelUploadPopup('','fnExcelUpoadCallback');
	});
	
	var fnExcelUpoadCallback = function(data){
		
		var jsonData = JSON.stringify(data);
		gagajf.ajaxJsonSubmit('/goods/video/excel/save', jsonData, fnSaveCallback);
		
	}
	
	// 조회
	$('#btnSearch').on('click', function() {
		$("#goodsCd").val('');
		$("#goodsNm").val('');
		$("#goodsNum").val('');
		$("#supplyGoodsCd").val('');
		$("#"+$("#searchForm select[name=keyWord]").val()).val($("#searchForm input[name=searchTxt]").val());
		// 기간 값 체크
		if (!fnCalendarDateValidation('#sellTerms', 'stDate', 'edDate')){
			return false;
		}
		// Fetch data
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
		$("#btnNew").click();
	});
	
	// 검색조건 초기화
	$('#btnInit').on('click', function() {
		$("#searchForm")[0].reset();
	});
	
	// 선택상품 사용안함
	$("#btnNotUse").on('click', function() {
		var selectRowData = gagaAgGrid.selectedRowData(gridOptions);
		if(selectRowData.length>0){
			mcxDialog.confirm('선택한 상품동영상을 미노출처리 하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					var jsonData = JSON.stringify(selectRowData);
					gagajf.ajaxJsonSubmit('/goods/video/update/notUse', jsonData, fnSaveCallback);
				}
			})
		}else{
			mcxDialog.alert("선택된 상품동영상이 없습니다.");
		}
	});
	
	// 동영상 저장
	$("#btnSave").on('click', function() {
		
		var formId = '#detailForm';
		var videoSq = $(formId + " input[name=videoSq]").val();
		var displocVal = $(formId + " input[name=goodsCd]").val();
		var videoGb = $(formId + " select[name=videoGb]").val();
		var videoVal = $(formId + " input[name=videoVal]").val();
		var dispYn = $(formId + " input:radio[name=dispYn]:checked").val();
		
		if(displocVal==''){
			gagajf.alertMessage(formId + " input[name=goodsCd]", 'input');
			return;
		}
		if(videoGb==''){
			gagajf.alertMessage(formId + " select[name=videoGb]", 'select');
			return;
		}
		if(videoVal==''){
			gagajf.alertMessage(formId + " input[name=videoVal]", 'input');
			return;
		}
		
		if(videoVal.indexOf("http")>-1){
			if(videoGb=='Y'){
				mcxDialog.alert('동영상URL 형식이 유투브와 맞지 않습니다.');
				return;
			}
		}else{
			if(videoGb=='M'){
				mcxDialog.alert('동영상URL 형식이 MP4와 맞지 않습니다.');
				return;
			}
		}
		
		mcxDialog.confirm('저장 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				var data = {videoSq : videoSq
							,displocGb : 'G'
							,displocValArr : [displocVal]
							,videoGb : videoGb
							,videoVal : videoVal
							,dispYn : dispYn
							};
				var jsonData = JSON.stringify(data);
				gagajf.ajaxJsonSubmit('/goods/video/save', jsonData, fnSaveCallback);
			}
		})
	});
	
	var fnSaveCallback = function() {
		$('#btnSearch').click();
	}
	
	$(document).ready(function() {
		
		cfnCreateCalendar('#sellTerms', 'stDate', 'edDate', true, '등록일', true);
		
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
		
		//$('#btnSearch').click();
	});
/*]]>*/
</script>

</html>
