<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改爬虫任务')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-spiderMission-edit" th:object="${spiderMission}">
            <input name="missionId" th:field="*{missionId}" type="hidden">

            <div class="form-group">
                <label class="col-sm-3 control-label">爬虫配置：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="spiderConfigId" name="spiderConfigId" th:field="*{spiderConfigId}" class="form-control" required type="hidden">
                        <input id="spiderConfigName" class="form-control valid" th:value="${spiderConfigName}" type="text" onclick="selectSpiderConfig()"   readonly="true"  aria-invalid="false">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">任务名称：</label>
                <div class="col-sm-8">
                    <input name="missionName" th:field="*{missionName}" required class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">入口地址：</label>
                <div class="col-sm-8">
                    <textarea name="entryUrls" rows="8" class="form-control" required>[[*{entryUrls}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开启翻页：</label>
                <div class="col-sm-8">
                    <input id="loopFlag" name="loopFlag" class="form-control" type="hidden" th:field="*{loopFlag}">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="checkbox_loopFlag" name="checkbox_loopFlag" th:checked="${spiderMission.loopFlag==1}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group loop">
                <label class="col-sm-3 control-label">翻页参数：</label>
                <div class="col-sm-8">
                    <input id="loopParam" th:field="*{loopParam}" placeholder="将页码位置替换成#" name="loopParam" style="width: calc(100% - 100px);display: inline-block;" class="form-control" type="text">
                    &nbsp;&nbsp; <input id="loopNum" th:field="*{loopNum}" placeholder="翻页次数" name="loopNum" style="width: 80px;display: inline-block;" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">退出方式：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('spider_exit_way')}">
                        <input type="radio" th:id="${'exitWay_' + dict.dictCode}" name="exitWay" th:value="${dict.dictValue}" th:checked="${dict.default}"  th:field="*{exitWay}">
                        <label th:for="${'exitWay_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group" id="div_value" style="display: none;">
                <label class="col-sm-3 control-label">退出值：</label>
                <div class="col-sm-8">
                    <input name="exitWayCount" th:field="*{exitWayCount}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">Cookie：</label>
                <div class="col-sm-8">
                    <textarea name="cookieStr"  rows="8" class="form-control" >[[*{cookieStr}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">Header：</label>
                <div class="col-sm-8">
                    <textarea name="headerStr"  rows="8" class="form-control">[[*{headerStr}]]</textarea>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "spider/spiderMission";
        $("#form-spiderMission-edit").validate({
            focusCleanup: true
        });
        function selectSpiderConfig() {
            var url=ctx+"spider/spiderMission/openSelectSpiderConfig";
            $.modal.open("爬虫配置选择",url);
        }
        function selectSpiderConfigFinish(id,name) {
            $("#spiderConfigId").val(id);
            $("#spiderConfigName").val(name);
            $("#missionName").val(name);
        }
        function submitHandler() {
            if ($.validate.form()) {
                var loopFlag=$("#loopFlag").val();
                if(loopFlag==1||loopFlag=='1'){
                    var loopParam=$("#loopParam").val();
                    var loopNum=$("#loopNum").val();
                    if($.common.isEmpty(loopParam)){
                        $.modal.msgError("请输入将页码位置替换成#后的内容!");
                        return;
                    }
                    if($.common.isEmpty(loopNum)){
                        $.modal.msgError("请输入翻页次数!");
                        return;
                    }
                }
                $.operate.save(prefix + "/edit", $('#form-spiderMission-edit').serialize());
            }
        }

        $(function(){
            $('[name=exitWay]').on('ifChecked', function(event){
                showHideValue();
            });
            showHideValue();

            $("#checkbox_loopFlag").on("change",function(){
                var v=$(this).prop("checked");
                if(v){
                    $("#loopFlag").val("1");
                    $(".loop").show();
                }else{
                    $("#loopFlag").val("0");
                    $(".loop").hide();
                }
            });
            $("#checkbox_loopFlag").change();

        })
        function showHideValue(){
            var v=$("[name=exitWay]:checked").val();
            if(v=="DEFAULT"){
                $("#div_value").hide();
                $("#exitWayCount").removeAttr("required");
            }else{
                $("#div_value").show();
                $("#exitWayCount").attr("required","required");
            }
        }
    </script>
</body>
</html>
