
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h4 class="modal-title" id="myModalLabel">分配/回收资产</h4>
</div>

<div class="modal-body" style="padding-bottom: 0px;">
    <table aria-describedby="editable_info" role="grid" class="table table-striped table-bordered table-hover  dataTable" id="editable">
        <thead>
            <tr>
                <th class="text-center" style="background-color:white">
                    <input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
                </th>
                <th id="th_no">id</th>
                <th>资产名称</th>
                <th>IP</th>
                <th>硬件类型</th>
                <th>资产组</th>
                <th>部门</th>
            </tr>
        </thead>
        <tbody>
        {% for asset in asset_modal_list %}
            <tr>
            {% if asset.id in group_assets %}
                <td class="text-center" ><input type="checkbox" name="checked" value="{{ asset.id }}" checked="checked"></td>
            {% else %}
                <td class="text-center" ><input type="checkbox" name="checked" value="{{ asset.id }}"></td>
            {% endif %}
                <td>{{ asset.id }}</td>
                <td>{{ asset.hostname }}</td>
                <td>{{ asset.ip }}</td>
                <td>虚拟机</td>
                <td>网络设备</td>
                <td>微信事业部</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>

<div class="modal-footer">
    <button type="button" class="btn btn-default" id="close-btn">取消</button>
    <button type="button" class="btn btn-primary" id="save-btn">保存</button>
</div>

<script type="text/javascript">

//$(window).load(function (){
$(document).ready(function(){

    var table = $('#editable').DataTable({
        aLengthMenu: [[2, 25, 50, -1], ["2", "25", "50", "all"]],
        "aaSorting": [[2, "asc"]],
        "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] }],
        "bAutoWidth": false,
        columns: [
            {data: "checkbox"},
            {data: "id"},
            {data: "name"},
            {data: "ip"},
            {data: "type"},
            {data: "group"},
            {data: "dp"}
        ]
    });
    table.column('1').visible(false);
    $('#editable tbody').on( 'click', 'tr', function () {
        $(this).toggleClass('selected');
    });

    $('#save-btn').on('click',function(){
    //alert( table.rows('.selected').data().length +' row(s) selected' );
        var d = table.rows('.selected').data();
        var size = d.length;
        document.getElementById('add_asset').value = size;
        var column2 = table.rows('.selected').data();
        $("#asset_sed").find("input[name='assets']").remove();
        for(var i=0;i<column2.length;i++){
            var value = column2[i].id;
            $("#asset_sed").append("<input  type='hidden' name='assets' value='"+value+"'>");
        }
        $('#modal').modal('hide');
    });




});
    $('#close-btn').on('click',function(){
        //alert('点击关闭按钮时触发；')
        $('#modal').modal('hide');
    });





</script>
