<%@ Page Language="C#" AutoEventWireup="true"   CodeBehind="Pop_Users.aspx.cs" Inherits="Dotnet.Common.Pop_Users" %>
<%@ OutputCache Duration="300" VaryByParam="none" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> 
   
    <script src="../javascript/jquery-1.9.1.min.js"></script>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="../javascript/layer/layer.js"></script>
    
    <link href="../javascript/datatables/datatables.css" rel="stylesheet" />
    <script src="../javascript/datatables/datatables.min.js"></script>
    
    <link href="../javascript/Tree/bootstrap-treeview.min.css" rel="stylesheet" />
    <script src="../javascript/Tree/bootstrap-treeview.min.js"></script>
     
    <script src="../javascript/common.js"></script>
     <script src="../javascript/jquery.cookie.js"></script>
    <link href="../style/patch.css" rel="stylesheet" />
     

</head>
<body  style="margin:8px; font-size:13px;" >


    <form id="form1" runat="server">
     
       
         <style>
            #tree li {
             font-size:13px; line-height:13px;
            }
        </style>

     

       


 		 

    <table width="99%">
        <tr valign="top">
            <td valign="top" style="border-right:solid 1px #ccc; min-height:480px; padding-top:10px;" >
                  <div style="width:180px;padding:3px;">
                        <div id="tree"></div>
                   </div>
                 </td>
            <td valign="top">
 

<div style=" text-align:right"  class="form-inline">
	         
         

    已经选择人员: <span id="count" style="color:red">0</span> 人
    &nbsp; &nbsp; &nbsp;&nbsp;  
    
    
      <input class="form-control" id="txt_key" type="text"  placeholder="输入关键字搜索"   />
          
          <button class="btn btn-primary  " 
              onclick="if(!Issel()) return false; parent.setPopAttend($('#sel').val()); parent.layer.closeAll(); "
              > 提交选中</button>


     
    <button class="btn btn-success"  onclick="unSelect(); return false; ">反选</button> 
   
    
     
