I have an error about my Acknowledge button. when the acknowledge button is clicked pop up a modal that has a comment box (optional comment) and 2 buttons (proceed and cancel) and if the proceed button clicked, it will mark as acknowledged to the database. the error was in the javascript in the proceedfw() and pointing to the "acknowledge". I hope you can help thank you.
the Button part of the HTML
</div>
<div class="row">
<div class="col-6 col-xs-6 col-sm-6 col-md-6 col-lg-6 col-xl-6">
@if($fw->fw_status != "Disapproved" && $fw->fw_status != "Cancelled")
@if(($fw->fw_current_stg == "DH" || $fw->fw_current_stg == "ITOPS") && $upcoming->cmstg_user == $user )
<button type="button" class="btn btn-success btn-block" data-bs-toggle="modal" data-bs-target="#staticBackdrop"><i class="fas fa-check"></i> APPROVE</button>
@elseif($fw->fw_current_stg == "NETAD" && $now->cmstg_desc == "Acknowledged" && ($user == "jvagbay" ||$user == "agprotacio" ))
<button type="button" class="btn btn-info btn-block text-white" data-bs-toggle="modal" data-bs-target="#staticBackdrop"><i class="fas fa-check"></i> MARK AS DONE</button>
@elseif($fw->fw_current_stg == "NETAD" && ($user == "jvagbay" ||$user == "agprotacio" ))
<button type="button" class="btn btn-primary btn-block" data-bs-toggle="modal" data-bs-target="#staticBackdrop"><i class="fas fa-check"></i> ACKNOWLEDGE REQUEST</button>
@endif
<!-- disapprove -->
@if(!$fw->current == "UA" && $latest_approver == $user)
<button type="button" class="btn btn-danger btn-block" data-bs-toggle="modal" data-bs-target="#staticBackdropDA"><i class="fas fa-check"></i> DISAPPROVE</button>
@endif
@endif
<!-- revision -->
@if(($fw->fw_current_stg == "DH" || $fw->fw_current_stg == "NETAD") && $latest_approver == $user)
<button type="button" class="btn btn-warning text-light" data-bs-toggle="modal" data-bs-target="#staticBackdropRV" >FOR REVISION</button>
@endif
<!-- cancelled -->
@if($fw->fw_user == $user && $fw->fw_status == "Open")
<button type="button" class="btn btn-danger text-light" data-bs-toggle="modal" data-bs-target="#staticBackdropCancel" ><i class="fas fa-ban"></i> CANCEL REQUEST</button>
@endif
</div>
</div>
the modal
<!-- Modal -->
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Add Comment</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<textarea class="form-control" id="comment" placeholder="(Optional)"></textarea>
<div class="invalid-feedback">Please add comment..</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-allcard" id="btnProceed" onclick="proceed_fw()"><span class="spinner-border spinner-border-sm d-none" id="sp_proceed" aria-hidden="true"></span>Proceed</button>
</div>
</div>
</div>
</div>
javascript
function proceed_fw()
{
var comment = $('#comment').val();
$('#sp_proceed').removeClass('d-none');
$('#btnProceed').prop('disabled',true);
$('#comment').removeClass('is-invalid');
$('#comment').prop('disabled',true);
$.ajax({
url: "{{route('fw.status')}}",
type:"post",
data:{
fw_number:$('#fw_number').val(),
comment:$('#comment').val(),
user:'{{auth()->user()->status_xuser}}',
},
success: function(result){
$('#sp_proceed').removeClass('d-none');
if(result == "approved")
alert(result);
{
Swal.fire({
title: 'Firewall Request Approved',
text: '#'+$('#fw_number').val()+' has been marked approved.',
icon:'success',
confirmButtonText: 'View Request',
confirmButtonColor: '#fa0031',
}).then((result) => {
if (result.value) {
location.reload();
}
});
}
else if(result=="acknowledged")
{
Swal.fire({
title: 'Firewall Request Acknowledged',
text: '#'+$('#fw_number').val()+' has been marked acknowledged.',
icon:'success',
confirmButtonText: 'View Request',
confirmButtonColor: '#fa0031',
}).then((result) => {
if (result.value) {
let url = "{{route('fw.index')}}";
document.location.href=url;
}
});
}
else if (result=="closed")
{
Swal.fire({
title: 'Firewall Request Closed',
text: '#'+$('#fw_number').val()+' has been marked completed.',
icon:'success',
confirmButtonText: 'View Request',
confirmButtonColor: '#fa0031',
}).then((result) => {
if (result.value) {
let url = "{{route('fw.index')}}";
document.location.href=url;
}
});
}
},
error:function(result)
{
alert(result);
}
});
}
controller
public function StatusFW(Request $request)
{
$isAcknowledge = false;
$isClosed = false;
$fw_number = $request->fw_number;
$comment = $request->comment;
$fw = FirewallRequest::where('fw_number',$fw_number)->first();
$stages = $fw->fw_stage;
$array = explode(',',$stages);
$count = count($array);
$current_stage = $fw->fw_current_stg;
$fw_stage = ChangeManagementStages::where('cmstg_cmnumber',$fw_number)
->where('cmstg_stage',$current_stage)->first();
if(($count == 4 || $count == 3) && $current_stage == "DH")
{
$updated_current = 'ITOPS';
}
else if(($count == 4 ||$count == 3) && $current_stage == "ITOPS")
{
$updated_current = 'NETAD';
}
else if(($count == 3 || $count == 2) && $current_stage == "DH")
{
$updated_current = 'NETAD';
}
else if($current_stage == "NETAD" && $fw_current_stg->cmstg_desc == "acknowledged")
{
$updated_current = 'UA';
}
else if( $current_stage == "NETAD")
{
$updated_current = 'NETAD';
$isAcknowledge = true;
}
else if($current_stage == "UA")
{
$isClosed = true;
$updated_current = 'CLOSED/DONE';
}
try {
$fwUpdate = FirewallRequest::find($fw->fw_id);
$fwUpdate->updated_at = Carbon::now()->toDateTimeString();
$fwUpdate->fw_current_stg = $updated_current;
if($isClosed)
{
$fwUpdate->fw_status = 'Closed/Done';
$fwUpdate->fw_uacomment = $comment;
$fwUpdate->fw_uadate = Carbon::now()->toDateTimeString();
}
$fwUpdate->save();
//email notification
//if == Closed/Acknowledged/Delivered
if($isClosed) {
return "closed";
}
else {
$stageUpdate = ChangeManagementStages::find($cmstg_stage->cmstg_id);
{
$stageUpdate->cmstg_dateaction = Carbon::now()->toDateTimeString();
$stageUpdate->cmstg_desc = $isAcknowledge ? 'acknowledged':'Approved';
$stageUpdate->cmstg_note = $comment;
$stageUpdate->cmstg_user = $request->user;
$stageUpdate->save();
}
try {
// email notif
if($updated_current == "ITOPS"){
self::email_notif(self::getdephead('IT-Operations'),$pr->pr_number);
if($current_stage == "DH"){
self::email_stgnotif($pr->pr_user,$pr->pr_number,'Department Head',$comment,$current_stage);
}
if($current_stage == "ITOPS"){
self::email_stgnotif($pr->pr_user,$pr->pr_number,'IT-Operations Head',$comment,$current_stage);
}
}
else if($updated_current == "PURCH"){
self::email_notif('atko',$pr->pr_number);
self::email_notif('wschua',$pr->pr_number);
self::email_notif('jpramos',$pr->pr_number);
if($current_stage == "DH"){
self::email_stgnotif($pr->pr_user,$pr->pr_number,'Department Head',$comment,$current_stage);
}
else if($current_stage == "ITOPS") {
self::email_stgnotif($pr->pr_user,$pr->pr_number,'IT-Operations Head',$comment,$current_stage);
}
// }
else if($current_stage == "PURCH") {
// else if($current_stage == "PRES") {
// self::email_stgnotif($pr->pr_user,$pr->pr_number,'President',$comment,$current_stage);
self::email_stgnotif($pr->pr_user,$pr->pr_number,'Purchasing Department',$comment,$current_stage);
}
}
} catch (\Throwable $th) {
info($th);
}
$rt_val = "approved";
if($isAcknowledge) $rt_val = "acknowledged";
return $rt_val;
}
}
catch (\Throwable $th)
{
alert()->error($th->getMessage())->showConfirmButton('Return', '#fa0031');
return $th->getMessage();
}
}