<%@ Page Title="插件安装" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" CodeBehind="PlugInInstall.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.PlugIn.PlugInInstall" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="server">
   <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="server">
<style type='text/css'>
.mouseOver
{
    background-color:Red;
}
#exampleadmin
{
    width:300px;
    border-collapse:collapse;
}		
#exampleadmin td
{
    text-align:left;    
}		
#exampleadmin td span
{
     cursor:pointer;
}
#pluginMenuadmin
{
    color:Red;
}
#exampleuser
{
    width:300px;
    border-collapse:collapse;
}
#pluginMenuuser
{
    color:Red;
}		
#exampleuser td
{
    text-align:left;
}		
#exampleuser span
{
    cursor:pointer;
}
</style>
<script language="javascript">
    var clock = null;
    function getContent() {
        $.ajax({
            type: "Get",
            cache: false,
            url: '<%=BasePath %>Admin/Plugin/Ajax.xml',
            error: function(msg) {
                alert('Ajax请求出错！错误信息为：' + msg);
            },
            success: function(xml) {
                if ($("iscompleted", xml).text() != "True") {
                    $("#Info").html($("message", xml).text());
                    //getContent();
                } else {
                window.clearTimeout(clock);
                    if ($("iserror", xml).text() == "True") {
                        $("#loading").attr("src", "<%=BasePath %>Admin/Images/err.gif");
                        $("#Info").html($("message", xml).text());
                    } else {
                        $("input[id*='ButNext']").removeAttr("disabled");
                        $("#loading").attr("src", "<%=BasePath %>Admin/Images/ok.gif");
                    }
                }
            }
        });
    }
    var MenuAdminId = 0;
    var MenuUserId = 0;
    var pluginMenuadminInhiden = false;
    var pluginMenuuserInhiden = false;
    var pluginMenuadminInhidenId = -1;
    var pluginMenuuserInhidenId = -1;
    
		//表格排序
    function tableSort(obj) {
		    var tbody = $('#example'+obj+' > tbody');
			var rows = tbody.children();
			var selectedRow;
			//压下鼠标时选取行
			rows.mousedown(function(e){
			if (this.id == 'pluginMenu' + obj)
			   {
				selectedRow = this;
				tbody.css('cursor', 'move');
				}
				return false;	//防止拖动时选取文本内容，必须和 mousemove 一起使用
			});
			rows.mousemove(function(e){
			if (this.id == 'pluginMenu' + obj)
			   {
			   tbody.css('cursor', 'move');
			   }else
			   {
				tbody.css('cursor', 'default');
			   }
				return false;	//防止拖动时选取文本内容，必须和 mousedown 一起使用
			});
			//释放鼠标键时进行插入
			rows.mouseup(function() {
			    if (selectedRow) {
			        if (selectedRow != this) {
			            $(this).removeClass('mouseOver');
			            if (obj == 'admin') {
			                var objhidden = this;
			                if ($(objhidden).is("[id^='admin']")) {
			                    pluginMenuadminInhiden = true;
			                    var tempid = $(objhidden).attr("id");
			                    var tempre = /_(\d+)_/ig;
			                    while (r = tempre.exec(tempid)) {
			                        pluginMenuadminInhidenId = r[1];
			                    }
			                } else {
			                    if ($(objhidden).next() && $(objhidden).next().is("[id^='admin']") && !$(objhidden).next().is(":hidden")) {
			                        pluginMenuadminInhiden = true;
			                        pluginMenuadminInhidenId = $(objhidden).attr("id");
			                    } else {
			                        pluginMenuadminInhiden = false;
			                        pluginMenuadminInhidenId = -1;
			                    }
			                }
			                while ($(objhidden).next() && $(objhidden).next().is(":hidden")) {
			                    objhidden = $(objhidden).next();
			                }
			                $(objhidden).after($(selectedRow))//插入
			                MenuAdminId = $(this).attr("id");
			                if (pluginMenuadminInhiden) {
			                    var o = $("#pluginMenuadmin >td");
			                    if (o.html().substr(0, 12) != '&nbsp;&nbsp;') {
			                        o.html("&nbsp;&nbsp;" + o.html());
			                    }
			                } else {
			                    var o = $("#pluginMenuadmin >td");
			                    var str = o.html();
			                    if (str.substr(0, 12) == '&nbsp;&nbsp;') {
			                        o.html(str.substr(12, str.length));
			                    }
			                }
			            } else {
			                var objhidden = this;
			                if ($(objhidden).is("[id^='user']")) {
			                    pluginMenuuserInhiden = true;
			                    var tempid = $(objhidden).attr("id");
			                    var tempre = /_(\d+)_/ig;
			                    while (r = tempre.exec(tempid)) {
			                        pluginMenuuserInhidenId = r[1];
			                    }
			                } else {
			                    if ($(objhidden).next() && $(objhidden).next().is("[id^='user']") && !$(objhidden).next().is(":hidden")) {
			                        pluginMenuuserInhiden = true;
			                        pluginMenuuserInhidenId = $(objhidden).attr("id");
			                    } else {
			                        pluginMenuuserInhiden = false;
			                        pluginMenuuserInhidenId = -1;
			                    }
			                }
			                while ($(objhidden).next() && $(objhidden).next().is(":hidden")) {
			                    objhidden = $(objhidden).next();
			                }
			                $(objhidden).after($(selectedRow)) //插入
			                MenuUserId = $(this).attr("id");

			                if (pluginMenuuserInhiden) {  //处理缩进
			                    var o = $("#pluginMenuuser >td");
			                    if (o.html().substr(0, 12) != '&nbsp;&nbsp;') {
			                        o.html("&nbsp;&nbsp;" + o.html());
			                    }
			                } else {
			                    var o = $("#pluginMenuuser >td");
			                    var str = o.html();
			                    if (str.substr(0, 12) == '&nbsp;&nbsp;') {
			                        o.html(str.substr(12, str.length));
			                    }
			                }
			            }
			        }
			        tbody.css('cursor', 'default');
			        selectedRow = null;
			    }
			});
			//标示当前鼠标所在位置
			rows.hover(
				function(){					
					if(selectedRow && selectedRow != this)
					{
						$(this).addClass('mouseOver');	//区分大小写的，写成 'mouseover' 就不行						
					}					
				},
				function(){
					if(selectedRow && selectedRow != this)
					{
						$(this).removeClass('mouseOver');
					}
				}
			);
			
			//当用户压着鼠标键移出 tbody 时，清除 cursor 的拖动形状，以前当前选取的 selectedRow			
			tbody.mouseover(function(event){
				event.stopPropagation(); //禁止 tbody 的事件传播到外层的 div 中
			});
			$('#contentMenu').mouseover(function(event) {
			if ($(event.relatedTarget).parents('#contentMenu')) //event.relatedTarget: 获取该事件发生前鼠标所在位置处的元素
				{
					tbody.css('cursor', 'default');
					selectedRow = null;
				}
			});

}

