<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title><!--{$UUDEV_PAGE_TITLE}--></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--{include file=elements/header.css.html}-->
<!--{include file=elements/header.js.html type=common}-->
<!--{include file=elements/header.js.html type=valid}-->
</head>
<body>
<div id="outside">
	<!--{include file=frame/top.html}-->
	<div id="mainareaContent">
		<!--{include file=frame/left.html}-->
		<div id="rightContent">
			<div id="topContent">
				<div class="sitmap">
					<span class="r"><!--{include file="elements/uuadvad.html"}--></span>模块管理&nbsp;&gt;&nbsp;音乐模块&nbsp;&gt;&nbsp;内容管理
				</div>
			</div>
			<div class="tabcontent">
				<a href="index.php?r=Music.musiclist" class="nolink">内管管理</a>
				<a href="index.php?r=SiteSet.musicset" class="link">属性设置</a>
				<a href="index.php?r=Music.musicListLayout" class="link">列表页布局</a>
					<a href="index.php?r=Music.musicPageLayout" class="link">内容页布局</a>
				<a href="index.php?r=Music.categorylist" class="link">风格</a>
				<a href="index.php?r=Music.languagelist" class="link">语种</a>
				<a href="index.php?r=Music.singerarealist" class="link">地区</a>
				<a href="index.php?r=Music.singerlist" class="link">歌手</a>
				<a href="index.php?r=Music.albumlist" class="link">专辑</a>
			</div>
			<div id="secrightContent">
				<div class="tableContent">
					<div style="display:none">
						<select id="slc_album">
							<option value="">请选择专辑</option>
							<!--{foreach from=$album item=item}-->
								<option value="<!--{$item.id}-->" singer_id="<!--{$item.singer_id}-->"><!--{$item.album_name}--></option>
							<!--{/foreach}-->
						</select>
					</div>
					<form id="editForm" action="index.php?r=Music.add" method="post">
						<input type="hidden" name="returnParams" value="<!--{$returnParams}-->"/>
						<table class="tbl_edit" width="100%">
							<tr>
								<td class="td_name">音乐名称<span class="red">*</span></td>
								<td class="td_content"><input type="text" class="text" id="title" name="data[Music][title]" value="<!--{$data.title}-->" maxlength='128'/><span id="span_title"></span></td>
							</tr>
							<tr>
								<td class="td_name">发布频道</td>
								<td class="td_content">
								<!--{if !empty($channel)}-->
									<!--{foreach from=$channel item=item name=channellist}-->
										<input type="checkbox" name="channel_id[]" value="<!--{$item.id}-->" <!--{if $item.id eq $channel_id}-->checked<!--{/if}-->/>[<!--{$item.id}-->]<!--{$item.channel_text}-->&nbsp;
										<!--{if ($smarty.foreach.channellist.index+1) % 4 == 0}--><br/><!--{/if}-->
									<!--{/foreach}-->
								<!--{else}-->
									无
								<!--{/if}-->	
								</td>
							</tr>
							<tr>
								<td class="td_name">风格</td>
								<td class="td_content"><select id="category_id" name="data[Music][category_id]">
									<option value="">请选择风格</option>
									<!--{foreach from=$category item=item}-->
										<option value="<!--{$item.id}-->" <!--{if $item.id eq $data.category_id}-->selected<!--{/if}-->><!--{$item.category_name}--></option>
									<!--{/foreach}-->
								</select><input type="hidden" id="category_name" name="data[Music][category_name]" value="<!--{$data.category_name}-->"/></td>
							</tr>
							<tr>
								<td class="td_name">语种</td>
								<td class="td_content"><select id="language_id" name="data[Music][language_id]">
									<option value="">请选择语种</option>
									<!--{foreach from=$language item=item}-->
										<option value="<!--{$item.id}-->" <!--{if $item.id eq $data.language_id}-->selected<!--{/if}-->><!--{$item.language}--></option>
									<!--{/foreach}-->
								</select><input type="hidden" id="language" name="data[Music][language]" value="<!--{$data.language}-->"/></td>
							</tr>
							<tr>
								<td class="td_name">歌手</td>
								<td class="td_content">
									<input type="text" class="text" id="singer_name" name="data[Music][singer_name]" autocomplete="off" value="<!--{$data.singer_name}-->" maxlength='32'/><input type="hidden" id="singer_id" name="data[Music][singer_id]" value="<!--{$data.singer_id}-->"/>&nbsp;
									<select id="album_id" name="data[Music][album_id]"></select><input type="hidden" id="album_name" name="data[Music][album_name]" value="<!--{$data.album_name}-->"/>
									<div id="singerlist" class="hidden"></div>
								</td>
							</tr>
							<tr>
								<td class="td_name">人气</td>
								<td class="td_content"><input type="text" id="click_count" class="number" name="data[Music][click_count]" value="0"/><span id="span_click_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">下载次数</td>
								<td class="td_content"><input type="text" id="down_count" class="number" name="data[Music][down_count]" value="0"/><span id="span_down_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">歌词</td>
								<td class="td_content"><textarea class="textarea" name="data[Music][lyric]"><!--{$data.lyric}--></textarea></td>
							</tr>
							<tr>
								<td class="noborder"></td>
								<td class="noborder"><button type="submit" class="butsubmit">提交</button>&nbsp;&nbsp;<button type="button" class="but2font" onClick="window.location.href='index.php?<!--{$returnParams}-->'">返回</button></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script>
