<{import file="header.html" title="相册管理"}> 
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/album.css?v=<{$js_version}>">
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/upload.css?v=<{$js_version}>">
<div class="tab"><span>相册管理</span></div>
<!--管理页面-->
<div class="manage"> 
	<div class="mgbox"> 
		<div class="chose">
			<span><label><input type="checkbox" name="all_ck"/><i>全选</i></label></span> 
		</div> 
		<div class="file2">
			<input type="file" name="images[]" id="imgFile" class="album_upload_button" multiple="multiple"/>上传文件
		</div>
		<a href="javascript:;" onClick="edit_floder('创建分类', '<{$__SELLER__}>album/type_edit?pid=<{if $smarty.get.pid}><{$smarty.get.pid}><{else}>0<{/if}>')">创建文件夹</a>
		<!--a href="javascript:;" onClick="type_set('设置分类', '<{$__SELLER__}>album/type_set?type=<{$smarty.get.type}>')">移动到分类</a---> 
		<a href="javascript:;" class="del_all">删除</a> 
		<{uqcms m="album" v="type_row" c="get_parent_id:id=smarty.get.pid"}>
		<{if $type_row.id}>
			<a href="<{$__SELLER__}>album/index?pid=<{$type_row.pid}>">后退</a>
		<{/if}>
		
		<{uqcms m="album" v="space" c="get_size"}>
		<div class="space">
			<span>使用容量 </span>
			<div class="capacity"><span style="width:<{$space.percent}>%"></span><i><{$space.size}>/<{$space.limit}></i></div> 
		</div>
	</div>
</div>

<!--相册列表-->
<div class="albumcon ajax_album_img"> 
	<div class="folder_menu"></div>
	<{uqcms m="album" v="data" c="get_list:pid=smarty.get.pid&page=smarty.get.page&page_size=21"}>
	<input type="hidden" name="pid" value="<{$smarty.get.pid}>" id="pid"/>
	<{if $data.catelog}>
		<{foreach item=i from=$data.catelog}>
			<div class="folder"> 
				<a href="<{$__SELLER__}>album/index?pid=<{$i.id}>" data-id="<{$i.id}>">
					 <img src="<{$__APP__}>public/images/floder.png"/>
				</a><i></i> 
				<div class="name"><{$i.name}></div>
			</div> 
		<{/foreach}>
	<{/if}>
	
	<{if $data.list}>
		<{foreach item=i from=$data.list}>
			<div class="abox">
				<div class="img">
					<a href="javascript:;">
						<img src="<{$__IMG__}><{$i.url|img_size:120x120}>"><input type="checkbox" name="ck_img" value="<{$i.id}>"/>
					</a><i></i>
				</div>
				<div class="opt">
					<div class="rt">
						<a href="javascript:;" class="copy" data-url="<{$__IMG__}><{$i.url}>" title="复制">复制</a>
						<a href="javascript:;" data-id="<{$i.id}>" data-type="<{$i.utype}>" class="del2" data-ntag="1" title="删除">删除</a>
					</div>
				</div>
			</div>
		<{/foreach}> 
	<{/if}>
	
</div> 
<!--分页-->
<{if $data.page}>
	<div class="page"><{$data.page}></div>
