<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AccessoryContainer.aspx.cs" Inherits="eFrameWork.Customs.Base.AccessoryContainer" %>
<%@ Import Namespace="System.Data" %>
<script>
//文件上传回调
function AccessoryContainer_callback(files) {

        for (var i = 0; i < files.length; i++) {
            AccessoryContainer_append(files[i]);				
        }
};
function file_del()
{
    layer.confirm('确认要删除吗?', {title: "删除",shadeClose: true, area:['200','300'], btn:['删除', '取消'],
        btn1:function(idx, layero)
        {
            layer.close(idx);
            file_del1();
        }
    });
}
    function file_del1()
    {
        //if (!confirm("确认删除吗？")) { return; }
        var modelid = "<%=modelid%>";
        var index = $(menu_a).index();
        var input = getobj("eformdata_" + modelid);
        var model = input.value.toJson();
        var _model = model.get("eformdata_" + modelid);
        _model = _model[index];
        var src = _model["m1_f5"];
        if (src.toLowerCase().indexOf("/temp/") > -1) {
            var url = "<%=eBase.getVirtualPath()%>Plugins/ProUpload.aspx?act=del&file=" + src;
            $.ajax({
                type: "GET", async: true,
                url: url,
                dataType: "html",
                success: function (data) {
                    //alert("ok:" + data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert("error:" + XMLHttpRequest.responseText + "::" + XMLHttpRequest.status + "::" + XMLHttpRequest.readyState + "::" + XMLHttpRequest.statusText);
                }
            });
        }
        if (_model["ID"].length == 0) {
            _model = model.get("eformdata_" + modelid)
            _model.remove(index);
            //tbody.removeChild(tr);
            $(menu_a).remove();
        }
        else {
            _model["Delete"] = "true";
            menu_a.style.display = "none";
        }
        input.value = model.toJson();

    };
    function file_view()
    {
        var path = $(menu_a).attr("epath");
        path = path.replace(/\.\.\//g,"");
        viewFile(path);
    };

function AccessoryContainer_delete2(obj)
{
    
    
};

function AccessoryContainer_delete(obj)
{
	var modelid="<%=modelid%>";
	if(!confirm("确认删除吗？")){return;}
	var tr = getParent(obj, "tr");
	if (tr.getAttribute("eRowID") == null)
	{
	    tr = tr.parentNode;
	    tr = getParent(tr, "tr");
	}
	var tbody = getParent(tr, "tbody");
	var index=tr.Index();
	
	var input=getobj("eformdata_" + modelid);
	var model=input.value.toJson();
    //alert(model.tostring());

	
	
	var _model=model.get("eformdata_" + modelid);
	_model = _model[index];

	var src = _model["m1_f5"];
	if (src.toLowerCase().indexOf("/temp/") > -1) {
	    var url = "<%=eBase.getVirtualPath()%>Plugins/ProUpload.aspx?act=del&file=" + src;
	    $.ajax({
	        type: "GET", async: true,
	        url: url,
	        dataType: "html",
	        success: function (data) {
	            //alert("ok:" + data);
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown) {
	            //alert("error:" + XMLHttpRequest.responseText + "::" + XMLHttpRequest.status + "::" + XMLHttpRequest.readyState + "::" + XMLHttpRequest.statusText);
	        }
	    });
	}


	if(_model["ID"].length==0)
	{
		_model=model.get("eformdata_" + modelid)
		_model.remove(index);	
		tbody.removeChild(tr);
	}
	else
	{
		_model["Delete"]="true";
		tr.style.display="none";
	}
	
	//alert(index + "::" + _model["ID"]);
	//alert(_model.tostring());
	//alert(model.tostring());
	input.value = model.toJson();
};
function AccessoryContainer_append(data)
{
	var modelid="<%=modelid%>";
	var input=getobj("eformdata_" + modelid);
	var model=input.value.toJson();		
	
	var _data=model.get("eformdata_" + modelid);	
	var json = new eJson2();
	
	json["ID"]="";
	json["Delete"]="false";
	json["m1_f1"]=data.name;
	json["m1_f2"]=data.ext;
	json["m1_f3"]=data.size;
	json["m1_f4"]=data.time;
	json["m1_f5"]=data.url;	
	_data.append(json);
	

	input.value = model.toJson();




	var src = data.url;
	if (src.toLowerCase().indexOf("upload/") > 0) { src = src.substring(src.toLowerCase().indexOf("upload/")); }

	var html = '<a href="javascript:;" epath="' + src + '" oncontextmenu="contextmenu(event,this,\'' + src + '\');"';


	html += ' onclick="top.viewFile(\'' + src + '\');"';

	html += ' title="' + data.name + '&#10;文件类型：' + data.ext + '&#10;上传时间：' + data.time + '&#10;大小：' + data.size + '"';
	html += '>';
	html += '<dl>';
	html += '<dt class="' + ("<%=allExt%>".indexOf(data.ext) > -1 ? data.ext.replace(".","") : "file") + '">';
	if (".jpg.jpeg.gif.bmp.png.tif".indexOf(data.ext) > -1) {
	    html += '<img src="../' + src + '" />';
	}
	html += '</dt>';
	html += '<dd>' + data.name + '</dd>';
	html += '</dl>';
	html += '</a>';
	$(".filemanage_template_files span").append(html);
};
    var menu_a = null;
    function contextmenu(evt, obj, path) {
        menu_a = obj;
        var oRect = obj.getBoundingClientRect();
        var top = eScroll().top + oRect.top + obj.offsetHeight;
        var left = eScroll().left + oRect.right - obj.offsetWidth;
        top = eScroll().top + evt.clientY;
        left = eScroll().left + evt.clientX;
        var menu = getobj("etreeMenu");
        menu.style.top = top + "px";
        menu.style.left = left + "px";

        $(".etreeMenu a:contains('下载')").attr("href", "<%=aspxfile%>?" + (typeof (AppItem) == "string" && AppItem.length > 0 ? "AppItem=" + AppItem : "ModelID=" + ModelID) + "&act=down" + "&path=" + path + "&name=" + $(obj).find("dd").text());
        show_etreeMenu();
    };
    function bodyck(e) {
        hide_etreeMenu();
    };
    function bodykd(e) {
        e = window.event || e;
        if (e.keyCode == 27) { hide_etreeMenu(); }
    };
    function show_etreeMenu() {
        var menu = getobj("etreeMenu");
        menu.style.display = "";
        if (document.body.addEventListener) { document.body.addEventListener("keydown", bodykd, false); } else { document.body.attachEvent("onkeydown", bodykd); }
        if (document.body.addEventListener) { document.body.addEventListener("click", bodyck, false); } else { document.body.attachEvent("onclick", bodyck); }
    };
    function hide_etreeMenu() {
        var menu = getobj("etreeMenu");
        menu.style.display = "none";
        if (document.body.addEventListener) { document.body.removeEventListener('keydown', bodykd, false); } else { document.body.detachEvent("onkeydown", bodykd); }
        if (document.body.addEventListener) { document.body.removeEventListener('click', bodyck, false); } else { document.body.detachEvent("onclick", bodyck); }
    };
</script>
<%if(1==11){ %>
<textarea id="eformdata_<%=modelid %>" style="width:600px;height:120px;" name="eformdata_<%=modelid %>"><%=HttpUtility.HtmlEncode(getJson) %></textarea>
<%}else{%>
<input type="hidden" id="eformdata_<%=modelid %>" name="eformdata_<%=modelid %>" value="<%=HttpUtility.HtmlEncode(getJson) %>">
<%}%>
<%if(IsMobile && 1==21){ %>

<table id="eformlist_<%=modelid %>" width="100%" cellpadding="0" cellspacing="0">
<tbody>
<%foreach(DataRow dr in Data.Rows){%>
<tr eRowID="" >
<td>
    <dl class="eCard">
    <dt field="m1_f1"><%=dr["MC"].ToString()%></dt>
     <dd>
       <table width="100%">
           <tr>
               <td width="70" class="title">文件类型：</td>
               <td field="m1_f2"><%=dr["ext"].ToString()%></td>             
           </tr>
           <tr>
               <td class="title">文件大小：</td>
               <td field="m1_f3"><%=dr["size"].ToString()%></td>
           </tr>
           <tr>
               <td class="title">上传时间：</td>
               <td field="m1_f4"><%=string.Format("{0:yyyy-MM-dd HH:mm:ss}",dr["addTime"])%></td>
           </tr>
           <tr>
               <td class="title">操作：</td>
               <td field="m1_f5">
                   <a class="btn" href="javascript:;" style="<%=(".jpg.jpeg.gif.bmp.png.tif.".IndexOf(new eFileInfo(dr["path"].ToString()).fileExtension + ".")==-1? "color:#cccccc;" : "") %>" onclick="top.viewFile('<%=dr["path"].ToString() %>');">查看</a>
                   <a class="btn" href="<%=aspxfile%>?act=down&path=<%= dr["path"].ToString() %>" href_bak="<%= dr["path"].ToString()%>" target="_blank">下载</a>
                   <%if (!act.Contains("view")){%><a class="btn" href="javascript:;" onclick="AccessoryContainer_delete(this);">删除</a><%}%>
               </td>
           </tr>
       </table>
     </dd>
    </dl>
</td>
</tr>
<%}%>
</tbody>
<tfoot style="display:none;">
<tr eRowID="" >
<td>
<dl class="eCard">
    <dt field="m1_f1">&nbsp;</dt>
     <dd>
       <table>
           <tr>
               <td class="title">文件类型：</td>
               <td field="m1_f2">&nbsp;</td>             
           </tr>
           <tr>
               <td class="title">文件大小：</td>
               <td field="m1_f3">&nbsp;</td>
           </tr>
           <tr>
               <td class="title">上传时间：</td>
               <td field="m1_f4">&nbsp;</td>
           </tr>
           <tr>
               <td class="title">操作：</td>
               <td field="m1_f5">&nbsp;</td>
           </tr>
       </table>
     </dd>
    </dl>
</td>



</tr>
</tfoot>
</table>
<%if(act=="add" || act=="edit" || act=="copy"){ %>
<a href="javascript:;" class="subbtnadd"<%=PictureMaxWidth.Length > 1 ? " maxwidth=\"" + PictureMaxWidth + "\"" : "" %>>
<input class="file" type="file" id="file1" name="file" exclude="true" vpath="../" callback="AccessoryContainer_callback" onchange="autoupload_change(this);" preventexts="<%=eConfig.PreventExtensions.ToString()%>" multiple="">
</a>
<%}%>
<%}else{ %>


<div id="etreeMenu" class="etreeMenu" style="display:none;z-index:1000;">
<a href="javascript:;" style="dis3play:none;" onclick="file_view();">查看</a>
<a href="javascript:;" style="display:none;" onclick="file_edit();">编辑</a>
<a href="javascript:;" target="_blank">下载</a>
<%if (act.Length > 0 && act != "list" && !act.Contains("view"))
  {%>
<a href="javascript:;" onclick="file_del();">删除</a>
<%} %>
</div>
<div class="filemanage_template_files eimages_view" oncontextmenu="return false;" style="border:none;">

<span>
<%foreach(DataRow dr in Data.Rows){%>     
<a href="javascript:;" epath="<%=dr["path"].ToString() %>" oncontextmenu="contextmenu(event,this,'<%=dr["path"].ToString() %>');" onclick="viewFile('<%=dr["path"].ToString() %>');" 
     title="<%=dr["MC"].ToString()%>&#10;文件类型：<%=dr["ext"].ToString()%>&#10;上传时间：<%=string.Format("{0:yyyy-MM-dd HH:mm:ss}",dr["addTime"])%>&#10;大小：<%=dr["size"].ToString()%>">
<dl>
<dt class="<%=(allExt.IndexOf(dr["ext"].ToString().ToLower())>-1 ? dr["ext"].ToString().Replace(".",""):"file") %>"><%if (".jpg.jpeg.gif.bmp.png.tif.".IndexOf(new eFileInfo(dr["path"].ToString()).fileExtension + ".") > -1)
                   { %><img src="<%= (System.IO.File.Exists(dr["path"].ToString().toLocalPath()) ? "../" + dr["path"].ToString() : "../images/unknow.gif" ) %>" /><%} %></dt>
<dd><%=dr["MC"].ToString()%></dd>
</dl>
</a>
<%}%>
</span>

<%if (act.Length > 0 && act != "list" && !act.Contains("view"))
  {%>
<a href="javascript:;" class="fileupload"<%=PictureMaxWidth.Length > 1 ? " maxwidth=\"" + PictureMaxWidth + "\"" : "" %>>
<input class="file" type="file" id="file" name="file" exclude="true" vpath="../" callback="AccessoryContainer_callback" onchange="autoupload_change(this);" preventexts="<%=eConfig.PreventExtensions.ToString()%>" multiple="">
</a>
<%}%>
<div class="clear"></div>
</div>
<%}%>