2018-10-19 12:29:12 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const $ = selector => document.querySelector(selector)
|
|
|
|
const $$ = selector => document.querySelectorAll(selector)
|
|
|
|
|
2018-10-08 23:49:04 +02:00
|
|
|
const debugStorage = () => {
|
|
|
|
for(var i = 0; i < localStorage.length; i++) {
|
|
|
|
let key = localStorage.key(i)
|
|
|
|
console.debug(key, " = ", localStorage[key])
|
2018-09-28 22:59:58 +02:00
|
|
|
}
|
2018-10-08 23:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-20 00:41:25 +02:00
|
|
|
const useTextInsteadOfInputFor = (textField) => {
|
|
|
|
let $name = $(`#${textField.name}`);
|
2019-03-19 14:09:21 +01:00
|
|
|
$name.outerHTML = `<span id="${textField.name}" class="champ-vide-long toggle-field">${$name.getAttribute('value')}</span>`;
|
2018-10-20 00:41:25 +02:00
|
|
|
return textField;
|
|
|
|
}
|
|
|
|
|
|
|
|
const createUpdateModalOnClickFor = (textField) => {
|
|
|
|
let $name = $(`#${textField.name}`);
|
|
|
|
$name.addEventListener("click", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
createModal(`<input type="text" name="${textField.name}" id="${textField.name}UpdateField" value="${e.target.textContent}"><button id="submitTextField" data-reference="${textField.name}">></button>`);
|
|
|
|
});
|
|
|
|
}
|
2018-10-20 00:12:58 +02:00
|
|
|
|
2018-10-20 00:41:25 +02:00
|
|
|
$$(".nfl-textfield").forEach((textField) => {
|
|
|
|
createUpdateModalOnClickFor(useTextInsteadOfInputFor(textField));
|
2018-10-19 12:29:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const removeOverlay = () => {
|
|
|
|
$('body').removeChild($('.overlay'))
|
2018-10-20 00:12:58 +02:00
|
|
|
$('body').removeChild($('.modal'))
|
2018-10-19 12:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const createModal = (text) => {
|
|
|
|
const overlay = document.createElement('div')
|
|
|
|
const popin = document.createElement('div')
|
|
|
|
|
|
|
|
popin.innerHTML = text
|
|
|
|
popin.className = 'modal'
|
|
|
|
overlay.className = 'overlay'
|
2018-10-20 00:12:58 +02:00
|
|
|
$('body').appendChild(overlay)
|
|
|
|
$('body').appendChild(popin)
|
|
|
|
|
2018-10-19 12:29:12 +02:00
|
|
|
overlay.addEventListener('click', removeOverlay)
|
|
|
|
$('body').insertBefore(overlay, $('main'))
|
|
|
|
|
2018-10-20 00:41:25 +02:00
|
|
|
$("#submitTextField").addEventListener("click", (e) => {
|
|
|
|
$(`#${e.target.dataset.reference}`).innerHTML = $(`#${e.target.dataset.reference}UpdateField`).value
|
2018-10-20 00:12:58 +02:00
|
|
|
removeOverlay()
|
|
|
|
});
|
|
|
|
}
|
2018-10-19 12:29:12 +02:00
|
|
|
|
2018-11-08 15:28:08 +01:00
|
|
|
const buildTextField = () => {
|
|
|
|
var field = document.createElement("input")
|
|
|
|
var deleteButton = document.createElement("button")
|
|
|
|
var fieldBloc = document.createElement("span")
|
|
|
|
fieldBloc.appendChild(field);
|
|
|
|
fieldBloc.appendChild(deleteButton);
|
|
|
|
return fieldBloc
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-26 22:07:05 +02:00
|
|
|
if($("#add-response-choice")) {
|
|
|
|
$("#add-response-choice").addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let response = document.createElement("li");
|
2018-11-08 15:28:08 +01:00
|
|
|
response.appendChild(buildTextField());
|
2018-10-23 07:56:42 +02:00
|
|
|
|
2018-10-26 22:07:05 +02:00
|
|
|
$("#responses").appendChild(response);
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 07:56:42 +02:00
|
|
|
|
2018-11-08 15:28:08 +01:00
|
|
|
|
2018-10-26 22:07:05 +02:00
|
|
|
$$(".next").forEach((button) => {
|
|
|
|
button.addEventListener("click", (e) => {
|
|
|
|
$$(".toggle-field").forEach((field) => {
|
|
|
|
localStorage.setItem(field.id, field.innerText);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 07:56:42 +02:00
|
|
|
|
2018-10-08 23:49:04 +02:00
|
|
|
if(document.getElementById("type_sondage")) {
|
|
|
|
type_sondage.addEventListener('change', function() {
|
|
|
|
let typeSondage = this.options[this.selectedIndex].text;
|
|
|
|
if(typeSondage == "classique") {
|
|
|
|
localStorage.setItem('type_sondage', this.options[this.selectedIndex].text);
|
2018-10-23 07:56:42 +02:00
|
|
|
$('#next').href = "responses.html";
|
2018-10-08 23:49:04 +02:00
|
|
|
} else {
|
|
|
|
localStorage.setItem('type_sondage', 'dates');
|
2018-10-19 12:29:12 +02:00
|
|
|
$('#next').href = "dates.html";
|
2018-10-08 23:49:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-10-08 22:47:50 +02:00
|
|
|
|
2018-10-08 23:49:04 +02:00
|
|
|
if(document.getElementById("startButton")) {
|
2018-11-27 23:55:54 +01:00
|
|
|
startButton.addEventListener('click', () => {
|
2018-10-08 23:49:04 +02:00
|
|
|
localStorage.clear()
|
|
|
|
localStorage.setItem('type_sondage', 'classique');
|
2018-10-08 22:47:50 +02:00
|
|
|
});
|
2018-09-28 22:59:58 +02:00
|
|
|
}
|
|
|
|
|
2018-11-27 23:55:54 +01:00
|
|
|
if(document.getElementById("addDateButton")) {
|
|
|
|
addDateButton.addEventListener('click', () => {
|
|
|
|
let newLi = document.createElement("li")
|
|
|
|
let content = $("ul>li").innerHTML.replace("date-1", `date-${$$("li").length + 1}`)
|
|
|
|
newLi.innerHTML = content
|
|
|
|
$("ul").appendChild(newLi);
|
|
|
|
initEventOnScreen();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-28 08:03:37 +01:00
|
|
|
if($('#validation-pool-title') && localStorage["title"]) {
|
|
|
|
$('#validation-pool-title').innerHTML = localStorage["title"]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-19 14:38:31 +01:00
|
|
|
|
|
|
|
if($('#ajouterDesHoraires')) {
|
|
|
|
ajouterDesHoraires.addEventListener('change', () => {
|
2019-03-19 14:44:09 +01:00
|
|
|
if (ajouterDesHoraires.value == 'avec des') {
|
2019-03-19 14:38:31 +01:00
|
|
|
identiquesDifferentsPourChaqueJour.style.display = 'inline'
|
2019-03-21 14:26:56 +01:00
|
|
|
$$('.horaire-identique').forEach((e) => {
|
|
|
|
e.style.display = 'inline'
|
|
|
|
});
|
2019-03-19 14:38:31 +01:00
|
|
|
} else {
|
|
|
|
identiquesDifferentsPourChaqueJour.style.display = 'none'
|
2019-03-21 14:26:56 +01:00
|
|
|
$$('.horaire-identique').forEach((e) => {
|
|
|
|
e.style.display = 'none'
|
|
|
|
});
|
2019-03-19 15:07:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if($('#horairesIdentiquesOuDifferents')) {
|
|
|
|
horairesIdentiquesOuDifferents.addEventListener('change', () => {
|
|
|
|
if (horairesIdentiquesOuDifferents.value == 'identiques') {
|
|
|
|
$('.horaire-identique').style.display = 'inline'
|
|
|
|
$$('.horaire-different').forEach( (e) => {
|
|
|
|
e.style.display = 'none'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('.horaire-identique').style.display = 'none'
|
|
|
|
$$('.horaire-different').forEach( (e) => {
|
|
|
|
e.style.display = 'inline'
|
|
|
|
});
|
2019-03-19 14:38:31 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-27 23:55:54 +01:00
|
|
|
const addDeleteParentEvent = () => {
|
|
|
|
$$(".remove").forEach((element) => {
|
|
|
|
element.addEventListener('click', () => {
|
|
|
|
element.parentElement.remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const addInputToStorageEvent = () => {
|
|
|
|
$$('input').forEach((inputElement) => {
|
|
|
|
inputElement.addEventListener("change", () => {
|
|
|
|
localStorage[inputElement.name] = inputElement.value
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const initEventOnScreen = () => {
|
|
|
|
addDeleteParentEvent();
|
|
|
|
addInputToStorageEvent();
|
|
|
|
}
|
|
|
|
|
2019-03-21 14:54:05 +01:00
|
|
|
if($('#recapitulatif')) {
|
|
|
|
|
|
|
|
var tableauDeDates = []
|
|
|
|
|
|
|
|
for(var i = 0; i < localStorage.length; i++) {
|
|
|
|
let key = localStorage.key(i)
|
|
|
|
let splittedKey = key.split('-')
|
|
|
|
if(splittedKey[0] == 'date') {
|
|
|
|
|
|
|
|
tableauDeDates.push(new Date(localStorage[key]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tableauDeDates.sort().reverse().forEach( (date) => {
|
|
|
|
var spanDate = document.createElement("span")
|
|
|
|
spanDate.className = "bold"
|
|
|
|
let jours = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"]
|
|
|
|
let mois = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"]
|
|
|
|
let dateEnTexte = `${jours[date.getDay()]} ${date.getDate()} ${mois[(date.getMonth())]} ${date.getFullYear()}`
|
|
|
|
spanDate.appendChild(document.createTextNode(dateEnTexte))
|
|
|
|
|
|
|
|
var article = document.createElement("article")
|
|
|
|
article.appendChild(spanDate)
|
|
|
|
|
|
|
|
$('#recapitulatif').appendChild(article)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-27 23:55:54 +01:00
|
|
|
initEventOnScreen();
|
2018-10-26 22:07:05 +02:00
|
|
|
debugStorage();
|