File: /var/www/html/hrms-production/resources/views/components/employee-relation-modal.blade.php
{{-- Add Employee Relation --}}
<div class="modal fade" id="addEmployeeRelation">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add EmployeeRelation</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- Main content -->
<form id="addEmployeeRelationform">
<input type="hidden" name="_token" id="token_emp_relation" value="{{ csrf_token() }}">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div class="form-group mb-2">
<label class="mb-0" for="name">Employee Relation Name<span
class="text-danger">*</label>
<input type="text" class="form-control form-control-sm" id="EmployeeRelationName"
name="EmployeeRelationName" onkeyup="checkDuplicateEmployeeRelation(this);"
required>
</span><span id='CheckEmployeeRelation'></span>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="col-12">
<div class="d-flex align-items-center justify-content-center">
<button type="button" class="btn btn-sm btn-outline-secondary mx-1"
data-dismiss="modal" aria-label="Close">Cancel</button>
<button type="submit" id="btn-save-new-employee-relation"
class="btn btn-sm btn-outline-info mx-1">Save & New</button>
<button type="submit" id="btn-save-employee-relation"
class="btn btn-sm btn-info mx-1">Save</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
{{-- Update Employee Relation --}}
<div class="modal fade" id="updateEmployeeRelation">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Employee Relation <span id="EmployeeRelationName" class="text-info"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- Main content -->
<form id="updateEmployeeRelationform">
<input type="hidden" name="_token" id="token_emp_relation_update" value="{{ csrf_token() }}">
<input type="hidden" id="EmployeeRelationId" name="EmployeeRelationId">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div class="form-group mb-2">
<label class="mb-0" for="name">Employee Relation Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control form-control-sm"
id="editEmployeeRelationName" name="EmployeeRelationName"
onkeyup="checkDuplicateEmployeeRelation(this);" required>
<span id='editCheckEmployeeRelation'></span>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="col-12">
<div class="d-flex align-items-center justify-content-center">
<button type="button" class="btn btn-sm btn-outline-secondary mx-1"
data-dismiss="modal" aria-label="Close">Cancel</button>
<button type="button" id="btn-update-employee-relation" name="Update" value="Update"
class="btn btn-sm btn-info mx-1" disabled>Update</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
{{-- JS Start Here --}}
{{-- Check Availablity --}}
<script>
function checkDuplicateEmployeeRelation(element, id){
var id = id;
var EmployeeRelationName = $(element).val();
if (EmployeeRelationName == "") {
$('span#CheckEmployeeRelation, #editCheckEmployeeRelation').css("display", "none");
} else {
$('span#CheckEmployeeRelation, #editCheckEmployeeRelation').css("display", "block");
}
//alert (EmployeeRelation);
$.ajax({
type: "GET",
url: '{{ url("/") }}/check-employee-relation/',
data: {EmployeeRelationName:EmployeeRelationName, id:id},
dataType: "json",
success: function(res) {
if(res.exists){
$('span#CheckEmployeeRelation, span#editCheckEmployeeRelation').html('<span class="text-danger">Employee Relation is already exist!</span>');
$('#btn-save-new-employee-relation, #btn-save-employee-relation, #btn-update-employee-relation').attr('disabled', true);
} else {
$('span#CheckEmployeeRelation, span#editCheckEmployeeRelation').html('<span class="text-success">Employee Relation is available!</span>');
$('#btn-save-new-employee-relation, #btn-save-employee-relation, #btn-update-employee-relation').attr('disabled', false);
}
},
error: function (jqXHR, exception) {
}
});
}
</script>
{{-- Store Employee Relation --}}
<script>
var reload = 0;
$(function () {
$.validator.setDefaults({
submitHandler: function () {
saveEmployeeRelationRecord();
}
});
// Reload page after data save
$('#btn-save-employee-relation').click(function(){
reload = 1;
});
// Validate Fields
$('#addEmployeeRelationform').validate({
rules: {
EmployeeRelationName: {
required: true,
},
},
messages: {
EmployeeRelationName: {
required: "Please enter the employee relation",
},
},
errorElement: 'span',
errorPlacement: function (error, element) {
error.addClass('invalid-feedback');
element.closest('.form-group').append(error);
},
highlight: function (element, errorClass, validClass) {
$(element).addClass('is-invalid');
},
unhighlight: function (element, errorClass, validClass) {
$(element).removeClass('is-invalid');
}
});
});
</script>
{{-- Save Data Function --}}
<script>
function saveEmployeeRelationRecord() {
event.preventDefault();
$.ajax({
type: "post",
url: "{{ url('store-employee-relation') }}",
dataType: "json",
data: $('form#addEmployeeRelationform').serialize(),
success: function(response) {
const Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})
Toast.fire({
icon: 'success',
title: 'Employee Relation added successfully!'
});
$('form#addEmployeeRelationform').each(function() {
this.reset();
});
$('span#CheckEmployeeRelation').html('');
if(reload)
{
location.reload();
}
},
error: function(response) {
const Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})
Toast.fire({
icon: 'error',
title: 'Sorry, Something went wrong!'
})
}
});
}
</script>
{{-- Activate / De-Activate --}}
<script>
// Activate
function activateEmployeeRelation(EmployeeRelationId) {
var EmployeeRelationId = EmployeeRelationId;
Swal.fire({
title: 'Activate EmployeeRelation?',
text: "Are you sure you want to activate Employee Relation!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, activate it!'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "get",
url: "{{ url('/') }}/change-status-employee-relation/" + EmployeeRelationId,
success: function(response) {
Swal.fire({
icon: 'success',
title: 'Employee Relation has been activated!',
showConfirmButton: false,
timer: 1500
}).then(function() {
location.reload();
});
}
});
}
});
}
// Deactivate
function deactivateEmployeeRelation(EmployeeRelationId) {
var EmployeeRelationId = EmployeeRelationId;
Swal.fire({
title: 'De-activate Employee Relation?',
text: "Are you sure you want to De-activate Employee Relation!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, De-activate it!'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "get",
url: "{{ url('/') }}/change-status-employee-relation/" + EmployeeRelationId,
success: function(response) {
Swal.fire({
icon: 'success',
title: 'Employee Relation has been De-activated!',
showConfirmButton: false,
timer: 1500
}).then(function() {
location.reload();
});
}
});
}
});
}
</script>
{{-- Edit Employee Relation --}}
<script>
function editEmployeeRelation(EmployeeRelationId)
{
var EmployeeRelationId = EmployeeRelationId;
$('#updateEmployeeRelation').modal('show');
$.ajax({
type: "GET",
url: "{{ url('/') }}/edit-employee-relation/" +EmployeeRelationId,
success: function (response) {
$('#editEmployeeRelationName').val(response.EmployeeRelation.EmployeeRelationName);
$('#EmployeeRelationId').val(EmployeeRelationId);
$('span#EmployeeRelationName').html('#' +response.EmployeeRelation.EmployeeRelationName);
}
});
}
</script>
{{-- Update Employee Relation --}}
<script>
$("#btn-update-employee-relation").click(function (event) {
event.preventDefault();
var Name = $("#editEmployeeRelationName").val();
if (Name == "") {
Swal.fire({
icon: "warning",
title: "Name is required!",
showConfirmButton: false,
timer: 2000,
});
} else {
$.ajax({
type: "post",
url: "{{ url('update-employee-relation') }}",
dataType: "json",
data: $("form#updateEmployeeRelationform").serialize(),
success: function (response) {
Swal.fire({
icon: "success",
title: "Employee Relation has been updated!",
showConfirmButton: false,
timer: 2000,
}).then(function () {
location.reload();
});
},
error: function (response) {
Swal.fire({
icon: "error",
title: "Sorry, Some thing went wrong!",
showConfirmButton: false,
timer: 2000,
});
},
});
}
});
</script>
{{-- Delete Employee Relation --}}
<script>
//Delete Employee Relation
function deleteEmployeeRelation(EmployeeRelationId) {
var EmployeeRelationId = EmployeeRelationId;
$.ajax({
type: "GET",
url: "{{ url('/') }}/check-employee-employee-relation/" + EmployeeRelationId,
success: function (response) {
if (response.exists) {
Swal.fire({
icon: "warning",
title: "Can't be deleted!",
text: "This Employee Relation is associated with empolyee(s)!",
showConfirmButton: true,
});
} else {
Swal.fire({
title: "Delete Employee Relation?",
text: "Are you sure you want to delete this Employee Relation?",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, delete it!",
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "get",
url:
"{{ url('/') }}/delete-employee-relation/" +
EmployeeRelationId,
success: function (response) {
Swal.fire({
icon: "success",
title: "Employee Relation has been deleted!",
showConfirmButton: false,
timer: 1500,
}).then(function () {
location.reload();
});
},
});
}
});
}
},
});
}
</script>