edit.blade.php 3.7 KB

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