<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script src="${contextRoot}/develop/lib/jobMapping/jquery-1.9.1.js"></script>
<script src="${contextRoot}/develop/lib/jobMapping/draggabilly.js"></script>
<script src="${contextRoot}/develop/lib/jobMapping/fabric.js"></script>
<script src="${contextRoot}/develop/lib/jobMapping/sly.js"></script>
<script src="${contextRoot}/develop/lib/jobMapping/underscore.js"></script>
<%--<script src="${contextRoot}/develop/lib/jobMapping/data.js"></script>--%>
<script src="${contextRoot}/develop/lib/jobMapping/tableViewer.js"></script>
<script>

    (function(win,$) {

        var checkRowObjs = $(parent.jobLayout.grid.getCheckedRowObjs()).find(".mapping");
        var pcurIndex = checkRowObjs.data("rowindex");
        var mappingData = parent.jobLayout.cacheMappingInitData[pcurIndex];
        $.ajax({
            url: "${contextRoot}/crawler/getRelations",
            type: "post",
            dataType: "json",
            data:{versionId: "${versionId}",datasetIdStr:"${datasetIdStr}",lines:mappingData},
            success: function (data) {
                if(data){
                    $('#main').tableViewer(data)
                }

            }
        });

        $("#btn_close").click(function () {
            parent.jobLayout.dialog.close();
        });
        $("#btn_save").click(function () {
            $.TableView.curTV.data.rels = $.TableView.curTV.getResult().lines;
            var parentCheckRowData =parent.jobLayout.grid.getCheckedRows()[0];
            var initData = JSON.stringify($.TableView.curTV.data);
            var mappingData = JSON.stringify($.TableView.curTV.getResult());

            //修改缓存数据映射的值
            parent.jobLayout.cacheMappingInitData[pcurIndex]= initData;
            parent.jobLayout.cacheMappingData[pcurIndex]= mappingData;

            $.ajax({
                url: "${contextRoot}/crawler/setRelationsCache",
                type: "post",
                dataType: "json",
                data:{versionId: "${versionId}",lines:mappingData},
                success: function (data) {
                    
                    if(data.successFlg){
                        parent.jobLayout.dialog.close();//关闭窗口
                    }

                }
            });




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

