<%@ page language="C#" autoeventwireup="true" inherits="disk__admin_manager_disk_Catalog, App_Web_nrfe0pyq" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>操作</title>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/easy_ui/jquery.min.js?v=1.7.2")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/easy_ui/jquery.easyui.min.js?v=1.3")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/easy_ui/locale/easyui-lang-zh_CN.js?v=1.0")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/easy_ui/jquery.load.js?v=1.0")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/easy_ui/jquery.json.js?v=1.0")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/easy_ui/jquery.easyui.validtor.js?v=1.0")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/disk/control/js/PageDialog.js?v=1.0")%>"></script>
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/disk/control/easy_ui/themes/gray/easyui.css?v=1.0")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/disk/control/easy_ui/themes/icon.css?v=1.0")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/disk/control/easy_ui/load.css?v=1.0")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/disk/control/css/main.css?v=1.0")%>" />

    <script language="javascript" type="text/javascript">
    var add = <%=add %>;
    var edit = <%=edit %>;
    var remove = <%=remove %>;
    
    $(function(){
         $("body").css("visibility","visible");
         $("#dataview").treegrid({
                toolbar:"#toolbar",
                url:"disk_Catalog/disk_Catalog_Nav.aspx",
               	idField:'id',
				treeField:'name',
				rownumbers:true,
			    singleSelect:false,
                fit:true
         });
        if(!add)
        $("#add").linkbutton('disable');
        if(!remove)
        $("#remove").linkbutton('disable')
    })
    
    function ToggleShow(key,obj,column){
         var check = $(obj);
         var schecked = check.attr("checked");
         $.ajax({
            type: "POST",
            url:"disk_Catalog/disk_Catalog_SetShow.aspx",
            data: {"id":key,"show":schecked=="checked"?true:false,"column":column},
            success: function(data){
                 var result = $.parseJSON(data);
                 if(result.state==1){
                 }else{
                    check.get(0).checked = false;$.messager.show({title: '错误',msg: result.data});
                 }
            }
         }); 
         event.stopPropagation();
    }
    
    
	function deleteList(){
	         var row = $('#dataview').treegrid('getSelections');
	         if(row==null){
	             $.messager.alert('提示',"请选择删除项！",'message');
	             return;
	         }
	         $.messager.confirm('确认','确定要删除选中吗?',function(r){
	                 if(r){
	                     load("删除中...");
	                     var list = new Array();
	                     for(var index =0; index<row.length;index++){
	                        list.push(row[index].id);
	                     }
	                     $.ajax({
	                        type: "POST",
	                        url:"disk_Catalog/disk_Catalog_Delete.aspx",
	                        dataType:"json",
	                        data: {"deleteList": list.join(",")}, 
	                        success: function(data){
	                          unload();
	                          if(data.state==1){
	                              $.messager.show({ title: '提示', msg: "总共删除"+data.data+"条信息" });
	                              $('#dataview').treegrid('reload').treegrid("unselectAll");
	                          }else{
                                 $.messager.alert('错误',data.data,'message');
                                 $('#dataview').treegrid('reload').treegrid("unselectAll");
                              }
	                  
	                       }
	                    });
	                 }
	         });
       }
       
    function deleteItem(key){
     $.messager.confirm('确认','确定要删除选中吗?',function(r){
             if(!r){ return }
             load("删除中...");
             $.ajax({
                type: "POST",
                url:"disk_Catalog/disk_Catalog_Delete.aspx",
                dataType:"json",
                data: {"deleteKey": key},
                success: function(data){
                  unload();
                  if(data.state==1){
                      $.messager.show({title: '提示', msg: data.data});
                      $('#dataview').treegrid('reload').treegrid("unselectAll");
                  }
                  else{
                     $.messager.alert('错误',data.data,'message');
                  }
               }
            });
     });
    }
    function editItem(key){
		    ShowDialog("edit","disk_Catalog/disk_Catalog_Edit.aspx?id="+key,500,300,100,100);
    }
    
    function OperFormat(value,row,index)
    {
	   var str = "";
	   str +=add?"<a href='javascript:void(0)' onclick=\"addChild('"+value+"')\">新增子目录</a>&nbsp;|&nbsp;":"<span class='disabled'>新增子目录</span>&nbsp;&nbsp;";
       str +=edit?"<a href='javascript:void(0)' onclick=\"editItem('"+value+"')\" >编辑</a>&nbsp;&nbsp;":"<span class='disabled'>编辑</span>&nbsp;&nbsp;";
       str +=remove?"<a href='javascript:void(0)' onclick=\"deleteItem('"+value+"')\">删除</a>":"<span class='disabled'>删除</span>";
       return str;
    }
    														
    function dc_showFormat(value,row,index){
		    return "<input type='checkbox'  "+ ($.trim(value)=="True"?"checked='checked'":"")+" onclick=\"ToggleShow('"+row.id+"',this,'dc_show')\"  />";
    }
    
    function addChild(parent){
            ShowDialog("addChild","disk_Catalog/disk_Catalog_Insert.aspx?parent="+parent,500,300,100,100);
    }
    
	function Add(){
		 	ShowDialog("add","disk_Catalog/disk_Catalog_Insert.aspx",500,300,100,100);
	}		
	
	function reload(param){
            $('#dataview').treegrid('reload');
    }
    
 
    </script>
</head>
<body class="easyui-layout" style="visibility:hidden" >
    <div region="center" border="false">
	    <table id="dataview">
            <thead>
                <tr>  
                    <th field="ck" checkbox="true"></th>
                    <th field="name" width="350" >科目名称</th>
                    <th field="dc_sort" width="70" >科目排序</th>
                    <th field="dc_show" width="100" formatter='dc_showFormat'>是否显示</th>
                    <th field="dc_cdate" width="120">修改日期</th>
                     <th field="id" width="150" formatter='OperFormat'>主键</th>
                </tr>
            </thead>
	    </table>
    </div>

    <div id="toolbar">
        <a id="add" href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="Add()">添 加</a>
        <a id="remove" href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="deleteList()">删除</a>
    </div>
</body>
</html>
