IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/resources/views/schools/hostel/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/resources/views/schools/hostel/bed.blade.php

@extends('schools.school_layout')
@section('content')
<div class="row clearfix">
    <div class="col-lg-6 col-md-6 col-sm-6">
        <div class="card">
            <div class="header">
                <h2><strong>@if(isset($bed))Edit @else  Add @endif</strong>Bed</h2>
            </div>
            <div class="body">
                @if(isset($bed))
                {!! Form::model( $bed, ['route' => ['beds.update', $bed->idBed], 'method' => 'put','class'=>'form-horizontal'] ) !!}
                @else
                {!! Form::open(['url' => 'school/beds','class'=>'form-horizontal','id'=>'form']) !!}
                @endif
                <div class="row clearfix">
                    <div class="col-sm-4 form-control-label required">
                        <label for="classname">Floor </label>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            {!! Form::select('idFloor',$floors,null,['class' => 'form-control show-tick ms','required'=>'required','onchange'=>'getRooms(this)']) !!}
                        </div>
                    </div>
                </div>
                @if(isset($bed))
                <div class="row clearfix">
                    <div class="col-sm-4 form-control-label required">
                        <label for="classname">Room</label>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            {!! Form::select('idRoom',$rooms,null,['class' => 'form-control show-tick ms','required'=>'required','id'=>'idRoom']) !!}
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-4 form-control-label required">
                        <label for="classname">Bed</label>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            {!! Form::text('bedName',null,['class' => 'form-control','required'=>'required']) !!}
                        </div>
                    </div>
                </div>
                @else
                <div class="row clearfix">
                    <div class="col-sm-4 form-control-label required">
                        <label for="classname">Room</label>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            {!! Form::select('idRoom',[''=>'--Select--'],null,['class' => 'form-control show-tick ms','required'=>'required','id'=>'idRoom']) !!}
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <table class="table">
                        <thead>
                            <tr>
                                <th></th>
                                <th>Bed Name</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody  id="optional_list">
                            <?php $i =1;?>
                            <tr>
                                <td class="sno">{{$i}}</td>
                                <td>
                                    {!! Form::text('beds[1][bedName]',null,['class' => 'form-control','required'=>'required']) !!}
                                    <span id="sublocerror1"></span>
                                </td>
                           </tr>
                            <?php $i++ ; ?>
                        </tbody>
                        <tr>
                            <td colspan="4" style="text-align: right"><input type="button" class="add-row btn btn-sm btn-success" value="Add Row"></td>
                        </tr>
                </table>
                </div>
                @endif
                <div class="row clearfix">
                    <div class="col-sm-8 offset-sm-2">
                        @if(isset($bed))
                        {!! Form::submit('UPDATE',['class' => 'btn btn-raised btn-primary btn-round waves-effect']) !!}
                        @else
                        {!! Form::submit('SAVE',['class' => 'btn btn-raised btn-primary btn-round waves-effect']) !!}
                        @endif
                        {!! Form::close() !!} 
                    </div>
                </div>
            </div>
        </div>
