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}`);
|
|
|
|
$name.outerHTML = `<span id="${textField.name}" class="toggle-field">${$name.getAttribute('value')}</span>`;
|
|
|
|
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-19 12:29:12 +02:00
|
|
|
$$('input').forEach((inputElement) => {
|
2018-10-08 23:49:04 +02:00
|
|
|
inputElement.addEventListener("change", () => {
|
|
|
|
localStorage[inputElement.name] = inputElement.value
|
|
|
|
});
|
|
|
|
});
|
2018-09-28 22:59:58 +02:00
|
|
|
|
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")) {
|
|
|
|
startButton.addEventListener('click', function () {
|
|
|
|
localStorage.clear()
|
|
|
|
localStorage.setItem('type_sondage', 'classique');
|
2018-10-08 22:47:50 +02:00
|
|
|
});
|
2018-09-28 22:59:58 +02:00
|
|
|
}
|
|
|
|
|
2018-10-26 22:07:05 +02:00
|
|
|
debugStorage();
|