<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>图片管理</title>
	<link rel="stylesheet" href="{url:@static/css/base.css}" />
	<link rel="stylesheet" href="{url:@static/css/admin.css}" />

	{echo:JS::import('jquery')}
	{echo:JS::import('form')}
	{echo:JS::import('dialog?skin=brief');}
	{echo:JS::import('dialogtools');}
	<script src="{url:@static/js/common.js}" charset="UTF-8" type="text/javascript"></script>
</head>
<body style="background:#fff;">
	<div style="width:100%;" class="tab">
		<ul class="tab-head"><li>本地图片</li><li>图库图片</li><li>网络图片</li></ul>
		{set:$type=Req::args('type')==null?0:intval(Req::args('type'));}
		<div class="tab-body form2">
			<div>
			<form id="image_form" action="{url:/admin/photoshop_upload}" method="post" enctype="multipart/form-data" >
				<dl class="lineD">
			      <dt>本地图片：</dt>
			      <dd>
			      	<input name="type" type="hidden" value="{$type}">
			        <input name="upfile" type="file" pattern="required" >
			        <label></label>
			      </dd>
			    </dl>
			    </form>
			</div>
			<div>
				<ul class="gallery clearfix">
				{query:name=gallery id=$obj page=1 where=type eq $type}
					<li><img height="100" width="100" src="{url:@$item[img]}" data-src="{$item['img']}"></li>
				{/query}
				</ul>
				<div class="page_nav">
				{echo:$obj->pageBar()}
				</div>
			</div>
			<div>
				<form id="form_netimg" callback="setNetImg">
				<dl class="lineD">
			      <dt>网络图片：</dt>
			      <dd>
			        <input id="netimg" name="netimg" type="text" pattern="http:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))+(\/\S*)+\.(jpg|png|bmp|gif)" value="{$name}">
			        <label>图片地址必须以http开头,以jpg,png,bmp,gif结束</label>
			      </dd>
			    </dl>
			    </form>
			</div>
		</div>
		
	</div>
	<div class="alone_footer tc"><button class="button" onclick="saveImage()">保存</button></div>
	<script type="text/javascript">
	function saveImage (){
		var status = $(".tab > .tab-head > li[class='current']").index();
		switch(status){
			case 0:
				$("form:first").submit();
				break;
			case 1:
				var img = $(".gallery > .current >img").attr('data-src');
				if(img)art.dialog.opener.setImg(img);
				else art.dialog.tips("<p class='fail'>未选择任何图片，无法添加！</p>");
				break;
			case 2:
				$("#form_netimg").submit();
				break;
			}
		}
		{if:isset($msg)}
			art.dialog.tips("<p class='{$msg[0]}'>{$msg[1]}</p>");
		{elseif:Req::args('msg')}
			{set:$msg = Req::args('msg')}
			art.dialog.tips("<p class='{$msg[0]}'>{$msg[1]}</p>");
		{/if}
		function setNetImg(e){
			if(e==null)art.dialog.opener.setImg($('#netimg').val());
			return false;
		}
		$(".gallery >li").each(function(){
			$(this).on("click",function(){
				$(".gallery >li").removeClass('current');
				$(this).addClass("current");
			})
		})
　　			{if:Req::args('p')!=null}
				$(document).ready(function(){ 
				　　tabs_select(0,1);
				});
			{/if}
	</script>
</body>
</html>