user roles, bug fixes
This commit is contained in:
@@ -271,4 +271,88 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// ==========================================
|
||||
// 4. NOTES LOGIC
|
||||
// ==========================================
|
||||
|
||||
// Initialize Select2 with the 'tags' feature enabled
|
||||
$('#note_services').select2({
|
||||
placeholder: "Select or type a new service...",
|
||||
allowClear: true,
|
||||
width: '100%',
|
||||
dropdownParent: $('#addNoteModal'),
|
||||
tags: true // This allows users to type and submit custom entries
|
||||
});
|
||||
|
||||
$('#addNoteForm').on('submit', function(e) {
|
||||
// ... (keep your existing ajax submit logic here) ...
|
||||
});
|
||||
|
||||
$('#addNoteModal').on('hidden.bs.modal', function () {
|
||||
$('#addNoteForm')[0].reset();
|
||||
$('#noteModalAlert').html('');
|
||||
$('#addNoteForm').find('.is-invalid').removeClass('is-invalid');
|
||||
$('#addNoteForm').find('.invalid-feedback').remove();
|
||||
|
||||
// Clear the Select2 dropdown properly
|
||||
$('#note_services').val(null).trigger('change');
|
||||
});
|
||||
$('#addNoteForm').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
let $form =$(this);
|
||||
let $submitBtn =$('#btnSubmitNote');
|
||||
let originalText = $submitBtn.html();
|
||||
let $alertBox =$('#noteModalAlert');
|
||||
|
||||
$submitBtn.html('<span class="spinner-border spinner-border-sm me-2"></span>Saving...').prop('disabled', true);
|
||||
$alertBox.html('');$form.find('.is-invalid').removeClass('is-invalid');
|
||||
|
||||
$.ajax({
|
||||
url: $form.attr('action'),
|
||||
type: 'POST',
|
||||
data: $form.serialize(),
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$('#addNoteModal').modal('hide');
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Saved!',
|
||||
text: response.message,
|
||||
confirmButtonColor: '#5c4df0'
|
||||
}).then(() => location.reload());
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
if (xhr.status === 422) {
|
||||
let errors = xhr.responseJSON.errors;
|
||||
$alertBox.html(`
|
||||
<div class="alert alert-danger d-flex align-items-center py-2 px-3 small" role="alert">
|
||||
<i class="bi bi-exclamation-triangle-fill me-2"></i>
|
||||
<div>Please fill in the required fields.</div>
|
||||
</div>
|
||||
`);
|
||||
$.each(errors, function(key, value) {
|
||||
let $input =$form.find('[name="' + key + '"]');
|
||||
if ($input.length) {
|
||||
$input.addClass('is-invalid');$input.parent().append('<div class="invalid-feedback d-block fw-medium small">' + value[0] + '</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
$submitBtn.html(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#addNoteModal').on('hidden.bs.modal', function () {
|
||||
$('#addNoteForm')[0].reset();
|
||||
$('#noteModalAlert').html('');
|
||||
$('#addNoteForm').find('.is-invalid').removeClass('is-invalid');
|
||||
$('#addNoteForm').find('.invalid-feedback').remove();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user