<%@ tag pageEncoding="UTF-8"%>
<%@ attribute name="resourceId" type="java.lang.Integer" rtexprvalue="true" required="true" %>
<%@ attribute name="resourceType" type="java.lang.String" rtexprvalue="true" required="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<script type="text/javascript" src="${ctx}/resources/customize/js/ajaxfileupload.js"></script>

<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $("#attachmentCreate").click(
				function() {
					House365Util.createRemoteModal("附件上传",
							"${ctx}/attachment/attachmentToAddSection/${resourceType}/${resourceId}", {},
							function() { 
								
								var validValue = $('#detail_add_form').valid();
								var name = $("input[name='name']").val();
		                        var remark = $("input[name='remark']").val();
		                        var resourceType = $("input[name='resourceType']").val();
		                        var bizType = $('#bizType option:selected') .val();
		                        var resourceId = $("input[name='resourceId']").val();
		                        
								 if (validValue) {
									 $.ajaxFileUpload({
			                                // 文件上传服务器地址
			                                url : $("#detail_add_form").attr("action"),
			                                // 文件上传服务器地址
			                                fileElementId : "file",
			                                // 响应类型
			                                //dataType : "json",
			                                date: $("#detail_add_form").serialize(),
			                                data: {name:name, remark:remark,resourceType:resourceType,bizType:bizType,resourceId:resourceId},
			                                success : function(data, status) {
			                                	House365Util.ajaxTurn2Page($("#attachment_list_container"),$("#attachment_list_container").attr("base-url"),1);
		                                        $('#modal_dialog').modal('hide');
		                                        //alert(resourceId);
		        		                       // window.location.href="${ctx}/product/listPic?id="+resourceId;
		        		                       // window.location.pathname = "${ctx}/product/listPic?id="+resourceId ;
		        		                       // window.location.href="${ctx}/product/listPic?id="+resourceId;
		        		                      //  window.location.replace( "${ctx}/product/listPic?id="+resourceId )
		                                       // window.location.reload();
		                                        //window.location.reload();
			                                },
			                                error : function(data, status, e) {
			                                    // 失败后操作
			                                    alert("上传失败，请联系管理员！");
			                                }
			                            });
		                                return true;
		                            }else{
		                            	return false;
		                            }
								 
								
							}, "确定", "btn-success", "取消", "btn-danger");
				});
    })
</script>

<div class="sectionTitle">
	<div class="portlet-title">
		<h4>附件信息(楼盘主图、区位图和户型图)</h4>
		<div class="tools">
			<a href="#" class="icon icon-plus" id="attachmentCreate" title="添加接口"></a>
		</div>
	</div>
</div>

<div id="attachment_list_container" class="portlet-body lazy-section" base-url="${ctx}/attachment/attachmentListSection/${resourceType}/${resourceId}">
</div>
