{% extends 'base.html' %}
{% load bootstrap %}
{% block content %}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-10">
            <div class="ibox float-e-margins">
                <div id="ibox-content" class="ibox-title">
                    <h5> 添加资产 </h5>
                    <div class="ibox-tools">
                        <a class="collapse-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">
                    <div class="panel blank-panel">
                        <div class="panel-body">
                            <div class="tab-content">
                                <div id="tab-1" class="ibox float-e-margins tab-pane active"></div>
                                    <form id="assetForm" method="post" class="form-horizontal">
                                        {% csrf_token %}
                                        <h3 class="widget-head-color-box">基本信息</h3>

                                        {{ form.hostname|bootstrap_horizontal }}

                                        {{ form.ip|bootstrap_horizontal }}

                                        <div class="form-group" id="id_port">
                                            <label class="col-sm-2 control-label">端口</label>
                                            <div class="col-sm-9">
                                                <input type="text" placeholder="" name="port" class="form-control">
                                            </div>
                                        </div>

                                        <div class="form-group" id="id_type">
                                            <label class="col-sm-2 control-label">资产类型</label>
                                            <div class="col-sm-9">
                                                <input type="text" placeholder="" name="type" class="form-control">
                                            </div>
                                        </div>

                                        {{ form.comment|bootstrap_horizontal }}

                                        <div class="hr-line-dashed"></div>
                                        <h3>关联资产用户</h3>
                                        <div class="form-group">
                                            <label for="j_group" class="col-sm-2 control-label">管理用户</label>
                                            <div class="col-sm-9">
                                                <div class="radio i-checks">
                                                   <label><input type="radio" checked="checked" id="id_use_default_auth" name="use_default_auth"><span>使用预定义管理用户</span></label>
                                                   <label><input type="radio" id="id_use_default_auth" name="use_default_auth"><span>自定义</span></label>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group" id="id_manager_user">
                                            <div class="col-sm-offset-2 col-sm-9">
                                                <input type="text" placeholder="请选择管理用户" name="manager_user" class="form-control">
                                            </div>
                                        </div>
                                        <p class="col-sm-offset-2">Tips: 管理用户是服务器存在的root或拥有sudo的用户，用来推送系统用户</p>

                                        <div class="form-group">
                                            <label for="system_user" class="col-sm-2 control-label">系统用户</label>
                                            <div class="col-sm-9">
                                                <input type="text" placeholder="" name="system_user" class="form-control">
                                            </div>
                                        </div>

                                        <div class="hr-line-dashed"></div>
                                        <h3>所属</h3>
                                        {{ form.idc|bootstrap_horizontal }}

                                        {{ form.group|bootstrap_horizontal }}

                                        <div class="hr-line-dashed"></div>
                                        <h3>标签</h3>

                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <div class="col-sm-4 col-sm-offset-5">
                                                <button class="btn btn-white" type="reset"> 重置 </button>
                                                <button class="btn btn-primary" type="submit"> 提交 </button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block self_footer_js %}
{#<script>#}
{#    $('document').ready(function(){#}
{#        var check_default = "{{ default_setting.name }}";#}
{#        console.log(check_default);#}
{#        if (check_default != 'default'){#}
{#            $('#id_use_default_auth').attr('disabled', true);#}
{#            $('#id_use_default_auth').attr('checked', false);#}
{#            $('#admin_account').css('display', 'block');#}
{#        } else {#}
{#            $('#id_use_default_auth').click(function(){#}
{#                if ($(this).is(':checked')){#}
{#                    $('#admin_account').css('display', 'none');#}
{#                }#}
{#                else {#}
{#                    $('#admin_account').css('display', 'block');#}
{#                }#}
{#            })#}
{#        }#}
{##}
{#    });#}
{##}
{#    var required_fields = ["id_ip", "id_hostname", "id_port"];#}
{#    required_fields.forEach(function(field) {#}
{#        $('label[for="' + field + '"]').parent().addClass("required");#}
{#    });#}
{##}
{#    $('#assetForm').validator({#}
{#        timely: 2,#}
{#        theme: "yellow_right_effect",#}
{#        rules: {#}
{#            check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],#}
{#            check_port: [/^\d{1,5}$/, '端口号不正确'],#}
{#            use_default_auth: function() {#}
{#                var str1 = $("#id_use_default_auth").is(":checked");#}
{#                if (str1 == true){#}
{#                    var decide = false;#}
{#                } else {#}
{#                    var decide = true;#}
{#                }#}
{#                return decide}#}
{#        },#}
{#        fields: {#}
{#            "ip": {#}
{#                rule: "check_ip;",#}
{#                tip: "输入IP",#}
{#                ok: "",#}
{#                msg: {required: "必须填写!"}#}
{#            },#}
{#            "hostname": {#}
{#                rule: "required;length[0~53]",#}
{#                tip: "填写主机名",#}
{#                ok: "",#}
{#                msg: {required: "必须填写!"}#}
{#            },#}
{#            "port": {#}
{#                rule: "required",#}
{#                tip: "输入端口号",#}
{#                ok: "",#}
{#                msg: {required: "必须填写!"}#}
{#            },#}
{#            "username": {#}
{#                rule: "required(use_default_auth)",#}
{#                tip: "输入用户名",#}
{#                ok: "",#}
{#                msg: {required: "必须填写!"}#}
{#            },#}
{#            "password": {#}
{#                rule: "required(use_default_auth);length[0~64]",#}
{#                tip: "输入密码",#}
{#                ok: "",#}
{#                msg: {required: "必须填写!"}#}
{#            }#}
{#        },#}
{#        valid: function(form) {#}
{#            form.submit();#}
{#        }#}
{#    });#}
{##}
{#</script>#}

{% endblock %}