

<?php $__env->startSection('pageTitle', 'Vega Soft'); ?>
<?php $__env->startSection('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">

<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">

<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; ?>"   >
    <?php if($rows->sedp != ""): ?>
  <?php $__currentLoopData = explode(',', $rows->sedp); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $z=>$info): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
     <?php 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 btn-dtbl" col_width="30" >
     <?php endif; ?> 
     <?php 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 btn-dtbl" col_width="40"  >
     <?php endif; ?> 
     <?php if($info == "1" && $z==3): ?>
          <input type="hidden" class="additional_btns" btn_text="Print" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm btn-dtbl" col_width="40"  >
     <?php endif; ?>
  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>
</div>
<div class="card">
    <div class="card-body">
    	<form class="forms-sample" autocomplete="off">
<div class="row">
  <div class="col-md-4">
    <div class="form-group row">
      <label class="col-sm-3 form-label">User Group</label>
      <div class="col-sm-9">
        <input type="text" class="form-control input_text" id="ug_name">
      </div>
    </div>
  </div>

  <div class="col-md-8">
    <h4 class="card-title text-primary">Menus</h4>
    <div class="form-group row"><label class="col-sm-4 form-label"></label>
      <div class="col-sm-8 row ">
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" onclick="select_multiple('s',this.checked);" > Save <i class="input-helper"></i>
          </label>
        </div>
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" onclick="select_multiple('e',this.checked);" > Edit <i class="input-helper"></i>
          </label>
        </div>
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" onclick="select_multiple('d',this.checked);" > Delete <i class="input-helper"></i>
          </label>
        </div>
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" onclick="select_multiple('p',this.checked);" > Print <i class="input-helper"></i>
          </label>
        </div>
      </div>
    </div>
    <div class="col-md-12" id="menu_all">
    
    </div>

  </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" onclick="submit_form();" class="btn btn-primary btn-icon-text save_btn btn-sm" >
                            <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">

tree();

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_group",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              row_id:row_id
          },
          error: function(response) {
          },
          success:function(response){
      
            details=response['details'];
           $('#ug_name').val(response['edit'].ug_name);


           $(details).each(function(key,val){


           })
             
          }
         });










}




  function submit_form() {
    status=0;
    if ($.trim($('#ug_name').val())=='') {
      alert('Enter USer Group ');
       status=1;
      return;
    }
     if ($('input[type="checkbox"]:checked').length=='0') {
      alert('Assign Atleast One Menu To User Group ');
       status=1;
      return;
    }
    if(status==0) Save_form();
  }

  
  function Save_form() {
    marr=[];
     $('.menu_list').each(function(){
      menu_id=$(this).attr('menu_id');
     
      if($('input[name="ugm'+menu_id+'"]:checked').length>0){
        c_string='';
       $('input[name="ugm'+menu_id+'"]').each(function(){
         
         if(this.disabled){
          c_string+=',';
         }else{
          if(this.checked){
            c_string+='1,';
          }else{
            c_string+='0,';
          }
          }
        });
        c_string = c_string.slice(0, -1);
        arr={
          menu_id:menu_id,
          sedp:c_string
        }
         marr.push(arr);
      }
     });
    // console.log(marr);
         $.ajax({
          url: "/op_user_group",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              hidden_status:$.trim($('#hidden_status').val()),
              ug_name:$.trim($('#ug_name').val()),
              marr:marr
          },
          error: function(response) {
          },
          success:function(response){
            alert(response.msg);
            if(response.flag==1) {
              
            }
          }
         });
  }


  get_menus();
  function get_menus() {
           $.ajax({
          url: "/get_menus",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
             ug_id:''
          },
          error: function(response) {
          },
          success:function(response){
            res='';
          var data = JSON.parse(response);
         if(data.length>0){
          $(data).each(function(i,val){
            menu=['Save','Edit','Delete','Print'];
            cls=['s','e','d','p'];
          res+='<div class="form-group row">';
      res+='<label class="col-sm-4 form-label">'+val['menu_name']+'</label>';
      res+='<div class="col-sm-8 row menu_list" menu_id="'+val['menu_id']+'">'; //alert(val['sedp']);
      arr=val['sedp'].split(',');
     /*  $(arr).each(function(j,val_c){ */
      for (var j = 0; j <4; j++) {
    //  alert(arr[j]);
        chk='disabled="" ';
        if(arr[j]=='0'){
          chk='';
        }else if(arr[j]=='1'){
          chk='checked=""';
        }
        res+='<div class="form-check form-check-primary  form-check-inline">';
          res+='<label class="form-check-label">';
            res+='<input type="checkbox" class="form-check-input c'+cls[j]+'"  name="ugm'+val['menu_id']+'" '+chk+'> '+menu[j]+' <i class="input-helper"></i></label>';
        res+='</div>';
       };
        res+='</div>';
      res+='</div>';
    res+='</div>';
            });
         }
         $('#menu_all').html(res);
          }
         });
  }
  function select_multiple(args,chk) { 
    if(chk){
        $('.c'+args).prop('checked',true);
    }else{
      $('.c'+args).prop('checked',false);
    }
    $('input[type="checkbox"]:disabled').prop('checked',false);
    
  }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\service\resources\views/aview/user_group.blade.php ENDPATH**/ ?>