pembuatan-program.blade.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php $getStatus = \App\Model\Privillage\Role::where('id',Auth::user()->role_id)->value('akses'); ?>
  2. @extends('dev.core.using')
  3. @section('content')
  4. <style>
  5. .parent-list {
  6. list-style: none;
  7. }
  8. .arr-btn{
  9. font-size: 20px;
  10. margin-right: .5em;
  11. cursor: pointer;
  12. width: 1.3rem;
  13. height: 1.3rem;
  14. border-radius: .5rem;
  15. text-align: center;
  16. }
  17. .arr-btn:hover{
  18. background: #cdcdcd
  19. }
  20. .ic-container{
  21. /* margin-top: .3em; */
  22. gap:.5em;
  23. }
  24. .ic-container > .ic {
  25. width: 1.5rem;
  26. height: 1.3rem;
  27. border-radius: .5rem;
  28. text-align: center;
  29. cursor:pointer;
  30. background: #cdcdcd;
  31. /* padding-top: .3rem; */
  32. font-size: .8em;
  33. list-style: none;
  34. color: #000;
  35. }
  36. .ic-container > .ic:hover {
  37. background: #eee;
  38. }
  39. @media only screen and (max-width: 700px) {
  40. .template-item{
  41. white-space: nowrap;
  42. overflow: hidden;
  43. text-overflow: ellipsis;
  44. max-width: 200px;
  45. padding-left:0px !important;
  46. }
  47. }
  48. </style>
  49. <br/>
  50. <br/>
  51. <div class="card card-stats">
  52. <div class="card-body">
  53. <div class="row">
  54. <div class="col-md-12">
  55. <a type="button" href="{{route('pembuatan-program.add')}}" class="btn btn-primary" style="background: #193865;color: #fff"><i class="fa fa-plus"></i> Tambah Baru</a>
  56. </div>
  57. </div><br>
  58. <ul class="parent-list" id="par-list">
  59. <li>
  60. </li>
  61. </ul>
  62. </div>
  63. </div>
  64. <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" id="modal-delete">
  65. <form action="" method="POST" id="form-delete">
  66. @csrf
  67. <div class="modal-dialog" role="document">
  68. <div class="modal-content">
  69. <div class="modal-header">
  70. <h5 class="modal-title" id="exampleModalLabel">Konfirmasi</h5>
  71. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  72. <span aria-hidden="true">&times;</span>
  73. </button>
  74. </div>
  75. <div class="modal-body">
  76. <input type="hidden" id="delete-id">
  77. <center>Anda yakin akan menghapus Program <span id="delete-nama" style="font-weight:bold"></span> ?</center>
  78. </div>
  79. <div class="modal-footer">
  80. <div class="form-group center">
  81. <button type="button" class="btn btn-secondary" data-dismiss="modal">Batalkan</button>
  82. <button type="submit" class="btn btn-danger">Hapus Data</button>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </form>
  88. </div>
  89. <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" id="form_assign">
  90. <form action="{{route('pembuatan-program.assign-role')}}" method="POST">
  91. @csrf
  92. <div class="modal-dialog" role="document">
  93. <div class="modal-content">
  94. <div class="modal-header">
  95. <h5 class="modal-title" id="exampleModalLabel">Program Role</h5>
  96. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  97. <span aria-hidden="true">&times;</span>
  98. </button>
  99. </div>
  100. <div class="modal-body">
  101. <input type="hidden" class="form_assign" id="form_assign_id_template_program" name="id_template_program">
  102. @foreach($roles as $row)
  103. <div class="form-check col-md-6">
  104. <input type="checkbox" class="form_assign" name="id_role_{{$row->id}}" id="form_assign_id_role_{{$row->id}}">
  105. <label>{{$row->role_name}}</label>
  106. </div>
  107. @endforeach
  108. </div>
  109. <div class="modal-footer">
  110. <div class="form-group">
  111. <button type="submit" class="btn btn-primary">Simpan Data</button>
  112. <button type="button" class="btn btn-secondary" data-dismiss="modal">Batalkan</button>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </form>
  118. </div>
  119. <script>
  120. $(document).ready(function () {
  121. var base = "{{url('/')}}"
  122. $(document).ready(function () {
  123. getList()
  124. })
  125. async function getList () {
  126. const url = "{{url('api/pembuatan-program')}}"
  127. const res = await fetch(url,{
  128. method: 'GET', // *GET, POST, PUT, DELETE, etc.
  129. mode: 'cors', // no-cors, *cors, same-origin
  130. cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
  131. credentials: 'same-origin', // include, *same-origin, omit
  132. headers: {
  133. 'Content-Type': 'application/json'
  134. // 'Content-Type': 'application/x-www-form-urlencoded',
  135. }
  136. })
  137. const resp = await res.json()
  138. console.log(resp.data)
  139. if (resp.status === 200) {
  140. var html = ""
  141. for (let dd in resp.data) {
  142. html += `<li class="row" style="padding-top:7px;">
  143. <div class="col-xs-4 col-sm-4 col-md-7 template-item" title="${resp.data[dd].nama}"><b>${resp.data[dd].nama}</b></div>
  144. <div class="ic-container" style="display:flex">
  145. <small><a href="#" class="badge" onClick="assignRole(${resp.data[dd].id})" style="background: #193865;color: #fff;text-transform:none !important">Assign Role</a></small>
  146. <a href="${base}/pengaturan/pembuatan-program/edit/${resp.data[dd].id}" class="ic"><i class="fas fa-edit" ></i></a>
  147. <a href="${base}/pengaturan/pembuatan-program/detail/${resp.data[dd].id}" class="ic"><i class="fas fa-eye" ></i></a>
  148. <a href="#" data-toggle="modal" id="btn-delete-${resp.data[dd].id}" data-nama="${resp.data[dd].nama}" data-target="#modal-delete" onClick="deleteData(${resp.data[dd].id})" class="ic"><i class="fas fa-trash" ></i></a>
  149. </div>
  150. </li>`
  151. }
  152. $('#par-list').html(
  153. html
  154. )
  155. }
  156. }
  157. })
  158. function deleteData(id){
  159. var nama = $('#btn-delete-'+id).attr('data-nama');
  160. $('#form-delete').attr("action","{{url('pengaturan/pembuatan-program/delete')}}/"+id);
  161. $('#delete-id').val(id);
  162. $('#delete-nama').text();
  163. $('#delete-nama').text(nama);
  164. }
  165. function assignRole(id_template){
  166. $.ajax({
  167. url: "{{url('api/pembuatan-program')}}/"+id_template,
  168. dataType: "json",
  169. type: "GET",
  170. async: true,
  171. data: { },
  172. beforeSend: function(){
  173. $('.form_assign').val('');
  174. $('.form_assign').attr('checked',false);
  175. },
  176. success: function (data) {
  177. $('#form_assign_id_template_program').val(id_template);
  178. $('#form_assign').modal('show');
  179. $.each( data.data.template_program_role, function( key, value ) {
  180. $('#form_assign_id_role_'+value.id_role).attr('checked',true);
  181. });
  182. console.log(data);
  183. },
  184. error: function (xhr, exception) {
  185. var msg = "";
  186. if (xhr.status === 0) {
  187. msg = "Not connect.\n Verify Network." + xhr.responseText;
  188. } else if (xhr.status == 404) {
  189. msg = "Requested page not found. [404]" + xhr.responseText;
  190. } else if (xhr.status == 500) {
  191. msg = "Internal Server Error [500]." + xhr.responseText;
  192. } else if (exception === "parsererror") {
  193. msg = "Requested JSON parse failed.";
  194. } else if (exception === "timeout") {
  195. msg = "Time out error." + xhr.responseText;
  196. } else if (exception === "abort") {
  197. msg = "Ajax request aborted.";
  198. } else {
  199. msg = "Error:" + xhr.status + " " + xhr.responseText;
  200. }
  201. console.log(msg);
  202. }
  203. });
  204. };
  205. </script>
  206. @endsection