New-OMIS/resources/views/crud/generated/users/index.blade.php

305 lines
13 KiB
PHP
Raw Normal View History

2024-04-07 07:28:58 +00:00
@extends('layouts.app')
2024-04-05 05:22:15 +00:00
@section('content')
2024-04-07 07:28:58 +00:00
<div class="row">
2024-04-05 05:22:15 +00:00
<div class="col-lg-4">
2024-04-07 07:28:58 +00:00
<div class="card">
<div class="card-header">
<h2>{{ label('Create User') }}</h2>
</div>
<div class="card-body">
<form action="{{ $editable ? route('users.update', [$data->id]) : route('users.store') }}" id="updateCustomForm"
method="POST">
@csrf <input type=hidden name='id' value='{{ $editable ? $data->id : '' }}' />
<div class="row">
<div class="col-lg-12">{{ createText('name', 'name', 'Name', '', $editable ? $data->name : '') }}
</div>
<div class="col-lg-12">
{{ createText('email', 'email', 'Email', '', $editable ? $data->email : '') }}
</div>
<div class="col-lg-12">
{{ createText('username', 'username', 'Username', '', $editable ? $data->username : '') }}
</div>
<div class="col-lg-12">
{{ createPassword('password', 'Password', '', $editable ? $data->password : '') }}
</div>
2024-04-05 05:22:15 +00:00
2024-04-07 07:28:58 +00:00
<div class="col-lg-12">
{{ createCustomSelect(
'tbl_roles',
'title',
'role_id',
$editable ? $data->roles_id : '',
'Roles Id',
'roles_id',
'form-control
select2',
'status<>-1',
) }}
</div>
<div class="col-lg-12">
{{ createCustomSelect(
'tbl_branches',
'title',
'branch_id',
$editable ? $data->branches_id : '',
'Branches Id',
'branches_id',
'form-control
select2',
'status<>-1',
) }}
</div>
2024-04-05 05:22:15 +00:00
2024-04-07 07:28:58 +00:00
<div class="col-lg-12">
{{ createCustomSelect(
'tbl_employees',
'title',
'employee_id',
$editable ? $data->employees_id : '',
'employees Id',
'employees_id',
'form-control
select2',
'status<>-1',
) }}
</div>
<div class="col-md-12">
<?php createButton('btn-primary btn-update', '', 'Submit'); ?>
<?php createButton('btn-primary btn-cancel', '', 'Cancel', route('users.index')); ?>
</div>
2024-04-05 05:22:15 +00:00
</div>
2024-04-07 07:28:58 +00:00
</form>
2024-04-05 05:22:15 +00:00
</div>
2024-04-07 07:28:58 +00:00
</div>
2024-04-05 05:22:15 +00:00
</div>
<div class="col-lg-8">
2024-04-07 07:28:58 +00:00
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h2>{{ label('Users List') }}</h2>
<!-- <a href="{{ route('users.create') }}" class="btn btn-primary"><span>{{ label('Create New') }}</span></a> -->
</div>
<div class="card-body">
<table class="dataTable table" id="tbl_users" data-url="{{ route('users.sort') }}">
<thead class="table-light">
<tr>
<th class="tb-col"><span class="overline-title">{{ label('Sn.') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Name') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Email') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('User Name') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Role') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Branch') }}</span></th>
2024-04-05 05:22:15 +00:00
2024-04-07 07:28:58 +00:00
<th class="tb-col"><span class="overline-title">{{ label('Employee') }}</span></th>
<th class="tb-col" data-sortable="false"><span class="overline-title">{{ label('Action') }}</span>
</th>
</tr>
</thead>
<tbody>
@php
$i = 1;
@endphp
@foreach ($data as $item)
<tr data-id="{{ $item->id }}" data-display_order="{{ $item->display_order }}"
class="draggable-row <?php echo $item->status == 0 ? ' bg-light bg-danger' : ''; ?>">
<td class="tb-col">{{ $i++ }}</td>
<td class="tb-col">{{ $item->name }}</td>
<td class="tb-col">{{ $item->email }}</td>
<td class="tb-col">{{ $item->username }}</td>
<td class="tb-col">{!! getFieldData('tbl_roles', 'title', 'role_id', $item->roles_id) !!}
<td class="tb-col">{!! getFieldData('tbl_branches', 'title', 'branch_id', $item->branches_id) !!}
2024-04-05 05:22:15 +00:00
2024-04-07 07:28:58 +00:00
<td class="tb-col">{!! getFieldData('tbl_employees', 'title', 'employee_id', $item->employees_id) !!}
</td>
<td class="tb-col">
<div class="dropdown d-inline-block">
<button class="btn btn-soft-secondary btn-sm dropdown" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
<i class="ri-more-fill align-middle"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a href="{{ route('users.show', [$item->id]) }}" class="dropdown-item"><i
class="ri-eye-fill text-muted me-2 align-bottom"></i>
{{ label('View') }}</a></li>
<li><a href="{{ route('users.edit', [$item->id]) }}" class="dropdown-item edit-item-btn"><i
class="ri-pencil-fill text-muted me-2 align-bottom"></i>
{{ label('Edit') }}</a></li>
<li>
<a href="{{ route('users.toggle', [$item->id]) }}" class="dropdown-item toggle-item-btn"
onclick="confirmToggle(this.href)">
<i class="ri-article-fill text-muted me-2 align-bottom"></i>
{{ $item->status == 1 ? label('Unpublish') : label('Publish') }}
</a>
</li>
<li>
<a href="{{ route('users.destroy', [$item->id]) }}" class="dropdown-item remove-item-btn"
onclick="confirmDelete(this.href)">
<i class="ri-delete-bin-fill text-muted me-2 align-bottom"></i> {{ label('Delete') }}
</a>
</li>
</ul>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
2024-04-05 05:22:15 +00:00
</div>
2024-04-07 07:28:58 +00:00
</div>
2024-04-05 05:22:15 +00:00
</div>
2024-04-07 07:28:58 +00:00
</div>
2024-04-05 05:22:15 +00:00
@endsection
2024-04-07 07:28:58 +00:00
@push('css')
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/rowreorder/1.4.0/css/rowReorder.dataTables.min.css">
2024-04-05 05:22:15 +00:00
@endpush
2024-04-07 07:28:58 +00:00
@push('js')
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.68/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.68/vfs_fonts.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/rowreorder/1.4.0/js/dataTables.rowReorder.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
2024-04-05 05:22:15 +00:00
$(d.ready(function(e) {
2024-04-07 07:28:58 +00:00
$('.change-alias-badge').on('click', function() {
var aliasWrapper = $(this).prev('.alias-wrapper');
var aliasSpan = aliasWrapper.find('.alias');
var aliasInput = aliasWrapper.find('.alias-input');
var isEditing = $(this).hasClass('editing');
aliasInput.toggleClass("d-none");
if (isEditing) {
// Update alias text and switch to non-editing state
var newAlias = aliasInput.val();
aliasSpan.text(newAlias);
aliasSpan.show();
aliasInput.hide();
$(this).removeClass('editing').text('Change Alias');
var articleId = $(aliasWrapper).data('id');
var ajaxUrl = "{{ route('users.updatealias') }}";
var data = {
articleId: articleId,
newAlias: newAlias
};
$.ajax({
url: ajaxUrl,
type: 'POST',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: data,
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.error(error);
}
});
} else {
// Switch to editing state
aliasSpan.hide();
aliasInput.show().focus();
$(this).addClass('editing').text('Save Alias');
}
});
var mytable = $(".dataTable").DataTable({
ordering: true,
rowReorder: {
//selector: 'tr'
},
});
var isRowReorderComplete = false;
mytable.on('row-reorder', function(e, diff, edit) {
isRowReorderComplete = true;
});
mytable.on('draw', function() {
if (isRowReorderComplete) {
var url = mytable.table().node().getAttribute('data-url');
var ids = mytable.rows().nodes().map(function(node) {
return $(node).data('id');
}).toArray();
console.log(ids);
$.ajax({
url: url,
type: "POST",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
data: {
id_order: ids
},
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.error(error);
}
});
isRowReorderComplete = false;
}
});
});
2024-04-05 05:22:15 +00:00
2024-04-07 07:28:58 +00:00
function confirmDelete(url) {
event.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: 'You will not be able to recover this item!',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
cancelButtonText: 'Cancel',
reverseButtons: true
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: url,
type: 'DELETE',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(response) {
Swal.fire('Deleted!', 'The item has been deleted.', 'success');
location.reload();
},
error: function(xhr, status, error) {
Swal.fire('Error!', 'An error occurred while deleting the item.', 'error');
}
});
2024-04-05 05:22:15 +00:00
}
2024-04-07 07:28:58 +00:00
});
}
2024-04-05 05:22:15 +00:00
2024-04-07 07:28:58 +00:00
function confirmToggle(url) {
event.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: 'Publish Status of Item will be changed!! if Unpublished, links will be dead!',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Proceed',
cancelButtonText: 'Cancel',
reverseButtons: true
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: url,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(response) {
Swal.fire('Updated!', 'Publishing Status has been updated.', 'success');
location.reload();
},
error: function(xhr, status, error) {
Swal.fire('Error!', 'An error occurred.', 'error');
}
});
2024-04-05 05:22:15 +00:00
}
2024-04-07 07:28:58 +00:00
});
}
</script>
@endpush