
@extends('layouts.admin')
@section('pageTitle', 'Vega Soft')
@section('page-content')

<style type="text/css">
 .form-check .form-check-label input[type="checkbox"]:disabled + .input-helper::before {
  background-color: #797d83;
  border: #797d83;
}


</style>
<div id="form-div">
<div class="page-header form-header" >
  <h3 class="page-title text-white"><?= $rows->menu_name;?> </h3>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      
        <li class="breadcrumb-item text-success  icon-md " aria-current="page"><i class="icon-list slide1"></i> </li>
      </ol>
    </nav>
    

    <input type="hidden" id="table_settings_field" branch_id="" branch_name=""  column_heading="<?= $rows->column_heading;?>" column_width="<?= $rows->column_width;?>" column_alighn="<?= $rows->column_alighn;?>"  column_conversion="<?= $rows->column_conversion;?>" settings_row_id="<?= $id;?>" sp_date_picker="<?= $rows->sp_date_picker;?>"  header_from_date="<?=date('d-m-Y', strtotime('-7 days')); ?>"   header_till_date="<?=date('d-m-Y'); ?>"  sp_sort="<?= $rows->menu_id; ?>"   >
    @if ($rows->sedp != "")
  @foreach(explode(',', $rows->sedp) as  $z=>$info) 
     @if ($info == "1" && $z==1)
       <input type="hidden" class="additional_btns" btn_text="Edit" btn_click_function="call_edit_modal" btn_class="btn btn-success btn-sm" col_width="30" >
     @endif 
     @if ($info == "1" && $z==2)
        <input type="hidden" class="additional_btns" btn_text="Remove" btn_click_function="call_remove_modal" btn_class="btn btn-danger btn-sm" col_width="40"  >
     @endif 
     @if ($info == "1" && $z==3)
          <input type="hidden" class="additional_btns" btn_text="View" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm" col_width="40"  >
     @endif
  @endforeach
@endif
</div>
<div class="card">
    <div class="card-body">
    	<form class="forms-sample" autocomplete="off">
<div class="row">
  <div class="col-md-6">
    <div class="form-group row">
      <label class="col-sm-3 form-label">Name</label>
      <div class="col-sm-9">
        <input type="text" class="form-control focusable input_text" id="name">
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">User Name</label>
      <div class="col-sm-9">
        <input type="text" class="form-control focusable input_text" id="uname">
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">Password</label>
      <div class="col-sm-9">
        <input type="text" class="form-control focusable input_text" id="password">
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">Phone</label>
      <div class="col-sm-9">
        <input type="text" class="form-control focusable input_text" id="phone">
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">Email</label>
      <div class="col-sm-9">
        <input type="text" class="form-control focusable input_text" id="email">
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">Address</label>
      <div class="col-sm-9">
        <input type="text" class="form-control focusable input_text" id="address">
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">User Group</label>
      <div class="col-sm-9">

         <select class="select2-multiple form-control focusable" name="tags[]" multiple="multiple"
                id="select2Multiple" >
                @foreach ($ug  as $i=>$s)
              
                  <option value="{{ $s->ug_id}}">{{ $s->ug_name}}</option>
                  @endforeach
          </select>
          
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">Branch</label>
      <div class="col-sm-9">
        
                @foreach ($br  as $i=>$s)
              
                  <div class="form-check form-check-success">
                              <label class="form-check-label">
                                <input type="radio" class="form-check-input focusable" name="ExampleRadio2" id="ExampleRadio2" value="{{ $s->CID}}" checked=""> {{ $s->BranchName}} <i class="input-helper"></i></label>
                            </div>
                  @endforeach
         
      </div>
    </div>
    <div class="form-group row">
      <label class="col-sm-3 form-label">Reset Menu</label>
      <div class="col-sm-9">
        <div class="form-check form-check-danger  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="rs_menu"  value="1">  <i class="input-helper"></i>
          <i class="input-helper"></i></label>
        </div>
      </div>
    </div>
  </div>

  <div class="col-md-8"></div>
