Ekapp/skolehjem/resources/views/admin/guides/index.blade.php

214 lines
8.7 KiB
PHP
Raw Normal View History

@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Vejledning - Vis
@endsection
@section("path")
2020-10-07 06:25:00 +00:00
<a href="{{ route('guides.index') }}" class="text-white">Vis Vejledning</a> /
@endsection
@section("content")
<style>
.letterSpaceTable{
letter-spacing: 1.2px;
}
</style>
@if(auth()->user()->can('guides.create'))
<div class="row align-items-center mb-2">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('guides.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Bruger Vejledning</a>
2020-09-10 13:31:06 +00:00
<a class="btn btn-inline btn-sde-blue mb-0 ml-1" href="{{ route('guides-category.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret vejlednings kategori</a>
</div>
@endif
<div id="guides" class="letterSpaceTable">
2020-09-10 13:31:06 +00:00
<label>Vejledninger</label>
2020-12-01 11:05:18 +00:00
</div>
<table class="tbl letterSpaceTable fixOverflow">
<tr>
<th>Navn</th>
<th>Kategori</th>
<th class="w-1em"><img class="w-100" src="{{ asset('/images/icons/preview.svg') }}" alt="preview"></th>
@if(auth()->user()->can('guides.edit'))
<th class="w-1em"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th>
@endif
@if(auth()->user()->can('guides.delete'))
<th class="w-1em"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
@endif
</tr>
@foreach($guides as $guide)
2020-12-01 11:05:18 +00:00
<tr id="guide_row_{{ $guide->id }}" data-id="guide_category_row{{ \App\GuidesCategory::query()->where('id', '=', $guide->guide_category_id)->first()->id }}">
<td>{{$guide->name}}</td>
<td>{{ \App\GuidesCategory::query()->where('id', '=', $guide->guide_category_id)->first()->guidesCategoryName }}</td>
2021-04-27 10:27:46 +00:00
<td><a id="preview" onclick="modalGuidesContent({{$guide->id}})" style="cursor: pointer" ><img class="w-100" src="{{ asset('/images/icons/preview-dark.svg') }}" alt="preview"></a></td>
@if(auth()->user()->can('guides.edit'))
<td><a href="{{ route("guides.edit", [ "guide" => $guide ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
@endif
@if(auth()->user()->can('guides.delete'))
2020-12-01 11:05:18 +00:00
<td>
@csrf
<a class="w-100 nostyle" onclick="delete_guide({{ $guide->id }})"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></a>
</td>
@endif
</tr>
@endforeach
2020-10-07 06:25:00 +00:00
@if(count($guides) == 0)
<tr>
<td colspan="5">Ingen vejledninger</td>
2020-10-07 06:25:00 +00:00
</tr>
@endif
</table>
<div id="guidesCategory" class="mt-2 letterSpaceTable">
2020-09-10 13:31:06 +00:00
<label>Kategorier til de forskellige vejledninger</label>
<table class="tbl">
<tr>
<th>Vejlednings kategorier</th>
@if(auth()->user()->can('guides.edit'))<!--Jeg ved ikke om vi lave mere specifike permissions-->
<th class="w-1em"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th>
2020-09-10 13:31:06 +00:00
@endif
@if(auth()->user()->can('guides.delete'))<!--Jeg ved ikke om vi lave mere specifike permissions-->
<th class="w-1em"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
2020-09-10 13:31:06 +00:00
@endif
</tr>
@foreach(\App\GuidesCategory::query()->get() as $guideCategory)
2020-12-01 11:05:18 +00:00
<tr id="category_row_{{ $guideCategory->id }}">
2020-09-10 13:31:06 +00:00
<td>{{$guideCategory->guidesCategoryName}}</td>
2020-09-14 06:57:31 +00:00
@if(auth()->user()->can('guides.edit'))
<td><a href="{{ route("guides-category.edit", $guideCategory) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update2"></a></td>
@endif
@if(auth()->user()->can('guides.delete'))
2020-12-01 11:05:18 +00:00
<td>
@csrf
<a class="w-100 nostyle" onclick="delete_category({{ $guideCategory->id }})"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></a>
2020-09-14 06:57:31 +00:00
</td>
@endif
2020-09-10 13:31:06 +00:00
</tr>
@endforeach
</table>
</div>
2021-04-27 10:27:46 +00:00
<div id="guidesModal" class="modal zindex-100">
<div id="modal-content" class="modal-content text-black d-block w-50">
<span class="close" onclick="closeModal()">&times;</span>
<center>
<h1 id="name"></h1>
<hr>
<img id="eventimg">
<strong><label for="guide_articles">Vejledning</label></strong>
<p id="guide_articles"></p>
</center>
</div>
</div>
@endsection
@section('scripts')
<script>
2021-04-27 10:27:46 +00:00
var modalGuides = document.getElementById("guidesModal");
2021-04-27 10:27:46 +00:00
function modalGuidesContent(id) {
$.ajax({
type: 'get',
url: '{{route('guides.preview')}}',
data: {'preview':id},
success:function (data) {
2021-04-28 12:35:08 +00:00
modalGuides.style.display = "flex";
var l = JSON.parse(data);
console.log(l);
$("#name").html(l.name);
$("#guide_articles").html(l.guide_articles);
if (l.filename)
$("#eventimg").attr('src', l.filename);
},
error:function (data) {
console.log(data);
}
});
}
function closeModal() {
2021-04-27 10:27:46 +00:00
modalGuides.style.display = "none";
$("#name").html('');
$("#guide_articles").html('');
$("#eventimg").attr('src', '');
}
window.onmousedown = function(event) {
2021-04-27 10:27:46 +00:00
if (event.target == modalGuides) {
modalGuides.style.display = "none";
$("#name").html('');
$("#guide_articles").html('');
$("#eventimg").attr('src', '');
}
}
</script>
2020-12-01 11:05:18 +00:00
<script>
function delete_guide(id) {
var token = $("input[name='_token']").val();
Swal.fire({
title: 'Er du sikker?',
text: "Dette kan ikke blive ændret tilbage!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Slet Vejledningen',
cancelButtonText: 'Annuller'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "guides/"+id,
data:{'_token':token, _method: 'DELETE'},
success: function () {
$('#guide_row_'+id).remove();
Swal.fire(
'Vejledningen er slettet!',
'',
'success'
)
},
error:function (data) {
console.log(data);
}
});
}
})
}
function delete_category(id) {
var token = $("input[name='_token']").val();
Swal.fire({
title: 'Er du sikker?',
text: "Dette kan ikke blive ændret tilbage!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Slet Kategorien',
cancelButtonText: 'Annuller'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "guides-category/"+id,
data:{'_token':token, _method: 'DELETE'},
success: function () {
$('#category_row_'+id).remove();
location.reload();
},
error:function (data) {
console.log(data);
}
});
}
})
}
</script>
@endsection