{js:kindeditor}
<div class="headbar">
	<div class="position"><span>工具</span><span>></span><span>文章管理</span><span>></span><span>{if:isset($this->articleRow['id'])}编辑{else:}添加{/if}文章</span></div>
</div>
<div class="content_box">
	<div class="content form_content">
		<form action='{url:/tools/article_edit_act}' method='post' name='article'>
			<input type='hidden' name='id' value="" />
			<table class="form_table">
				<colgroup>
					<col width="150px" />
					<col />
				</colgroup>
				<tr>
					<th>分类：</th>
					<td>
						<select class="auto" name="category_id" pattern="required" alt="请选择分类值">
							<option value=''>选择文章分类</option>
							{query:name=article_category order=path asc}
							<option value='{$item['id']}'>{echo:str_repeat('&nbsp;&nbsp;&nbsp;',substr_count($item['path'],',')-2)}{$item['name']}</option>
							{/query}
						</select>
						<label>*选择文章所属分类（必填）</label>
					</td>
				</tr>
				<tr>
					<th>标题：</th>
					<td><input type='text' name='title' class='normal' value='' pattern='required' alt='标题不能为空' /></td>
				</tr>
				<tr>
					<th>是否发布：</th>
					<td>
						<label class='attr'><input type='radio' name='visibility' value='1' checked=checked />是</label>
						<label class='attr'><input type='radio' name='visibility' value='0' />否</label>
					</td>
				</tr>
				<tr>
					<th>首页推荐：</th>
					<td>
						<label class='attr'><input type='radio' name='top' value='1' checked=checked />是</label>
						<label class='attr'><input type='radio' name='top' value='0' />否</label>
					</td>
				</tr>
				<tr>
					<th>标题字体：</th>
					<td>
						<label class='attr'><input type='radio' name='style' value='0' checked=checked />正常</label>
						<label class='attr'><input type='radio' name='style' value='1' /><b>粗体</b></label>
						<label class='attr'><input type='radio' name='style' value='2' /><span style="font-style:oblique;">斜体</span></label>
					</td>
				</tr>
				<tr>
					<th>标题颜色：</th>
					<td>
						<div class="color_sel">
							{set:$color = ($this->articleRow['color']===null) ? '#000000' : $this->articleRow['color']}
							<input type='hidden' name='color' value='' />
							<a class="color_current" style='color:{$color};background-color:{$color};' href='javascript:void(0)' onclick='showColorBox();' id='titleColor'>{$color}</a>
							<div id='colorBox' class="color_box" style='display:none'></div>
						</div>
					</td>
				</tr>
				<tr>
					<th>排序：</th><td><input type='text' class='small' name='sort' value='' /></td>
				</tr>
				<tr>
					<th>关联相关商品：</th>
					<td>
						<table class='border_table' style='width:70%;margin-bottom:10px;'>
							<thead><tr><th>商品名称</th><th>操作</th></tr></thead>
							<tbody id="goodsListBox"></tbody>
						</table>
						<button class='btn' type='button' onclick="searchGoods('{url:/block/search_goods/type/checkbox}',searchGoodsCallback);"><span>选择商品</span></button>
						<label>文章所要关联的商品（可选）</label>
					</td>
				</tr>

				<tr>
					<th valign="top">内容：</th><td><textarea id="content" name='content' style='width:700px;height:300px' pattern='required' alt='内容不能为空'>{echo:htmlspecialchars($this->articleRow['content'])}</textarea></td>
				</tr>
				<tr>
					<th>关键词(SEO)：</th><td><input type='text' class='normal' name='keywords' value='' /></td>
				</tr>
				<tr>
					<th>描述简要(SEO)：</th><td><input type='text' class='normal' name='description' value='' /></td>
				</tr>
				<tr>
					<th></th><td><button class='submit' type='submit'><span>确 定</span></button></td>
				</tr>
			</table>
		</form>
	</div>
</div>

<!--商品模板-->
<script type="text/html" id="goodsItemTemplate">
<tr>
	<td>
		<input type='hidden' name='goods_id[]' value='<%=templateData['goods_id']%>' />
		<img src="<%=webroot(templateData['img'])%>" style="width:80px;" />
		<%=templateData['name']%>
	</td>
	<td style="text-align:center"><img src="{skin:images/admin/icon_del.gif}" alt="删除" title="删除" onclick="$(this).parent().parent().remove();" /></td>
</tr>
</script>

<script type='text/javascript'>
jQuery(function(){
	//调色板颜色
	var colorBox = new Array('#000','#930','#330','#030','#036','#930','#000080','#339','#333','#800000','#f60','#808000','#808080','#008080','#00f','#669','#f00','#f90','#9c0','#396','#3cc','#36f','#800080','#999','#f0f','#fc0','#ff0','#0f0','#0ff','#0cf','#936','#c0c0c0','#f9c','#fc9','#ff9','#cfc','#cff','#9cf','#c9f','#fff');
	for(color in colorBox)
	{
		var aHTML = '<a href="javascript:void(0)" onclick="changeColor(this);" style="background-color:'+colorBox[color]+';color:'+colorBox[color]+'">'+colorBox[color]+'</a> ';
		$('#colorBox').html($('#colorBox').html() + aHTML);
	}

	var FromObj = new Form('article');
	FromObj.init({echo:JSON::encode($this->articleRow)});

	KindEditor.ready(function(K){
		K.create('#content');
	});

	{if:$this->articleRow}
	{set:$goodsList = Api::run("getArticleGoods",array("#article_id#",$this->articleRow['id']))}
	createGoodsList({echo:JSON::encode($goodsList)});
	{/if}
});

//弹出调色板
function showColorBox()
{
	var layer = document.createElement('div');
	layer.className = "poplayer";
	$(document.body).append(layer);
	var poplay = $('#colorBox');
	$('.poplayer').bind("click",function(){if(poplay.css('display')=='block') poplay.fadeOut();$("div").remove('.poplayer');})
	poplay.fadeIn();
}

//选择颜色
function changeColor(obj)
{
	var color = $(obj).html();
	$('#titleColor').css({color:color,'background-color':color});
	$('input[type=hidden][name="color"]').val(color);
	$('#colorBox').fadeOut();
	$("div").remove('.poplayer');
}

//输入筛选商品的条件
function searchGoodsCallback(goodsList)
{
	var result = [];
	goodsList.each(function()
	{
		var temp = $.parseJSON($(this).attr('data'));
		result.push(temp);
	});
	createGoodsList(result);
}

//创建商品数据
function createGoodsList(goodsList)
{
	for(var i in goodsList)
	{
		var templateHTML = template.render('goodsItemTemplate',{"templateData":goodsList[i]});
		$('#goodsListBox').append(templateHTML);
	}
}
</script>
