{% extends "Acc_Reportform.html" %}
{% load i18n %}
{% block id_main_div %}
    {% if request.user|HasPerm:"contenttypes.can_AllEventReportPage" %}

    {% if request.user|HasPerm:"iaccess.browse_accrtmonitor" %}
    
    <div ><li id="id_model_export" style="display:none"><a class="action_Model_Export" href="javascript:void(0)" alt="export"></a></li></div>

    <div id="id_datalist" style="z-index:-1" class="div_box h280"><h1>{% trans "所有事件" %}</h1>
    </div>
    {% endif %}<!--browse_accrtmonitor-->
    {% endif %}<!--contenttypes.can_AllEventReportPage-->
{% endblock %}

{% block acc_reportform %}
    {% if request.user|HasPerm:"contenttypes.can_AllEventReportPage" %}
    {% if request.user|HasPerm:"iaccess.browse_accrtmonitor" %}
    $("#id_datalist").model_grid({
        "model_url": "{{ dbapp_url }}iaccess/AccRTMonitor/",
        "model_actions": true,
        "object_actions": false,
        "obj_edit": false,
        "record_per_page": 15,
        "sort_fields": ["-time"],  
        "max_no_page": 20,            
        "disabled_actions": ["OpClearAbnormityLogs","_delete","_add","_clear","_change"],
        "multiple_select": null,
        "action_onclick_continue": false,
        "row_operations": [],
        "init_after_get_jdata": function(){
            $("#id_datalist div.action").append('<li id="id_export"><a alt="export" href="javascript:void(0)" class="action_Model_Export">'+gettext("导出报表")+'</a></li>')
            $("#id_datalist div.action").append('<li id="id_obtain_logs_time"><a alt="export" href="javascript:void(0)" class="action_Model_Export">'+gettext("设置定时获取记录时间")+'</a></li>')            
            $("#id_export").click(function(){
                $("#id_model_export").click();
            });
            $("#id_obtain_logs_time a").click(function(){
                var set_time_form = '<div id="id_obtain_logs_time_form" class="obtain_logs_time_form div_box">'
                                                +'<h1>'+gettext("设置定时获取记录时间")+'</h1>'
                                                +'<div>'
                                                    +'<table>'
                                                        +'<tr><td><ul>'
                                                                +'<li></li>'
                                                                +'<li>'+gettext("每天")+'<input id="id_new_hour" maxlength="3" style="width:25px">'+gettext(" 点自动从设备获取新记录")+'</input></li>'
                                                                +'<li style="height: 15px;"></li>'
                                                                +'<li style="color: red;">'+gettext("注：请确保服务器在设置的时间点处于开机状态。")+'</li>'
                                                        +'</ul></td></tr>'
                                                    +'</table>'
                                                +'</div>'
                                        +'<div class="btns_class"><button class="btn" id="set_time" type="button">'+gettext("确定")+'</button>'
                                        +'<button class="btn" id="id_Cancel" type="button">'+gettext("取消")+'</button></div>'
                                        +'</div>';
            
                $(set_time_form).dialog();

                $.ajax({
                    type: "GET",
                    url: "/{{ request.surl }}iaccess/GetData/?func=obtain_new_log_time",
                    dataType: "json",
                    async: false,
                    success: function(data)
                    {
                        $("#id_new_hour").val(data.hour);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown)
                    {
                        alert(gettext("服务器处理数据失败，请重试！错误码：-624"));
                    }
                });
                
                $("#id_obtain_logs_time_form").find("#id_Cancel").click(function(){
                    $("#id_close").click();
                });
                $("#set_time").click(function(){
                    var new_hour = $("#id_new_hour").val();
                    var reg_hour = /^[0-9]+$/;
                    if(!reg_hour.test(new_hour) || new_hour > 23 || new_hour < 0)
                    {
                        alert(gettext("请输入有效的时间点(0-23)！"));
                        $("#id_new_hour").focus();
                        return false;
                    }
                    
                    $.ajax({
                        type: "POST",
                        url: "/{{ request.surl }}iaccess/GetData/?func=obtain_new_log_time&new_hour="+new_hour,//24小时制
                        dataType: "json",
                        async: false,
                        success: function(data)
                        {
                            if(data.ret == 0)
                            {
                                alert(gettext("定时下载记录时间设置成功！该设置将在软件服务或者操作系统重启后生效！"));
                            }
                            else
                            {
                                alert(gettext("定时下载记录事件设置失败！请重试！"))
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown)
                        {
                            alert(gettext("服务器处理数据失败，请重试！错误码：-625"));
                        }
                    });
                    $("#id_close").click();
                });
            });
        }

    });
    {% endif %}<!--browse_accrtmonitor-->
    {% else %}
        $("#id_search").remove();
        alert(gettext("对不起，您没有访问该页面的权限，不能浏览更多信息！"));
        window.location.href = "/{{ request.surl }}accounts/login/";
    {% endif %}<!--contenttypes.can_AllEventReportPage-->
{% endblock %}


{% block addjs %}
    $("#id_event_type").hide();
    $("tr:nth-child(4) td:nth-child(2)").append("<div id='div_box' style='border:1px #7F9DB9 solid; height:17px;z-index:99;width:148px;CURSOR: default;'><div id='div_boxtext' style='display:none'></div><div id='div_boxImg'  style='float:left;width:132px;left:126px;overflow:hidden;'>&nbsp;---------</div><div style='float:left;align='right''><img src='/media/img/sug_down_on.gif' id='div_img'  ></img></div></div><div id='div_box_list'></div>");

    $("body").click(function(event){
        if($("#div_box_list").is(":visible"))
        {
            var app = navigator.appName;
            if(app.indexOf('Netscape') != -1) 
            {
                var target_id = event.target.id;
                if( target_id != "div_box_list" && target_id != "div_boxImg" && target_id != "div_img")
                {
                    $("#div_box_list").hide()
                }
            }
            else if (app.indexOf('Microsoft') != -1) 
            {
                var element_id = event.srcElement.id;
                if(element_id != "div_box_list" && element_id != "div_boxImg" && element_id != "div_img")
                {
                    $("#div_box_list").hide();
                } 
            }
        }
    });

    var c = "";
    var x = 0;
    $('#id_event_type>Option').each(function(){
        b = $(this).text();
        var cArr = b.match(/[^\x00-\xff]/ig);   
        zx = b.length + (cArr == null ? 0 : cArr.length)
        c = c + '<div id='+this.value+' onmouseover="over(id)" onmouseout="out(id)"    style="CURSOR: default;color:black;";    onclick="show(id)"    >'+'&nbsp;'+$(this).text()+'</div>';
    })

    var temp= false;
    $("#div_box").click(function(){
        //是否隐藏 
        if(temp == false)
        {
            $("#div_box_list").attr("style","display:block")
            $("#div_box_list").width(zx*14.5)
            temp=true
        }
        else
        {

            $("#div_box_list").attr("style","display:none")
            $("#div_box_list").width(zx*14.5)
            temp=false
        }
    });
    $("#div_box_list").html(c);

    function over(id)
    {
        document.getElementById(id).style.background = '#316AC5'
        document.getElementById(id).style.color = 'white'
    }
    function out(id)
    {
        document.getElementById(id).style.background = 'white'
        document.getElementById(id).style.color = 'black'
    }


    function show(b)
    {
        if(b == 'onmouseover="over(id)"')
        {
            document.getElementById("div_boxtext").innerHTML = '<select id="id_selects"><option value="">'+gettext("无")+'</option></select>';
        }
        else
        {
            document.getElementById("div_boxtext").innerHTML = '<select id="id_selects"><option value='+b+'>'+gettext("无")+'</option></select>';
        }
        var text = document.getElementById(b).innerHTML
        document.getElementById("div_boxImg").innerHTML = text
        document.getElementById("div_box_list").style.display = 'none'
        var x=document.getElementById("div_boxImg").innerText
        if(x == " ")
        {
            document.getElementById("div_boxImg").innerText =" "+text
            if(b == 'onmouseover="over(id)"')
            {
                document.getElementById("div_boxtext").innerText = '<select id="id_selects"><option value="">'+gettext("无")+'</option></select>';
            }
            else
            {
                document.getElementById("div_boxtext").innerText = '<select id="id_selects"><option value='+b+'>'+gettext("无")+'</option></select>';
            }
        }
    }

    $("#div_box_list").width(zx*14.5)

    $("#id_header_clear").click(function()
    {
        $("#id_selects").find("option:selected").val("");
        $("#div_boxImg").html("&nbsp;---------");
    })
{% endblock %}
