<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script>
$().ready(function(){
	$("#updateForm").validate({
		rules: {
			"data[SoftwarePackage][download_url]" : {
				"required":true
			},
			"data[SoftwarePackage][file_size]" : {
				'digits' : true
			},
			"data[SoftwarePackage][show_order]" : {
				'digits' : true
			}
		},
		messages: {
			"data[SoftwarePackage][download_url]" : {
				"required":"下载地址不能为空"
			},
			"data[SoftwarePackage][file_size]" : {
				"digits":"文件大小必须为整数"
			},
			"data[SoftwarePackage][show_order]" : {
				"digits":"排列顺序必须为整数"
			}
		},
		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
	});
});

function checkPlatformScreenEdit(id){
	$("#universal_flag_edit").val($("#slc_platform_edit option:selected").attr("universal_flag"));
	var screen = $("#slc_screen_edit");
	if (screen.val()) {
		$(".input_screen").each(function(){
			if ($(this).val() == screen.val() && $("#input_platform"+$(this).attr("index")).val() == $("#slc_platform_edit").val() && $("#input_platform"+$(this).attr("index")).attr("id") != "input_platform"+id) {
				alert("平台和屏幕不能重复");
				screen.val("");
			}
		});
		$(".slc_screen").each(function(){
			if ($(this).val() && $(this).val() == screen.val() && $("#slc_platform"+$(this).attr("index")).val() == $("#slc_platform_edit").val()) {
				alert("平台和屏幕不能重复");
				screen.val("");
			}
		});
	}
}

//jar上传事件
var jarbutton = $("#upload_edit");
new AjaxUpload($("#upload_edit"), {
	action: "index.php?r=Software.uploadpackage&software_id="+$("#input_software_id").val(),
	name: "package_file",
	onSubmit: function(file, ext){
		if ((ext && /^(jad)$/i.test(ext))){
        	alert(ext+'文件请用jad专用上传按钮上传！');
        	return false;
		}
		jarbutton.html('<img src="images/ajax.gif"/>');
		this.disable();
	},
	onComplete: function(file, response){
		jarbutton.html('上传');
		this.enable();
		var data = eval("("+response+")");
		if (data.flag == 1) {
			$("#download_url").val(data.name);
			$("#oldname_edit").html("("+data.filename+"."+data.fileext+")");
			$("#file_type").val(data.fileext);
			$("#file_size").val(data.size);
		} else if (data.flag == -2) {
			alert("不能上传" + data.fileext + "文件!");
		} else if (data.flag == -3) {
			alert("文件大小超出指定范围!");
		}
	}
});

