<%--
  Created by IntelliJ IDEA.
  User: llh
  Date: 2016/1/7
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script >
  (function ($, win) {
      var jobDataset = {};
      var Util = $.Util;
      var schemeId = '${schemeId}';
      
      var cacheDatasetId = Util.isStrEmpty(${cacheDatasetId})?{}:${cacheDatasetId};
      //数据集处理
      jobDataset.attr = {
        grid:null,
        $searchNm: $('#inp_datasetNm'),
        init: function () {
            if(this.grid)
                return;
               var me = this;
            this.$searchNm.ligerSearch({onClick: function (value) {
                var l_grid1 = $("#div_dataset_grid .l-grid1 .l-grid-body-table");
                var l_grid2 = $("#div_dataset_grid .l-grid2 .l-grid-body-table");
                var tr1 = l_grid1.find("tr");
                var tr2 = l_grid2.find("tr");
                if(Util.isStrEmpty(value)) {
                    $('tr',l_grid1).show();
                    $('tr',l_grid2).show();
                    return false;
                }
                $('tr',l_grid1).hide();
                $('tr',l_grid2).hide();
                tr2.each(function(index,element){
                    var td = $(this).find("td").find("div").eq(2);
                    if(td.html().indexOf(value)>=0){
                        td.closest('tr').show();
                        tr1.eq(index).show();
                    }
                });
            }});

            this.grid = $("#div_dataset_grid").ligerGrid({
                url: '${contextRoot}/crawler/getSchemeDataSets',
                parms:{versionId:"${versionId}"},
                method: 'get',
                checkbox: true,
                width:560,
                height:400,
                usePager: false,
                columns: [
                    { display: 'datasetId', name: 'datasetId', hide:true },
                    {display:'数据集编码',name:'datasetCode', width: '50%'},
                    {display:'数据集名称',name:'datasetName',width: '50%'}
                ],
                onAfterShowData: function (gridData) {//显示完数据事件
                    var checkRowsList = jobDataset.attr.grid.getCheckedRows();
                        if(gridData.detailModelList.length==checkRowsList.length){
                            $(".l-grid1 .l-grid-header-table tr").eq(0).addClass("l-checked");
                        }
                },
                //默认选中
                isChecked:function(row){
                    
                    var datasetIdList = Util.isObjEmpty(cacheDatasetId) ?[]:cacheDatasetId.split(",");
                    for(var i=0;i<datasetIdList.length;i++){
                        if(datasetIdList[i]== row.datasetId){
                            return true;
                        }
                    }
                    return false;
                },
                //选中修改值
                onCheckRow:function(checked,data,rowid,rowdata)
                {
                    var checkRowsList = jobDataset.attr.grid.getCheckedRows();
                    if(jobDataset.attr.grid.data.detailModelList.length==checkRowsList.length){
                        $(".l-grid1 .l-grid-header-table tr").eq(0).addClass("l-checked");
                    }else{
                        $(".l-grid1 .l-grid-header-table tr").eq(0).removeClass("l-checked");
                    }
                    //修改行checked值
                    if(checked)
                        data.checked ="1";
                    else
                        data.checked ="0";
                },
            });

          this.event();


        },
        event: function () {
          $("#btn_save").click(function () {
              
                var checkRowsList = jobDataset.attr.grid.getCheckedRows();
                var pcheckRowObjs = $(parent.jobLayout.grid.getCheckedRowObjs()).find(".sel-dataset-name");//父窗口选中行的数据集列
                var pcurIndex = pcheckRowObjs.attr("data-rowindex");
                var datasetName = "",dataSetIds = "",datasetCodes = "";
                for(var  i=0;i<checkRowsList.length;i++){
                      datasetName += checkRowsList[i].datasetName+",";//数据集名称
                      dataSetIds+=checkRowsList[i].datasetId+",";//数据集ID
                      datasetCodes+=checkRowsList[i].datasetCode+",";//数据集编码
                }
              pcheckRowObjs.val(datasetName.toString().substring(0,datasetName.length-1));//给父级窗口的数据集名称赋值

              //修改缓存数据集ID和数据集编码的值
              parent.jobLayout.cacheDatasetIdList[pcurIndex]= dataSetIds;
              parent.jobLayout.cacheDatasetCodeList[pcurIndex]= datasetCodes;
              debugger

              if(!parent.validAdd.validate()){
                  parent.jobLayout.dialog.close(); //关闭窗口
                  return false;
              }
              parent.jobLayout.dialog.close(); //关闭窗口

          });
          $("#btn_close").click(function () {
              parent.jobLayout.dialog.close(); //关闭窗口
          });
        }
      };

      $(function(){
          jobDataset.attr.init();
      })

  })(jQuery, window);
</script>
