<%
/**
 * <pre>
 * @Class Name : confirmRend.jsp
 * 
 * @Description : 방문열람신청 확인 화면 
 * 
 * 
 * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
 *
 * </pre>
 *
 * @ ------------    --------    ---------------------------
 * @ 수정일                     수정자             수정내용
 * @ ------------    --------    ---------------------------
 * @ 2021. 10. 25.   KNKIM       최초 생성
 *
 * 
 * @author 이씨플라자 * DIGITALSHIP KNKIM
 * @since 2021. 10. 25.
 * @version 1.0
 *
 */
 %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<script>
var BTN_APP_PREFIX = "대출신청/예약"; 

$( document ).ready(function() {
    
    $("[id^=chk_item_]").prop("disabled", true);
    $("[id^=chk_all_]").prop("disabled", true);
    
    $("[id=selMngOrgCd]").change(function(obj) {
        var checked = $(this).prop("checked");
        var mngOrgCd = $(this).val();
        
        if(checked) {
            // uncheck others and disable
            // enable 
            //$("[id^=chk_item_" + mngOrgCd + "]").prop("checked", false);
            $("[id^=chk_item_" + mngOrgCd + "]").prop("disabled", false);
            $("[id^=chk_all_" + mngOrgCd + "]").prop("disabled", false);
            
            $("[id^=chk_item_]").not("[id^=chk_item_" + mngOrgCd + "]").prop("checked", false);
            $("[id^=chk_item_]").not("[id^=chk_item_" + mngOrgCd + "]").prop("disabled", true);
            
            $("[id^=chk_all_]").not("[id^=chk_all_" + mngOrgCd + "]").prop("checked", false);
            $("[id^=chk_all_]").not("[id^=chk_all_" + mngOrgCd + "]").prop("disabled", true);

        }
        $("#mngOrgCd").val(mngOrgCd);
        $("[id^=chk_item_" + mngOrgCd + "]").filter(":first").trigger("change");
        
    });

    $("[id^=chk_item_]").change(function(obj) {
        var mngOrgCd = $(this).attr("id").substr(9);
        
        var totNum = $("[id^=chk_item_" + mngOrgCd + "]").length;
        var selNum = $("[id^=chk_item_" + mngOrgCd + "]:checked").length;
        
        var checked = false;
        if(totNum <= selNum) checked = true;
        $("[id^=chk_all_" + mngOrgCd + "]").prop("checked", checked);

        $("#btnApp").val(BTN_APP_PREFIX + " (" + selNum + ")");
        $("#appCnt").text("(" + selNum + ")");
    });
    
    $("[id^=selMngOrgCd]").filter(":first").prop("checked", true);
    $("[id^=selMngOrgCd]").filter(":first").trigger("change",true);
    
}); // document ready



// 선택한 게시글 상세 보기로 이동
function fn_viewDetail(articleNo) {
    $("#articleNo").val(articleNo);
    $("#articleForm").attr("action", "${pageContext.request.contextPath}/board/selectNotice.do");
    $("#articleForm").submit();
}

function fn_insertReadItems() {
    
    <sec:authorize access="not isAuthenticated()">
        alert("먼저 로그인하신 후, 이용해 주시기 바랍니다.");
    </sec:authorize>
    
    <sec:authorize access="isAuthenticated()">
        if($("#selItems").val() == "" || $("#selItems").val() == ",") {
            alert("방문열람할 대상정보가 없습니다.");
            return;
        }
        
        if($("#hopeReqPridDtmFrom").val() > $("#hopeReqPridDtmTo").val()) {
            alert("희망방문일 종료일은 시작일보다 이후 일자로 선택해 주세요.");
            $("#hopeReqPridDtmTo").focus();
            return;
        }
        
        <c:if test='${fromCart == "Y" }'>
        $("#frm").attr("action","${pageContext.request.contextPath}/read/insertReadItemsFromCart.do");
        </c:if>

        <c:if test='${fromCart != "Y" }'>
        $("#frm").attr("action","${pageContext.request.contextPath}/read/insertReadItems.do");
        </c:if>

        $("#frm").submit();    
    </sec:authorize>
    
}

function fn_changeInterest(masterId, onOff) {
    alert("관심등록/삭제 준비중 : " + masterId + ", " + onOff);
}

function fn_listCartItems() {
    

    <c:if test='${fromCart == "Y" }'>
    $("#frm").attr("action","${pageContext.request.contextPath}/cart/listCartItems.do");
    $("#frm").submit();     
    </c:if>
    
    <c:if test='${fromCart != "Y" }'>
    location.href = "/";
    </c:if>
    
}

