Files
lelong/resources/views/pengurusanpengguna/index.blade.php
T

310 lines
13 KiB
PHP

@extends('layouts.app')
@section('content')
<div class="container-fluid">
<div class="row ">
<div class="col mx-auto">
<div class="card">
<div class="card-header header-style">
<div class="header-style-title">
Senarai Pengguna
</div>
</div>
<div class="card-body">
@if ($message = Session::get('success'))
<div class="alert alert-success">
{{ $message }}
</div>
@endif
@if ($message = Session::get('failed'))
<div class="alert alert-danger">
{{ $message }}
</div>
@endif
<?php
$totaluser = count($alluser);
?>
<form id="exportform" action="{{route('pengguna.export')}}" method="POST">
@csrf
<input type="hidden" name="type" value="User">
<div class="overflow-auto">
<table class="table table-bordered" id="pengguna" style="width:100%">
<thead class="bg-primary text-white">
<tr>
{{-- <th><input type="checkbox" aria-label="Checkbox for following text input" onclick="selectall(this)"></th> --}}
<th>Bil</th>
<th>Nama</th>
<th>Nama Pengguna</th>
<th>Emel</th>
<th class="text-center">Cawangan</th>
<th class="text-center">Taraf</th>
<th>Status</th>
<th class="text-center">Tindakan</th>
</tr>
</thead>
<tbody>
@foreach ($alluser as $user)
<tr>
{{-- <td><input type="checkbox" aria-label="Checkbox for following text input" name="checkboxdata[]" value="{{ $user->id }}"></td> --}}
<td>{{$loop->iteration}}</td>
<td style='white-space:nowrap;'>{{ $user->name }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->email }}</td>
<td style='white-space:nowrap;'>
@if($user->cawangan != NULL)
<span class="badge badge-pill badge-info text-white" style="font-size:100%">{{$user->cawangan->caw_name}}</span>
@endif
</td>
<td class="text-center">
@foreach ($user->roles as $taraf)
<span class="badge badge-pill badge-primary">{{$taraf->name}}</span>
@endforeach
</td>
<td>
@if ($user->status =='active')
<span class="badge badge-pill badge-success">Aktif</span>
@elseif ($user->status == 'inactive')
<span class="badge badge-pill badge-warning">Tidak Aktif</span>
@elseif ($user->status =='banned')
<span class="badge badge-pill badge-danger">Disekat</span>
@endif
</td>
<td class="text-center" style="white-space:nowrap;">
<a class="btn m-1 btn-primary" href="{{ route('pengguna.show',$user->id) }}" data-toggle="tooltip" data-placement="top" title="Kemaskini" style="margin-right:30px"><i class="far fa-edit"></i></a>
<a class="confirmdel btn m-1 btn-danger" href="{{ route('pengguna.delete',$user->id) }}" data-toggle="tooltip" data-placement="top" title="Padam"><i class="far fa-trash-alt"></i></a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" id="myModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Tambah Pengguna</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('pengguna.storepengguna') }}" method="POST" id="formpengguna">
@csrf
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Nama</label>
<input type="text" class="form-control" name="name" id="name" required>
</div>
<div class="form-group col-md-6">
<label for="username">Nama Pengguna</label>
<input type="text" class="form-control" name="username" id="username" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="name">Cawangan</label>
<select class="custom-select" name="caw" id="caw" required>
<option disabled>Pilih Cawangan</option>
<option selected value="">-</option>
@foreach ($caw as $item)
<option value="{{$item->caw_code}}">{{$item->caw_name}}</option>
@endforeach
<!-- <option value="all">Select All</option> -->
</select>
</div>
<div class="form-group col-md-6">
<label for="email">Emel</label>
<input type="email" class="form-control" name="email" id="email" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="notelbimbit">No.Telefon Bimbit</label>
<input type="text" class="form-control" name="notelbimbit" id="notelbimbit" required>
</div>
</div>
<div class="form-row">
<h4 class="col-md-3">Taraf Pengguna</h4>
<div class="form-group col-md-9">
@foreach ($allRolesPluck as $namataraf)
<div class="col-4 form-check form-check-inline">
<input class="form-check-input checkbox" name="taraf{{$namataraf}}" onclick="checkboxRoles(this)" type="checkbox" id="taraf{{$namataraf}}" value="{{$namataraf}}">
<label class="form-check-label" for="taraf{{$namataraf}}">{{$namataraf}}</label>
</div>
@endforeach
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
<button type="button" class="btn btn-primary" onclick="storepengguna()">Simpan</button>
</div>
</div>
</div>
</div>
<script>
var allRoles = JSON.parse('<?php echo json_encode($allRolesPluck) ?>');
var allRolesWithTaraf = [];
for (item of allRoles) {
var itemToAdded = "";
itemToAdded = itemToAdded.concat("taraf", item);
allRolesWithTaraf.push(itemToAdded);
}
function checkboxRoles(taraf) {
for (const item of allRolesWithTaraf) {
if (taraf.id == item) {
if (taraf.checked == true) {
if (taraf.id == "tarafadmin") {
$(".checkbox").each(function() {
$(this).not('#tarafadmin').prop("disabled", true);
});
} else if (taraf.id == "tarafaccount") {
$(".checkbox").each(function() {
$(this).not('#tarafaccount').prop("disabled", true);
});
}else if (taraf.id == "tarafajk") {
$(".checkbox").each(function() {
$(this).not('#tarafajk').prop("disabled", true);
});
} else if (taraf.id == "tarafcallcenter") {
$(".checkbox").each(function() {
$(this).not('#tarafcallcenter').prop("disabled", true);
});
} else if (taraf.id == "tarafpembida") {
$(".checkbox").each(function() {
$(this).not('#tarafpembida').prop("disabled", true);
});
} else if (taraf.id == "tarafpenilai" || taraf.id == "tarafkhazanah" || taraf.id == "tarafpengurus-cawangan") {
$(".checkbox").each(function() {
$(this).not('#tarafpenilai, #tarafkhazanah, #tarafpengurus-cawangan').prop("disabled", true);
});
} else if (taraf.id == "tarafoperasi" || taraf.id == "tarafjurulelong" || taraf.id == "tarafpengurus-operasi") {
$(".checkbox").each(function() {
$(this).not('#tarafoperasi, #tarafjurulelong, #tarafpengurus-operasi').prop("disabled", true);
});
}
} else {
$(".checkbox").each(function() {
if ($('.checkbox:checked').length == 0) {
$(this).prop("disabled", false);
}
});
}
}
}
}
//Enable tooltips everywhere
$(function() {
$('[data-toggle="tooltip"]').tooltip()
})
$('a.confirmdel').confirm({
title: 'Padam Simulasi',
content: 'Adakah anda pasti? Tindakan ini tidak dapat dikembalikan.',
icon: 'fa fa-exclamation-triangle',
type: 'red',
boxWidth: '500px',
useBootstrap: false,
typeAnimated: true,
buttons: {
Batal: {
btnClass: 'btn-default',
action: function() {}
},
Hapus: {
btnClass: 'btn-red',
action: function() {
location.href = this.$target.attr('href');
}
}
}
});
var tablepengguna = $('#pengguna').DataTable({
"columnDefs": [{
"targets": 0,
"orderable": false
},
{
"targets": 4,
// "orderable": false
},
{
"targets": 5,
// "orderable": false
}
],
order: [
[0, 'asc']
],
// "ordering": false,
"info": false,
"lengthChange": false,
"pageLength": 15,
dom: 'Bfrtip',
buttons: [
// 'copy', 'excel', 'pdf'
// { text: 'copy', className: 'btn btn-primary' },
{
className: 'btn btn-outline-success pl-4 pr-4 btn-sm adduser',
text: '<i class="fas fa-plus" id="test"></i>',
titleAttr: 'Tambah Pengguna',
action: function(e, dt, node, config) {
//alert( 'Button activated' );
// console.log('hye');
$('#myModal').modal("show");
$('#myModal').on('shown.bs.modal', function() {
$('#rolename').trigger('focus')
})
}
},
{
className: 'btn btn-outline-secondary pl-4 pr-4 btn-sm export',
titleAttr: 'Eksport kpd CSV',
text: '<i class="fas fa-download"></i>',
action: function(e, dt, node, config) {
$("#exportform").submit();
}
}
]
});
$('.adduser').tooltip();
$('.export').tooltip();
// $( '.dt-buttons').addClass('btn-group');
$('.adduser').removeClass('dt-button');
$('.export').removeClass('dt-button');
function selectall(cb) {
tablepengguna.rows().nodes().to$().find('input[type="checkbox"]').each(function() {
$(this).prop('checked', cb.checked);
})
}
function storepengguna() {
$("#formpengguna").submit();
}
</script>
@endsection