{% extends "base.html" %}
{% block content %}
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css">
    <script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
    <script language="javascript">
        $(function(){

            function remove_parameter(){
                $(this).parents('.spider_parameter_row').remove();
             }
            $('#btnadd').click(function(){
                var new_parameter_section = $('<div class="spider_parameter_row">');
                new_parameter_section.append($('<input name="SpiderParameterKey">'));
                new_parameter_section.append($('<input name="SpiderParameterValue">'));
                var remove_btn = $('<span class="ui-icon ui-icon-minus">')
                remove_btn.click(remove_parameter);
                new_parameter_section.append(remove_btn);
                $('#spider_parameters').append(new_parameter_section);
            });

            $('.btn_remove_parameter').click(remove_parameter);
        });

    </script>
</head>
<body>
    <form method="POST">
        {% module xsrf_form_html() %}
    <div>
        <label>Concurrency:</label>
        <input name="concurrency" value="{{settings['concurrency']}}">
    </div>
    <div>
        <label>Timeout(secs):</label>
        <input name="timeout" value="{{settings['timeout']}}">
    </div>
    <div>
        <label>Tag:</label>
        <input name="tag" value="{{settings['tag']}}">
    </div>
    <div>
        <label>Webhook Payload URL</label>
        <input name="webhook_payload" value="{{settings.get('webhook_payload', '')}}">
    </div>
    <div>
        <label>Webhook Batch Size</label>
        <input name="webhook_batch_size" value="{{settings.get('webhook_batch_size', '')}}">
    </div>
    <div>
        <label>Extra Requirements(; seperated)</label>
        <input name="extra_requirements" value="{{settings.get('extra_requirements', '') or ''}}">
    </div>
    <div id="spider_parameters">
        <label>Spider Parameters:</label><span id="btnadd" class="ui-icon ui-icon-plus"></span>
        {% for spider_parameter in spider_parameters %}
            <div class="spider_parameter_row">
                <input name="SpiderParameterKey" value="{{spider_parameter.parameter_key}}">
                <input name="SpiderParameterValue" value="{{spider_parameter.value}}">
                <span class="ui-icon ui-icon-minus btn_remove_parameter"></span>
            </div>
        {% end %}
        <div>
            <input name="SpiderParameterKey">
            <input name="SpiderParameterValue">
        </div>
    </div>
    <div>
        <button type="submit" >保存</button>
        <a href="/projects/{{project.name}}/spiders/{{spider.name}}">返回</a>
    </div>
    </form>
{% end %}