{% extends "data_list.html" %}
{% load i18n %}
{% block model_extend %}{%endblock%}
{% block content %}
    <div style="margin-left:10px;">
        <form method="post" onkeydown="if(event.keyCode==13){return false;}"  id="id_edit_form" enctype="multipart/form-data">
        <div>
            <div class="div_box1"><h2>{% trans "来访时间过长提醒" %}</h2>
                <span>&nbsp;&nbsp;&nbsp;{% trans "来访时长: " %}
                <input type="text" name="time_length" id="id_time_length" size="3"></input>&nbsp;{% trans "小时" %}
                </span>
            </div>
            <div class="div_box1"><h2>{% trans "来访次数过多提醒" %}</h2>
                <span>&nbsp;&nbsp;&nbsp;{% trans "间隔时间: " %}
                <input type="text" name="time_table" id="id_time_table" size="3"></input>&nbsp;{% trans "天" %}
                </span>
                <span>&nbsp;&nbsp;&nbsp;{% trans "次数: " %}
                <input type="text" name="times" id="id_times" size="3"></input>&nbsp;{% trans "次" %}
                </span>
            </div>
            <div class="div_box1"><h2>{% trans "设置离开未登记是否提醒" %}</h2>
                <span>&nbsp;&nbsp;&nbsp;{% trans "离开未登记是否提醒:" %}
                    <select id="id_is_warn" name="is_warn" ><option value="1">{% trans "是" %}</option><option value="0">{% trans "否" %}</option></select><br>
                    <div>
                        <span class="icon_note">&nbsp;</span>
                        <font color="#FF6600">
                            {% trans "选择提醒，访客离开未按正常流程登记，下次来访时自动提醒登记人员。"%}
                        </font>
                    </div>
                </span>
            </div>
            
        </div>
        <span id="id_error" style="display:none;"></span>
        <div class="editformbtn">
            <div class="lineH22 img_padding">
                <span class="action_OK"></span>
                <a id="OK" href="javascript:void(0)" class="Link_blue1">{% trans "确定" %}</a>
            </div>
        </div>
        <input type="hidden" name="down_event_hours" id="id_down_event_hours" value=""/>
        </form>
    </div>
    
{% endblock %}
{% block extend_js %}
    <script>
        //发送请求从后端获取上次设置的内容
        $.ajax({
            type: "GET",
            url: "/{{ request.surl }}visitor/ProcessVisitorOption/?func=get_option",
            dataType: "json",
            async: false,
            success: function(data)
            {
                $("#id_time_length").val(data.time_length);
                $("#id_time_table").val(data.time_table);
                $("#id_times").val(data.times);
                $("#id_is_warn").val(data.is_warn);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown)
            {
                alert(gettext("服务器处理数据失败，请重试！错误码：-624"));
            }
        });
       
        $("#OK").click(function(){
            $("#id_edit_form").ajaxSubmit({
                url:"/visitor/ProcessVisitorOption/?func=set_option", 
                dataType:"json",
                success:function(msgback){
                    $("#id_error").attr("style", "display:block");
                    if (msgback.ret == 0){
                        $("#id_error").html('<ul class="successlist"><li><font color="blue">'+gettext("设置成功，重启服务后生效！")+'</font></li></ul>');
                    }else{
                        $("#id_error").html('<ul class="successlist"><li><font color="red">'+msgback.ret+'</font></li></ul>');
                    }
                }
            })
        });
        
    </script>
{% endblock %}
