<%@ Page Title="" Language="C#" MasterPageFile="Main.Master" AutoEventWireup="true" CodeFile="ApplicationItems.aspx.cs" Inherits="eFrameWork.Manage.ApplicationItems" %>
<%@ Import Namespace="EKETEAM.FrameWork" %>
<%@ Import Namespace="EKETEAM.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="nav">您当前位置：<a href="Default.aspx">首页</a> -> 应用管理</div>
<script>
var AppId = "<%=AppId%>";
function showloading()
{
	$("#divloading").show();
};
function hideloading()
{
	$("#divloading").hide();
};
function getValue(obj)
{
	if (obj.type.toLowerCase() == "radio" || obj.type.toLowerCase() == "checkbox") 
	{
		return (obj.checked ? "1" : "0");
    }
	else
	{
		return obj.value.encode();
    }
};
function addApp(obj)
{
	var _reload=parseBool(Attribute(obj,"reload"));
	var _url = "?act=addapp&AppId=" + AppId + "&t=" + now();
	showloading();
	$.ajax({
		type: "GET", async: true,
        url: _url,
        dataType: "json",
        success: function (data)
        {
			hideloading();
			//if(!_reload){return;}
            loadData();
        },
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			hideloading();
		}	
    });
};
function setApp(obj, ApplicationItemID, Item)
{
	var _reload=parseBool(Attribute(obj,"reload"));
	if (obj.getAttribute("oldvalue") == obj.value) { return; }
	var value = getValue(obj);
	if (value == "error") { return; }
	showloading();
    var url = "?act=setapp&AppId=" + AppId + "&ApplicationItemID=" + ApplicationItemID + "&item=" + Item + "&value=" + value + "&t=" + now();
    $.ajax({
		type: "GET", async: true,
		url: url,
		dataType: "html",
		success: function (data)
		{
		    if (Item == "finsh")
		    {
		        obj.style.color = obj.value == 1 ? "#33cc00" : "#FF0000";
		    }
			hideloading();
			if(!_reload){return;}
            loadData();
        },
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			hideloading();
		}		
	});
};
function delApp(obj, ApplicationItemID)
{
	var _reload=parseBool(Attribute(obj,"reload"));
	if (!confirm('确认要删除吗？')) { return; }
	showloading();
	var _url = "?act=delapp&AppId=" + AppId + "&ApplicationItemID=" + ApplicationItemID + "&t=" + now();
    $.ajax({
		type: "GET", async: true,
		url: _url,
        dataType: "json",
        success: function (data) {
			hideloading();
			$(getParent(obj,"tr")).remove();
			//if(!_reload){return;}
			//loadData();
        },
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			hideloading();
		}
    });
};
function loadData()
{
	showloading();
	var url = "ApplicationItems.aspx?AppId=" + AppId + "&act=getdata&t=" + now();
	$.ajax({
		type: "GET", async: true,
        url: url,
        dataType: "html",
        success: function (data) {
			hideloading();
            $("#content").html(data);
			bindEvent();
        },
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			hideloading();
		}
    });
};
function bindEvent()
{
	var tb=getobj("eDataTable_Items");
	if(tb)
	{
		tb=new eDataTable("eDataTable_Items",1);
		tb.moveRow=function(index,nindex)
		{
			var count=$("#eDataTable_Items tr").length;
			var cur=$("#eDataTable_Items tr:eq("+ nindex +")");
			
			//outText(cur.find("td:eq(1) span").html() + "::" + cur.attr("parentid") + "::"+ cur.find("td:eq(1)").css("text-indent"));		

			
			//if(nindex<index){document.title="上移";}else{document.title="下移";}
			var idx=0;
			if(nindex<count-1)
			{
				idx=nindex+1;
			}
			else
			{
				idx=nindex-1;
			}	
			var obj=$("#eDataTable_Items tr:eq("+ idx +")");
			cur.find("td:eq(2)").css("text-indent", obj.find("td:eq(2)").css("text-indent"));
			
			var url = "?act=setorders&AppId=" + AppId + "&AppItem=" + cur.attr("erowid");
			var oldpid= cur.attr("parentid");
			var newpid= obj.attr("parentid");
			if(oldpid!=newpid)
			{
				url+="&parentid=" + newpid;
				cur.attr("parentid",newpid);
			}			
			url+="&t=" + now();	
			var ids="";
			$("#eDataTable_Items tr[parentid='" + newpid + "']").each(function(index1,node){	
				if(index1>0){ids+=",";}
				ids+=$(node).attr("erowid");
			}); 
			if(ids.length==0){return;}
			
			//alert(ids);
			//return;
			//alert($("#eDataTable_Items tr[parentid='" + newpid + "']").length);
			//alert(url);
			//return;
			//outText(obj.find("td:eq(1) span").html() + "::" + obj.attr("parentid") + "::"+ obj.find("td:eq(1)").css("text-indent"));
			
			$.ajax({
				type: "POST", async: true,
				data:{ids:ids},
				url: url,
				dataType: "json",
				success: function (data) 
				{
					hideloading();
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					hideloading();
				}
   			});
			
			
			
		};
		tb.moveRow2=function(index,nindex)
		{
			$("#eDataTable_Items tbody tr td:last-child").each(function(index1,obj){
				$(obj).html(1+index1);
			}); 
			var ids="";
			$("#eDataTable_Items tbody tr td:nth-child(2) input:checked").each(function(index1,obj){	
				if(index1>0){ids+=",";}
				ids+=$(obj).parent().parent().attr("erowid");
			}); 
			if(ids.length==0){return;}
			alert(ids);
			return;
			showloading();
			var url = "?act=setorders&AppId=" + AppId + "&t=" + now();	
			$.ajax({
				type: "POST", async: true,
				data:{ids:ids},
				url: url,
				dataType: "json",
				success: function (data) 
				{
					hideloading();
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					hideloading();
				}
   			});
		};
	}
};
var icon_a = null;
function openIconForm(obj)
{
    icon_a = obj;
    var url = "../Plugins/IconSelect.aspx?path=icons";
    layer.open({
        type: 2
      , title: "选择图标"
      , shadeClose: true //点击遮罩关闭层
      , area: ["750px", "500px"]

      , content: url

      , success: function (layero, index) {
          arrLayerIndex.push(index);
      }
      , cancel: function (index, layero) {
          arrLayerIndex.pop();
      }

    });
};
function setIcon(path) {

    var img = $(icon_a).parent().find("img:eq(0)");
    img.attr("src", "../" + path);
    var input = $(icon_a).parent().find("input:eq(0)");
    input.val(path);
    //input.get(0).onBlur();
    input.trigger('blur');
    layer.close(arrLayerIndex.pop());
};
$(document).ready(function () {
	bindEvent();
});
function showsub(obj)
{
	layer.msg("暂不支持!");
	//obj.className = obj.className == "close" ? "open" : "close";
};
</script>
<style>
.text{display:inline-block;width:100%;border:1px solid #ccc;font-size:12px;height:23px;line-height:23px;}
.divloading{filter:alpha(opacity=50);-moz-opacity:0.5;-khtml-opacity: 0.5; opacity: 0.5; position:fixed;width:100%;height:100%;top:0px;left:0px;background:#cccccc url(images/loading.gif) no-repeat center center;}

.eDataTable td * {vertical-align:middle;}
a.close, a.open {border:0px solid #000;display:inline-block;width:18px;height:18px;}
a.close {background:url("../images/close.gif") no-repeat left center;}
a.open {background:url("../images/open.gif") no-repeat left center;}

</style>
<div id="divloading" class="divloading" style="display:none;">&nbsp;</div>
<div style="margin:6px;line-height:23px;"><%=appName%></div>
<div id="content" style="margin:6px;border:0px solid #ff0000;">

<asp:Literal id="litBody" runat="server" />


</div>
</asp:Content>
