377 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			377 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			PHP
		
	
	
| @extends('layouts.master')
 | |
| 
 | |
| @section('page-css')
 | |
| <link rel="stylesheet" media="screen, print" href="{{asset('assets/css/datagrid/datatables/datatables.bundle.css')}}">
 | |
| <link rel="stylesheet" href="{{asset('assets/css/formplugins/dropzone/dropzone.css')}}">
 | |
| <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.css"> -->
 | |
| <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js"></script> -->
 | |
| 
 | |
| <style type="text/css">
 | |
|     .listItem{
 | |
|         list-style: none;
 | |
|         margin: 0;
 | |
|         padding: 0;
 | |
|     }
 | |
|     .listItem > li{
 | |
|         display: inline-block;
 | |
|         margin: 10px;
 | |
|     }
 | |
|     .listItem > li:hover{
 | |
|         cursor: pointer;
 | |
|     }
 | |
|     .listItem > li .number{
 | |
|         font-size: 14px;
 | |
|         color: #fff;
 | |
|         background: #0ba360 !important;
 | |
|         padding: 10px;
 | |
|         border-radius: 10%;
 | |
|     }
 | |
|     .level{
 | |
|         float: right;
 | |
|         color: #fff;
 | |
|         text-align: center;
 | |
|         width: 100px;
 | |
|     }
 | |
|     .nav-link{
 | |
|         border-radius: 0px!important;
 | |
|     }
 | |
|     .pageNumber{ list-style:none; padding:0px; margin: 0px;}
 | |
|     .pageNumber > li{ display: inline-block; padding: 12px; background: rgba(255, 255, 255, 0.5); margin: 5px 1px;}
 | |
|     .pageNumber > li:hover{cursor: pointer;}
 | |
|     .page.active {
 | |
|         background-color: #007bff; /* Warna biru */
 | |
|         color: white;
 | |
|         font-weight: bold;
 | |
|     }
 | |
| /*    #file-list{ margin: 0px; padding: 0px; width: 40%;}*/
 | |
|     #file-list > li{
 | |
| /*        padding: 10px;*/
 | |
| /*      border: 1px solid #ddd;*/
 | |
| /*      border-radius: 5px;*/
 | |
| /*      margin: 5px 0px;*/
 | |
|     }
 | |
| </style>
 | |
| @endsection
 | |
| @section('content')
 | |
| <div class="subheader">
 | |
|     <h1 class="subheader-title">
 | |
|         <i class='subheader-icon fal fa-edit'></i> {{$title}}
 | |
|     </h1>
 | |
| </div>
 | |
| <div class="row">
 | |
|     <div class="col-lg-12">
 | |
|         @if ($errors->any())
 | |
|             <div class="alert alert-danger">
 | |
|                 <ul>
 | |
|                     @foreach ($errors->all() as $error)
 | |
|                         <li>{{ $error }}</li>
 | |
|                     @endforeach
 | |
|                 </ul>
 | |
|             </div>
 | |
|         @endif
 | |
|         <form method="POST" id="form">
 | |
|         {{csrf_field()}}
 | |
|         <input type="hidden" name="secure_id" value="{{encode_id($kuesioner->KuesionerId)}}">
 | |
|             <div class="card">
 | |
|                 <div class="card-body">
 | |
|                     <div class="row">
 | |
|                         <div class="col-md-12 p-3">
 | |
|                             <table class="" border="0" style="width:100%">
 | |
|                                 <tr>
 | |
|                                     <td rowspan="5" width="5" style="vertical-align: middle; padding-right: 10px;">
 | |
|                                         <i class="fal fa-building fa-5x"></i>
 | |
|                                     </td>
 | |
|                                 </tr>
 | |
|                                 <tr>
 | |
|                                     <td colspan="2"><h5 class="text-success">NPSN: {{session('npsn')}}</h5></td>
 | |
|                                 </tr>
 | |
|                                 <tr>
 | |
|                                     <td colspan="2"><h4><b>{{session('name')}}</b></h4></td>
 | |
|                                 </tr>
 | |
|                                 <tr>
 | |
|                                     <td colspan="2"><span class="badge badge-primary">{{session('tingkat_sekolah')}}</span> <span class="badge badge-success">{{session('status_sekolah')}}</span></td>
 | |
|                                 </tr>
 | |
|                                 <tr>
 | |
|                                     <td colspan="2"><p>{{session('alamat_sekolah')}}</p></td>
 | |
|                                 </tr>
 | |
|                             </table>
 | |
|                         </div>
 | |
|                         <div class="col-md-12">
 | |
