<?php $this->view("includes/Inc_pagehead");?>
<style>
.m-form .m-form__group {
  margin-bottom: 0;
  padding-top: 0px;
  padding-bottom: 0px;
}
</style>
<!-- Page Styles Goes Here-->

<?php $this->view("includes/Inc_navigation");?>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
  <!-- BEGIN: Subheader -->
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto">
        <h3 class="m-subheader__title m-subheader__title--separator">
          User Roles
        </h3>
        <ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
          <li class="m-nav__item m-nav__item--home">
            <a href="#" class="m-nav__link m-nav__link--icon">
              <i class="m-nav__link-icon la la-home"></i>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'dashboard'?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Home
              </span>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'user/roles_permissions' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                User Roles
              </span>
            </a>
          </li>


        </ul>
      </div>
      <div>

      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              List of User Roles
            </h3>
          </div>
        </div>
      </div>
      <div class="m-portlet__body">
        <!--begin: Datatable -->
        <table width="100%" class="table m-table stripe nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="role_view_table">
          <thead>
            <tr class="">
              <th>ID</th>
              <th>Sl No</th>
              <th>Role</th>
              <th>Status</th>
              <th>Status</th>
              <th>Actions</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>

        <div class="modal fade" tabindex="-1" id="role_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog " role="document" style="max-width: 800px">
            <div class="modal-content">
              <div class="modal-header" style="background-color: #00c5dc;border-radius: 4px">
                <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
                  Edit User Role
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">
                    &times;
                  </span>
                </button>
              </div>
              <form autocomplete="off" id="form_role_edit" data-form-type="update" data-modal-id="role_edit_modal" method="post" action="<?php echo base_url().'user/update_role'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
                <div class="modal-body">
                  <div class="m-form__content">
                    <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="role_edit_msg">
                      <div class="m-alert__icon">
                        <i class="la la-warning"></i>
                      </div>
                      <div class="m-alert__text">
                        Oh snap! Change a few things up and try submitting again.
                      </div>
                      <div class="m-alert__close">
                        <button type="button" class="close" data-close="alert" aria-label="Close"></button>
                      </div>
                    </div>
                    <div class="form-group m-form__group">
                      <label for="user_name">
                        Role Title
                      </label>
                      <div class="m-input-icon m-input-icon--right">
                        <input placeholder="role Name" name="role_title" id="role_title_edit" required type="text"  class="form-control m-input m-input--pill m-input--air form_role_edit_fields "  aria-describedby="basic-addon1">
                        <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                      </div>
                      <span class="m-form__help"></span>
                    </div>
                    <div class="form-group m-form__group">
                      <label for="user_name">
                        Status
                      </label>
                      <div >
                        <span class="m-bootstrap-switch m-bootstrap-switch--pill m-bootstrap-switch--air">
                          <input id="status_edit" name="status" data-switch="true" type="checkbox" data-on-color="success" data-off-color="danger" data-on-text="Active" data-off-text="In Active" >
                        </span>
                      </div>
                    </div>
                  </div>
                  <input type="hidden" name="role_id" id="role_id">
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    Close
                  </button>
                  <button type="submit" class="form_submit_btn btn btn-primary">
                    Submit
                  </button>
                </div>
              </form>
            </div>
          </div>
        </div>

      </div>
    </div>
  </div>
</div>
</div>
<!-- end:: Body -->
<!-- begin::Footer -->

<?php $this->view("includes/Inc_footer");?>
<!-- end::Footer -->
</div>
<!-- end:: Page -->

<?php $this->view("includes/Inc_sidebar");?>
<?php $this->view("includes/Inc_scripts");?>
<?php $this->view("modules/include_scripts/form_submit_scripts");?>
<!--begin::Page Snippets -->
<script>
$("#user_menu").addClass('m-menu__item--active');
//$("#<?php //echo strtolower(str_replace(" ","_",$module_element_data->modulename))."_menu"; ?>").addClass('m-menu__item--active m-menu__item--open');
//$("#<?php //echo strtolower(str_replace(" ","_",$module_element_data->modulename))."_menu_".$module_element_data->elem_slno; ?>").addClass('m-menu__item--active');


var Datatable=function() {
  var t=function() {
    var table = $('#role_view_table').DataTable({
      "ajax":{
        url :"<?php echo base_url().'user/select_roles' ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function(d){

        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,
      "scrollX" : true,
      buttons: [
        { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'} },
        { extend: 'csv', className: 'btn purple btn-outline ' },
        { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
      ],
      dom:"<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
      "lengthMenu": [
        [25, 50, 100, -1],
        [25, 50, 100, "All"] // change per page values here
      ],
      "columnDefs": [
        {
          "targets": [ 0,4 ],
          className: "hidden"
        }
      ],
      // set the initial value
      "pageLength": 25,
      'order': [[0, 'asc']]
    });
    $(".table_filter").on("change", function() {
      table.ajax.reload();
    });
    $(".hidden").hide();

};
return {
  init:function() {
    t()
  }
}
}

();
jQuery(document).ready(function() {
  Datatable.init();
}

);
</script>

<script>
$('body').on('click', '#role_edit_btn', function() {
  var no = $(this).closest('tr').children('td');

  $('#role_id').val(no.eq(0).text());
  $('#role_title_edit').val(no.eq(2).text());
  var status = no.eq(4).text();
  if(status==1)
  {
    $('#status_edit').bootstrapSwitch('state',true)
  }else
  {
    $('#status_edit').bootstrapSwitch('state',false)
  }
})
</script>
