<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>刀客建站系统   管理中心  - 设置当前模板</title>
<%{include file="header.html"}%>
</head>
<body>
<h1>

<span class="action-span1"><a href="index.php?act=index.default_page">刀客建站系统   管理中心</a>  - 设置当前模板 &nbsp;&nbsp;<a href="index.php?act=help.get&h=template_settemplate&width=450"  class="jTip"  name="我希望获得更多帮助"><img src='images/help.png'></a></span>
<span class="action-span"><a href="index.php?act=template_set.addblock&file=<%{$smarty.get.file|escape:url}%>">添加自定义区块</a></span>
<span style='float:right;margin-right:10px;'><img src='images/top_help.gif'><a href="http://sitepub.cn/help"> 帮助 </a></span>
<span style='float:right;margin-right:10px;'><img src='images/top_forum.gif'><a href="http://bbs.sitepub.cn"> 论坛 </a></span>
<div style="clear:both"></div>
</h1>
<div class="form-div">
  <form method="GET" action="index.php" id='select_tpl_id'>
	<input type='hidden' name='act' value='template_set.settemplate'>
  请选择模板页面:  <select name="file"  onchange='$("#select_tpl_id")[0].submit();'>
   <%{foreach from=$out.tpl_config.tpl_file_name item=v key=k}%>
    <option value="<%{$k}%>"  <%{if $smarty.get.file==$k}%>  selected=true<%{/if}%>><%{$v.name|escape:html}%></option>
	<%{/foreach}%>	
	 </select>
  </form>
</div>

<!-- start template options list -->
<%{foreach from=$out.seat_res item=v key=k}%>
	<div class="list-div" style='margin-bottom:30px;'>
	<div class="form-div" style='margin:0px;border:0px;'><h3><%{$v.name|escape:html}%> &nbsp;  <%{if $v.width}%> 宽:<%{$v.width}%>PX<%{/if}%></h3></div>
	<div >
		<table width="100%" >
		<tr>
    		<th>区块类型</th>
   	 	<th>区块</th>
			<th>排序</th>
			<th>显示</th>
			<th>添加 / 更新时间</th>
			<th>操作</th>
		</tr>	
		<tr style='background-color:#F4FBE1' >
    		<td align=center  > 调用区块 &nbsp;&nbsp;&nbsp;
				<select onchange='get_type_block(this);' id='block_type_<%{$k}%>_id' >
					<%{foreach from=$out.block_type_arr item=v2 key=k2}%>
						<option value='<%{$k2}%>'> <%{$v2.name}%></option>
					<%{/foreach}%>
				</select>
				</td>
		 	<td align=center><select id='block_id_<%{$k}%>_id'>
				<%{foreach from=$out.default_block_res item=v3 key=k3 }%>
						<option value='<%{$v3.block_id}%>'> <%{$v3.block_name}%></option>
				<%{/foreach}%>
			</select></td>
			<td align=center><input size=1 id='sort_order_<%{$k}%>_id'></td>
			<td align=center><input  type='checkbox' value=1 checked=true  id='is_open_<%{$k}%>_id'></td>
			<td align=center></td>	
			<td align=center><a href="javascript:void(0);" onclick='add_block_to_seat(this,"<%{$k}%>")'>调用到该区域</a></td>	
		</tr>	

		<%{foreach from=$v.block item=v1 key=k1}%>
		<tr>
    		<td align=center><%{$v1.block_type_name|escape:html}%></td>
		 	<td align=center><%{$v1.block_name|escape:html}%></td>
			<td align=center><span name='sort_order_name'  id='<%{$v1.seat_block_id}%>'> <%{$v1.sort_order}%></span></td>
			<td align=center><img style='cursor:pointer;'  onclick='is_open(<%{$v1.seat_block_id}%>,this)' src='images/<%{if $v1.is_open}%>yes<%{else}%>no<%{/if}%>.gif'></td>
			<td align=center><%{$v1.update_time|date_format:"%Y-%m-%d %H:%I:%S"}%></td>
			<td align=center><a href="<%{$out.tpl_to_url}%>?preview_seat_block_id=<%{$v1.seat_block_id}%>">可视化</a>&nbsp;&nbsp;<a href="index.php?act=template_set.edit_block&block_id=<%{$v1.block_id}%>">编辑区块</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick='del_seat_block(<%{$v1.seat_block_id}%>,this)'>移除</a></td>	
		</tr>
		<%{/foreach}%>
			
	
	</table>
	</div>
	</div>
<%{/foreach}%>
<script>