$("#editForm").validate({
	rules: {
		'data[Music][click_count]':{
			'number': true,
			'digits' : true
		},
		'data[Music][down_count]':{
			'number': true,
			'digits' : true
		},
		"data[Music][title]": "required"
	},
	messages: {
		'data[Music][click_count]':{
			'number': '人气值必须为正整数',
			'digits':'人气值必须为正整数'
		},
		'data[Music][down_count]':{
			'number': '下载次数必须为正整数',
			'digits':'下载次数必须为正整数'
		},
		"data[Music][title]": "标题不能为空"
	},
	errorPlacement: function(error, element){
		$("#span_" + element.attr("id")).html(error).attr("class", "error");
	},
	submitHandler: function(form){
		setDisabled("button", window.document);
		form.submit();
	},
	errorClass: "invalid",
	success: function(label){
		label.parent().html("&nbsp;").attr("class", "valid");
	},
	onkeyup: false
});

$("#category_id").change(function(){
	$("#category_name").val($("#category_id option:selected").html());
});
$("#language_id").change(function(){
	$("#language").val($("#language_id option:selected").html());
});

var singer_name = $("#singer_name").val();
$("#singer_name").change(function(){
	$("#album_id").html($("#slc_album").html());
	$("#album_id").children().each(function(){
		if ($(this).val() != "" && $(this).attr("singer_id") != $("#singer_id").val()) {
			$(this).remove();
		}
	});
});
$("#singer_name").keyup(function(e){
	if (!e) e = window.event;
	if ($(this).val() != singer_name) {
		singer_name = $(this).val();
		$("#singer_id").val("");
		if (singer_name == "") {
			$("#singerlist").html("");
			$("#singerlist").attr("class", "hidden");
		} else {
			$.ajax({
				type: "get",
				url: "index.php?r=Music.getsinger",
				data: {
					singer_name : $("#singer_name").val()
				},
				cache: false,
				dataType: "json",
				success: function(data){
					var singer_index = 0;
					for (var e in data) {
						singer_index++;
					}
					if (singer_index > 0) {
						var str = "";
						for (var i = 0; i < singer_index; i++) {
							str += "<a class=\"automatch_list\">[" + data[i].id + "]" + data[i].singer_name + "</a>";
						}
						str += "<a class=\"automatch_close\">关闭</a>";
						$("#singerlist").html(str);
						$(".automatch_list").each(function(){
							$(this).click(function(){
								$("#singer_id").val($(this).html().substring($(this).html().indexOf("[")+1, $(this).html().indexOf("]")));
								$("#singer_name").focus();
								$("#singer_name").val($(this).html().substring($(this).html().indexOf("]")+1));
								singer_name = $("#singer_name").val();
								$("#singerlist").attr("class", "hidden");
							});
						});
						$(".automatch_close").click(function(){
							$("#singer_id").val("");
							$("#singerlist").html("");
							$("#singerlist").attr("class", "hidden");
						});
						$("#singerlist").attr("class", "automatch");
					} else {
						$("#singer_id").val("");
						$("#singerlist").html("");
						$("#singerlist").attr("class", "hidden");
					}
				}
			});
		}
	}
});

$("#singer_name").change();
</script>
</html>