</div>


                      <div class="template-demo">
                        
                     <button id="save_btn" type="button" class="btn btn-success btn-icon-text save_btn btn-sm"  onclick="submit_form();">
                            <i class="icon-doc btn-icon-prepend"></i> Submit </button>


                            <button id="edit_btn" type="button" class="btn btn-primary btn-icon-text save_btn btn-sm"  onclick="submit_form();">
                            <i class="icon-doc btn-icon-prepend"></i> Edit </button>
                      <button type="button" class="btn btn-danger btn-icon-text reset_btn btn-sm"  >
                            <i class="icon-reload btn-icon-prepend"></i> Reset </button>
                            <input type="hidden" id="row_id" value="0">
                            <input type="hidden" id="hidden_status" value="0">
                          </div>
                    </form>
    </div>
</div>
</div>

<div id="table-div">
<div class="page-header form-header" >
  <h3 class="page-title text-white">  Tables </h3>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      
        <li class="breadcrumb-item text-success  icon-md " aria-current="page"><i class="icon-plus slide2"></i> </li>
      </ol>
    </nav>
</div>

  

<div class="card">
  


    <div class="col-lg-12 col-sm-12 col-md-12" id="table_result">
                                            
                                            </div>


    
    
</div>
</div>







<script type="text/javascript">


 $(document).ready(function() {
            // Select2 Multiple
            $('.select2-multiple').select2({
                placeholder: "Select",
                allowClear: false
            });

           $('#select2Multiple').on("select2:unselecting", function(e){

           
      var unselected_value = e.params.args.data.id;
         $('.ug_id'+unselected_value).remove();
    }).trigger('change');

        });

  function submit_form() {
    status=0;
    if ($.trim($('#name').val())=='') {
      alert('Enter Name ');
      $('#name').focus();
       status=1;
      return;
    }
    if ($.trim($('#uname').val())=='') {
      alert('Enter User Name ');
      $('#uname').focus();
       status=1;
      return;
    }
    if ($.trim($('#password').val())=='') {
      alert('Enter Password ');
      $('#password').focus();
       status=1;
      return;
    }
    if ($.trim($('#select2Multiple').val())=='') {
      alert('Enter User Group ');
      $('#select2Multiple').focus();
       status=1;
      return;
    }
     if ($('input[name="ExampleRadio2"]:checked').length=='0') {
      alert('Assign Atleast One Menu To User Group ');
       status=1;
      return;
    }
    if(status==0) Save_form();
  }
  function Save_form() {
        ug_id = $("#select2Multiple").val();  
         $.ajax({
          url: "/op_user",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
              hidden_status:$.trim($('#hidden_status').val()),
              row_id:$.trim($('#row_id').val()),
              name:$.trim($('#name').val()),
              uname:$.trim($('#uname').val()),
              password:$.trim($('#password').val()),
              email:$.trim($('#email').val()),
              phone:$.trim($('#phone').val()),
              address:$.trim($('#address').val()),
              ug_id:ug_id.join(),
              rs_menu:$.trim($('input[name="rs_menu"]:checked').val()),
              branch_id:$.trim($('input[name="ExampleRadio2"]:checked').val())
          },
          error: function(response) {
          },
          success:function(response){
            alert(response.msg);
            $('#hidden_status,#row_id' ).val('0');
$("#edit_btn").hide();
$("#save_btn").show();
$('#select2Multiple').val('').trigger('change');


reset_form();
            /*if(response.flag==1) {
              
            }*/
          }
         });
  }

function  show_form(){
    $("#form-div").show(500);
$("#table-div").hide();
}

  function set_edit_form(row_id){
  show_form();
$('#hidden_status' ).val("1");
$('#row_id' ).val(row_id);
$("#edit_btn").show();
$("#save_btn").hide();
 $.ajax({
          url: "/edit_user",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
              row_id:row_id
          },
          error: function(response) {
          },
          success:function(response){
            if(response.ug_id!=null){
           ug_id= response.ug_id.split(',');
           $('#select2Multiple').val(ug_id).trigger('change');
         }else{
            $('#select2Multiple').val('').trigger('change');
         }

           $('#name').val(response.name);
              $('#uname').val(response.uname);
              $('#email').val(response.email);
              $('#password').val(response.password);
              $('#phone').val(response.phone);
              $('#address').val(response.address);
              $
              $('input[name="ExampleRadio2"]:checked').val(response.branch_id);
          }
         });



}

</script>
@endsection