function del_seat_block(seat_block_id,obj)
{
	if(!window.confirm('确定从区域中移除该区块?')){
		return false;
	}
	$.ajax({
		url			:	"index.php?act=template_set.handle_seat_block&seat_block_id="+seat_block_id+"&is_ajax=1",
		dataType		:	"json",
		type			:	"POST",
		data			:	"handle[delete]=1",
		success		:	function(json){
			if(json=='ok'){
				alert('移除成功');
				$(obj).parent().parent().remove();
			}
		}

	});
}
function is_open(seat_block_id,obj)
{
	if(obj.src.match('yes')){
		obj.src='images/no.gif';
		var is_open	=	0;
	}else{
		obj.src='images/yes.gif';
		var is_open	=	1;
	}

	$.ajax({
		url			:	"index.php?act=template_set.handle_seat_block&seat_block_id="+seat_block_id+"&is_ajax=1",
		dataType		:	"json",
		type			:	"POST",
		data			:	"handle[is_open]="+is_open,
		success		:	function(json){
		}
	});


}

function get_type_block(obj)
{
	var d	=	$(obj).parent().next().children("select");
	$.ajax({
		url		:		"index.php?act=template_set.get_type_block&block_type="+encodeURIComponent($(obj).val())+"&is_ajax=1",
		dataType	:	"json",
		type		:	"GET",
		success		:	function(json){
			d[0].options.length = 0;  
			for(i in json){
				 d[0].options.add(new Option(json[i]['block_name'],json[i]['block_id']));  
			}
		}	
	});
}
function add_block_to_seat(obj,seat) 
{
	var block_obj		=		$("#block_id_"+seat+"_id");
	var block_id		=		block_obj.val();
	var block_name		=		$.trim(block_obj[0].options[block_obj[0].selectedIndex].text);
	if(!block_name){
		alert('该区块类型中暂无可用区块');
		return false;
	}

	var is_open			=		$("#is_open_"+seat+"_id")[0].checked?1:0;
	var table_obj		=		$(obj).parent().parent().parent();
	var sort_order		=		$("#sort_order_"+seat+"_id").val()?$("#sort_order_"+seat+"_id").val():table_obj.find("tr").length-1;
	var seat_name		=		$.trim($("#seat_name_"+seat+"_id").val());
	var index			=		$("#block_type_"+seat+"_id")[0].selectedIndex;
	var block_type_name	=	$.trim($("#block_type_"+seat+"_id")[0].options[index].text);
	$.ajax({
		url		:	"index.php?act=template_set.add_block_to_seat&is_ajax=1",
		dataType	:	"json",
		type		:	"POST",
		data		:	"block_id="+block_id+"&is_open="+is_open+"&sort_order="+sort_order+"&seat="+seat+"&file=<%{$smarty.get.file}%>",
		success		:	function(json){
			if(json=='no'){
				alert('操作失败')
			}else{
				var time	=	json['time'];
				var seat_block_id	=	json['seat_block_id'];
				alert('成功调用 "'+block_name+'" 区块');
				var html	=	'<tr><td align=center>'+block_type_name+'</td><td align=center>'+block_name+'</td><td align=center><span name="sort_order_name" id="'+seat_block_id+'">'+sort_order+'</span></td><td align=center><img style="cursor:pointer;" onclick="is_open('+seat_block_id+',this)" src="images/'+(is_open?"yes":"no")+'.gif"></td><td align=center>'+time+'</td><td align=center><a href="<%{$out.tpl_to_url}%>?preview_seat_block_id='+seat_block_id+'">可视化</a>&nbsp;&nbsp;<a href="index.php?act=template_set.edit_block&block_id='+block_id+'">  编辑区块</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="del_seat_block('+seat_block_id+',this)">移除</a></td></tr>';
				$(html).insertAfter($(obj).parent().parent());	
				sort_order_init();
			}
		}	
	});	
}

function sort_order_init()
{
	$("span[name=sort_order_name]").each(function(){
		this.style.width	=	'45px';
		this.style.display	=	'inline-block';
		$(this).hover(function(){this.style.backgroundColor	=	'#808080';},
										function(){this.style.backgroundColor=''});	

		$(this).click(function(){
				var sort_order	=	$(this).text();
				if(sort_order.match(/[0-9]+/)){
					var html			=	"<input size=1 value='"+sort_order+"' onblur	='sort_order_handle(this)'>";
					$(this).html(html);	
					$(this).children()[0].focus();
				}
		});
	});

}
function sort_order_handle(obj)
{
	var s_obj			=		 $(obj).parent();
	var seat_block_id	=	s_obj[0].id
	var sort_order		=	$(obj).val().replace(/[^0-9]/g,'');
	s_obj.html(sort_order);
	$.ajax({
		url		:	"index.php?act=template_set.handle_seat_block&seat_block_id="+seat_block_id+"&is_ajax=1",
		dataType	:	"json",
		type		:	"POST",
		data		:	"handle[sort_order]="+sort_order,
		success		:	function(json){
		}	
	});

}


$(document).ready(function(){	
		sort_order_init();
});



</script>

</body>
</html>


