{% 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-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-options">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="/jasset/asset_add/" class="text-center"><i class="fa fa-laptop"></i> 单台添加 </a></li>
                                <li><a href="/jasset/host_add_multi" class="text-center"><i class="fa fa-bar-chart-o"></i> 批量添加 </a></li>
                            </ul>
                        </div>
                        <div class="panel-body">
                            <div class="tab-content">
                                <div id="tab-1" class="ibox float-e-margins tab-pane active">
                                    {% if error %}
                                        <div class="alert alert-warning text-center">{{ error }}</div>
                                    {% endif %}
                                    {% if msg %}
                                        <div class="alert alert-success text-center">{{ msg }}</div>
                                    {% endif %}
                                    <form id="assetForm" method="post" class="form-horizontal">
                                        <div class="form-group"><label class="col-sm-2 control-label"> IP地址<span class="red-fonts">*</span> </label>
                                            <div class="col-sm-8"><input type="text" name="ip" placeholder="IP" class="form-control"></div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="j_group" class="col-sm-2 control-label">使用默认</label>
                                            <div class="col-sm-1">
                                                <div class="radio i-checks">
                                                    <label>
                                                        <input type="checkbox" checked="" value="1" id="use_default" name="use_default">
                                                    </label>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group" id="port" style="display: none">
                                            <label class="col-sm-2 control-label"> 端口号<span class="red-fonts">*</span> </label>
                                            <div class="col-sm-8">
                                                <input type="text" placeholder="Port" name="port" class="form-control">
                                            </div>
                                        </div>
                                        <div class="form-group" id="admin_account" style="display: none">
                                            <label class="col-sm-2 control-label"> 管理用户名<span class="red-fonts">*</span> </label>
                                            <div class="col-sm-3">
                                                <input type="text" placeholder="Username" name="username" class="form-control">
                                            </div>

                                            <label class="col-sm-1 control-label"> 密码<span class="red-fonts">*</span> </label>
                                            <div class="col-sm-4">
                                                <input type="password" placeholder="Password" name="password" class="form-control">
                                            </div>
                                        </div>

                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="groups" class="col-sm-2 control-label">所属主机组</label>
                                            <div class="col-sm-8">
                                                <select id="groups" name="groups" class="form-control m-b" multiple size="10">
                                                    {% for asset_group in asset_group_all %}
                                                        <option type="checkbox" value="{{ asset_group.id }}">{{ asset_group.name }} {% if asset_group.comment %} --- {{ asset_group.comment }} {% endif %}</option>
                                                    {% endfor %}
                                                </select>
                                            </div>
                                        </div>

                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>
                                            <div class="col-sm-8">
                                                <div class="radio i-checks">
                                                    <label> <input type="radio" checked="" value="1" name="is_active">激活 </label>
                                                    <label> <input type="radio"  value="0" name="is_active"> 禁用</label>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
                                            <div class="col-sm-8"><input type="text" placeholder="comment" name="comment" class="form-control"></div>
                                        </div>

                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <div class="col-sm-4 col-sm-offset-2">
                                                <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(){
    $('#use_default').click(function(){
        if ($(this).is(':checked')){
            $('#admin_account').css('display', 'none');
            $('#port').css('display', 'none')
        }
        else {
            $('#admin_account').css('display', 'block');
            $('#port').css('display', 'block')
        }
    })
});

$('#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}$/, '端口号不正确'],
    },
    fields: {
        "ip": {
            rule: "required;check_ip",
            tip: "输入IP",
            ok: "",
            msg: {required: "必须填写!"}
        }
    },
    valid: function(form) {
        form.submit();
    }
});

</script>

{% endblock %}