/
home
/
sjslayjy
/
public_html
/
cropnet
/
resources
/
views
/
admin
/
master
/
Upload File
HOME
@extends('admin.layouts.app') @section('title','Animal Type') @section('style') <meta name="csrf-token" content="{{ csrf_token() }}"> {{-- {{Html::style("assets/css/bootstrap-datepicker3.min.css")}} --}} @endsection @section('content') <!-- Content Wrapper. Contains page content --> <div class="content-wrapper"> <div class="container-full"> <!-- Header Dynamic --> <div class="content-header"> <div class="d-flex align-items-center"> <div class="me-auto"> <h4 class="page-title">Master</h4> <div class="d-inline-block align-items-center"> <nav> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="#"><i class="fa fa-home"></i></a></li> <li class="breadcrumb-item active" aria-current="page">Animal Type</li> </ol> </nav> </div> </div> </div> </div> <!-- End Header Dynamic --> <!-- Main content --> <section class="content"> <div class="row"> <div class="col-12"> <div class="box"> <div class="box-header with-border"> <div class="clearfix"> <div class="row"> <div class="col-sm-6"> <button type="button" class="btn btn-sm btn-default pull-left" data-bs-toggle="modal" data-bs-target="#addAnimalTypeModal"> Add Animal Type </button> </div> {{-- <div class="col-sm-6"> <button type="button" class="btn-sm waves-effect waves-light md-5 btn bg-gradient-success pull-right" data-bs-toggle="modal" data-bs-target="#importMccModal">Import</button> </div> --}} </div> </div> </div> <!-- /.box-header --> <!-- /.box-header --> <div class="box-body"> <div class="table-responsive"> <table id="dynamic-table" class="table table-bordered table-hover display nowrap margin-top-10 w-p100 text-center"> <thead> <tr> <th style="text-align: center;">S.N.</th> <th style="text-align: center;">Animal Type</th> <th style="text-align: center;">Status</th> <th style="text-align: center;">Action</th> </tr> </thead> <tbody> @php $sr=1; @endphp @foreach($animalTypes as $animal_type) <tr> <td>{{$sr}}</td> <td>{{$animal_type->animal_type}}</td> <td>@if($animal_type->is_active==1)<span class="badge badge-success">Active</span>@else <span class="badge badge-danger">Inactive</span>@endif</td> <td><a class="btn btn-xs btn-primary" onclick="getEdit({{$animal_type->id}})" title="Edit"><i class="ace-icon fa fa-edit bigger-120" ></i></a> <a class="btn btn-xs btn-danger" onclick="deleteMcc({{$animal_type->id}})" title="Delete"><i class="ace-icon fa fa-trash bigger-120" ></i></a></td> </tr> @php $sr++@endphp @endforeach </tbody> <tfoot> </tfoot> </table> </div> </div> <!-- /.box-body --> <!-- /.box-body --> </div> <!-- /.box --> </div> </div> </section> <!-- /.content --> </div> </div> <!-- /edit modal --> <div id="editMccModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog modal-sm"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel">Edit Animal Type</h4> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body" id="EditBody"> </div> <!--<div class="modal-footer">--> <!-- <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>--> <!--</div>--> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /edit modal --> <!-- /save modal --> <div id="addAnimalTypeModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="addAnimalTypeLabel" aria-hidden="true"> <div class="modal-dialog modal-sm"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="addAnimalTypeLabel">Add Animal Type</h4> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <form action="{{URL('/admin/add-animal-type')}}" role="form" id="addAnimalTypeForm" enctype="multipart/form-data"> <div class="box-body"> <div class="form-group"> <label class="form-label">Animal Type</label> <input type="text" class="form-control" name="animal_type" id="animal_type" placeholder="Enter Animal Type"> <span class="label label-danger" id="animal_type_error" style="display: none;"></span> </div> </div> <!-- /.box-body --> <div class="box-footer text-end"> <button type="button" class="btn btn-danger me-1" data-bs-dismiss="modal">Cancel</button> <button id="addAnimalTypeBtn" type="button" class="btn btn-success" onclick="saveAnimalType()">Add</button> </div> </form> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /save modal --> @endsection @section('script') {{-- <script src="{{asset("src/js/pages/patients.js")}}"></script> --}} <script src="../src/js/pages/validation.js"></script> <script src="../src/js/pages/form-validation.js"></script> <script> $(document).ready(function() { }); function showError(id, error) { if (typeof(error) === "undefined") { $('#' + id).hide(); } else { $('#' + id).show(); $('#' + id).text(error); } } function getEdit(id) { if (id == "") { Swal.fire('Error', 'Animal Type id is missing', 'warning'); } else { $.ajax({ url: "{{url('/admin/edit-animal-type')}}" + "/" + id, type: 'GET', success: function(data) { $('#EditBody').html(data); $('#editMccModal').modal('toggle'); } }); } } function updateMcc() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); var url=$('#editMccForm').attr('action'); var form_data = new FormData(document.getElementById("editMccForm")); $.ajax({ url: url, method: 'POST', data: form_data, cache:false, contentType: false, processData: false, success: function(data) { console.log(data); if (!data.flag) { showError('add_name_error', data.errors.name); showError('add_code_error', data.errors.code); } else { Swal.fire({ title: "Success!", text: data.message, icon: "success" }).then(function() { window.location.reload(); }); } } }); } function saveAnimalType() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); // Clear error messages $('#animal_type_error').hide(); let animalType = $('#animal_type').val(); let formData = new FormData($('#addAnimalTypeForm')[0]); $.ajax({ url: "{{URL('/admin/add-animal-type')}}", type: "POST", data: formData, contentType: false, processData: false, success: function(response) { if (response.success) { Swal.fire({ title: "Success!", text: response.message, // Use response.message correctly here icon: "success", confirmButtonText: "OK" }).then(function() { $('#addAnimalTypeModal').modal('hide'); // Optionally reload the page or update data window.location.reload(); }); } else { Swal.fire({ title: "Error!", text: "An error occurred while adding the animal type.", icon: "error", confirmButtonText: "OK" }); } }, error: function(xhr) { let errors = xhr.responseJSON.errors; if (errors && errors.animal_type) { $('#animal_type_error').text(errors.animal_type[0]).show(); } Swal.fire({ title: "Error!", text: "Failed to add the animal type. Please try again.", icon: "error", confirmButtonText: "OK" }); } }); } function deleteMcc(id){ if(id == ""){ swal('Error','Animal Type id is missing','warning'); }else{ swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!", closeOnConfirm: false }).then(function() { $.ajax({ url: "{{url('/admin/delete-animal-type/')}}"+"/"+id, type: 'GET', success:function(data){ if(data.flag){ // $('#tr_'+id).remove(); Swal.fire({ title: "Success!", text: data.message, icon: "success" }).then(function() { window.location.reload(); }); }else{ swal("Error", data.message, "error"); } } }); }); } } </script> @endsection