<{/if}>
<{import file="footer.html"}>
<script type="text/javascript" src="<{$__APP__}>public/js/upload_album.js?v=<{$js_version}>"></script> 
<script type="text/javascript"> 
function type_set(name, url){ 
	ajax_dialog(name, url, 440); 
}
function edit_floder(name, url){ 
	ajax_dialog(name, url, 380); 
}
$(function(){
	// 相册弹窗 分页操作
	$(document).on('click', ".ajax_album_page a", function(event){ 
		if(window.event){
			window.event.returnValue = false;
		}else{  
			event.preventDefault();	 //for firefox
		}
		var jump_url = $(this).attr('href');
		if(jump_url){
			pid = '0';	// 参数失效
			get_album_list(pid, jump_url);
		}
	});
	
	// 目录操作
	$(document).on('contextmenu','.folder a',function(e){
		$this = $(this);
		var X = $this.offset().top; 
		var Y = $this.offset().left;
		id = $(this).attr('data-id'); 
		html = '<div class="rit_click_box">'+
					'<a href="javascript:;" onClick="edit_floder(\'创建分类\', \'<{$__MEMBER__}>album/type_edit?pid='+id+'\')">创建目录</a>'+
					'<a href="javascript:;" onClick="edit_floder(\'重命名文件夹\', \'<{$__MEMBER__}>album/type_edit?id='+id+'\')">重命名</a>'+
					'<a href="javascript:;" class="floder_del" data-id="'+id+'">删除</a>'+
				'</div>'; 
		$(".folder_menu").html(html); 
		$(".rit_click_box").css({top:X+22, left:Y+18});
		return false;
	});
	
	// 删除目录
	$(document).on('click','.floder_del',function(e){
		id = $(this).attr('data-id');
		 $.get(SELLER+'album/type_del?id='+id, function(result){
			var data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				location.reload();
			}else{
				$.alert(data.msg);
			} 
		 });
	}); 
	// atree弹出的 移除
	$(document).click(function(){
		$(".rit_click_box").remove();
	});
 	
	// ---------------------选中--------------------
	$(document).on('click','.abox .img a',function(e){
		$this = $(this);
		ck_status = $this.attr('data-ck');
		if(ck_status == 'ck'){
			$this.parents('.abox').removeClass('ck_img');
			$this.find('input').attr("checked",false);
			$this.attr('data-ck','');
		}else{
			$this.parents('.abox').addClass('ck_img');
			$this.find('input').attr("checked","checked");
			$this.attr('data-ck','ck'); 
		}
	});
	
	// 全选
	$("input[name='all_ck']").click(function(){ 
    	if(this.checked){ 
			$(".abox").each(function(){
				$(this).addClass('ck_img');
				$(this).find('input').attr("checked","checked");
				$('.img a',this).attr('data-ck','ck'); 
			});
    	}else{
			$(".abox").each(function(){
				$(this).removeClass('ck_img');
				$(this).find('input').attr("checked",false);
				$('.img a',this).attr('data-ck',''); 
			});
    	}   
 	});
	
	// 图片复制 
	$(document).on('click', '.copy', function(e){
		data = $(this).attr('data-url');
	 	var flag = copyText(data); 
		$.alert(flag ? "复制成功！" : "复制失败！");
	});
	
	// 删除
	$(document).on('click', 'a.del2', function(e){
		$this = $(this);
		id = $this.attr('data-id');
		if(!confirm("确定要删除吗？")) { 
			if(window.event){
				window.event.returnValue = false;
			}else{  
				event.preventDefault();	//for firefox
			}
		}else{ 
			$.post(SELLER+'album/del', {id:id}, function(result){
				data = jQuery.parseJSON(result); 
				if(data.error == '0'){
					$.alert('删除成功', function(){
						location.reload();
					}); 
				}else{
					$.alert(data.msg); 
				} 
			}); 
		}
	});
	
	$(document).on('click', 'a.del_all', function(e){
		if(!confirm("确定要删除吗？")) { 
			if(window.event){
				window.event.returnValue = false;
			}else{  
				event.preventDefault();	//for firefox
			}
		}else{
			var str=""; 
			$("input[name='ck_img']:checked").each(function(){ 
				str+=$(this).val()+','; 
			});
			ck_id = str.substring(0,str.length-1);
			if(str){ 
				$.post(SELLER+'album/del_all', {'ck_id':ck_id},function(result){
					data = jQuery.parseJSON(result); 
					if(data.error == '0'){
						$.alert('删除成功', function(){
							location.reload();
						}); 
					}else{
						$.alert(data.msg);
					}
				});
			}else{
				$.alert('没有选中图片');
			}	
		} 
	});  
}); 
 
</script>