<style type="text/css">
.tab tr {
	height: 40px;
}
.tab th {
	text-align:left;
	width:100px;
}
</style>
<script type="text/javascript">
<!--
function editDisplayorder(id) {
	var value = $('#displayorder_'+id).val();
	$.ajax({
		type: 'GET',
		url: '<?php echo $this->createUrl('/admin/smiles/editdisplayorder');?>&id='+id+'&value='+value,
		success:function(msg) {
			if ('' != msg) {
				alert(msg);
			}
		}
	});
}

function editCode(id) {
	var value = $('#code_'+id).val();
	$.ajax({
		type: 'POST',
		url: '<?php echo $this->createUrl('/admin/smiles/editcode');?>&id='+id,
		data: 'code='+value,
		success:function(msg) {
			if ('' != msg) {
				alert(msg);
			}
		}
	});
}
//-->
</script>
<h2>表情管理 - <?php echo $category->name;?></h2>
<div class="form">
	<fieldset>
		<legend><?php echo $category->name;?></legend>
		<table class="tab">
		<thead>
			<tr>
				<th>表情ID</th>
				<th>显示顺序</th>
				<th>表情代码</th>
				<th>文件名</th>
				<th>图片</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($smiles as $smile):?>
				<tr>
					<td><?php echo $smile->id;?></td>
					<td><?php echo CHtml::textField('smile['.$smile->id.'][displayorder]',$smile->displayorder,array('size'=>4,'id'=>'displayorder_'.$smile->id,'onchange'=>'editDisplayorder('.$smile->id.')'));?></td>
					<td><?php echo CHtml::textField('smile['.$smile->id.'][code]',$smile->code,array('id'=>'code_'.$smile->id,'onchange'=>'editCode('.$smile->id.')'))?></td>
					<td><?php echo $smile->path;?>
					<td><?php echo CHtml::image($smile->getSmileUrl($category->path).'/'.$smile->path);?></td>
					<td>[<?php echo CHtml::link('删除',array('/admin/smiles/deleteitem','id'=>$smile->id));?>]</td>
				</tr>
			<?php endforeach;?>
		</tbody>
		</table>
	</fieldset>
</div>

<?php echo CHtml::beginForm(array('/admin/smiles/additem','id'=>$category->id));?>
<div class="form">
	<fieldset>
		<legend>该目录下尚未被添加的表情</legend>
		<?php if (!empty($others)):?>
			<table>
			<thead>
				<tr>
					<th>全选</th>
					<th>图片路径</th>
					<th>表情代码</th>
					<th>图片预览</th>
				</tr>
			</thead>
			<tbody>
			<?php foreach ($others as $other):?>
				<tr>
					<td><?php echo CHtml::checkBox('new[]','',array('value'=>$other));?></td>
					<td><?php echo $category->path;?>/<?php echo $other;?></td>
					<td><?php echo CHtml::textField('code['.$other.']')?></td>
					<td><?php echo CHtml::image(Smiles::model()->getSmileUrl($category->path.'/'.$other));?></td>
				</tr>			
			<?php endforeach;?>
			</tbody>
			</table>
			<?php echo CHtml::submitButton('添加');?>
		<?php else:?>
			暂无图片
		<?php endif;?>
	</fieldset>
</div>
<?php echo CHtml::endForm();?>