<%@ page  language="java" contentType="text/html;charset=UTF-8"%>
	<input type="hidden" id="currentMenu" value="cache"/>
<%@ include file="../includes.jsp"%>
	<div class="main main-person-auth">
		<div class="search-bar clearfix">
			<c:if test="${isWrite==30}">
				<div class="search-factor">
					<a class="btn-cancel" href="javascript:void(0)"  id="deleteCache">清空缓存</a>
				</div>
			</c:if>
		</div>
			<table class="table-public table-person-auth">
			<thead>
				<tr>
					<th class="t-check">
						<a class="input-c" href="javascript:void(0)" id="check_all"></a>
					</th>
					<th class="">缓存类别</th>
					<th  >数量</th>
					<c:if test="${isWrite==30}">
						<th  >操作</th>
					</c:if>
				</tr>
			</thead>
				<c:set var="classAlt" value="class='tr-alt'"> </c:set>
			<tbody>
				<c:forEach items="${cacheList}" var="cache" varStatus="s">
					<tr ${(s.index+1)%2==1?classAlt:""}>
						<td> <a class="input-c " cacheType ="${cache.type}"  id="cache_${cache.type}" href="javascript:void(0);"> </a> </td>
						<td>${cache.cacheName}</td>
						<td >${cache.cacheNum}</td>
						<c:if test="${isWrite==30}">
							<td>
								<a class="link-action deleteCacheOne" href="javascript:void(0)" cacheType="${cache.type}" cacheName="${cache.cacheName}">
									<i class="icon-del01"></i>
									<b>清空缓存</b>
								</a>
							</td>
						</c:if>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>
<script type="text/javascript">
	var l;
	$(function(){
		l = $.checkBoxToggle("[id^='cache_']","#check_all");
		$("#deleteCache").click(function(){
			var cacheTypeArray = [];
			var ll = l.getLength();
			if(ll==0){
				$.warn("至少选择一项!");
	    		return false;
			}
			var obj = l.getCheckedObj();
	    	obj.each(function(){
	    		cacheTypeArray.push($(this).attr("cacheType")); 
			})
			$.confirm("您确定要清空选中的缓存吗?",function(){
				deleteCache(cacheTypeArray);
			})
		})
		
		$(".deleteCacheOne").click(function(){
			var cacheTypeArray = [];
			var cacheType = $(this).attr("cacheType");
			var cacheName = $(this).attr("cacheName");
	    	cacheTypeArray.push(cacheType); 
			$.confirm("您确定要清空“"+cacheName+"”吗?",function(){
				deleteCache(cacheTypeArray)
			})
		})
	})
	
	function  deleteCache(cacheTypeArray){
		$.ajax({
            type: "post",
            url: CONTEXTPATH+"/cache/removeCache.mooc",
            data: {
    			cacheTypes:cacheTypeArray
            },
            success: function (retStr) {
            	if(retStr.returnCode=='1'){
            		$.success("清空缓存操作成功!");
            		location.reload();
            	}else{
            		$.error(retStr.errorMsg);
            	}
            },
            error: function (jqXHR, textStatus, errorThrown) {
                
            }
        })
	}
</script>