<%@ page language="C#" autoeventwireup="true" inherits="disk__admin_manager_disk_ResourceFile, 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 currentColumn = "";
    var add = <%=add %>;
    var edit = <%=edit %>;
    var remove = <%=remove %>;
    $(function(){
        $("body").css("visibility","visible");
        $("#dataview").datagrid({
            toolbar:"#toolbar",
            fit:true,
            idfield:"id",
            border:false,
            pageSize:30,
            resizable:true,
            pagination:true,
            rownumbers:true,
            url:"disk_ResourceFile/disk_ResourceFile_dataview.aspx",
            queryParams:{
                df_id:'<%=id %>'
            },
            onLoadSuccess:function(){ $('#dataview').datagrid("unselectAll"); }
          
        });
        
        if(!add)
        $("#add").linkbutton('disable');
        if(!remove)
        $("#remove").linkbutton('disable')
        
//        $("#Catalog").tree({
//                url:"disk_Catalog/disk_Catalog_Tree.aspx",
//                onSelect:function(node){
//                    currentColumn = node.id;
//                    $("#dataview").datagrid("load",{ 'df_dcid' :node.id});
//                }
//        });
    });
    		
    function OperFormat(value,row,index){
        var str = "";
        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>&nbsp;&nbsp;":"<span class='disabled'>删除</span>&nbsp;&nbsp;";
        str +=edit?"<a href='javascript:void(0)' onclick=\"deleteFile('"+value+"')\" >删除所属文件</a> ":"<span class='disabled'>删除所属文件</span>"
        return str;
    }
																											             
    function nameFormat(value,row,index){
        return "<a href='disk_ResourceFile/disk_Down.aspx?id="+row.id+"'>"+value+"</a>";
    }
    
    function df_RecommendFormat(value,row,index){
        var str = "";
        str +=edit?"<input type='checkbox'  "+ ($.trim(value)=="True"?"checked='checked'":"")+" onclick=\"ToggleShow('"+row.id+"',this,'df_Recommend')\"  />"
        :$.trim(value)=="True"?"<span style='color:red'>是</span>":"否";
        return str;
	}
	
    function ToggleShow(key,obj,column){
 	     var check = $(obj);
         var schecked = check.attr("checked");
         $.ajax({
            type: "POST",
            url:"disk_ResourceFile/disk_ResourceFile_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 deleteItem(key){
         $.messager.confirm('确认','确定要删除选中吗?',function(r){
                 if(!r){ return }
                 load("删除中...");
                 $.ajax({
                    type: "POST",
                    url:"disk_ResourceFile/disk_ResourceFile_Delete.aspx",
                    dataType:"json",
                    data: {"deleteKey": key},
                    success: function(data){
                      unload();
                      if(data.state==1){
                          $.messager.show({title: '提示', msg: data.data});
                          $('#dataview').datagrid('reload').datagrid("unselectAll");
                      }
                      else{
                         $.messager.alert('错误',data.data,'message');
                      }
                   }
                });
         });
	 }
	 
	 function deleteFile(key){
         $.messager.confirm('确认','确定要删除该项的资源文件吗?',function(r){
                 if(!r){ return }
                 load("删除中...");
                 
                 $.ajax({
                    type: "POST",
                    url:"disk_ResourceFile/disk_ResourceFile_Delete.aspx",
                    dataType:"json",
                    data: {"deleteFile":key},
                    success: function(data){
                      unload();
                      if(data.state==1){
                          $.messager.show({title: '提示', msg: data.data});
                      }
                      else{
                         $.messager.alert('错误',data.data,'message');
                      }
                   }
                });
         });
	 }
	 
	 

	   function editItem(key){
		  window.open("disk_ResourceFile/disk_ResourceFile_Edit.aspx?id="+key)
	   }
	   function deleteList(){
	         var row = $('#dataview').datagrid('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_ResourceFile/disk_ResourceFile_Delete.aspx",
	                        dataType:"json",
	                        data: {"deleteList": list.join(",")}, 
	                        success: function(data){
	                          unload();
	                          if(data.state==1){
	                              $.messager.show({ title: '提示', msg: "总共删除"+data.data+"条信息" });
	                              $('#dataview').datagrid('reload').datagrid("unselectAll");
	                          }else{
                                 $.messager.alert('错误',data.data,'message');
                              }
	                  
	                       }
	                    });
	                 }
	         });
       }

	   function Add(){

//		 	ShowDialog("add","disk_ResourceFile/disk_ResourceFile_Insert.aspx?id="+currentColumn,850,350,100,100);
		 	
		    window.location="disk_ResourceFile/disk_ResourceFile_Insert.aspx?id="+currentColumn;
		 	
		 	
	   }
       function reload(param){
            if(param=='last'){
                var grid = $('#dataview'); 
                var gridOptions = grid.datagrid("options"); 
                var options = grid.datagrid('getPager').data("pagination").options;  
                var pagenumber = options.total==0?1:Math.ceil( options.total/options.pageSize);
                gridOptions.pageNumber = pagenumber 
                options.pageNumber = pagenumber;
          
                $("#dataview").datagrid("load",{});
            }
            $("#dataview").datagrid("load",{});
       }
       function query(){
            var selects = $("#txtQCatalog").combotree("getValues");
            var list = new Array();
            
            for(var index =0; index<selects.length;index++){
                  list.push("'"+selects[index]+"'");
	        }
	     
	        $("#dataview").datagrid("load",{
	             df_name:$("#txtQname").val(),
	             catalog:list.join(','),
	             df_code:$("#txtQcode").val(),
	             df_user:$("#txtQUser").val(),
	             df_Recommend:$("#txtQtj").get(0).checked,
	             df_term:$("#ddlTerm").val()
	        });
   	   }
   	   function allData(){
   	       $("#dataview").datagrid("load",{});
   	   }
    </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="ur_name" width="70" sortable="true">上传用户</th>
                    
                    <th field="t_name" width="150" sortable="true">所属学期</th>
                    
					<th field="dc_name" width="80" sortable="true">所属科目</th>
	
					<th field="df_name" width="300"  formatter='nameFormat' >教案名称</th>
			
					<th field="df_code" width="80" sortable="true">资源提取码</th>
				
					<th field="df_Recommend" width="70" formatter='df_RecommendFormat' >推荐</th>
					
					<th field="df_cdate" width="120" sortable="true">修改日期</th>
					
				    <th field="id" width="150" formatter='OperFormat'>操作</th>
				    
                </tr>
            </thead>
        </table>
    </div>
    