</div>
<div class="col-sm-6">
        <div class="card">
            <div class="header">
                <h2><strong>List Of Beds </strong></h2>
            </div>
            <div class="body table-responsive">
                <table class="table table-bordered table-striped table-hover js-basic-example dataTable">
                    <thead>
                        <tr>
                            <th>S.NO.</th>
                            <th>Bed Name</th>
                            <th>Room No</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $i = 1; ?>
                        @foreach($beds as $var)
                        <tr>
                            <td>{{ $i }}</td>
                            <td>{{$var->bedName}}</td>
                            <td>{{$var->room->roomName}}</td>
                            <td>
                                <a href='{{url('/school/beds/'.$var->idBed.'/edit')}}'  class="btn btn-raised btn-info waves-effect btn-round"><i class="fa fa-edit"></i>Edit</a>
                                <button class="btn btn-raised btn-danger waves-effect btn-round js-sweetalert" data-id="{{$var->idBed}}" data-type="confirm">DELETE</button>
                            </td>
                        </tr>
                        <?php $i++; ?>
                        @endforeach

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@stop
@section('script')
<script>
$(document).ready(function() {
    var i = $('.sno:last').text();
    $(".add-row").click(function(){
        i++;  
        var markup = '<tr><td class="sno">'+i+'</td>\
                <td><input class="form-control" type="text" name="beds['+i+'][bedName]" required="required"><span id="depterror'+i+'"></span></td>\n\
                <td style="text-align:right;vertical-align: middle;"><input type="button" class="btn btn-sm btn-danger" value="Delete" id="remove_row"></td></tr>';
            
            $("#optional_list").append(markup);
    });
    
    $('#optional_list').on('click', 'input[type="button"]', function () {
        $(this).closest('tr').remove();
         i = $('.sno:last').text();
         
    });
    //Add Input field if others is selecyted
});
function getRooms(selected){
    //console.log($key);
    var floorID = selected.value;
        if (floorID) {
            $.ajax({
                url: "{{url('/school/floor-rooms') }}" + '/' + floorID + "/rooms",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    $('#idRoom').empty();
                    $('#idRoom').append('<option value="">--Select--</option>');
                    $.each(data, function (key, value) {
                        $('#idRoom').append('<option value="' + key + '">' + value + '</option>');
                    });
                }
            });
        } 
    }
$(document).on('click', '.js-sweetalert', function (e) {
    $.ajaxSetup({
        headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    e.preventDefault();
    var id = $(this).data('id');
    swal({
            title: "Are you sure?",
            text: "Are You sure you want to delete this  Bed!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, delete it!",
            closeOnConfirm: true
        },
        function() {
         //   console.log('here');
            $.ajax({
                type: "DELETE",
                url: "{{url('/school/beds/')}}" +"/"+id,
                data: {id:id}
                       
            })
            .done(function(data) {
                swal({
                    title: "Deleted", 
                    text: "Bed has been successfully deleted", 
                    type: "success"
                },function() {
                    location.reload();
                });
            })
            .error(function(data) {
              swal("Oops", "We couldn't connect to the server!", "error");
            });
            return false;
    });
});
// Saving form data
$('#form').on('submit',function(e){
    $.ajaxSetup({
    header:$('meta[name="_token"]').attr('content')
});
 var formData =  new FormData($('#form')[0]);
 $("#submit-btn").prop('disabled', true);
    $.ajax({
        type:"POST",
        url: "{{url('school/beds') }}",
        processData: false,
        contentType: false,
        data:formData,
        dataType: 'json',
        success:function(data){
            if( data[Object.keys(data)[0]] === 'SUCCESS' ){
                $("#submit-btn").prop('disabled', true);
                window.location = "{{url('school/beds')}}";
            }
            else {                  //False Case: With error msg
            $("#msg").html(data);   //$msg is the id of empty msg
            }

        },

        error: function(data){
                    if( data.status === 422 ) {
                        $("#submit-btn").prop('disabled', false);
                        var errors = data.responseJSON.errors;
                        var errorHtml = '<div class="alert alert-danger"><ul>';
                           $('#formerrors').html(errorHtml);
                                $.each(errors, function (key, value) {
                                    if (key.split(".")[1] + '.bedName' === key.split(".")[1] + '.' + key.split(".")[2])
                                    {
                                        errordept = '<span class="help-block">' + value + '</span>';
                                        $('#depterror' + key.split(".")[1]).html(errordept);
                                    }
                                    if (key.split(".")[1] + '.roomName' === key.split(".")[1] + '.' + key.split(".")[2])
                                    {
                                        errordept = '<span class="help-block">' + value + '</span>';
                                        $('#sublocerror' + key.split(".")[1]).html(errordept);
                                    }
                        });
                    }
            }
    });
    return false;
});
</script>
@stop

Copyright © 2021 - 2025 IMMREX7