|                             <div class="alert alert-warning">
 | |
|                                 <p class="mb-0"><i class="fal fa-info-circle"></i> Anda Belum Melakukan Finalisasi Proses Data Kriteria</p>
 | |
|                                 <p class="mb-0"><i class="fal fa-info-circle"></i> Klik <b class="text-danger">Progress Usulan</b> untuk melakukan Finalisasi Proses Data Kriteria</p>
 | |
|                             </div>
 | |
|                         </div>
 | |
|                         <div class="col-md-12" style="background: rgba(23, 162, 184, 0.2) !important;">
 | |
|                             <ul class="pageNumber">
 | |
|                                 @foreach($page as $hal)
 | |
|                                 <li class="page {{ (checkPenilaian($hal) == true ? 'bg-success text-white' : '' )}}" data-number={{$hal}}>{{$hal}}</li>
 | |
|                                 @endforeach
 | |
|                                 <li class="resume">Resume</li>
 | |
|                                 <li class="progress_usulan">Progress Usulan</li>
 | |
|                             </ul>
 | |
|                         </div>
 | |
|                         <div class="col-md-12 mt-3">
 | |
|                             <div class="alert alert-primary mb-2 p-2">
 | |
|                                 <h6 class="mb-0"><b class="changeTitle">I. Perencanaan Gerakan PBLHS</b></h6>
 | |
|                             </div>
 | |
|                         </div>
 | |
|                         <div class="col-md-12 bodyInput">
 | |
|                             <div id="loading-spinner" style="display: none; text-align: center;">
 | |
|                                 <img src="{{ asset('assets/spinner.gif') }}" alt="Loading..." width="20">
 | |
|                             </div>
 | |
|                             <div class="changeForm">
 | |
|                                 {!! formKriteria(1) !!}
 | |
|                             </div>
 | |
|                         </div>
 | |
|                         
 | |
|                     </div>
 | |
|                 </div>
 | |
|                 <div class="card-footer">
 | |
|                     @if(session('group_alias') == 'sekolah')
 | |
|                         @if($kuesioner->status == 1)
 | |
|                             <button id="btnSave" class="btn btn-success"><i class="fal fa-save"></i> Simpan Data</button>
 | |
|                         @endif
 | |
|                     @endif
 | |
|                 </div>
 | |
|                 
 | |
|             </div>
 | |
|         </form>
 | |
|         
 | |
|     </div>
 | |
| </div>
 | |
| @endsection
 | |
| @section('page-js')
 | |
| <script type="text/javascript" src="{{asset('assets/js/formplugins/dropzone/dropzone.js')}}"></script>
 | |
| <script type="text/javascript">
 | |
|     @if(session('group_alias') == 'sekolah')
 | |
|         @if($kuesioner->status != 1)
 | |
|             $('.dropzone').remove();
 | |
|         @endif
 | |
|     @endif
 | |
|     // $('.dropzone').on('click',function(){
 | |
|         // Dropzone.autoDiscover = false; // Penting supaya tidak auto-initialize!
 | |