//jad上传事件
var jadbutton = $("#uploadjad_edit");
new AjaxUpload($("#uploadjad_edit"), {
	action: "index.php?r=Software.uploadpackage&software_id="+$("#input_software_id").val(),
	name: "package_file",
	onSubmit: function(file, ext){
		if (! (ext && /^(jad)$/i.test(ext))){
        	alert('jad专用上传按钮不能上传'+ext+'文件！');
        	return false;
		}
		jadbutton.html('<img src="images/ajax.gif"/>');
		this.disable();
	},
	onComplete: function(file, response){
		jadbutton.html('上传');
		this.enable();
		var data = eval("("+response+")");
		if (data.flag == 1) {
			$("#download_additional_url").val(data.name);
		} else if (data.flag == -2) {
			alert("不能上传" + data.fileext + "文件!");
		} else if (data.flag == -3) {
			alert("文件大小超出指定范围!");
		}
	}
});
</script>
<form id="updateForm" action="index.php?r=Software.editpackage" method="post">
	<input type="hidden" name="returnParams" value="<!--{$packagelistReturnParams}-->"/>
	<input type="hidden" name="data[SoftwarePackage][id]" value="<!--{$data.id}-->"/>
	<input type="hidden" name="data[SoftwarePackage][software_id]" value="<!--{$data.software_id}-->"/>
	<table class="tbl_edit" width="100%">
		<tr>
			<td class="td_name">平台</td>
			<td class="td_content"><select id="slc_platform_edit" name="data[SoftwarePackage][mobile_platform_id]" onchange="checkPlatformScreenEdit('<!--{$data.id}-->')">
				<!--{foreach from=$platform item=item}-->
				<option value="<!--{$item.id}-->" universal_flag="<!--{$item.universal_flag}-->" <!--{if $item.id eq $data.mobile_platform_id}-->selected<!--{/if}-->><!--{$item.platform_name}--></option>
				<!--{/foreach}-->
			</select><input type="hidden" id="universal_flag_edit" name="data[SoftwarePackage][universal_flag]" value="<!--{$data.universal_flag}-->"/></td>
		</tr>
		<tr>
			<td class="td_name">屏幕</td>
			<td class="td_content"><select id="slc_screen_edit" name="data[SoftwarePackage][mobile_screen_id]" onchange="checkPlatformScreenEdit('<!--{$data.id}-->')">
				<option value="">通用</option>
				<!--{foreach from=$screen item=item}-->
				<option value="<!--{$item.id}-->" <!--{if $item.id eq $data.mobile_screen_id}-->selected<!--{/if}-->><!--{$item.screen_size}--></option>
				<!--{/foreach}-->
			</select></td>
		</tr>
		<!--{if $data.download_type eq 2}-->
			<tr>
				<td class="td_name">包下载地址</td>
				<td class="td_content"><input type="text" class="text" id="download_url" name="data[SoftwarePackage][download_url]" value="<!--{$data.download_url}-->"/><span id="span_download_url"></span></td>
			</tr>
			<tr>
				<td class="td_name">jad下载地址</td>
				<td class="td_content"><input type="text" class="text" id="download_additional_url" name="data[SoftwarePackage][download_additional_url]" value="<!--{$data.download_additional_url}-->"/></td>
			</tr>
			<tr>
				<td class="td_name">文件类型</td>
				<td class="td_content"><input type="text" class="text" id="file_type" name="data[SoftwarePackage][file_type]" value="<!--{$data.file_type}-->"/></td>
			</tr>
			<tr>
				<td class="td_name">文件大小</td>
				<td class="td_content"><input type="text" class="text" id="file_size" name="data[SoftwarePackage][file_size]" value="<!--{$data.file_size}-->"/><span id="span_file_size"></span></td>
			</tr>
		<!--{else}-->
			<tr>
				<td class="td_name">包下载地址</td>
				<td class="td_content"><input type="text" class="text" id="download_url" name="data[SoftwarePackage][download_url]" value="<!--{$data.download_url}-->" readonly/><div class="button" id="upload_edit">上传</div><div id="oldname_edit" style="display:inline;"></div><span id="span_download_url"></span></td>
			</tr>
			<tr>
				<td class="td_name">jad下载地址</td>
				<td class="td_content"><input type="text" class="text" id="download_additional_url" name="data[SoftwarePackage][download_additional_url]" value="<!--{$data.download_additional_url}-->" readonly/><div class="button" id="uploadjad_edit">上传</div></td>
			</tr>
			<tr>
				<td class="td_name">文件类型</td>
				<td class="td_content"><input type="text" class="text" id="file_type" name="data[SoftwarePackage][file_type]" value="<!--{$data.file_type}-->" readonly/><input type="hidden" name="data[SoftwarePackage][download_type]" value="1"/></td>
			</tr>
			<tr>
				<td class="td_name">文件大小</td>
				<td class="td_content"><input type="text" class="text" id="file_size" name="data[SoftwarePackage][file_size]" value="<!--{$data.file_size}-->" readonly/><span id="span_file_size"></span></td>
			</tr>
		<!--{/if}-->
		<tr>
			<td class="td_name">排序</td>
			<td class="td_content"><input type="text" class="text" id="show_order" name="data[SoftwarePackage][show_order]" value="<!--{$data.show_order}-->"/><span id="span_show_order"></td>
		</tr>
		<tr>
			<td class="td_name">显示机型</td>
			<td class="td_content"><textarea class="textarea" name="data[SoftwarePackage][agent_description]"><!--{$data.agent_description}--></textarea></td>
		</tr>
		<tr>
			<td class="noborder"></td>
			<td class="noborder"><button type="submit" class="butsubmit">提交</button></td>
		</tr>
	</table>
</form>