$(document).ready(function() {
    
    /* 탭메뉴 */
    var selectedIdx = '> li:eq(' + (${cartTypeCd } -1) + ')';
    $('.cartTab ul.tabs').addClass('active').find(selectedIdx).addClass('current');
    
    $('.tab ul.tabs li a').click(function (g) { 
        var tab = $(this).closest('.tab'), 
            index = $(this).closest('li').index();
    
        tab.find('ul.tabs > li').removeClass('current');
        $(this).closest('li').addClass('current');
    
        tab.find('.tab_content').find('div.tabs_item').not('div.tabs_item:eq(' + index + ')').hide();
        tab.find('.tab_content').find('div.tabs_item:eq(' + index + ')').show();
        g.preventDefault();
    });
    
    if("${message}" != "") alert("${message}");
    
});



</script>
    
<form name="frm" id="frm" action="${pageContext.request.contextPath}/cart/listCartItems.do" method="post"> 
      <input type="hidden" id="cartTypeCd" name="cartTypeCd" value="${readVO.cartTypeCd }" />
      <input type="hidden" id="mngOrgCd" name="mngOrgCd" value="${readVO.mngOrgCd }" />
      <input type="hidden" id="mngOrgNm" name="mngOrgNm" value="${readVO.mngOrgNm }" />
      
    <!-- 카트 섹션 -->
    <section class="location cart cart-confirm">
        <h2 class="blind">카트 섹션영역</h2>
        <div class="inner">
            <div class="row-top">
                <div class="location-box">
                    <ul class="loc">
                        <li>HOME</li>
                        <c:if test='${fromCart == "Y" }'>
                        <li>카트</li>
                        </c:if>
                        <li class="on">방문열람신청</li>
                    </ul>
                    <ul class="tit">
                        <li><span>방문열람</span>신청</li>
                    </ul>
                </div>
                <div class="arr"><img src="/images/icon/icon-join-arr2.png" alt="화살표 아이콘"></div>
            </div>
            <div class="contents row-bottom">
                <div class="cart-box">
                    <div class="tab">
                        <div class="tab_content loan-confirm visit-confirm">
                            <div class="tabs_item">
                                <div class="inner">
                                    <div class="list-cart-wrap confirm">

      
          <c:set var="totCnt" value="0" />
          <c:set var="rentType1Cnt" value="0" />
          <c:set var="rentType2Cnt" value="0" />
          <c:set var="curType" value="" />
          <c:set var="selItems" value="" />
          
                            <h3><label>방문열람신청확인  ${readVO.mngOrgNm }</label></h3>
                                <div class="list-cart">
                                    <div class="list t-tit-line">
                                        <div class="t-data t-mo">자료정보</div>
                                        <div class="t-state t-mo">이용상태</div>
                                        <div class="t-date t-mo">반납예정일</div>
                                    </div>
          
                                <c:forEach var="read" items="${list}" varStatus="status">
                                
                                    <c:set var="curType" value="0" />
                                    
                                    <%
                                    //-----------------------------------
                                    // 대출신청인 경우 
                                    //-----------------------------------
                                    // 대출가능코드(operOutRangeCd)가 01:대출가능이면서
                                    // 이용상태코드 (useStatus)가 01:이용가능, 또는 05 : 이용가능, 또는 04 : 열람대기(대출가능) 인 경우
                                    %>
                                    <c:if test="${read.operOutRangeCd == '01' and (read.useStatus == '01' or read.useStatus == '04' or read.useStatus == '05')  }">
                                    <c:set var="rentType1Cnt" value="${rentType1Cnt+1}" />
                                    <c:set var="curType" value="1" />
                                    <c:set var="selItems" value='${selItems += "," += read.masterId }' />
                                    </c:if>

                                    <%
                                    //-----------------------------------
                                    // 대출예약신청인 경우 
                                    //-----------------------------------
                                    // 대출가능코드(operOutRangeCd)가  01 :대출가능이면서 
                                    // 이용상태코드 (useStatus)가 02 : 대출중 (대기자 0명) 인 경우
                                    %>
                                    <c:if test="${read.operOutRangeCd == '01' and read.useStatus == '02'  }">
                                    <c:set var="rentType2Cnt" value="${rentType2Cnt+1}" />
                                    <c:set var="curType" value="2" />
                                    <c:set var="selItems" value='${selItems += "," += read.masterId }' />
                                    </c:if>
                                    
                                    <div class="list list-content">
                                        <div class="t-data">
                                            <div class="img"><a href="javascript:void(0)"><img src="${read.rprsThumbUrlWithDefaultSmall }" alt="썸네일" width="60" height="91" title="상세보기" onclick="gfn_getDetail('${read.masterId }')"></a>
                                                  <c:if test='${read.MUseYn == "Y"}'>
                                                      <span id="favorites_${read.masterId}" class="favorites" onclick="fn_changeInterest('${read.masterId }', 'off')" title="관심자료에서 삭제합니다.">
                                                      <img src="/images/icon/icon-cart-Favorites-on.png" class="off" alt="즐겨찾기 아이콘">
                                                      <img src="/images/icon/icon-cart-Favorites.png" class="on" alt="즐겨찾기 아이콘">
                                                      </span>
                                                  </c:if>
                                                  <c:if test='${read.MUseYn != "Y"}'>
                                                      <span id="favorites_${read.masterId}" class="favorites" onclick="fn_changeInterest('${read.masterId }', 'on')" title="관심자료로 등록합니다.">
                                                      <img src="/images/icon/icon-cart-Favorites.png" class="off" alt="즐겨찾기 아이콘">
                                                      <img src="/images/icon/icon-cart-Favorites-on.png" class="on" alt="즐겨찾기 아이콘">
                                                      </span>
                                                  </c:if>                                            
                                            </div>
                                            <div class="type">
                                                <c:if test="${read.ableOnline }">
                                                <span class="online">온라인열람</span>
                                                </c:if>
                                                
                                                <c:if test="${read.ableRent }">
                                                <span class="loan">대출</span>
                                                </c:if>
                                                
                                                <c:if test="${read.ableRead }">
                                                <span class="visit">방문열람</span>
                                                </c:if>
                                            </div>
                                            <div class="title"><a href="javascript:void(0)" onclick="gfn_getDetail('${read.masterId }')" title="상세보기">${read.title }</a></div>
                                        </div>
                                        <div class="t-state <c:if test="${read.useStatus != '03' and read.useStatus != '06' }">poss</c:if> <c:if test="${read.useStatus == '03' or read.useStatus == '06' }">imposs</c:if>"><p>${read.useStatusNm }</p></div>
                                        <div class="t-date">${read.rtnExpctDd }</div>
                                        <!-- <div class="t-reser poss">대출신청</div> : 2021.11.22 LEE 확인필요 DDDDDDDDDDDDDDDDDDDDDDDDD -->
                                    </div>
                                    
                                </c:forEach>   
                                
                                    </div> <!-- 목록 테이블  list-cart : 종료 -->
                                </div>
                                <p class="visit-text">-  관리자의 승인이 필요하며, 희망하신 날짜와 시간과는 다르게 조정될 수 있습니다.</p>
                                
                                <div class="visit-select-box">
                                    <%
                                    //-----------------------------------
                                    // 희망방문일 선택 가능 기준 
                                    //-----------------------------------
                                    // 시작일, 종료일 : 당일부터 2주이내 날짜 선택가능
                                    // 단, 문화원 운영시간이 지난 경우, 익일부터 2주이내 날짜 선택가능
                                    %>
                                    <h3><span>희망</span>방문일</h3>
                                    <div class="select-box">
                                    	<div>
	                                        <select id="hopeReqPridDtmFrom" name="hopeReqPridDtmFrom"  class="visitDate">
	                                            <c:forEach var="dtItem" items="${listDates}" varStatus="status">
	                                                <option value="${dtItem.dt }">${dtItem.dt }</option>
	                                            </c:forEach>
	                                        </select> 에서
	                                        <label for="hopeReqPridDtmFrom" style="display:none">희망방문 시작일자</label>
                                        </div>
                                        <div>
	                                        <select id="hopeReqPridDtmTo" name="hopeReqPridDtmTo"  class="visitDate">
	                                            <c:forEach var="dtItem" items="${listDates}" varStatus="status">
	                                                <option value="${dtItem.dt }"
	                                                    <c:if test='${status.count == 2}'>selected</c:if>
	                                                >${dtItem.dt }</option>
	                                            </c:forEach>
	                                        </select> 사이
	                                        <label for="hopeReqPridDtmTo" style="display:none">희망방문 종료일자</label>
                                        </div>
                                    </div>
                                </div>
                                <p class="text">- 자료 열람은 방문열람신청이 승인된 후, 지정된 시간에 가능합니다.</p>
                                <p class="text">- 방문열람신청이 승인되면 문자(SMS)나 이메일을 통해 안내 드립니다.</p>
                                
                                <div class="btn-wrap">  
                                    <button type="button" class="btn btn-gray" onclick="fn_listCartItems()">취소</button>
                                    <button type="button" class="btn btn-color"
                                        <c:if test="${(rentType1Cnt + rentType2Cnt) > 0}">
                                        onclick="fn_insertReadItems()"
                                        </c:if>
                                        <c:if test="${(rentType1Cnt + rentType2Cnt) < 1}">
                                        onclick="alert('방문열람 신청할 자료가 없습니다.');"
                                        </c:if>
                                        >신청하기 <span id="totCnt" class="count">(${rentType1Cnt + rentType2Cnt})</span></button>
                                </div>
                                
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    
    <input type="hidden" id="selItemsOld" name="selItemsOld" value="${readVO.selItems }" />
    <input type="hidden" id="selItems" name="selItems" value="${selItems }" />
    
</form>

      

                      