function Ajax(obj) {
    var result = false;
    var url;
    if (obj == 'admin') {
        url = 'PluginInstall.aspx?IsAjax=true&IsSetMenu=true&IsSetAdmin=true&id=' + MenuAdminId + '&IsInHidden=' + pluginMenuadminInhiden;
    } else {
        url = 'PluginInstall.aspx?IsAjax=true&IsSetMenu=true&IsSetAdmin=fase&id=' + MenuUserId + '&IsInHidden=' + pluginMenuuserInhiden;
    }
    var html=$.ajax({
        type: "Get",
        cache: false,
        url: url,
        async: false,
        error: function(msg) {
            alert('Ajax请求出错！错误信息为：' + msg);
            result= false;
        },
        success: function(xml) {
            if ($("iserror", xml).text() == "True") {
                alert('Ajax请求出错！错误信息为：' + $("msg", xml).text());
                result= false;
            }
            result= true;
        }
    }).responseText;
    if (result) {
        return true;
    } else {
        return false;
    }
}

function list(actionobj,obj,flag) {
    var objid = $(obj).parent().parent().attr("id");
    var listid = actionobj+'_' + objid + '_';
    if (flag) {
        $("tr[id^=" + listid + "]").show();
        $(obj).find("img").attr("src", "<%=BasePath %>Admin/images/icon_del.gif");
        obj.onclick = function() { list(actionobj,this, false); return false; };
    } else {
        $("tr[id^=" + listid + "]").hide();
        $(obj).find("img").attr("src", "<%=BasePath %>Admin/images/icon_add.gif");
        obj.onclick = function() { list(actionobj, this, true); return false; };
        if(pluginMenuadminInhiden)
        {
            if (objid != pluginMenuadminInhidenId)
                return;
        }
        if (pluginMenuuserInhiden) {
            if (objid != pluginMenuuserInhidenId)
                return;
        }
        if (actionobj == 'admin') {
            if (pluginMenuadminInhiden) {
                var obj = $("#pluginMenuadmin");
                var islast = true;
                while ($(obj).next() && $(obj).next().is(":hidden")) {
                    obj = $(obj).next();
                    islast = false;
                }
                if (!islast) {
                    $(obj).after($("#pluginMenuadmin"));
                }
                pluginMenuadminInhiden = false;
                pluginMenuadminInhidenId = -1;
                
                var o = $("#pluginMenuadmin >td");
                var str=o.html();
                if (str.substr(0, 12) == '&nbsp;&nbsp;') {
                    o.html(str.substr(12,str.length));
                }
            }
        } else {
            if (pluginMenuuserInhiden) {
                var obj = $("#pluginMenuuser");
                var islast = true;
                while ($(obj).next() && $(obj).next().is(":hidden")) {
                    obj = $(obj).next();
                    islast = false;
                }
                if (!islast) {
                    $(obj).after($("#pluginMenuuser"));
                }
                pluginMenuuserInhiden = false;
                pluginMenuuserInhidenId = -1;

                var o = $("#pluginMenuuser >td");
                var str = o.html();
                if (str.substr(0, 12) == '&nbsp;&nbsp;') {
                    o.html(str.substr(12, str.length));
                }
            }
        }
    }
    
}

