Ekapp/skolehjem/resources/views/admin/news/edit.blade.php

123 lines
4.4 KiB
PHP
Raw Normal View History

2020-08-06 10:21:19 +00:00
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Nyhed - Rediger
@endsection
@section("path")
<a href="{{route('news.edit', ['news' => $news])}}" class="text-white">Rediger nyhed</a> /
@endsection
@section("content")
<style>
#editor {
2020-08-06 10:21:19 +00:00
margin-bottom: 1rem;
}
</style>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
2020-08-06 10:21:19 +00:00
<h1>Rediger nyhed:</h1>
<form method="post" action="{{route("news.update", ["news" => $news])}}">
@csrf
@method("PUT")
<label for="title">Navn</label>
2020-08-17 08:21:02 +00:00
<label hidden id="error" for="errormesseages">Dette navn findes allerede</label>
<input value="{{$news->subname}}" type="text" name="subname" id="title" required>
<div id="editor">{!! $news->content !!}</div>
<textarea name="content" class="d-none" id="hiddenArea"></textarea>
2020-08-17 08:21:02 +00:00
<input id="disable" type="submit" class="btn btn-dark text-white" value="Rediger">
2020-08-06 10:21:19 +00:00
</form>
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
2020-08-06 10:21:19 +00:00
<script>
var container = document.getElementById("editor");
var fullEditor = new Quill(container, {
modules: {
'toolbar': [
[ 'bold', 'italic', 'underline', 'strike' ],
[{ 'color': [] }],
[{ 'script': 'super' }, { 'script': 'sub' }],
[{ 'header': '1' }, { 'header': '2' }, 'blockquote' ],
[{ 'list': 'ordered' }, { 'list': 'bullet'}, { 'indent': '-1' }, { 'indent': '+1' }],
[ {'direction': 'rtl'}, { 'align': [] }],
[ 'link' ],
[ 'clean' ]
],
},
theme: 'snow'
});
</script>
<script>
var form = document.querySelector('form');
form.onsubmit = function() {
var myEditor = document.getElementById('editor');
var html = myEditor.children[0].innerHTML;
document.getElementById('hiddenArea').innerText = html;
}
2020-08-06 10:21:19 +00:00
</script>
@endsection
@section("scripts")
<script>
$(function() {
$('form').areYouSure(
{
message: 'It looks like you have been editing something. '
+ 'If you leave before saving, your changes will be lost.'
}
);
});
2020-08-17 08:21:02 +00:00
//Dont delete me, if the user reloads the pages with text in the text-box this code runs.
$(document).ready(function () {
$value = $('#title').val();
$.ajax({
type: 'get',
url: '{{route('news.nameCheckUpdate')}}',
data: {'nameCheck':$value, 'id': {{$news->id}}},
success:function (data) {
console.log(data);
if(data){
$("#error").show(100);
$("#error").css('color', 'red');
$("#disable").prop('disabled', true);
$('#disable').css('cursor','not-allowed');
}else{
$("#error").hide();
$("#disable").prop('disabled', false);
$('#disable').css('cursor','pointer');
}
},
error:function (data) {
console.log(data);
}
});
});
$('#title').on('keyup', function () {
$value = $(this).val();
$.ajax({
type: 'get',
url: '{{route('news.nameCheckUpdate')}}',
data: {'nameCheck':$value, 'id': {{$news->id}}},
success:function (data) {
if(data){
$("#error").show(100);
$("#error").css('color', 'red');
$("#disable").prop('disabled', true);
$('#disable').css('cursor','not-allowed');
}else{
$("#error").hide();
$("#disable").prop('disabled', false);
$('#disable').css('cursor','pointer');
}
},
error:function (data) {
console.log(data);
}
});
})
</script>
@endsection