<%--     
     <div  region="east" border="false" title="栏目" split="true" style="width: 200px;">
        <ul id="Catalog" class="easyui-tree">
        </ul>
     </div>--%>
    <div id="toolbar" style="height: 55px">
        教案名称：
        <input id="txtQname" name="name" type="text" maxlength="255" onkeydown="if(event.keyCode==13)query()" style="width: 82px" />
        提取码：
        <input id="txtQcode" name="name" type="text" maxlength="255" onkeydown="if(event.keyCode==13)query()" style="width: 61px" />
        上传用户：
        <input id="txtQUser" name="name" type="text" maxlength="255" onkeydown="if(event.keyCode==13)query()" style="width: 45px" />
        所属学期：
        <select id="ddlTerm" style="width: 111px">
            <%=bindTerm() %>
        </select>
        
        是否推荐：<input id="txtQtj" type="checkbox" />
        <br />
        <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> 
        目录：
        <select id="txtQCatalog" class="easyui-combotree" name="catalog" data-options="url:'disk_Catalog/disk_Catalog_Tree.aspx',cascadeCheck:false" multiple="multiple" style="width: 300px">
        </select>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-cancel'" onclick='$("#txtQCatalog").combotree("clear")' title="清空选项"></a>
        <a href="#" class="easyui-linkbutton"  iconcls="icon-search" plain="true" onclick="query()">查询</a>
        <a href="#" class="easyui-linkbutton"  iconcls="icon-search" plain="true" onclick="allData()">所有</a>
      
     
    </div>
    
</body>
</html>