</script>
        <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
            <tr align="center">
              <td class="spacingtitle">
                <strong><asp:Label ID="LabTitle" runat="server" Text="Label"></asp:Label></strong>
              </td>
            </tr>
            <tr align="center" runat="server" id="pluginInfo">
               <td>
                   <pe:ExtendedLabel ID="LbInfo" runat="server" Text="" HtmlEncode="false"></pe:ExtendedLabel>
               </td>
            </tr>
            <tr align="center" runat="server" id="pluginInstallInfo" visible="false">
               <td>
                   <pe:ExtendedLabel ID="LbInstallInfo" runat="server" Text="" HtmlEncode="false"></pe:ExtendedLabel>
                   <div id="Info">
                   </div>
               </td>
            </tr>
            <tr align="center" runat="server" id="pluginInstallMenu" visible="false">
               <td>
               <table width="300" border="0" cellpadding="0" cellspacing="0" id="contentMenu" class="border" >
               <tr>
               <td  align="center">
               菜单设置
               </td>
               </tr>
               <asp:PlaceHolder ID="PlaceHolder1" runat="server">
               <tr>
               <td class="spacingtitle" align="left">
               后台菜单设置
               </td>
               </tr>
                              <tr>
               <td>
               <pe:ExtendedLabel ID="AdminMenu" runat="server" Text="" HtmlEncode="false"></pe:ExtendedLabel>
               </td>
               </tr>
               </asp:PlaceHolder>
               <asp:PlaceHolder ID="PlaceHolder2" runat="server">
                              <tr>
               <td class="spacingtitle" align="left">
               前台菜单设置
               </td>
               </tr>
               <tr>
               <td>
               <pe:ExtendedLabel ID="UserMenu" runat="server" Text="" HtmlEncode="false"></pe:ExtendedLabel>
               </td>
               </tr>
               </asp:PlaceHolder>
               </table>
               </td>
            </tr>
            <tr align="center">
              <td class="tdbgbottom">
                  <asp:Button ID="ButNext" runat="server" Text="下一步" OnClick="ButNext_OnClick" />
              </td>
            </tr>
        </table>
        <asp:HiddenField ID="HFStepTotal" runat="server" />
        <asp:HiddenField ID="HFStepNow" runat="server" />
        <br />
        <asp:PlaceHolder ID="HelpShow" runat="server" Visible="false">
            <div id="prompt-note">
	            <dl>
	            <dt class="prompt-note-tit">
	            <span>提示说明</span>
	            </dt>
	            <dd class="prompt-note-con">
	            <span style="COLOR: blue"><strong>注意：</strong></span>红色部份菜单为新增菜单，可以使用鼠标拖动。
	            </dd>  
	            </dl>
            </div>
        </asp:PlaceHolder>
</asp:Content>
