<%@ Page language="c#" Codebehind="share.aspx.cs" AutoEventWireup="True" Inherits="Webdisk.share" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
		<META http-equiv="Content-Type" content="text/html; charset=gb2312">
		<% @ Import Namespace="Webdisk" %>
        <link rel="stylesheet" href="js/artDialog/css/ui-dialog.css" />
		<link href="<%=xml.GetStyle()%>" type=text/css rel=stylesheet>
		<link href="css/webdialog.css" type=text/css rel=stylesheet>
			
            <style type="text/css">
            html,body{overflow:hidden; height:100%;}
            form
            {
                overflow-y:auto;overflow-x:hidden;height:100%;}
            </style>
	<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="js/artDialog/dist/dialog-plus.js" type="text/javascript"></script>
	<script type="text/javascript" language="javascript">
	    function EditOpt() {
	        Webdisk.share.EditOpt(document.all.overshare.checked);
	    }
	    function Result() {
	        var kind = document.getElementById("kind1");
	        if (kind.value == '不指定') {
	            document.all("kind2").length = 0;
	            document.all("kind2").options.add(new Option('不指定', '不指定'));
	        }
	        else Webdisk.share.GetKind2All(kind.value, get_Result_CallBack);
	    }

	    function get_Result_CallBack(response) {
	        if (response.value != null) {
	            document.all("kind2").length = 0;
	            var ds = response.value;
	            if (ds != null && typeof (ds) == "object" && ds.Tables != null) {
	                for (var i = 0; i < ds.Tables[0].Rows.length; i++) {
	                    var name = ds.Tables[0].Rows[i].rootkind1;
	                    var id = ds.Tables[0].Rows[i].rootkind3;
	                    document.all("kind2").options.add(new Option(name, id));
	                }
	                if (document.all("kind2").options.length == 0) document.all("kind2").options.add(new Option("不指定", "0"));
	                document.all.hidkind.value = document.all.kind2.value;
	            }
	        }
	        return
	    }
	    function closeWindow(flag) {
	        if (window.top.closeWindow) {
	            if (flag) {
	                window.top.closeWindow(flag);
	            } else {
	                window.top.closeWindow();
	            }
	        } else {
	            history.go(-1)
	        }
	    }
	    function shareuser(url) {
	        window.open(url, '', 'scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no,location=no,width=800,height=650,top=' + screen.availWidth + ',left=' + screen.availHeight);
	    }
	    function removeItem() {
	        var checks = $(".chkSelect:checked");
	        if (checks.size() > 0) {
                checks.closest("li").remove();
	        }
        }
        function finishShareNoClose() {
            var sharelist = $("#Label1").html().replace(/<br>/gm, ",");
            var checks = $(".chkSelect");
            var targets = "";
            if (checks.size() > 0) {
                checks.each(function () {
                    targets = targets + "," + this.value;
                });
                targets = targets.substr(1);
                $.ajax({
                    url: "FileSpaceHandler.ashx?cmd=Share",
                    dataType: "json",
					cache:false,
                    type: "POST",
                    data: { username: $("#hiddenUser").val(), sendsms: $("#sendsms").attr("checked") == "checked", sharelist: encodeURI(sharelist),shareIds:$("#hidIds").val(), targets: targets, content: encodeURI($("#Label1").val()), overshare: $("#overshare").attr("checked") == "checked" },
                    success: function (data) {
                    }
                });
            }
        }
        function finishShare(self) {
            var sharelist = $("#Label1").html().replace(/<br>/igm, ",");
            var checks = $(".chkSelect");
            var shareWindow = this, alertWindow = dialog({align: 'top left',quickClose: true}).show(self);
            var targets="";
            if (checks.size() > 0) {
                checks.each(function () {
                    targets=targets+ ","+this.value;
                });
                targets=targets.substr(1);
                $.ajax({
                    url: "FileSpaceHandler.ashx?cmd=Share",
                    dataType:"json",
					cache:false,
                    type: "POST",
                    data:{username:$("#hiddenUser").val(),sendsms:$("#sendsms").attr("checked")=="checked",sharelist:encodeURI(sharelist),shareIds:$("#hidIds").val(),targets:targets,content:encodeURI($("#Label1").val()),overshare:$("#overshare").attr("checked")=="checked"},
                    success:function(data){
                        if (data.code == 0) {
                            alertWindow.content("<span style='color: #1DA7DD;'>共享成功</span>");
                        } else {
                            alertWindow.content("<span style='color: #f00;'>共享失败</span>");
                        }
                        setTimeout(function () {
                            closeWindow(true);
                        }, 2000);
                    }
                });
            }else{
				setTimeout(function () {
					closeWindow(true);
				}, 2000);
			}
        }
	    function deleteShara() {
	        var id = getUrlParam("id");
	        var shareWindow = this;
	        var alertWindow = dialog().showModal();
	        $.ajax({
	            url: "FileSpaceHandler.ashx?cmd=CancelShare",
	            dataType: "json",
				cache:false,
	            type: "POST",
	            data: { user: $("#hiddenUser").val(), ids: id, isFile: getUrlParam("type"), overShare: $("#overshare").attr("checked") == "checked" },
	            success: function (data) {
	                if (data.code == 0) {
	                    alertWindow.content("取消共享成功");
	                } else {
	                    alertWindow.content("取消共享失败");
	                }
	                setTimeout(function () {
//	                    alertWindow.close().remove();
	                    closeWindow(true);
	                }, 2000);
	            }
	        });
	    }
	    function getUrlParam(type) {
	        var s = location.search;
	        var urlParam = {};
	        if (s != "") {
	            if (s.indexOf('?') < 0) {
	                urlParam = {};
	            } else {
	                var sarr = s.substr(s.indexOf('?') + 1).split("&");
	                var tarr;
	                for (i = 0; i < sarr.length; i++) {
	                    tarr = sarr[i].split("=");
	                    urlParam[tarr[0]] = tarr[1];
	                }
	            }
	        }
	        return urlParam[type];

	    }

            </script>
