{% load i18n %}


<style> 
    .word-wrap{
        width: 100%;white-space: normal;word-wrap: break-word;word-break: break-all;
    }

    #tb tbody td:nth-child(9){
        padding-top:2px;
        padding-bottom:2px;
    }

    #tb tbody td:nth-child(10){
        padding-top:2px;
        padding-bottom:2px;
    }


    #tb td.details-control {
        background: url('/static/js/jquerydatatable/DataTables-1.10.20/images/details_open.png') no-repeat center center;
        cursor: pointer;
    }
    #tb tr.shown td.details-control {
        background: url('/static/js/jquerydatatable/DataTables-1.10.20/images/details_close.png') no-repeat center center;
    }


    #tb .btn{
        margin-top:0px;
        margin-bottom:0px;
    }


</style>



<script type="text/javascript">
    $(document).ready(function(){    
        var page_length=10; 

        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,
            //order: {{order|safe}},
            data:{{data|safe}},
            
            //columnDefs: [{"targets": [0, 10 ], "visible": false }],
            createdRow: function ( row, data, index) {
                $(row).attr('obj_id', data[11]);
                //if(parseInt(data[4])>0){
                //    $('td',row).eq(0).addClass("details-control");
                //};
            }
        });

        /*
        $('#tb tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = table.row(tr);
            if ( row.child.isShown()) {
                row.child.hide();
                tr.removeClass('shown');
            } else {
                $.ajax({
                    url: '/company/franchise/get/list/'+$(tr).attr('obj_id')+'/',
                    success: function(res) {
                        if(res.e == '') {
                            var html='<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;width:100%;">',d,s;
                            for(var i in res.data){                                
                                d=res.data[i];
                                if(d.remark==''){
                                    s='无特殊情况备注';
                                }else{
                                    s=d.remark;
                                };
                                html=html+'<tr><td colspan=5 style="text-align:center">'+d.name+'</td>'+
                                '<td>'+d.address+'</td><td>'+d.city+'</td><td>'+d.series.name+'</td>'+
                                '<td>'+d.status.name+'</td><td>'+s+'</td></tr>';
                            };
                            html=html+'</table>';
                            row.child(html).show();
                            tr.addClass('shown');
                        }
                    }
                });
            }  
        });   
        */

        table.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        });







        /*
        $('#tb tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = table.row(tr);

            if ( row.child.isShown() ) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                // Open this row
                row.child( format(row.data()) ).show();
                tr.addClass('shown');
            }
        });
        */

        $(".btn-obj-add").click(function () { 
            event.preventDefault();
            $.RefreshContent($(this).attr('href'));        
        })

        $('#tb').on("click","td a.edit",function(event){
            event.preventDefault();    
            $.RefreshContent($(this).attr('href'));            
        });      

        $('#tb').on('click','button.approve',function(){        
            var tr=$(this).closest('tr');
            var td=$(this).closest('td');
            var name=$(tr).find('a.edit').text();
            var id=$(tr).attr('obj_id');   
        
            var msg = name+':\n您确定要通过当前加盟商的审核吗？';                 
            if (confirm(msg)==true){
                $.ajax({
                    type:'GET',
                    processData: false,
                    contentType: 'application/json; charset=utf-8',
                    url:'/company/franchise/action/agent/approve/'+id+'/',
                    success:function(data){
                        $(td).html('已审核');
                    }
                });
            };
        });
        $('#tb').on('click','button.delete',function(){        
            var tr=$(this).closest('tr');
            var td=$(this).closest('td');
            var name=$(tr).find('a.edit').text();
            var id=$(tr).attr('obj_id');   
        
            var msg ='您确定要删除加盟商"'+name+'"及其下门店吗？';                 
            if (confirm(msg)==true){
                $.ajax({
                    type:'GET',
                    processData: false,
                    contentType: 'application/json; charset=utf-8',
                    //url:'/company/franchise/action/agent/approve/'+id+'/',
                    url:'/obj/delete/agent/'+id+'/',
                    success:function(data){
                        $(td).html('已删除');
                    }
                });
            };
        });
    });
</script>



<ol class="breadcrumb">
        <li>{{subtt.0}}</li>
        <li>加盟商列表</li>     
</ol>


{% if show_add %}
    <div class="title_right">
        <div class="pull-right">
            <span class='input-group'>
                <a type="button" class='btn btn-obj-add l-a create-btn' href='{{murl}}'>
                    <span class='glyphicon glyphicon-plus' style='padding-right:5px;'></span>{% trans '新建' %}
                </a>
            </span>
        </div>
    </div>        
{% endif %}


<div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div  class="table-responsive">
            <table id='tb'  class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
            <thead>
                {% for c in clmns %}
                    <th>{{c}}</th>
                {% endfor %}
            </thead>
            <tbody></tbody>
            <tfoot>
                {% for c in clmns %}                   
                    <th><input type="text" placeholder="{{c}}"></th>                    
                {% endfor %}            
            </tfoot>
            </table>
        </div>
    </div>
</div>
