<?php
$base_url = base_url();
$this->load->view('layout/admin/header', array('base_url' => $base_url));
$this->load->view('layout/admin/sidebar', array('base_url' => $base_url, 'method'=>$this->router->method, 'class'=>$this->router->class  ));
?>
<script type="text/javascript">
    function init_page()
    {

        $(".ajax_paging").click(function () {
            $.ajax({
                url: $(this).attr("href"),
                type: "POST",
                data: $("#collaborator").serialize(),
                success: function (data, textStatus, jqXHR)
                {
                    // $result = jQuery.parseJSON(data);
                    $("#content").html(data);
                    init_page();

                },
                error: function (jqXHR, textStatus, errorThrown)
                {
                    $(".ajaxloading").hide();
                }
            });
            return false;
        })
        $('#keyword').keyup(function (event) {
            if (event.keyCode == '13') {
                filter();
            }
            return false;
        });
        
        
        $( '.sorting, .sorting_desc, .sorting_asc' ).click(function( index ) {
            var current_class=$( this ).attr('class');
            $(".sorting_desc").attr("class","sorting");
            $(".sorting_asc").attr("class","sorting");
     
            if(current_class=='sorting')
            {
                $(this).attr("class","sorting_desc");
            }
            else
            {
                if(current_class=='sorting_desc')
                {
                    $(this).attr("class","sorting_asc");
                }
                else
                    {
                    if(current_class=='sorting_asc')
                    {
                        $(this).attr("class","sorting");
                    }
                }
            }
            $("#sorting_field").val($(this).attr("id"));
            $("#sorting_order").val($(this).attr("class"));
            filter();
        });
        $('[data-toggle="ajaxModal"]').on('click',
              function(e) {
                $('#ajaxModal').remove();
                e.preventDefault();
                var $this = $(this)
                  , $remote = $this.data('remote') || $this.attr('href')
                  , $modal = $('<div class="modal" id="ajaxModal"><div class="modal-body"></div></div>');
                $('body').append($modal);
                $modal.modal({backdrop: 'static', keyboard: false});
                $modal.load($remote);
              }
            );


    }


    function filter()
    {
        $.ajax({
            url: '<?php echo base_url();?>admin/cong_tac_vien/trang/1',
            type: "POST",
            data: $("#collaborator").serialize(),
            success: function (data, textStatus, jqXHR)
            {
                // $result = jQuery.parseJSON(data);
                $("#content").html(data);
                init_page();
                $("#keyword").focus();
                $("#keyword").setCursorToTextEnd();

            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                $(".ajaxloading").hide();
            }
        });
    }


</script>
<div class="main-content" id="content">
    <?php echo $content; ?>
</div><!-- /.main-content -->
</div><!-- /.main-container-inner -->

<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="icon-double-angle-up icon-only bigger-110"></i>
</a>
</div><!-- /.main-container -->


<div id="addUser" class="modal fade in" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">×</span>
                    </button>
                    Thêm cộng tác viên
                </div>
            </div>

            <div class="modal-body">
                <form id="add_user" onsubmit="return false;" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Tên đầy đủ </label>

                        <div class="col-sm-9">
                            <label class="block clearfix has-error">
                            <span class="input-icon">
                                <input name="full_name" type="text" id="form-field-1" placeholder="Tên cộng tác viên">
                                <i class="icon-user blue"></i>
                            </span>
                            <div id="full_name" class="help-block error"></div>
                            </label>
                        </div>
                        <div class="help-block"> </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Tên đăng nhập </label>

                        <div class="col-sm-9">
                            <label class="block clearfix has-error">
                            <span class="input-icon">
                                <input name="login_name" type="text" id="form-field-1" placeholder="Tài khoản">
                                <i class="icon-user blue"></i>
                            </span>
                            <div id="login_name" class="help-block error"></div>
                            </label>
                        </div>
                        <div class="help-block"> </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Số điện thoại</label>

                        <div class="col-sm-9">
                            <label class="block clearfix has-error">
                            <span class="input-icon">
                                <input name="cellphone" type="text" id="form-field-1" placeholder="Số điện thoại">
                                <i class="icon-user blue"></i>
                            </span>
                            <div id="cellphone" class="help-block error"></div>
                            </label>
                        </div>
                        <div class="help-block"> </div>
                    </div>
                    <div class="space-4"></div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-2"> Mật khẩu </label>

                        <div class="col-sm-9">
                            <label class="block clearfix has-error">
                            <span class="input-icon">
                                <input type="password" name="passwd" id="form-field-2" placeholder="Mật khẩu">
                                <i class="icon-lock blue"></i>
                            </span>
                            <div id="passwd" class="help-block error"></div>
                            </label>
                        </div>
                        <div class="help-block"> </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-2"> Mật khẩu </label>

                        <div class="col-sm-9">
                            <span class="input-icon">
                                <input type="password" name="passwd2" id="form-field-2" placeholder="Nhập lại mật khẩu">
                                <i class="icon-lock blue"></i>
                            </span>
                        </div>
                        <div class="help-block"> </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Kích hoạt</label>

                        <div class="col-sm-9">
                            <span class="input-icon">
                                <input type='checkbox' name="activated" checked="checked" value="1"  />
                            </span>
                        </div>
                        <div class="help-block"> </div>
                    </div>

                    <div class="space-4"></div>
                    <div class="form-group errors" id="add_user"></div>
                        
                    </div>
                    <div class="clearfix form-actions">
                        <div class="col-md-offset-3 col-md-9">
                            <button class="btn btn-info" id="add_user" type="button">
                                <i class="icon-ok bigger-110"></i>
                                Hoàn tất
                            </button>

                            &nbsp; &nbsp; &nbsp;
                            <button class="btn" type="reset">
                                <i class="icon-undo bigger-110"></i>
                                Xóa hết
                            </button>
                        </div>
                    </div>

                </form></div>

        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
<?php
$this->load->view('layout/admin/footer', array('base_url' => $base_url, 'adminjs' => array('assets/js/admin/collaborator.js')));
?>