|     const myDropzone = new Dropzone(".dropzone", {
 | |
|                 url: "{{ url('uploadTemp') }}", // URL ke controller kamu
 | |
|                 method: "POST",
 | |
|                 headers: {
 | |
|                     'X-CSRF-TOKEN': "{{csrf_token()}}"
 | |
|                 },
 | |
|                 maxFilesize: 1, // dalam MB
 | |
|                 acceptedFiles: ".pdf",
 | |
|                 paramName: "file", // nama input file yang dikirim ke controller
 | |
|                 uploadMultiple: true,
 | |
|                 init: function() {
 | |
|                     this.on("successmultiple", function(files, response) {
 | |
|                         console.log('Upload success multiple:', response);
 | |
| 
 | |
|                         const fileList = document.getElementById('file-list');
 | |
| 
 | |
|                         response.files.forEach(function(fileInfo) {
 | |
|                             const li = document.createElement('li');
 | |
|                             li.innerHTML = `<a>${fileInfo.filename}</a>`;
 | |
|                             fileList.appendChild(li);
 | |
| 
 | |
|                             // Tambahkan ke hidden input kalau perlu
 | |
|                             const hiddenInput = document.createElement('input');
 | |
|                             hiddenInput.type = 'hidden';
 | |
|                             hiddenInput.name = 'input_upload_files[]';
 | |
|                             hiddenInput.value = fileInfo.filename;
 | |
|                             hiddenInput.class = 'removeFormKriteria';
 | |
|                             var elem = '<input type="hidden" name="input_upload_files[]" value="'+fileInfo.filename+'" class="removeFormKriteria">';
 | |
|                             $('.changeForm').append(elem);
 | |
|                         });
 | |
|                     });
 | |
| 
 | |
|                     this.on("error", function(file, response) {
 | |
|                         console.error('Upload error:', response);
 | |
|                         toastr.error(response, 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
 | |
|                         this.removeFile(file);
 | |
|                     });
 | |
|                 }
 | |
|             });
 | |
|             
 | |
|     // });
 | |
|     
 | |
| 
 | |
| </script>
 | |
| <script type="text/javascript">
 | |
|    $('.page').on('click',function(e){
 | |
|         e.preventDefault();
 | |
|         let number = $(this).data('number');
 | |
|         let base_url = "{{url('/')}}";
 | |
|         // Tambahkan kelas active dan hapus dari yang lain
 | |
|         $('.page').removeClass('active');
 | |
|         $(this).addClass('active');
 | |
| 
 | |
|         $.ajax({
 | |
|             url: base_url+'/getForm', // Ganti dengan URL API-mu
 | |
|             type: 'POST', // Bisa juga 'POST' kalau perlu
 | |
|             data: { 
 | |
|                 _token:'{{csrf_token()}}',
 | |
|                 page: number 
 | |
|             }, // Kirim number sebagai parameter
 | |
|             dataType: 'json', // Format respons JSON
 | |
|             beforeSend: function () {
 | |
|                 $('#loading-spinner').show(); // Menampilkan spinner
 | |
|                 $('.removeFormKriteria').remove();
 | |
|             },
 | |
|             success: function (response) {
 | |
|                 console.log('Response:', response);
 | |
|                 $('.changeForm').append(response.data);
 | |
|                 $('.changeTitle').html(response.title);
 | |
| 
 | |
|                 $('.numberInput').on('input', function() {
 | |
|                     this.value = this.value.replace(/[^0-9]/g, ''); // Hanya angka 0-9
 | |
|                 });
 | |
|                 const myDropzone = new Dropzone(".dropzone", {
 | |
|                     url: "{{ url('uploadTemp') }}", // URL ke controller kamu
 | |
|                     method: "POST",
 | |
|                     headers: {
 | |
|                         'X-CSRF-TOKEN': "{{csrf_token()}}"
 | |
|                     },
 | |
|                     maxFilesize: 1, // dalam MB
 | |
|                     acceptedFiles: ".pdf",
 | |
|                     paramName: "file", // nama input file yang dikirim ke controller
 | |
|                     uploadMultiple: true,
 | |
|                     init: function() {
 | |
|                         this.on("successmultiple", function(files, response) {
 | |
|                             console.log('Upload success multiple:', response);
 | |
| 
 | |
|                             const fileList = document.getElementById('file-list');
 | |
| 
 | |
|                             response.files.forEach(function(fileInfo) {
 | |
|                                 const li = document.createElement('li');
 | |
|                                 li.innerHTML = `<a>${fileInfo.filename}</a>`;
 | |
|                                 fileList.appendChild(li);
 | |
| 
 | |
|                                 // Tambahkan ke hidden input kalau perlu
 | |
|                                 const hiddenInput = document.createElement('input');
 | |
|                                 hiddenInput.type = 'hidden';
 | |
|                                 hiddenInput.name = 'input_upload_files[]';
 | |
|                                 hiddenInput.class = 'removeFormKriteria';
 | |
|                                 hiddenInput.value = fileInfo.filename;
 | |
|                                 var elem = '<input type="hidden" name="input_upload_files[]" value="'+fileInfo.filename+'" class="removeFormKriteria">';
 | |
|                                 $('.changeForm').append(elem);
 | |
|                             });
 | |
|                         });
 | |
| 
 | |
|                         this.on("error", function(file, response) {
 | |
|                             console.error('Upload error:', response);
 | |
|                             toastr.error(response, 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
 | |
|                             this.removeFile(file);
 | |
|                         });
 | |
|                     }
 | |
|                 });
 | |
| 
 | |
|                 @if(session('group_alias') == 'sekolah')
 | |
|                     @if($kuesioner->status != 1)
 | |
|                         $('.dropzone').remove();
 | |
|                     @endif
 | |
|                 @endif
 | |
|             },
 | |
|             error: function (xhr, status, error) {
 | |
|                 console.error('AJAX Error:', status, error);
 | |
|                 alert('Failed to fetch data!');
 | |
|             },
 | |
|             complete: function () {
 | |
|                 $('#loading-spinner').hide(); // Sembunyikan spinner setelah request selesai
 | |
|             }
 | |
|         });        
 | |
|    });
 | |
| 
 | |
|    $('.resume').on('click',function(e){
 | |
|         window.location.href = "{{url('usulan/adiwiyata/kriteria/resume/'.encode_id(session('sekolah_id')))}}";
 | |
|    });
 | |
| 
 | |
|    $('.progress_usulan').on('click',function(e){
 | |
|         window.location.href = "{{url('usulan/adiwiyata/kriteria/progress/'.encode_id(session('sekolah_id')))}}";
 | |
|    });
 | |
| 
 | |
|    $('#btnSave').on('click',function(e){
 | |
|         e.preventDefault();
 | |
|         let currentForm = $("#form").serializeArray();
 | |
|         console.log(currentForm);
 | |
| 
 | |
|         let formData = {};
 | |
|         let allData = {};
 | |
|         let isValid = true; // Flag validasi
 | |
| 
 | |
|         currentForm.forEach(field => {
 | |
|             let name = field.name.replace(/\[\]$/, ''); // Hapus "[]" di akhir nama input
 | |
| 
 | |
|             if (allData[name]) {
 | |
|                 if (!Array.isArray(allData[name])) {
 | |
|                     allData[name] = [allData[name]];
 | |
|                 }
 | |
|                 allData[name].push(field.value);
 | |
|             } else {
 | |
|                 allData[name] = field.value;
 | |
|             }
 | |
|         });
 | |
| 
 | |
|         $('.is-required').each(function () {
 | |
|             let type = $(this).attr('type');
 | |
|             let name = $(this).attr('name');
 | |
|             let value = $(this).val()?.trim(); // Pastikan nilai di-trim untuk menghindari spasi kosong
 | |
| 
 | |
|             if (type === 'radio' || type === 'checkbox') {
 | |
|                 // Validasi radio: setidaknya satu opsi harus dipilih
 | |
|                 if ($(`input[name="${name}"]:checked`).length === 0) {
 | |
|                     isValid = false;
 | |
|                     $(`input[name="${name}"]`).closest('.custom-control-input').addClass("is-invalid");
 | |
|                 } else {
 | |
|                     $(`input[name="${name}"]`).closest('.custom-control-input').removeClass("is-invalid");
 | |
|                 }
 | |
|             } else {
 | |
|                 // Validasi input teks atau lainnya
 | |
|                 if (!value) {
 | |
|                     isValid = false;
 | |
|                     $(this).addClass("is-invalid");
 | |
|                 } else {
 | |
|                     $(this).removeClass("is-invalid");
 | |
|                 }
 | |
|             }
 | |
|         });
 | |
| 
 | |
|         // Jika validasi gagal, hentikan submit
 | |
|         if (!isValid) {
 | |
|             toastr.error("Harap isi semua field yang wajib diisi", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
 | |
|             // alert(".");
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         $.ajax({
 | |
|             url: "{{route($route.'.store')}}", // Ganti dengan URL API-mu
 | |
|             type: 'POST', // Bisa juga 'POST' kalau perlu
 | |
|             data: { 
 | |
|                 _token:'{{csrf_token()}}',
 | |
|                 data: allData 
 | |
|             }, // Kirim number sebagai parameter
 | |
|             dataType: 'json', // Format respons JSON
 | |
|             beforeSend: function () {
 | |
|                 $('#loading-spinner').show(); // Menampilkan spinner
 | |
|             },
 | |
|             success: function (response) {
 | |
|                 // console.log('Response:', response);
 | |
|                 toastr.success("Berhasil menyimpan data", 'Success!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
 | |
| 
 | |
|                 
 | |
|                 $('.page').closest('.active').addClass('bg-success');
 | |
|                 $('.page').closest('.active').addClass('text-white');
 | |
|                 $('.page').removeClass('active');
 | |
|                 // (checkPenilaian($hal) == true ? 'bg-success text-white' : '' )
 | |
|             },
 | |
|             error: function (xhr, status, error) {
 | |
|                 // console.error('AJAX Error:', status, error);
 | |
|                 // alert('Failed to fetch data!');
 | |
|                 toastr.error("Maaf Terjadi Kesalahan Menyimpan Data", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
 | |
|             },
 | |
|             complete: function () {
 | |
|                 $('#loading-spinner').hide(); // Sembunyikan spinner setelah request selesai
 | |
|             }
 | |
|         });
 | |
| 
 | |
|    });
 | |
| </script>
 | |
| @endsection |