edit.blade.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. @extends('admin.partial.template')
  2. @include('admin.settings.sidebar')
  3. @section('section')
  4. <div class="title">
  5. <h3 class="font-weight-bold">Edit Page</h3>
  6. <p class="lead">{{$page->slug}}</p>
  7. </div>
  8. <hr>
  9. <div>
  10. <input type="hidden" id="slug" name="slug" value="{{$page->slug}}">
  11. <input class="form-control form-control-lg" id="title" name="title" placeholder="Title">
  12. <p class="small text-muted">
  13. Page URL: <span class="page-url font-weight-bold">{{$page->url()}}</span>
  14. {{-- <span class="pl-1"><a href="#" class="font-weight-bold">Edit</a></span> --}}
  15. </p>
  16. <div id="editor" style="height: 400px">
  17. {!!$page->content!!}
  18. </div>
  19. <div class="mt-3 d-flex justify-content-between">
  20. <div>
  21. <div class="custom-control custom-switch d-inline pr-3">
  22. <input type="checkbox" class="custom-control-input" id="activeSwitch" {{$page->active?'checked="true"':''}}>
  23. <label class="custom-control-label font-weight-bold" for="activeSwitch">Active</label>
  24. </div>
  25. {{-- <a class="btn btn-light font-weight-bold py-0" href="#">Set Expire Date</a> --}}
  26. </div>
  27. <div>
  28. {{-- <a class="btn btn-light font-weight-bold py-0" href="#">Preview</a> --}}
  29. <a class="btn btn-outline-danger font-weight-bold py-0 btn-delete" href="#">Delete</a>
  30. <a class="btn btn-primary font-weight-bold py-0 btn-save" href="#">Save</a>
  31. </div>
  32. </div>
  33. </div>
  34. @endsection
  35. @push('styles')
  36. <link rel="stylesheet" href="{{mix('css/quill.css')}}"/>
  37. <style type="text/css">
  38. .ql-container {
  39. box-sizing: border-box;
  40. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",
  41. Roboto,Helvetica,Arial,sans-serif;
  42. font-size: 16px;
  43. height: 100%;
  44. margin: 0px;
  45. position: relative;
  46. }
  47. </style>
  48. @endpush
  49. @push('scripts')
  50. <script src="{{mix('js/quill.js')}}"></script>
  51. <script>
  52. window.editor = new Quill('#editor', {
  53. theme: 'snow'
  54. });
  55. $('.btn-save').on('click', function(e) {
  56. e.preventDefault();
  57. let confirm = window.confirm('Are you sure you want to save this page?');
  58. if(confirm !== true) {
  59. return;
  60. }
  61. let html = editor.container.firstChild.innerHTML;
  62. let title = $('#title').val();
  63. let active = $('#activeSwitch')[0].checked;
  64. axios.post(window.location.href, {
  65. slug: '{{$page->slug}}',
  66. title: title,
  67. content: html,
  68. active: active
  69. }).then((res) => {
  70. window.location.href = '{{$page->url()}}';
  71. }).catch((err) => {
  72. console.log(err)
  73. });
  74. });
  75. $('.btn-delete').on('click', function(e) {
  76. e.preventDefault();
  77. let confirm = window.confirm('Are you sure you want to delete this page?');
  78. if(confirm == true) {
  79. axios.post('/i/admin/settings/pages/delete', {
  80. id: '{{$page->id}}'
  81. }).then(res => {
  82. window.location.href = '/i/admin/settings/pages';
  83. }).catch(err => {
  84. swal('Error', 'An error occured!', 'error');
  85. console.log(err);
  86. });
  87. }
  88. });
  89. $('#title').on('change input', function(e) {
  90. e.preventDefault();
  91. let title = this.value.split(' ').join('-').toLowerCase();
  92. })
  93. </script>
  94. @endpush