IMMREX7
@extends('schools.school_layout')
@section('content')
<div class="row clearfix">
<div class="col-sm-5">
<div class="card">
<div class="header">
<h2><strong>Assign Subject</strong></h2>
</div>
<div class="body">
@if(isset($teachersubj))
{!! Form::model($teachersubj, ['method' => 'PATCH', 'action' => ['School\AssignSubjectController@update', $teachersubj->idTeacherSubject], 'class' => 'form-horizontal']) !!}
@else
{!! Form::open(['url' => 'school/assignsubject', 'class' => 'form-horizontal','id'=>'assignsubject']) !!}
@endif
<div class="row clearfix">
<div class="col-sm-4 form-control-label">
<label for="classname">Select Teacher</label>
</div>
<div class="col-sm-7">
<div class="form-group">
{!! Form::select('idTeacher',$teachers,null,['class' => 'form-control show-tick ms select2']) !!}
@if ($errors->has('idTeacher'))
<label id="minmaxlength-error" class="error" for="minmaxlength">
<strong>{{ $errors->first('idTeacher') }}</strong>
</label>
@endif
<span id='teachererror'></span>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-4 form-control-label">
<label for="classname">Select Class</label>
</div>
<div class="col-sm-7">
<div class="form-group">
{!! Form::select('idClass',$classes,null,['class' => 'form-control show-tick ms select2']) !!}
@if ($errors->has('idClass'))
<label id="minmaxlength-error" class="error" for="minmaxlength">
<strong>{{ $errors->first('idClass') }}</strong>
</label>
@endif
<span id='classerror'></span>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-4 form-control-label">
<label for="classname">Select Section</label>
</div>
<div class="col-sm-7">
<div class="form-group">
@if(isset($teachersubj))
{!! Form::select('idSection',$section,null,['class' => 'form-control show-tick ms']) !!}
@else
<!--<select name='idSection' class="form-control show-tick ms"></select>-->
<div id="idSection" style="border:1px solid #ccc; width:200px; height: 110px; overflow-y: scroll;">
</div>
@if ($errors->has('idSection'))
<label id="minmaxlength-error" class="error" for="minmaxlength">
<strong>{{ $errors->first('idSection') }}</strong>
</label>
@endif
@endif
<span id='sectionerror'></span>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-4 form-control-label">
<label for="classname">Select Subject</label>
</div>
<div class="col-sm-7">
<div class="form-group">
@if(isset($teachersubj))
{!! Form::select('idSubject',$subject,null,['class' => 'form-control show-tick ms']) !!}
@else
<!--<select name='idSubject' class="form-control show-tick ms"></select>-->
<div id="subjectlist" style="border:1px solid #ccc; width:200px; height: 110px; overflow-y: scroll;">
</div>
@if ($errors->has('idSubject'))
<label id="minmaxlength-error" class="error" for="minmaxlength">
<strong>{{ $errors->first('idSubject') }}</strong>
</label>
@endif
@endif
<span id='subjecterror'></span>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-8 offset-sm-2">
@if(isset($teachersubj))
{!! 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','id'=>'submit-btn']) !!}
@endif
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-7">
<div class="card">
<div class="header">
<h2><strong>List Of Assign Subjects</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>Class</th>
<th>Section</th>
<th>Subject</th>
<th>Teacher</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
@foreach($teachersubjects as $value)
<tr>
<th scope="row">{{$i}}</th>
<td>{{$value->classM->className}}</td>
<td>{{$value->section->sectionName}}</td>
<td>{{$value->subject->subjectName}}</td>
<td>{{$value->teacher->firstName}} {{$value->teacher->lastName}}</td>
<td>
<a href="{{ url('school/assignsubject/' . $value->idTeacherSubject . '/edit') }}" class="btn btn-raised btn-info waves-effect btn-round">Edit </a>
<button class="btn btn-raised btn-danger waves-effect btn-round js-sweetalert" data-id="{{$value->idTeacherSubject}}" data-type="confirm">DELETE</button>
</td>
</tr>
<?php $i++; ?>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
@stop
@section('script')
<script>
$(document).ready(function() {
$('select[name="idClass"]').on('change', function() {
var classID = $(this).val();
if(classID) {
$.ajax({
url: "{{url('/school/class') }}"+'/' +classID + "/sections",
type: "GET",
dataType: "json",
success:function(data) {
$('#idSection').empty();
$('#idSection').append('<div class="checkbox-inline" style="padding-left:10px;padding-top:5px;"><label style="margin-right:42px;"><strong>Select All</label></strong><input type="checkbox" class="select-all" id="selectall"></div>');
$.each(data, function(key, value) {
$('#idSection').append('<div class="checkbox-inline" style="padding-left:10px;"><label style="margin-right:100px;">'+value+'</label><input type="checkbox" name="sections[]" value="'+key+'" class="secclass"></div>');
});
}
});
}else{
$('select[name="idSection"]').empty();
}
});
$('select[name="idClass"]').on('change', function() {
var classID = $(this).val();
if(classID) {
$.ajax({
url: "{{url('/school/class') }}"+'/' +classID + "/subjects",
type: "GET",
dataType: "json",
success:function(data) {
$('#subjectlist').empty();
$('#subjectlist').append('<div class="checkbox-inline" style="padding-left:10px;padding-top:5px;"><label style="margin-right:42px;"><strong>Select All</label></strong><input type="checkbox" class="select-allsub" id="selectallsub"></div>');
$.each(data, function(key, value) {
$('#subjectlist').append('<div class="checkbox-inline" style="padding-left:10px;"><label style="margin-right:10px;">'+value+'</label><input type="checkbox" name="subjects[]" value="'+key+'" class="subclass"></div>');
});
}
});
}else{
$('select[name="subjectlist"]').empty();
}
});
});
$(document).on('click', '.select-all', function(){
var checkAll = this.checked;
if(checkAll === true){
$('.secclass').each(function () {
this.checked = checkAll;
});
}else{
$('.secclass').each(function () {
this.checked = checkAll;
});
}
});
$(document).on('click', '.select-allsub', function(){
var checkAllsub = this.checked;
if(checkAllsub === true){
$('.subclass').each(function () {
this.checked = checkAllsub;
});
}else{
$('.subclass').each(function () {
this.checked = checkAllsub;
});
}
});
$(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 Assigned Subject!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: true
},
function() {
// console.log('here');
$.ajax({
type: "DELETE",
url: "{{url('/school/assignsubject/')}}" +"/"+id,
data: {id:id}
})
.done(function(data) {
swal({
title: "Deleted",
text: "This Subject Assignment has been successfully deleted",
type: "success"
},function() {
location.reload();
});
})
.error(function(data) {
swal("Oops", "We couldn't connect to the server!", "error");
});
return false;
});
});
$('#assignsubject').on('submit',function(e){
$.ajaxSetup({
header:$('meta[name="_token"]').attr('content')
});
var formData = new FormData($('#assignsubject')[0]);
$("#submit-btn").prop('disabled', true);
$.ajax({
type:"POST",
url: "{{url('school/assignsubject') }}",
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/assignsubject')}}";
}
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);
if(errors['idClass']=== undefined){
$( '#classerror' ).empty();
}else{
errorname = '<span class="help-block"><strong>'+errors['idClass']+'</strong></span>';
$( '#classerror' ).html( errorname );
}
if(errors['idSection']=== undefined){
$( '#sectionerror' ).empty();
}else{
errorname = '<span class="help-block"><strong>'+errors['idSection']+'</strong></span>';
$( '#sectionerror' ).html( errorname );
}
if(errors['idTeacher']=== undefined){
$( '#teachererror' ).empty();
}else{
errorname = '<span class="help-block"><strong>'+errors['idTeacher']+'</strong></span>';
$( '#teachererror' ).html( errorname );
}
if(errors['idSubject']=== undefined){
$( '#subjecterror' ).empty();
}else{
errorname = '<span class="help-block"><strong>'+errors['idSubject']+'</strong></span>';
$( '#subjecterror' ).html( errorname );
}
}
}
});
return false;
});
</script>
@stop
Copyright © 2021 -