{% extends 'base.html' %}

{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5> 命令批量执行 </h5>
                    <div class="ibox-tools">
                        <a class="collapise-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form method="post" id="ruleForm" class="form-horizontal" action="">
                        {% if error %}
                            <div class="alert alert-warning text-center">{{ error }}</div>
                        {% endif %}
                        {% if msg %}
                            <div class="alert alert-success text-center">{{ msg }}</div>
                        {% endif %}
                        <div class="form-group">
                            <label for="asset" class="col-sm-2 control-label">资产<span class="red-fonts">*</span></label>

                            <div class="col-sm-8">
                                <select name="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b"
                                        multiple tabindex="2">
                                    {% for asset in assets %}
                                        <option value="{{ asset.ip }}">{{ asset.ip }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">命令<span class="red-fonts">*</span></label>
                            <div class="col-sm-8">
                                <input class="form-control" name="cmd" placeholder="请输入要执行的命令">
                            </div>

                        </div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-white" type="clean">清除</button>
                                <button id="submit_button" class="btn btn-primary" type="submit">运行</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}
{% block self_head_css_js %}
    {% load staticfiles %}
    <script src="{% static 'js/jquery.shiftcheckbox.js' %}"></script>
    <link href="/static/css/plugins/datepicker/datepicker3.css" rel="stylesheet">
    <link href="/static/css/plugins/chosen/chosen.css" rel="stylesheet">
    <script src="/static/js/plugins/chosen/chosen.jquery.js"></script>
{% endblock %}
{% block self_footer_js %}
<script>
    $(document).ready(function () {

        var config = {
            '.chosen-select': {},
            '.chosen-select-deselect': {allow_single_deselect: true},
            '.chosen-select-no-single': {disable_search_threshold: 10},
            '.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},
            '.chosen-select-width': {width: "95%"}
        };

        for (var selector in config) {
            $(selector).chosen(config[selector]);
        }

        $('.del').click(function(){
            var row = $(this).closest('tr');
            if (confirm("确定删除")) {
            $.get(
                    $(this).attr('value'),
                    {},
                    function(data){
                        row.remove();
                        alert(data);
                    }
            )}
        });

        $('#del_btn').click(function(){
            var check_array = [];
            if (confirm("确定删除")) {
                $(".gradeX input:checked").each(function() {
                    check_array.push($(this).attr("value"))
                });
                $.post("/juser/user_del/",
                        {id: check_array.join(",")},
                        function(data){
                            $(".gradeX input:checked").closest("tr").remove();
                            alert(data);
                        }
                )
            }

        });

        $('.email').click(function(){
            $.get('/juser/send_mail_retry/?uuid=' + $(this).attr('value'),
                    {},
                    function(data){
                        alert(data)
                    }
            )
        });
        $("tbody tr").shiftcheckbox({
            checkboxSelector: 'input:checkbox',
            selectAll: $('#select_all'),
            ignoreClick: 'a'
        });
        $('.shiftCheckbox').shiftcheckbox();
    });
</script>
{% endblock %}