</div>

    
                
                           
  <div style="font-size:13px; margin:5px;">
                  
        最近访问(<a href="###" onclick="clears()">清除</a>): <span  style="margin-left:0px;" id="history"></span>
  </div>    



   <table   class="table table-hover" style="border-top:solid 1px #eee; display:none" id="tbl_users"  >
        <thead>
            <tr> 
                <th  style="width:50px">登录名</th>
                <th  style="width:70px">显示名</th>
                <th  style="width:200px">邮件</th>
                <th style="width:120px" >部门</th>              
                   
            </tr>
        </thead>

       <tbody></tbody>
        
    </table> 

         
         <div id="loading" style="width:600px; text-align:center;">
                    <img src="../images/loading.gif" /> 数据加载中
          </div>
                      
                 

            </td>
        </tr>

    </table>



         
     
         

    
         
         


   

       <input type="hidden" name="sel" id="sel"/>


                  
        
 
 <script>

      


     $(document).ready(function () { 

         $.ajax({
             url: 'json_dept.aspx',
             cache: false,
             dataType: 'json',
             success: function (datasource) {

                 $('#tree').treeview({
                     levels: 1,
                     data: datasource,
                     enableLinks: false,
                     onNodeSelected: function (event, key) {
                      }
                 });

                 InitTable();
             },
             error: function () {
                 
             }
         });

     });





     function InitTable()
     {
         

         $('#tbl_users').DataTable({
             stateSave: false, "sDom": '<"top">rt<"bottom"p><"clear">', 
             "ajax": 'json_users.aspx',
         });
       
         

         $("#tbl_users").show();

         $("#loading").hide();




         $('#tbl_users').on('draw.dt', function () {
            
             //$("#tbl_users th:nth-child(5)").hide();
             //$("#tbl_users th:nth-child(6)").hide();
             //$("#tbl_users td:nth-child(5)").hide();
             //$("#tbl_users td:nth-child(6)").hide();
             //$("#tbl_users").css("width", "100%");

         });



         var table = $('#tbl_users').DataTable();

         $('#tbl_users tbody').on('click', 'tr', function () {

             var count = $("#count").html();
            
             if ($(this).hasClass("selected"))
             {
                 $("#count").html((parseInt(count) - 1));
             }
           else
             {
               $("#count").html((parseInt(count) +1));
             }

             $(this).toggleClass('selected');
         });

          

         $('#txt_key').on('keyup', function () {
             table.column(3).search("").draw();
             table.search(this.value).draw();
         });

          

         $('#tree').on('nodeSelected', function (event, data) {
            
             table.search("").draw(); 
             if (data.tags == "==所有人员==") { 
                 table.column(3).search("").draw();
             }
             else { 
             table.column(3).search(data.tags).draw();
             }
         });

     }
      





     function unSelect() {

         var table = $('#tbl_users').DataTable();
         $('#tbl_users tbody tr').each(function () {
            $(this).toggleClass('selected');
         });

         var rows = table.rows('.selected').data();
         $("#count").html(rows.length);
     }



     function Issel() {
         var checked = 0;
         var result = '';
         var table = $('#tbl_users').DataTable();
         var _c = 0;

         var rows = table.rows('.selected').data();


         for (var i = 0; i < rows.length; i++) { 
             checked++;
             var tds = rows[i] 
             var username = tds[0];
             var displayname = tds[1]; 
             result = result +  "$" + username + "$" + displayname + "!"; 
         }


         if (checked > 0) {
             $("#sel").val(result);
             storeHistory();
             return true;
         }
         else {
             layer.alert('请至少选择一条记录', 12);
             return false;
         }
     }


 </script>

         
        
   <script>

       var itemSplit = "_b_";
       var cookieName = "bookHistory";
       var MAX = 12;
       function storeHistory() { 
           //  $abc$张三!$def$李四！
           var items = $("#sel").val().split('!'); 
           var count = items.length;
           if (count > 0) {
               for (var i = 0; i < count; i++) {
                   var item = items[i];
                   // $abc$张三
                   var _loginname = item.split('$')[1]; //abc
                   var _displayname = item.split('$')[2]; //张三
                   if (typeof (_loginname) != "undefined") {
                       SetHistory(_displayname, _loginname);
                   }
               }


           }

       }

       function clears() {
           Cookies.set(cookieName, null);
           $("#history").html("");
       }



       function SetHistory(cKey, cName) {
           var itemCookie = escape(cKey) + "+" + escape(cName) + itemSplit;
           var old_itemCookies = Cookies.get(cookieName);
           var insert = true;

           if (old_itemCookies == null) {
               Cookies.set(cookieName, itemCookie, { expires: 300 });
               $("#history").html("");
               InitHis();
               return;
           }
           else {

               try {
                   var old_itemCookie = old_itemCookies.split(itemSplit);
                   var c = old_itemCookie.length;
                   if (c > MAX)
                   {
                       c = MAX;
                   }

                   //COOKIE new  value
                   var newCookie = "";
                   for (var j = 0; j < c; j++)
                   {
                       newCookie += old_itemCookie[j] + itemSplit;
                   }
                   Cookies.set(cookieName, newCookie, { expires: 300 });


                   for (var j = 0; j < c; j++) {
                       if ((old_itemCookie[j] + itemSplit).indexOf(itemCookie) != -1) {
                           insert = false;
                       }
                   }
               }
               catch (e) {
               }
           }

           if (insert) {
               Cookies.set(cookieName, itemCookie + old_itemCookies, { expires: 300 });
               $("#history").html("");
               InitHis();
           }

       }




       function InitHis() {

           var itemCookies = Cookies.get(cookieName);

           if (itemCookies != null) {
               var cont = "";
               var itemCookie = itemCookies.split(itemSplit);

               for (var j = 0; j < MAX; j++) {
                   try {
                       var items = itemCookie[j];
                       var item = items.split("+");
                       var name = item[0]; //张三
                       var mail = item[1]; //zhangsan

                       if (name != 'null') {
                           cont = cont + "<a href=### onclick=setQuickHis(this,'" + name + "','" + mail + "')>" + unescape(name) + "</a>  ";
                       }
                   }
                   catch (e)
                   { }
               }

               $("#history").html(cont);


           }
           else {

           }

       }



       function setQuickHis(obj,k, v) {
           $(obj).css("color", "gray");
           var _r = unescape('$' + v + '$' + k);
           parent.setPopAttend(_r);
       }

       $(document).ready(function () {
           InitHis();
       } );

</script>

    </form>
</body>
</html>


  