<?php TPL::output('admin/global/header.tpl.htm'); ?>

<!--left-->
<?php TPL::output('admin/global/left.tpl.htm'); ?>
<!--left-->

<!-- main -->
<div id="main-content">
	<div class="clear"></div>
	<div class="content-box">
		<div class="content-box-header">
			<h3><?php echo $this->crumb['last']['name']; ?></h3>
			<ul class="content-box-tabs">
				<li><a href="#tab1" class="default-tab current">Management topics</a></li>
				<li><a href="admin/feature/list/" class="">Topic list</a></li>
				<li><a href="#tab2">Add Feature</a></li>
			</ul>
			<div class="clear"></div>
		</div>
		<div class="content-box-content">
			<div class="tab-content default-tab" id="tab1">
				<?php if($this->list){ ?>
				<div id="addtxt" class="add_C" style="line-height:23px;">
				<?php foreach($this->list as $key => $val){ ?>
				<span id="<?php echo $val['topic_id']; ?>" val="tag"><a rel="<?php echo $val['topic_id']; ?>" target="_blank" href="topic/<?php echo $val['url_token']; ?>"><?php echo $val['topic_title']; ?></a><a href="javascript:;" onClick="ajax_request(GET_BASE_URL + '/admin/feature/delete_topic_ajax/feature_id-<?php echo $this->feature['id']; ?>__topic_id-<?php echo $val['topic_id']; ?>');" title="Delete Topic">[x]</a></span>
				<?php } ?>
				</div>
				<?php } ?>
				<form id="_save_form" action="admin/feature/add_topic_ajax/feature_id-<?php echo $this->feature['id']; ?>" method="post" style="margin-top:10px;">
					<p>
						<label>Add a topic:&nbsp;&nbsp;
						<input class="text-input" style="width:120px;" type="text" id="topic" name="topic" value=""/>
						<input type="hidden" id="topic_id" name="topic_id" value=""/>
						&nbsp;&nbsp;
						<input class="button" type="button" onClick="ajax_post($('#_save_form'), _form_process);" value="Add" />
						</label>
					</p>
				</form>
			</div>
			<div class="tab-content" id="tab2" style="display: none;">
				<h3>Add Feature</h3>
				<form id="_add_form" action="admin/feature/save_ajax/" method="post">
					<p>
						<label>Feature title:</label>
						<input type="text" value="" class="text-input medium-input" name="title">
					</p>
					<p>
						<label>Feature description:</label>
						<input id="description" type="text" value="" class="text-input medium-input" name="description">
					</p>
					<p>
						<label>Special icon :</label>
						<input name="icon" class="upload-input" type="file">
						<br />
						<small>(Supported picture format: jpg,jpeg,gif,png)</small> </p>
					<p>
						<input class="button" type="button" onClick="ajax_post($('#_add_form'), _form_process);" value="Add a new topic" />
					</p>
					</label>
					</p>
				</form>
			</div>
		</div>
		<div class="clear"></div>
		<div id="notf_tip" style="display:none;" class="notification png_bg"> <a href="javascript:;" class="close"><img src="<?php echo GET_STATIC_URL;?>/admin/images/icons/cross_grey_small.png" alt="Close" /></a>
			<div id="notf_cont"></div>
		</div>
	</div>

<!-- footer -->
<?php TPL::output('admin/global/footer.tpl.htm'); ?>
<!-- footer -->

</div>
<!-- main -->

</div>

<script>

$("#topic").keyup(function(){
	$("#topic").focus();
});

$("#topic").autocomplete(GET_BASE_URL + "/search/ajax/search/type-topic_add", {
    width: 134,
	multiple: false,
	dataType: "json",
	parse: function(data) {
		var flag = 0;
		  return $.map(data, function(row) {
		  		if(flag == 1)
				{
				  return {
					  data: row,
					  value: row.sno,
					  result: row.name
				  }
				}
				flag = 1;
		  });
		
	},
	formatItem: function(item) {
		return item.name + "\n";
	}
}).result(function(event, data, formatted) {
	$('#topic_id').val(formatted);
	ajax_post($('#_save_form'), _form_process);
});

</script>

</body>
</html>
