589 lines
29 KiB
PHP
589 lines
29 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => 'Form'])
|
|
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
|
|
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<div id="pageloader">
|
|
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
|
|
{{-- @php
|
|
echo "<pre>";
|
|
print_r($form);
|
|
@endphp --}}
|
|
|
|
@php
|
|
$regions = DB::table('team2_bf_educators')->select('region')->distinct()->orderBy('region', 'ASC')->get();
|
|
@endphp
|
|
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
|
|
<div class="card bg-pattern">
|
|
<div class="card-body p-3 row">
|
|
|
|
@if (Session::has('error'))
|
|
<div class="alert alert-danger">{{ Session::get('error') }}</div>
|
|
<br>
|
|
@endif
|
|
@if (session('success'))
|
|
<div class=" alert alert-success">{{ session('success') }}
|
|
</div>
|
|
<br>
|
|
@endif
|
|
<div class="col-8">
|
|
<h4 class="page-title">{{ $form->title }}</h4>
|
|
</div>
|
|
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="col-4">
|
|
@if ($form->link_type == 'form')
|
|
<a href="/form/history" class="float-end pt-1">View History</a>
|
|
@else
|
|
<a href="{{ url()->previous() }}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
|
|
@php
|
|
$history = Formhelper::getMultiformData(
|
|
$form->partition,
|
|
$form->form_id,
|
|
$form->user_id,
|
|
);
|
|
@endphp
|
|
|
|
|
|
|
|
<div id="form-wrapper">
|
|
<form method="POST" action="/form/submit" id="report-form">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
@csrf
|
|
|
|
@if (isset($form->manager_can_submit) && $form->manager_can_submit == true)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-user_id" class="form-label"> Select User / Territory <span
|
|
class="text-danger">*</span> </label>
|
|
<select class="form-control" id="field-user_id" name="tm_name" required>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($form->users as $option)
|
|
<option value="{{ isset($option->user_info->name) ? $option->user_info->name : '' }}"
|
|
data-emp_code="{{ $option->user_info->employee_code ?? '' }}"
|
|
data-tm_hq="{{ $option->display ? trim(explode('-', $option->display)[0]) : '' }}"
|
|
hierarchy="{{ $option->hierarchy_id }}"
|
|
tm_userid="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
<input type="hidden" id="field-hierarchy_id" name="tm_hierarchy_id"
|
|
value="">
|
|
<input type="hidden" id="field-tm_user_id" name="tm_user_id"
|
|
value="">
|
|
</div>
|
|
@endif
|
|
|
|
@foreach ($questions as $question)
|
|
@if (in_array($question->code, ['']))
|
|
@continue
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('textarea')
|
|
<textarea id="field-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
@if ($question->code == 'region')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($regions as $row)
|
|
<option value="{{ $row->region }}">{{ $row->region }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@else
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
@endif
|
|
@break
|
|
|
|
@case('checkbox')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary">
|
|
<input class="form-check-input" type="checkbox"
|
|
id="field-{{ $question->code }}-{{ $option->value }}"
|
|
name="{{ $question->code }}[]" value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
|
|
<label class="form-check-label"
|
|
for="field-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
|
|
<div class="col-md-12 mb-3">
|
|
<button type="button" id="add-educator" class="btn btn-success">
|
|
+ Add Educator
|
|
</button>
|
|
</div>
|
|
|
|
<div id="educator-wrapper" class="mb-3"></div>
|
|
|
|
<div id="educator-template" style="display:none;">
|
|
<div class="educator-group border rounded p-3 mb-3 bg-light">
|
|
|
|
<div class="row g-3 align-items-end">
|
|
|
|
<div class="col-md-4">
|
|
<label class="form-label">BF Educator Name</label>
|
|
<select class="form-control educator-name" name="educator_name[]">
|
|
<option value="">-- Select --</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
<label class="form-label">TL Code</label>
|
|
<input type="text" class="form-control tl-code"
|
|
name="tl_code[]" readonly>
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
<label class="form-label">Designation</label>
|
|
<input type="text" class="form-control designation"
|
|
name="edudesignation[]" readonly>
|
|
</div>
|
|
|
|
<div class="col-md-2 text-end">
|
|
<button type="button"
|
|
class="btn btn-danger remove-educator w-100">
|
|
Remove
|
|
</button>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center d-grid mt-3">
|
|
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
|
|
</button>
|
|
</div>
|
|
@endif
|
|
</form>
|
|
</div>
|
|
|
|
{{-- <div id="execution-form-wrapper">
|
|
<form method="POST" action="/form/submit" id="execution-form"
|
|
enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
@csrf
|
|
<input type="hidden" name="id" value="" id="execution-id">
|
|
@foreach ($questions as $question)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="execution-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('textarea')
|
|
<textarea id="execution-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
<select class="form-control" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
|
|
@case('checkbox')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary">
|
|
<input class="form-check-input" type="checkbox"
|
|
id="execution-{{ $question->code }}-{{ $option->value }}"
|
|
name="{{ $question->code }}[]" value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
|
|
<label class="form-check-label"
|
|
for="execution-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('file')
|
|
<input type="file" id="execution-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control" value=""
|
|
accept="image/jpg, image/jpeg, image/png">
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center d-grid mt-3">
|
|
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
|
|
</button>
|
|
</div>
|
|
@endif
|
|
</form>
|
|
</div> --}}
|
|
|
|
|
|
</div> <!-- end card-body -->
|
|
</div>
|
|
<!-- end card -->
|
|
|
|
<!-- end row -->
|
|
|
|
</div> <!-- end col -->
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end container -->
|
|
</div>
|
|
<!-- end page -->
|
|
<style type="text/css">
|
|
#pageloader {
|
|
background: rgba(255, 255, 255, 0.8);
|
|
display: none;
|
|
height: 100%;
|
|
position: fixed;
|
|
width: 100%;
|
|
z-index: 9999;
|
|
}
|
|
|
|
#pageloader img {
|
|
left: 50%;
|
|
margin-left: -32px;
|
|
margin-top: -32px;
|
|
position: absolute;
|
|
top: 50%;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
|
|
<script>
|
|
let educatorData = [];
|
|
|
|
/* ================= USER CHANGE ================= */
|
|
$('#field-user_id').change(function() {
|
|
|
|
let selected = $('option:selected', this);
|
|
|
|
$('#field-hierarchy_id').val(selected.attr('hierarchy') || '');
|
|
$('#field-tm_user_id').val(selected.attr('tm_userid') || '');
|
|
|
|
$('#field-tm_employee_code').val(selected.attr('data-emp_code') || '');
|
|
$('#field-tm_hq').val(selected.attr('data-tm_hq') || '');
|
|
});
|
|
|
|
|
|
/* ================= READONLY FIELDS ================= */
|
|
$('#field-tm_employee_code').prop('readonly', true);
|
|
$('#field-tm_hq').prop('readonly', true);
|
|
|
|
|
|
/* ================= REGION API ================= */
|
|
$(document).on('change', '#field-region', function() {
|
|
|
|
let region = $(this).val();
|
|
if (!region) return;
|
|
|
|
$.ajax({
|
|
url: "/form/team2bfeducators",
|
|
type: "GET",
|
|
data: {
|
|
region: region
|
|
},
|
|
success: function(res) {
|
|
|
|
console.log('API DATA:', res);
|
|
|
|
educatorData = res || [];
|
|
|
|
$('#educator-wrapper').empty();
|
|
|
|
toggleSubmit();
|
|
},
|
|
error: function() {
|
|
educatorData = [];
|
|
$('#educator-wrapper').empty();
|
|
alert('Unable to load educators for the selected region.');
|
|
toggleSubmit();
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
/* ================= INIT ================= */
|
|
$(document).ready(function() {
|
|
|
|
const maxFields = 48;
|
|
|
|
const urlRegion = new URLSearchParams(window.location.search).get('region');
|
|
if (urlRegion) {
|
|
$('#field-region').val(urlRegion).trigger('change');
|
|
}
|
|
|
|
/* ================= ADD EDUCATOR ================= */
|
|
$('#add-educator').on('click', function() {
|
|
|
|
if (!educatorData.length) {
|
|
alert('Please select region first');
|
|
return;
|
|
}
|
|
|
|
let count = $('.educator-group').length;
|
|
|
|
if (count >= maxFields) {
|
|
alert('Maximum 48 educators allowed');
|
|
return;
|
|
}
|
|
|
|
let template = $('#educator-template').html();
|
|
let $row = $(template);
|
|
|
|
let $select = $row.find('.educator-name');
|
|
|
|
$.each(educatorData, function(i, edu) {
|
|
|
|
$select.append(`
|
|
<option
|
|
value="${edu.name_of_employee}"
|
|
data-tl_code="${edu.employee_code}"
|
|
data-designation="${edu.designation || ''}">
|
|
${edu.name_of_employee}
|
|
</option>
|
|
`);
|
|
|
|
});
|
|
|
|
$('#educator-wrapper').append($row);
|
|
|
|
updateEducatorDropdowns();
|
|
toggleSubmit();
|
|
});
|
|
|
|
|
|
/* ================= REMOVE EDUCATOR ================= */
|
|
$(document).on('click', '.remove-educator', function() {
|
|
|
|
$(this).closest('.educator-group').remove();
|
|
|
|
updateEducatorDropdowns();
|
|
toggleSubmit();
|
|
});
|
|
|
|
|
|
/* ================= ON CHANGE ================= */
|
|
$(document).on('change', '.educator-name', function() {
|
|
|
|
let selected = $(this).find('option:selected');
|
|
|
|
let parent = $(this).closest('.educator-group');
|
|
|
|
parent.find('.tl-code').val(selected.attr('data-tl_code') || '');
|
|
parent.find('.designation').val(selected.attr('data-designation') || '');
|
|
|
|
updateEducatorDropdowns();
|
|
toggleSubmit();
|
|
|
|
});
|
|
|
|
|
|
/* ================= DUPLICATE PREVENTION ================= */
|
|
function updateEducatorDropdowns() {
|
|
|
|
let selectedValues = [];
|
|
|
|
$('.educator-name').each(function() {
|
|
let val = $(this).val();
|
|
if (val) selectedValues.push(val);
|
|
});
|
|
|
|
$('.educator-name').each(function() {
|
|
|
|
let current = $(this).val();
|
|
|
|
$(this).find('option').each(function() {
|
|
|
|
let val = $(this).val();
|
|
|
|
if (!val) return;
|
|
|
|
if (selectedValues.includes(val) && val !== current) {
|
|
$(this).prop('disabled', true);
|
|
} else {
|
|
$(this).prop('disabled', false);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
/* ================= FORM SUBMIT ================= */
|
|
$('#report-form').on('submit', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
let validCount = 0;
|
|
let emptyRows = [];
|
|
|
|
$('.educator-group').each(function() {
|
|
|
|
let select = $(this).find('.educator-name');
|
|
let value = select.val();
|
|
|
|
let selected = select.find('option:selected');
|
|
|
|
if (value) {
|
|
|
|
validCount++;
|
|
|
|
$(this).find('.tl-code').val(selected.attr('data-tl_code') || '');
|
|
$(this).find('.designation').val(selected.attr('data-designation') || '');
|
|
|
|
} else {
|
|
emptyRows.push(this);
|
|
}
|
|
});
|
|
|
|
/* remove empty rows safely */
|
|
$(emptyRows).remove();
|
|
|
|
if (validCount === 0) {
|
|
alert('Please add at least 1 Educator');
|
|
return;
|
|
}
|
|
|
|
$("#pageloader").fadeIn();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: new FormData($('#report-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
|
|
$("#pageloader").fadeOut();
|
|
|
|
if (data.status === 'success') {
|
|
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
}).then(() => {
|
|
window.location.reload();
|
|
});
|
|
|
|
} else {
|
|
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again.'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
/* ================= SUBMIT BUTTON TOGGLE ================= */
|
|
function toggleSubmit() {
|
|
|
|
let hasValue = $('.educator-name').filter(function() {
|
|
return $(this).val();
|
|
}).length > 0;
|
|
|
|
$('#submit-btn').prop('disabled', !hasValue);
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|