</HEAD>
	<body style="margin:0px;padding:0px;">
		<form id="Form1" method="post" runat="server" style="margin:0px;padding:0px;">
		<table class="wfrom-table">
			<tbody>
				<tr style="display:none;">
					<td colspan="2">
						<asp:linkbutton id="LinkButton1" style="color:#0000FF;" runat="server" onclick="LinkButton1_Click">>>>点此处设置发布</asp:linkbutton>
					</td>
				</tr>
				<tr>
					<td colspan="2">
					<label class="input-check wtc-1EA7DE" style="float:right;">
							<input id="overshare" type="checkbox" checked="" name="overshare" runat="server" onchange="EditOpt();">
							覆盖子目录及文件的共享设置
						</label>
					<span class="input-label">以下是您共享的目录和文件：</span><br>
						<div class="wtips" style="max-height: 100px;overflow-y:auto;overflow-x:hidden;clear:both;">
						<asp:label id="Label1" runat="server"></asp:label>
						</div>
                        <input type="hidden" id="hidIds" runat="server"/>
					</td>
				</tr>
				<tr>
					<td class="label" style="width: 120px;">共享给下列用户/组：
					</td>
					<td>
                        <a class="wbtn-4" id="remove" href="javascript:void(0);" onclick="removeItem();" style="float:right;">移除选定</a>
						<a class="wbtn-4" id="Button52" href="javascript:void(0);" onclick="finishShareNoClose()+shareuser('sel_dept.aspx');" >添加部门</a>
						<a class="wbtn-4" id="Button54" href="javascript:void(0);" onclick="finishShareNoClose()+shareuser('searchAdd_user.aspx?share=1');" >添加用户</a>
						
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<ul class="listContent" style="max-height:190px;overflow-y:auto;overflow-x:hidden;">
							<li ><span class="itme1">部门或用户</span><span  class="itme2">权限</span><span  class="itme3">操作</span></li>
							<asp:repeater id="repeater" runat="server" enableviewstate="False">
								<itemtemplate>
									<li>
										<span class="itme1"><%# DataBinder.Eval(Container.DataItem, "ico") %><%# DataBinder.Eval(Container.DataItem, "name") %></span>
										<span class="itme2"><%# DataBinder.Eval(Container.DataItem, "type") %></span>
										<span class="itme3">
										<label><input type="checkbox" runat="server" id="chkSelect" class="chkSelect" value='<%#DataBinder.Eval(Container.DataItem,"index")%>' name="chkSelect"/>   
											勾选移除</label>
										</span>
									</li> 
								</itemtemplate>
							</asp:repeater>
						</ul>
					</td>
					</tr><tr id="showa3" runat="server">
							<td  colspan="2">
								<label class="input-check wtc-1EA7DE">
									<input id="sendsms" type="checkbox" name="sendsms" runat="server">发送短消息给共享人</font>
								</label>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<input class="wbtn-1" id="btnfinish" type="button" value="完成设置" name="btnfinish" onclick="finishShare(this)">
								<input id="btnremove" type="button" value="删除共享" class="wbtn-1" onclick="deleteShara()">
								<input class="wbtn-2" type="button" value="取消" name="btnreturn" id="btnreturn" onclick="closeWindow()">
                                 <label id="notice" runat="server" style="color:Red">您所使用的角色在共享后需进行后台审核</label>
								<input id="hidcompany" style="WIDTH: 23px; HEIGHT: 22px" type="hidden" size="1" name="hidcompany" runat="server">
								<input id="hiddept" style="WIDTH: 23px; HEIGHT: 22px" type="hidden" size="1" name="hiddept" runat="server">
								<input id="hiduser" style="WIDTH: 23px; HEIGHT: 22px" type="hidden" size="1" name="hiduser" runat="server">
								<input id="type" style="WIDTH: 23px; HEIGHT: 22px" type="hidden" size="1" name="type" runat="server">
								<input id="HdnSelectedValues" type="hidden" name="HdnSelectedValues" runat="server">
	<input type="hidden" id="hiddenUser" value ='<%=Session["username"]==null?"":Session["username"].ToString() %>'/>     
							</td>
						</tr>
			</tbody>
		</table>
	</form>
	</body>
</HTML>