<style>
    .checkbox label::after {
        left:1.2px !important;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div id="usercustomerAlert"></div>
            <div class="panel-title"><?php print $title; ?></div>

            <div class="clearfix"></div>
        </div>

        <div class="panel-body">

            <table class="table table-bordered inventory table-hover demo-table-search " id="tableWithSearch">
                <thead>
                    <tr>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('salesman'); ?></th> 
                        <th class="text-center" ><?php print CommonLanguage::getMessage('Depot'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>

    </div>
</div>


<script>
    var CurentCustomer_ToDelete;
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            title = <?php echo json_encode($title); ?>;
    $(function () {
//        build_select2($("#salesman_id"), "xhr/employeeSearch")

        change_table()
                build_select2($("input.depot_id"), "xhr/depotSearch")
        $("#tableWithSearch").on("click", ".submit_salesman", function () {
            var tr=$(this).parents("tr");

            var data = {
                depot_id: $("input.depot_id",tr).val(),
                salesman_id: $(this).attr("data-emp")
            };
            $.ajax({
                type: 'POST',
                url: 'InventoryAjax/assign_salesman_depot',
                data: data,
                complete: function (data, vv) {
                    if (vv == "success") {
                        if (data.responseText == 'OK') {
                            toastr.clear();
                            toastr.success(Submitted_Successfully)
                            change_table()
//                            RebuildDataTable(title, [1, 2, 3], 'InventoryAjax/UserCustomersList',  {uid: $("#users").val()});
                        } else {
                            toastr.error(Failed_Submit)
                        }
                    }
                }
            })
        })

        $('#tableWithSearch').on('draw.dt', function () {
            var row = $("#tableWithSearch").dataTable().fnGetNodes();
            for (var i = 0; i < row.length; i++) {
                var current_select = $('input.depot_id', $(row[i]));
                build_select2(current_select, "xhr/depotSearch")

            }
        })
    });
    function change_table() {
        RebuildDataTable(title, [1, 2, 3, 4], 'InventoryAjax/salesman_depot_list', {});
    }


</script>
