<section class="efl-learner-profile__section previous-experience" data-behavior="efl-learner-profile-previous-experience">
<div class="efl-learner-profile__section--header">
<h3 class="previous-experience">My previous experience</h3>
<button aria-label="edit my previous experience" class="efl-learner-profile__section--edit"></button>
</div>
<p class="paragraph placeholder-text">Share past experience within football or any sport</p>
<div class="efl-learner-profile__section__experience--container">
<div class="efl-learner-profile__section__experience--pagelist">
<div class="efl-learner-profile__section__experience" data-experience-detail='{
"name": "Name of team / experience 1" ,
"role" : "Name of role taken",
"description" : "Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.",
"dateStarted" : "2012/07/25",
"dateCompleted" : "2012/08/25"}' data-edit-id="0">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">Jul 2012 - Aug 2012</div>
<h5>Name of team / experience 1</h5>
<p class="role"><strong>Name of role taken</strong></p>
<p>Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.</p>
</div>
</div>
<div class="efl-learner-profile__section__experience" data-experience-detail='{
"name": "Name of team / experience 2" ,
"role" : "Name of role taken",
"description" : "Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.",
"dateStarted" : "2011/03/25",
"dateCompleted" : "2011/04/25"}' data-edit-id="1">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">Mar 2011 - Apr 2011</div>
<h5>Name of team / experience 2</h5>
<p class="role"><strong>Name of role taken</strong></p>
<p>Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.</p>
</div>
</div>
<div class="efl-learner-profile__section__experience" data-experience-detail='{
"name": "Name of team / experience 3" ,
"role" : "Name of role taken",
"description" : "Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.",
"dateStarted" : "2010/05/25",
"dateCompleted" : "2010/06/25"}' data-edit-id="2">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">May 2010 - Jun 2010</div>
<h5>Name of team / experience 3</h5>
<p class="role"><strong>Name of role taken</strong></p>
<p>Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.</p>
</div>
</div>
</div>
<button class="cta cta--secondary" id="show-all-button" aria-label="show all 3 experiences">Show All 3 Experiences</button>
<button class="cta cta--secondary" id="show-less-cta" aria-label="show less previous experiences">Show Less</button>
</div>
<div class="efl-profile-left-popup previous-experience" role="dialog" aria-modal="true" data-behavior="efl-profile-left-popup">
<button class="efl-profile-left-popup__close" aria-label="close previous experience popup window"></button>
<div class="efl-learner-profile__section--header">
<h3 class="previous-experience">My previous experience</h3>
</div>
<div id="previous-experience-main" class="efl-profile-left-popup--inner">
<p class="paragraph">Coach? Medic? Referee? If you're already involved in football, share your previous experience below.</p>
<div class="efl-learner-profile__section__experience--container">
<div class="efl-learner-profile__section__experience--list">
<div class="efl-learner-profile__section__experience" data-start-date="2012/07/25" data-end-date="2012/08/25" data-edit-id="0">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">Jul 2012 - Aug 2012</div>
<h5>Name of team / experience 1</h5>
<p class="role"><strong>Name of role taken</strong></p>
<p>Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.</p>
</div>
<button aria-label="edit Name of team / experience 1 experience" class="efl-learner-profile__section__qualification--edit"></button>
</div>
<div class="efl-learner-profile__section__experience" data-start-date="2011/03/25" data-end-date="2011/04/25" data-edit-id="1">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">Mar 2011 - Apr 2011</div>
<h5>Name of team / experience 2</h5>
<p class="role"><strong>Name of role taken</strong></p>
<p>Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.</p>
</div>
<button aria-label="edit Name of team / experience 2 experience" class="efl-learner-profile__section__qualification--edit"></button>
</div>
<div class="efl-learner-profile__section__experience" data-start-date="2010/05/25" data-end-date="2010/06/25" data-edit-id="2">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">May 2010 - Jun 2010</div>
<h5>Name of team / experience 3</h5>
<p class="role"><strong>Name of role taken</strong></p>
<p>Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.</p>
</div>
<button aria-label="edit Name of team / experience 3 experience" class="efl-learner-profile__section__qualification--edit"></button>
</div>
</div>
<button class="cta cta--secondary" id="show-all-button" aria-label="show all 3 experiences">Show All 3 Experiences</button>
<button class="cta cta--secondary" id="show-less-cta" aria-label="show less previous experiences">Show Less</button>
</div>
<button class="cta cta--secondary" id="previous-experience-add-button" aria-label="add experience">Add Experience</button>
</div>
<div id="previous-experience-form" class="efl-profile-left-popup--inner hidden">
<button class="efl-profile-left-popup__back" aria-label="back to previous experiences">Back</button>
<h4 class="efl-learner-profile__section--subheading" data-form-title-add="Add Experience" data-form-title-edit="Edit Experience"><strong>Add Experience</strong></h4>
<form>
<label for="previous-experience-form--title">Title of experience</label>
<input type="text" name="experience title" autocomplete="off" id="previous-experience-form--title" maxlength="100" />
<p><span class="character-count__name">0</span>/100 characters</p>
<label for="previous-experience-form--role">Your role</label>
<input type="text" name="experience role" autocomplete="off" id="previous-experience-form--role" maxlength="100" />
<p><span class="character-count__role">0</span>/100 characters</p>
<label>Date of Experience</label>
<div class="previous-experience-form--date-range">
<input autocomplete="off" type="text" placeholder="Date from" name="start date of experience" id="previous-experience-form--date-start" />
<input autocomplete="off" type="text" placeholder="Date to" name="end date of experience" id="previous-experience-form--date-end" />
</div>
<label for="previous-experience-form--desc">Description of experience</label>
<textarea rows="3" cols="30" maxlength="500" name="description of experience" id="previous-experience-form--desc" maxlength="500"></textarea>
<p><span class="character-count__textarea">0</span>/500 characters</p>
</form>
<button class="cta cta--efl " id="previous-experience-save-experience-button" aria-label="save experience" aria-disabled="true">
<span>Save Experience</span>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px" height="20px" viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">
<rect x="0" y="10" width="4" height="10" fill="#fff" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
</rect>
<rect x="8" y="10" width="4" height="10" fill="#fff" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
</rect>
<rect x="16" y="10" width="4" height="10" fill="#fff" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
</rect>
</svg>
</button>
<button class="cta cta--secondary" id="delete-experience-button" aria-label="delete experience">Delete Experience</button>
</div>
<div class="efl-profile-left-popup__toast-notification" tabindex="-1" aria-label="" data-toast-update-text="Previous Experience Saved!" data-toast-delete-text="Previous Experience Deleted!">
Previous Experience Saved!
</div>
<div class="efl-profile-left-popup__alert-modal" role="dialog" aria-modal="true" aria-live="polite" data-unsaved-changes-header="You have unsaved changes" data-unsaved-changes-copy="Continue editing to save your changes." data-fill-all-fields-header="you must fill in all fields" data-fill-all-fields-copy="Continue editing to save your changes." data-make-bio-public-header="Time to make your bio public?" data-make-bio-public-copy="Publishing your bio allows others to view your information. This is a great way to connect with clubs, coaches and the football community." data-innapropriate-content-header="Innapropriate content" data-innapropriate-content-copy="Lorem ipsum dolor sit amet, consectetur adipiscing elit." data-iwf-error-content-header="Error" data-iwf-error-content-copy="Lorem ipsum dolor sit amet, consectetur adipiscing elit." data-invalid-data-content-header="Error" data-invalid-data-content-copy="Lorem ipsum dolor sit amet, consectetur adipiscing elit.">
<h5 class="efl-category-title">This Image is Not Appropriate</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ultricies, nibh sit amet varius faucibus, est
ipsum commodo mi, a rutrum urna mauris ut.</p>
<button class="cta cta--efl " id="previous-experience-continue-editing-button" aria-label="Continue Editing">Continue Editing</button>
<button class="cta cta--secondary " id="previous-experience-lose-changes-button" aria-label="Lose My Changes">Lose My Changes</button>
<button class="cta cta--efl " id="previous-experience-make-bio-public-button" aria-label="Make Bio Public">Make Bio Public</button>
<button class="cta cta--secondary " id="previous-experience-keep-bio-private-button" aria-label="Keep Bio Private">Keep Bio Private</button>
<button class="cta cta--efl " id="efl-learner-profile-edit-previous-experience-button" aria-label="Edit Experience">Edit Experience</button>
<button class="cta cta--efl " id="efl-learner-profile-error-previous-experience-button" aria-label="Try again">Try again</button>
</div>
</div>
</section>
No notes defined.
{
"experiences": [
{
"title": "Name of team / experience 1",
"date": "Jul 2012 - Aug 2012",
"role": "Name of role taken",
"desc": "Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.",
"dateStart": "2012/07/25",
"dateEnd": "2012/08/25"
},
{
"title": "Name of team / experience 2",
"date": "Mar 2011 - Apr 2011",
"role": "Name of role taken",
"desc": "Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.",
"dateStart": "2011/03/25",
"dateEnd": "2011/04/25"
},
{
"title": "Name of team / experience 3",
"date": "May 2010 - Jun 2010",
"role": "Name of role taken",
"desc": "Bit of descriptive text about their experience with the team and what they learned. Limited to 500 characters.",
"dateStart": "2010/05/25",
"dateEnd": "2010/06/25"
}
],
"show-all-button": {
"href": "#",
"copy": "Show All",
"id": "show-all-button"
},
"show-less-button": {
"href": "#",
"copy": "Show Less",
"id": "show-less-cta"
},
"add-experience-button": {
"href": "#",
"id": "previous-experience-add-button",
"copy": "Add Experience"
},
"save-experience-button": {
"href": "#",
"id": "previous-experience-save-experience-button",
"copy": "Save Experience"
},
"save-button": {
"href": "#",
"copy": "Save",
"id": "previous-experience-save-button"
},
"delete-experience-button": {
"href": "#",
"copy": "Delete Experience",
"id": "delete-experience-button",
"additionalClass": "hidden",
"modifier": "secondary"
},
"continue-editing-button": {
"href": "#",
"copy": "Continue Editing",
"id": "previous-experience-continue-editing-button",
"modifier": "efl"
},
"lose-changes-button": {
"href": "#",
"copy": "Lose My Changes",
"id": "previous-experience-lose-changes-button",
"modifier": "secondary"
},
"make-bio-public-button": {
"href": "#",
"copy": "Make Bio Public",
"id": "previous-experience-make-bio-public-button",
"modifier": "efl"
},
"keep-bio-private-button": {
"href": "#",
"copy": "Keep Bio Private",
"id": "previous-experience-keep-bio-private-button",
"modifier": "secondary"
},
"edit-previous-experience-button": {
"href": "",
"copy": "Edit Experience",
"id": "efl-learner-profile-edit-previous-experience-button",
"modifier": "efl"
},
"error-previous-experience-button": {
"href": "",
"copy": "Try again",
"id": "efl-learner-profile-error-previous-experience-button",
"modifier": "efl"
}
}
// import { Rive, Layout } from '@rive-app/canvas';
import DateRangePicker from 'vanillajs-datepicker/js/DateRangePicker';
import {
updatePlayerProfile,
updateProfileCompletion,
} from '../efl-learner-profile/efl-learner-profile-update';
export default parentElement => {
// Variables
const eflProfileLayout = document.querySelector('.efl-profile-layout');
const eflExperiences = parentElement.querySelector(
'.efl-learner-profile__section__experience--container'
);
const placeholderText = parentElement.querySelector('.placeholder-text');
const editbtn = parentElement.querySelector(
'.efl-learner-profile__section--edit'
);
// Pop Up
const popUp = parentElement.querySelector('.efl-profile-left-popup');
const closeBtn = popUp.querySelector('.efl-profile-left-popup__close');
const eflPopUpExperiences = popUp.querySelector(
'.efl-learner-profile__section__experience--container'
);
const addExperienceBtn = popUp.querySelector(
'.cta[id=previous-experience-add-button]'
);
const backButton = popUp.querySelector('.efl-profile-left-popup__back');
const mainSection = popUp.querySelector('#previous-experience-main');
const formSection = popUp.querySelector('#previous-experience-form');
const { formTitleAdd, formTitleEdit } = formSection.querySelector(
'h4'
).dataset;
// Form
const saveExperienceButton = popUp.querySelector(
'.cta[id=previous-experience-save-experience-button]'
);
const deleteExperienceBtn = popUp.querySelector(
'.cta[id=delete-experience-button]'
);
const titleInput = formSection.querySelector(
'#previous-experience-form--title'
);
const roleInput = formSection.querySelector(
'#previous-experience-form--role'
);
const dateRangeElement = formSection.querySelector(
'.previous-experience-form--date-range'
);
const dateStartInput = formSection.querySelector(
'#previous-experience-form--date-start'
);
const dateEndInput = formSection.querySelector(
'#previous-experience-form--date-end'
);
const textareaInput = formSection.querySelector(
'#previous-experience-form--desc'
);
const characterCount = popUp.querySelector('.character-count__name');
const roleCharacterCount = popUp.querySelector('.character-count__role');
const textareaCharacterCount = popUp.querySelector(
'.character-count__textarea'
);
const toastNotification = popUp.querySelector(
'.efl-profile-left-popup__toast-notification'
);
const { toastUpdateText, toastDeleteText } = toastNotification.dataset;
const MOBILE_BREAKPOINT = 820;
// const riveCanvas = toastNotification.querySelector('#rive');
// const animation = new Rive({
// src: '/assets/example-content/tick_animation.riv',
// // Or the path to a local Rive asset
// // src: './example.riv',
// canvas: riveCanvas,
// layout: new Layout({ fit: 'fill' }),
// });
saveExperienceButton.setAttribute('aria-disabled', 'true');
// Alert Modal
const alertModal = popUp.querySelector(
'.efl-profile-left-popup__alert-modal'
);
const privacyInput = document.querySelector('#learner-profile-privacy-check');
// Alert Modal - Buttons
const continueEditingBtn = alertModal.querySelector(
'#previous-experience-continue-editing-button'
);
const loseChangesBtn = alertModal.querySelector(
'#previous-experience-lose-changes-button'
);
const makeBioPublicBtn = alertModal.querySelector(
'#previous-experience-make-bio-public-button'
);
const keepBioPrivateBtn = alertModal.querySelector(
'#previous-experience-keep-bio-private-button'
);
const editExperienceBtn = alertModal.querySelector(
'#efl-learner-profile-edit-previous-experience-button'
);
const errorExperienceBtn = alertModal.querySelector(
'#efl-learner-profile-error-previous-experience-button'
);
// eslint-disable-next-line no-unused-vars
let rangePicker = null;
// Functions
const showAll = (container, threshold) => {
const showAllButton = container.querySelector('#show-all-button');
const showLessButton = container.querySelector('#show-less-cta');
const experiences = container.querySelectorAll(
'.efl-learner-profile__section__experience'
);
if (experiences.length) {
placeholderText.classList.add('hidden');
}
if (showLessButton) {
showLessButton.classList.add('hidden');
}
if (experiences.length > threshold) {
experiences.forEach((experience, index) => {
if (index + 1 > threshold) {
experience.classList.add('hidden');
}
});
showAllButton.innerHTML = `Show All ${experiences.length} Experiences`;
showAllButton.classList.remove('hidden');
showAllButton.addEventListener('click', e => {
e.preventDefault();
showAllButton.classList.add('hidden');
showLessButton.classList.remove('hidden');
setTimeout(() => {
showLessButton.focus();
}, 10);
experiences.forEach(experience => {
experience.classList.remove('hidden');
});
});
showLessButton.addEventListener('click', e => {
e.preventDefault();
const clickedElement = e.target;
const eflExperience = clickedElement.closest(
'.efl-learner-profile__section__experience--container'
);
const eflPopUpExperience = clickedElement.closest(
'.efl-learner-profile__section__experience--container'
);
if (eflExperience) {
showAll(eflExperience, 2);
showAllButton.classList.remove('hidden');
setTimeout(() => {
showAllButton.focus();
}, 10);
showLessButton.classList.add('hidden');
} else if (eflPopUpExperience) {
showAll(eflPopUpExperience, 3);
showAllButton.classList.remove('hidden');
setTimeout(() => {
showAllButton.focus();
}, 10);
showLessButton.classList.add('hidden');
}
});
} else {
showAllButton.classList.add('hidden');
showLessButton.classList.add('hidden');
}
};
const closeModal = e => {
e.preventDefault();
alertModal.classList.remove('add-animation');
setTimeout(() => {
popUp.classList.remove('dark-overlay');
}, 300);
};
const modalAlert = type => {
const header = alertModal.getAttribute(`data-${type}-header`);
const copy = alertModal.getAttribute(`data-${type}-copy`);
// Reset Alert Modal ClassName
alertModal.removeAttribute('data-err');
alertModal.setAttribute('data-err', type);
alertModal.querySelector('h5').innerHTML = header;
alertModal.querySelector('p').innerHTML = copy;
alertModal.classList.add('add-animation');
popUp.classList.add('dark-overlay');
};
const resetForm = () => {
titleInput.value = '';
roleInput.value = '';
dateStartInput.value = '';
dateEndInput.value = '';
textareaInput.value = '';
saveExperienceButton.setAttribute('aria-disabled', 'true');
characterCount.innerHTML = '0';
roleCharacterCount.innerHTML = '0';
textareaCharacterCount.innerHTML = '0';
};
const closeForm = () => {
backButton.setAttribute('aria-disabled', 'false');
closeBtn.setAttribute('aria-disabled', 'false');
formSection.setAttribute('data-unsaved', 'false');
mainSection.classList.remove('hidden');
formSection.classList.add('hidden');
closeBtn.classList.remove('not-saved');
};
const openForm = () => {
mainSection.classList.add('hidden');
formSection.classList.remove('hidden');
formSection.scroll(0, 0);
};
// eslint-disable-next-line no-unused-vars
const closePopUp = () => {
// Reset UI back to default
closeForm();
popUp.classList.remove('add-animation');
popUp.classList.remove('dark-overlay');
eflProfileLayout.style.zIndex = null;
document.body.classList.remove('efl-profile-dark-overlay');
formSection.setAttribute('data-unsaved', 'false');
closeBtn.classList.remove('not-saved');
};
// eslint-disable-next-line complexity
const formValidation = () => {
if (
titleInput.value === '' ||
roleInput.value === '' ||
dateStartInput.value === '' ||
dateEndInput.value === '' ||
textareaInput.value === ''
) {
saveExperienceButton.setAttribute('aria-disabled', 'true');
backButton.setAttribute('aria-disabled', 'true');
} else {
saveExperienceButton.setAttribute('aria-disabled', 'false');
formSection.setAttribute('data-unsaved', 'true');
closeBtn.classList.add('not-saved');
}
if (
titleInput.value === '' &&
roleInput.value === '' &&
dateStartInput.value === '' &&
dateEndInput.value === '' &&
textareaInput.value === ''
) {
formSection.setAttribute('data-unsaved', 'false');
closeBtn.classList.remove('not-saved');
} else {
formSection.setAttribute('data-unsaved', 'true');
closeBtn.classList.add('not-saved');
}
};
const editExperience = e => {
const experience = e.target.closest(
'.efl-learner-profile__section__experience'
);
const experienceTitle = experience.querySelector('h5').innerText;
const experienceRole = experience.querySelector('.role').innerText;
const experienceDescription = experience.querySelector('p:not(.role)')
.innerHTML;
const { editId, startDate, endDate } = experience.dataset;
// Need to remove z-index for popup to work
eflProfileLayout.style.zIndex = 'unset';
document.body.classList.add('efl-profile-dark-overlay');
openForm();
formSection.setAttribute('data-editing', editId);
saveExperienceButton.setAttribute('aria-disabled', 'true');
// fill inputs with default values
titleInput.value = experienceTitle;
roleInput.value = experienceRole;
textareaInput.value = experienceDescription;
dateStartInput.value = startDate;
dateEndInput.value = endDate;
rangePicker.setDates(new Date(startDate), new Date(endDate));
characterCount.innerHTML = experienceTitle.length;
roleCharacterCount.innerHTML = experienceRole.length;
textareaCharacterCount.innerHTML = experienceDescription.length;
popUp.classList.add('add-animation');
deleteExperienceBtn.classList.remove('hidden');
formSection.querySelector('h4 strong').innerText = formTitleEdit;
};
const editExperienceInit = () => {
const editExperienceLinks = mainSection.querySelectorAll(
'.efl-learner-profile__section__qualification--edit'
);
editExperienceLinks.forEach(editlink => {
editlink.addEventListener('click', e => {
e.preventDefault();
editExperience(e);
setTimeout(() => {
closeBtn.focus();
}, 50);
});
editlink.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
editlink.click();
}
});
});
};
const dateSorting = (a, b) => {
if (
new Date(a.dateCompleted).getTime() > new Date(b.dateCompleted).getTime()
) {
return -1;
}
return 1;
};
const makeBioPublic = status => {
privacyInput.checked = status;
};
const updateExperienceDetails = editMode => {
const monthNames = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
const previousExpPage = document.querySelector(
'[data-behavior="efl-learner-profile-previous-experience"]'
);
const experienceListDiv = mainSection.querySelector(
'.efl-learner-profile__section__experience--list'
);
const experienceListPageDiv = previousExpPage.querySelector(
'.efl-learner-profile__section__experience--pagelist'
);
let experienceList = experienceListPageDiv.querySelectorAll(
'.efl-learner-profile__section__experience'
);
let experienceJson = [];
let count = 0;
const newExperienceJson = `{
"name": "${titleInput.value}" ,
"role" : "${roleInput.value}",
"description" : "${textareaInput.value}",
"dateStarted" : "${dateStartInput.value}",
"dateCompleted" : "${dateEndInput.value}"}`;
if (editMode === 'new') {
experienceList.forEach((experience, index) => {
const { experienceDetail } = experience.dataset;
experienceJson[index] = JSON.parse(experienceDetail);
count = index;
});
experienceJson[count + 1] = JSON.parse(newExperienceJson);
} else if (editMode === 'edit') {
const editId = formSection.getAttribute('data-editing');
const editDateStart = new Date(dateStartInput.value);
const editDateEnd = new Date(dateEndInput.value);
const editStartMonth = editDateStart.getMonth();
const editEndMonth = editDateEnd.getMonth();
const editStartYear = editDateStart.getFullYear();
const editEndYear = editDateEnd.getFullYear();
const editPopupList = experienceListDiv.querySelector(
`.efl-learner-profile__section__experience[data-edit-id="${editId}"]`
);
const editPageList = experienceListPageDiv.querySelector(
`.efl-learner-profile__section__experience[data-edit-id="${editId}"]`
);
editPopupList.querySelector('h5').innerText = titleInput.value;
editPopupList.querySelector('.role > strong').innerText = roleInput.value;
editPopupList.querySelector('p:not(.role)').innerHTML =
textareaInput.value;
editPopupList.querySelector('.efl-category-title').innerText = `${
monthNames[editStartMonth]
} ${editStartYear} - ${monthNames[editEndMonth]} ${editEndYear}`;
editPageList.querySelector('h5').innerText = titleInput.value;
editPageList.querySelector('.role > strong').innerText = roleInput.value;
editPageList.querySelector('p:not(.role)').innerHTML =
textareaInput.value;
editPageList.querySelector('.efl-category-title').innerText = `${
monthNames[editStartMonth]
} ${editStartYear} - ${monthNames[editEndMonth]} ${editEndYear}`;
editPageList.setAttribute('data-experience-detail', newExperienceJson);
experienceList = experienceListPageDiv.querySelectorAll(
'.efl-learner-profile__section__experience'
);
experienceJson = [];
// console.log(experienceList);
experienceList.forEach((experience, index) => {
const { experienceDetail } = experience.dataset;
experienceJson[index] = JSON.parse(experienceDetail);
// count = index;
});
} else if (editMode === 'delete') {
const editId = formSection.getAttribute('data-editing');
const deletePopupList = experienceListDiv.querySelector(
`.efl-learner-profile__section__experience[data-edit-id="${editId}"]`
);
const deletePageList = experienceListPageDiv.querySelector(
`.efl-learner-profile__section__experience[data-edit-id="${editId}"]`
);
deletePopupList.remove();
deletePageList.remove();
experienceList = experienceListPageDiv.querySelectorAll(
'.efl-learner-profile__section__experience'
);
experienceJson = [];
// console.log(experienceList);
experienceList.forEach((experience, index) => {
const { experienceDetail } = experience.dataset;
experienceJson[index] = JSON.parse(experienceDetail);
// count = index;
});
if (experienceJson.length === 0) {
placeholderText.classList.remove('hidden');
}
}
// console.log(experienceJson);
// sort the latest experience to top list
const sortedExperience = experienceJson.sort(dateSorting);
// console.log(sortedExperience);
// empty popup previous experience list
experienceListDiv.innerHTML = '';
// empty page previous experience list
experienceListPageDiv.innerHTML = '';
sortedExperience.forEach((experience, index) => {
const dateStart = new Date(experience.dateStarted);
const dateEnd = new Date(experience.dateCompleted);
const startMonth = dateStart.getMonth();
const endMonth = dateEnd.getMonth();
const startYear = dateStart.getFullYear();
const endYear = dateEnd.getFullYear();
const popupExperienceHtml = `
<div class="efl-learner-profile__section__experience" data-start-date="${
experience.dateStarted
}" data-end-date="${experience.dateCompleted}" data-edit-id="${index}">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">${
monthNames[startMonth]
} ${startYear} - ${monthNames[endMonth]} ${endYear}</div>
<h5>${experience.name}</h5>
<p class="role"><strong>${experience.role}</strong></p>
<p>${experience.description}</p>
</div>
<button aria-label="edit experience" class="efl-learner-profile__section__qualification--edit"></button>
</div>`;
const pageExperienceHtml = `
<div class="efl-learner-profile__section__experience"
data-experience-detail='{
"name": "${experience.name}" ,
"role" : "${experience.role}",
"description" : "${experience.description}",
"dateStarted" : "${experience.dateStarted}",
"dateCompleted" : "${
experience.dateCompleted
}"}' data-edit-id="${index}">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">${
monthNames[startMonth]
} ${startYear} - ${monthNames[endMonth]} ${endYear}</div>
<h5>${experience.name}</h5>
<p class="role"><strong>${experience.role}</strong></p>
<p>${experience.description}</p>
</div>
</div>`;
// bind html object to popup previous experience list
experienceListDiv.insertAdjacentHTML('beforeend', popupExperienceHtml);
// bind html object to page previous experience list
experienceListPageDiv.insertAdjacentHTML('beforeend', pageExperienceHtml);
});
showAll(eflExperiences, 2);
showAll(eflPopUpExperiences, 3);
editExperienceInit();
formSection.removeAttribute('data-editing');
resetForm();
closeForm();
};
const saveExperience = (editMode, saveButton) => {
if (editMode === 'delete') {
updateExperienceDetails(editMode);
} else {
saveButton.classList.add('loading-bar');
saveButton.setAttribute('aria-disabled', 'true');
}
// eslint-disable-next-line complexity
updatePlayerProfile().then(abusiveContent => {
if (
abusiveContent &&
abusiveContent.FAIWFResponse &&
abusiveContent.FAIWFResponse.IsAbusive
) {
modalAlert('innapropriate-content');
saveButton.classList.remove('loading-bar');
saveButton.setAttribute('aria-disabled', 'false');
} else if (
abusiveContent &&
!abusiveContent.FAIWFResponse &&
abusiveContent.Error
) {
modalAlert('iwf-error-content');
saveButton.classList.remove('loading-bar');
saveButton.setAttribute('aria-disabled', 'false');
} else if (abusiveContent && abusiveContent.Error === 'Future Date') {
modalAlert('invalid-data-content');
saveButton.classList.remove('loading-bar');
saveButton.setAttribute('aria-disabled', 'false');
} else {
if (editMode !== 'delete') {
if (
privacyInput &&
!privacyInput.checked &&
formSection.getAttribute('data-initial-filled') !== 'true'
) {
formSection.setAttribute('data-initial-filled', 'true');
modalAlert('make-bio-public');
setTimeout(() => {
makeBioPublicBtn.focus();
}, 100);
saveButton.classList.remove('loading-bar');
saveButton.setAttribute('aria-disabled', 'false');
return;
}
// profile completion notification
updateProfileCompletion(3);
updateExperienceDetails(editMode);
}
// Rive
// if (animation.playingAnimationNames.includes('Animation')) {
// animation.pause('Animation');
// } else {
// animation.play('Animation');
// }
saveButton.classList.remove('loading-bar');
saveButton.setAttribute('aria-disabled', 'false');
if (editMode === 'delete') {
toastNotification.innerText = toastDeleteText;
} else {
toastNotification.innerText = toastUpdateText;
}
if (window.innerWidth >= MOBILE_BREAKPOINT) {
toastNotification.style.left = `${(431 -
toastNotification.offsetWidth) /
2}px`;
}
toastNotification.classList.add('enter-animation');
setTimeout(() => {
toastNotification.classList.remove('enter-animation');
}, 3000);
backButton.setAttribute('aria-disabled', 'false');
closeBtn.classList.remove('not-saved');
}
});
};
// Event Listeners
// Alert Modal
continueEditingBtn.addEventListener('click', event => {
closeModal(event);
setTimeout(() => {
saveExperienceButton.focus();
}, 10);
});
continueEditingBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
continueEditingBtn.click();
} else {
setTimeout(() => {
if (loseChangesBtn) {
loseChangesBtn.focus();
} else {
continueEditingBtn.click();
}
}, 10);
}
});
loseChangesBtn.addEventListener('click', event => {
closeModal(event);
resetForm();
closeForm();
setTimeout(() => {
closeBtn.focus();
}, 10);
});
loseChangesBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
loseChangesBtn.click();
} else {
setTimeout(() => {
continueEditingBtn.focus();
}, 10);
}
});
makeBioPublicBtn.addEventListener('click', event => {
closeModal(event);
makeBioPublic(true);
setTimeout(() => {
closeBtn.focus();
}, 10);
});
makeBioPublicBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
makeBioPublicBtn.click();
} else {
setTimeout(() => {
keepBioPrivateBtn.focus();
}, 10);
}
});
keepBioPrivateBtn.addEventListener('click', event => {
closeModal(event);
makeBioPublic(false);
setTimeout(() => {
closeBtn.focus();
}, 10);
});
keepBioPrivateBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
keepBioPrivateBtn.click();
} else {
setTimeout(() => {
makeBioPublicBtn.focus();
}, 10);
}
});
// Form
// form-related actions only, efl-learner-pop-up.js for animation
closeBtn.addEventListener('click', e => {
e.preventDefault();
if (formSection.getAttribute('data-unsaved') === 'true') {
modalAlert('unsaved-changes');
setTimeout(() => {
continueEditingBtn.focus();
}, 50);
return;
}
setTimeout(() => {
editbtn.focus();
}, 100);
if (!formSection.classList.contains('hidden')) {
resetForm();
closeForm();
}
});
if (closeBtn) {
closeBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
closeBtn.click();
} else if (event.shiftKey && event.keyCode === 9) {
event.preventDefault();
}
});
}
backButton.addEventListener('click', e => {
e.preventDefault();
if (formSection.getAttribute('data-unsaved') === 'true') {
modalAlert('unsaved-changes');
setTimeout(() => {
continueEditingBtn.focus();
}, 50);
return;
}
setTimeout(() => {
closeBtn.focus();
}, 100);
if (!formSection.classList.contains('hidden')) {
resetForm();
closeForm();
}
});
backButton.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
backButton.click();
}
});
titleInput.addEventListener('input', e => {
characterCount.innerHTML = e.target.value.length;
formValidation();
});
roleInput.addEventListener('input', e => {
roleCharacterCount.innerHTML = e.target.value.length;
formValidation();
});
const today = new Date();
rangePicker = new DateRangePicker(dateRangeElement, {
maxDate: today,
minDate: new Date(new Date().setFullYear(new Date().getFullYear() - 150)),
prevArrow: '',
nextArrow: '',
autohide: true,
allowOneSidedRange: true,
});
dateStartInput.addEventListener('change', () => {
formValidation();
});
dateEndInput.addEventListener('change', () => {
formValidation();
});
textareaInput.addEventListener('input', e => {
textareaCharacterCount.innerHTML = e.target.value.length;
formValidation();
});
addExperienceBtn.addEventListener('click', e => {
e.preventDefault();
resetForm();
openForm();
deleteExperienceBtn.classList.add('hidden');
formSection.removeAttribute('data-editing');
formSection.querySelector('h4 strong').innerText = formTitleAdd;
rangePicker.destroy();
rangePicker = new DateRangePicker(dateRangeElement, {
maxDate: today,
minDate: new Date(new Date().setFullYear(new Date().getFullYear() - 150)),
prevArrow: '',
nextArrow: '',
autohide: true,
allowOneSidedRange: true,
});
setTimeout(() => {
closeBtn.focus();
}, 50);
});
addExperienceBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
addExperienceBtn.click();
} else {
setTimeout(() => {
closeBtn.focus();
}, 10);
}
});
saveExperienceButton.addEventListener('click', e => {
e.preventDefault();
if (saveExperienceButton.getAttribute('aria-disabled') === 'true') {
modalAlert('fill-all-fields');
setTimeout(() => {
continueEditingBtn.focus();
}, 100);
return;
}
if (!formSection.getAttribute('data-editing')) {
saveExperience('new', saveExperienceButton);
} else {
saveExperience('edit', saveExperienceButton);
}
setTimeout(() => {
closeBtn.focus();
}, 50);
});
saveExperienceButton.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
saveExperienceButton.click();
} else {
// eslint-disable-next-line no-lonely-if
if (deleteExperienceBtn.classList.contains('hidden')) {
setTimeout(() => {
closeBtn.focus();
}, 10);
}
}
});
deleteExperienceBtn.addEventListener('click', e => {
e.preventDefault();
saveExperience('delete', deleteExperienceBtn);
setTimeout(() => {
closeBtn.focus();
}, 50);
});
deleteExperienceBtn.addEventListener('keydown', event => {
if (event.keyCode === 13) {
event.preventDefault();
deleteExperienceBtn.click();
} else {
setTimeout(() => {
closeBtn.focus();
}, 10);
}
});
editExperienceBtn.addEventListener('click', event => {
closeModal(event);
});
errorExperienceBtn.addEventListener('click', event => {
closeModal(event);
});
showAll(eflExperiences, 2);
showAll(eflPopUpExperiences, 3);
editExperienceInit();
};
<section class="efl-learner-profile__section previous-experience"
data-behavior="efl-learner-profile-previous-experience">
<div class="efl-learner-profile__section--header">
<h3 class="previous-experience">My previous experience</h3>
<button aria-label="edit my previous experience" class="efl-learner-profile__section--edit"></button>
</div>
<p class="paragraph placeholder-text">Share past experience within football or any sport</p>
<div class="efl-learner-profile__section__experience--container">
<div class="efl-learner-profile__section__experience--pagelist">
{{#each experiences}}
<div class="efl-learner-profile__section__experience" data-experience-detail='{
"name": "{{title}}" ,
"role" : "{{role}}",
"description" : "{{desc}}",
"dateStarted" : "{{dateStart}}",
"dateCompleted" : "{{dateEnd}}"}' data-edit-id="{{@index}}">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">{{date}}</div>
<h5>{{title}}</h5>
<p class="role"><strong>{{role}}</strong></p>
<p>{{desc}}</p>
</div>
</div>
{{/each}}
</div>
<button class="cta cta--secondary" id="show-all-button" aria-label="show all 3 experiences">Show All 3 Experiences</button>
<button class="cta cta--secondary" id="show-less-cta" aria-label="show less previous experiences">Show Less</button>
</div>
<div class="efl-profile-left-popup previous-experience" role="dialog" aria-modal="true" data-behavior="efl-profile-left-popup">
<button class="efl-profile-left-popup__close" aria-label="close previous experience popup window"></button>
<div class="efl-learner-profile__section--header">
<h3 class="previous-experience">My previous experience</h3>
</div>
<div id="previous-experience-main" class="efl-profile-left-popup--inner">
<p class="paragraph">Coach? Medic? Referee? If you're already involved in football, share your previous experience below.</p>
<div class="efl-learner-profile__section__experience--container">
<div class="efl-learner-profile__section__experience--list">
{{#each experiences}}
<div class="efl-learner-profile__section__experience" data-start-date="{{dateStart}}" data-end-date="{{dateEnd}}" data-edit-id="{{@index}}">
<div class="efl-learner-profile__section__experience__content">
<div class="efl-category-title">{{date}}</div>
<h5>{{title}}</h5>
<p class="role"><strong>{{role}}</strong></p>
<p>{{desc}}</p>
</div>
<button aria-label="edit {{title}} experience" class="efl-learner-profile__section__qualification--edit"></button>
</div>
{{/each}}
</div>
<button class="cta cta--secondary" id="show-all-button" aria-label="show all 3 experiences">Show All 3 Experiences</button>
<button class="cta cta--secondary" id="show-less-cta" aria-label="show less previous experiences">Show Less</button>
</div>
<button class="cta cta--secondary" id="previous-experience-add-button" aria-label="add experience">Add Experience</button>
</div>
<div id="previous-experience-form" class="efl-profile-left-popup--inner hidden">
<button class="efl-profile-left-popup__back" aria-label="back to previous experiences">Back</button>
<h4 class="efl-learner-profile__section--subheading" data-form-title-add="Add Experience" data-form-title-edit="Edit Experience"><strong>Add Experience</strong></h4>
<form>
<label for="previous-experience-form--title">Title of experience</label>
<input type="text" name="experience title" autocomplete="off" id="previous-experience-form--title" maxlength="100" />
<p><span class="character-count__name">0</span>/100 characters</p>
<label for="previous-experience-form--role">Your role</label>
<input type="text" name="experience role" autocomplete="off" id="previous-experience-form--role" maxlength="100" />
<p><span class="character-count__role">0</span>/100 characters</p>
<label>Date of Experience</label>
<div class="previous-experience-form--date-range">
<input autocomplete="off" type="text" placeholder="Date from" name="start date of experience" id="previous-experience-form--date-start" />
<input autocomplete="off" type="text" placeholder="Date to" name="end date of experience" id="previous-experience-form--date-end" />
</div>
<label for="previous-experience-form--desc">Description of experience</label>
<textarea rows="3" cols="30" maxlength="500" name="description of experience"
id="previous-experience-form--desc" maxlength="500"></textarea>
<p><span class="character-count__textarea">0</span>/500 characters</p>
</form>
<button class="cta cta--efl " id="previous-experience-save-experience-button" aria-label="save experience" aria-disabled="true">
<span>Save Experience</span>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px" height="20px" viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">
<rect x="0" y="10" width="4" height="10" fill="#fff" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0s" dur="0.6s" repeatCount="indefinite"></animate>
</rect>
<rect x="8" y="10" width="4" height="10" fill="#fff" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.15s" dur="0.6s" repeatCount="indefinite"></animate>
</rect>
<rect x="16" y="10" width="4" height="10" fill="#fff" opacity="0.2">
<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.3s" dur="0.6s" repeatCount="indefinite"></animate>
</rect>
</svg>
</button>
<button class="cta cta--secondary" id="delete-experience-button" aria-label="delete experience">Delete Experience</button>
</div>
<div class="efl-profile-left-popup__toast-notification" tabindex="-1" aria-label="" data-toast-update-text="Previous Experience Saved!" data-toast-delete-text="Previous Experience Deleted!">
{{!-- <canvas id="rive" width="36" height="36"></canvas> --}}
Previous Experience Saved!
</div>
<div
class="efl-profile-left-popup__alert-modal" role="dialog" aria-modal="true" aria-live="polite"
data-unsaved-changes-header="You have unsaved changes"
data-unsaved-changes-copy="Continue editing to save your changes."
data-fill-all-fields-header="you must fill in all fields"
data-fill-all-fields-copy="Continue editing to save your changes."
data-make-bio-public-header="Time to make your bio public?"
data-make-bio-public-copy="Publishing your bio allows others to view your information. This is a great way to connect with clubs, coaches and the football community."
data-innapropriate-content-header="Innapropriate content"
data-innapropriate-content-copy="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
data-iwf-error-content-header="Error"
data-iwf-error-content-copy="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
data-invalid-data-content-header="Error"
data-invalid-data-content-copy="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
>
<h5 class="efl-category-title">This Image is Not Appropriate</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ultricies, nibh sit amet varius faucibus, est
ipsum commodo mi, a rutrum urna mauris ut.</p>
<button class="cta cta--efl " id="previous-experience-continue-editing-button" aria-label="Continue Editing">Continue Editing</button>
<button class="cta cta--secondary " id="previous-experience-lose-changes-button" aria-label="Lose My Changes">Lose My Changes</button>
<button class="cta cta--efl " id="previous-experience-make-bio-public-button" aria-label="Make Bio Public">Make Bio Public</button>
<button class="cta cta--secondary " id="previous-experience-keep-bio-private-button" aria-label="Keep Bio Private">Keep Bio Private</button>
<button class="cta cta--efl " id="efl-learner-profile-edit-previous-experience-button" aria-label="Edit Experience">Edit Experience</button>
<button class="cta cta--efl " id="efl-learner-profile-error-previous-experience-button" aria-label="Try again">Try again</button>
</div>
</div>
</section>