@extends('admin.layout.app')
@section('title', 'Add Schedule')
@push('custom_css')
<link rel="stylesheet" href="{{ asset('assets/js/loader/waitMe.css') }}">
@endpush
@section('content')
<div class="row">
<div class="col-12">
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
<h4 class="mb-sm-0">Edit Programme Schedule</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="{{route('admin.dashboard')}}">Dashboard</a></li>
<li class="breadcrumb-item active">Edit Programme Schedule</li>
</ol>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header align-items-center d-flex">
<h4 class="card-title mb-0 flex-grow-1">Edit Schedule</h4>
</div><!-- end card header -->
<div class="card-body">
<form id="schedule_form" data-post-uri="{{route('admin.schedule.update', $reference["id"])}}">
<div class="row gy-4 mb-3">
<div class="col-md-12">
<div>
<label for="placeholderInput" class="form-label">Show Name</label>
<input type="text" class="form-control" placeholder="Enter name of show" name="show_name" value="{{$reference["show_name"]}}">
</div>
</div>
<!--end col-->
</div>
<div id="wrapper">
<div class="row gy-4 align-items-end d-flex mb-3">
<div class="col-md-6">
<div>
<label for="placeholderInput" class="form-label">Presenters</label>
<input type="text" class="form-control" placeholder="Enter presenters"
name="presenters" value="{{$reference['presenters']}}">
</div>
</div>
<div class="col-md-6">
<div>
<label for="placeholderInput" class="form-label">Show Time</label>
<div class="row align-items-center d-flex">
<div class="col-md-6">
<div class="input-group">
<span class="input-group-text">From</span>
<input class="form-control form-control-sm" name="from" type="time" data-provider="timepickr" data-time-basic="true" value="{{$reference['from']}}">
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-text">To</span>
<input class="form-control form-control-sm" name="to" type="time" data-provider="timepickr" data-time-basic="true" value="{{$reference['to']}}">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row gy-4 align-items-end d-flex mb-2">
<div class="col-md-6">
<div>
<label for="placeholderInput" class="form-label">Show Days</label>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="monday" name="days[]" value="1" @if(in_array("1",($reference['days'])))checked @endif">
<label class="form-check-label" for="monday">
Monday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="tuesday" name="days[]" value="2" @if(in_array("2",$reference["days"]))checked @endif>
<label class="form-check-label" for="tuesday">
Tuesday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="wednesday" name="days[]" value="3" @if(in_array("3",$reference["days"]))checked @endif>
<label class="form-check-label" for="wednesday">
Wednesday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="thursday" name="days[]" value="4" @if(in_array("4",$reference["days"]))checked @endif>
<label class="form-check-label" for="thursday">
Thursday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="friday" name="days[]" value="5" @if(in_array("5",$reference["days"]))checked @endif>
<label class="form-check-label" for="friday">
Friday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="saturday" name="days[]" value="6" @if(in_array("6",$reference["days"]))checked @endif>
<label class="form-check-label" for="saturday">
Saturday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
<div class="form-check mb-2">
<input class="form-check-input days" type="checkbox" id="sunday" name="days[]" value="0" @if(in_array("0",$reference["days"]))checked @endif>
<label class="form-check-label" for="sunday">
Sunday
</label>
<div class="wrap">
<div class="time_area">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10">
<button type="submit" class="btn btn-primary float-end" id="submit">Submit</button>
</div>
</div>
</form>
</div>
</div>
@endsection
@push('custom_scripts')
<script src="{{ asset('assets/js/loader/waitMe.js') }}"></script>
<script>
$('.days').each(function (index, element) {
$(element).on('change', function () {
if ($(this).is(':checked')) {
if ($(this).attr('id') === 'sunday')
$(this).val(0)
else
$(this).val(index + 1)
}
})
})
//handle submit form
let form = $('#schedule_form'), submit_btn = $('#submit');
submit_btn.on('click', function (e) {
e.preventDefault()
$('body').waitMe({
effect: 'bounce',
text: 'Submitting. Please wait...',
color: "#fff",
bg: 'rgba(0,0,0,0.5)'
});
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: form.attr("data-post-uri"),
dataType: 'json',
type: 'POST',
data: form.serializeArray(),
success: function (json) {
$('body').waitMe("hide");
if (json.status) {
toastr.success('Schedule updated Successfully');
location.href = window.location
} else {
// console.log(json?.data)
if (json?.data?.length > 0) {
json.data.forEach((error, index) => {
toastr.error(error.error, {
CloseButton: true,
ProgressBar: true
});
})
}
Snackbar.show({
text: json.message,
pos: 'bottom-center',
backgroundColor: '#a3220f',
timeout: 3000
});
}
},
error: function (json) {
Snackbar.show({
text: 'Something went wrong. Please try again later!',
pos: 'bottom-center',
backgroundColor: '#a3220f'
});
$('body').waitMe("hide");
}
});
})
</script>
@endpush