Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed the message #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/controllers/archiving_commentary_controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
export default class archivingCommentaryController extends Controller {

static targets = ['archivingCommentary', 'archivingCommentaryMessage', 'archivingButton'];

Expand Down
67 changes: 67 additions & 0 deletions assets/controllers/closing_commentary_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Controller } from '@hotwired/stimulus';

export default class closingCommentaryController extends Controller {

static targets = ['closingCommentary', 'closingCommentaryMessage', 'closingButton'];

connect() {
// Initialization code or leave empty if not needed
}

closingCommentary() {
console.log("closingCommentary" + this.closingCommentaryTarget.value);
const commentary = this.closingCommentaryTarget.value.trim();
const isValid = commentary.length > 5;

if (isValid) {
this.closingCommentaryMessageTarget.textContent = "";
this.closingButtonTarget.disabled = false;
this.closingButtonTarget.hidden = false;
} else {
this.closingCommentaryMessageTarget.textContent = "Format invalide. Veuillez saisir un commentaire plus complet.";
this.closingCommentaryMessageTarget.style.color = "red"; // Display the message in red color.
}
}


closeWithCommentary(event) {

const entityType = this.trainingOperatorCodeTarget.dataset.entityType;
const efncid = this.trainingOperatorCodeTarget.dataset.efncid;

// Prevent default form submission behavior
event.preventDefault();

// Validate commentary as per your logic; here directly using validateCommentary method
this.validateCommentary();

if (!this.closingButtonTarget.disabled) {
const url = '/efnc/admin/close/'; // Replace with your actual endpoint
const commentary = this.closingCommentaryTarget.value;

fetch(url, {
method: 'POST',
body: JSON.stringify({ closingCommentary: commentary }),
headers: {
'Content-Type': 'application/json',
// Add other headers like CSRF token if necessary
}
})
.then(response => {
// Handle successful response
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json(); // Or `response.text()` if your server sends something other than JSON
})
.then(data => {
// Do something with the data
console.log(data);
})
.catch(error => {
// Handle errors here
console.error('Fetch error:', error);
});
}
}
}
10 changes: 10 additions & 0 deletions assets/js/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ document.addEventListener('turbo:load', function () {
const creationUserButtons = document.querySelectorAll(".submit-user-creation");
const deleteUserButtons = document.querySelectorAll(".delete-user");
const archiveEFNCButtons = document.querySelectorAll(".archive-EFNC");
const closeEFNCButtons = document.querySelectorAll(".close-EFNC");

const entityCreationButtons = document.querySelectorAll(".submit-entity-creation");

Expand Down Expand Up @@ -154,6 +155,15 @@ document.addEventListener('turbo:load', function () {
});
});

closeEFNCButtons.forEach((button) => {
button.addEventListener("click", (event) => {
confirmationHandler(
event,
"Êtes vous sûr de vouloir clore cette EFNC?"
);
});
});

entityCreationButtons.forEach((button) => {
button.addEventListener("click", (event) => {
confirmationHandler(
Expand Down
Loading
Loading