Commit 8cb2f1a8 by Simon

Pas mal

parent e40fdfff
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
const EDITMODE = this.config.editMode; const EDITMODE = this.config.editMode;
this.initLoad = () => { this.initLoad = () => {
console.log('INIT');
//Vide le localStorage au chargement de la page
localStorage.clear();
this.getJsonData(); this.getJsonData();
if(!this.json) { if(!this.json) {
console.warn('Invalid Json data'); console.warn('Invalid Json data');
...@@ -89,13 +93,6 @@ ...@@ -89,13 +93,6 @@
return tbodyFinal.html(); return tbodyFinal.html();
}; };
function createInputBox(hour, day) {
let dayFormat = moment(day, 'DD/MM/YYYY').format('DDMMYYYY');
console.log(dayFormat);
return "<input type='checkbox' data-check=" + dayFormat + '_' + hour + " />"
}
/** /**
* Create body content * Create body content
* @param index * @param index
...@@ -107,12 +104,11 @@ ...@@ -107,12 +104,11 @@
for(let key in this.hours) { for(let key in this.hours) {
if(this.json[index].includes(this.hours[key])) { if(this.json[index].includes(this.hours[key]))
html = '<td>' + createInputBox(this.hours[key], index) + '</td>'; html = '<td>' + createInputBox(this.hours[key], index) + '</td>';
} else { else
html = '<td></td>'; html = '<td></td>';
}
plop = $td.append(html); plop = $td.append(html);
} }
...@@ -120,6 +116,18 @@ ...@@ -120,6 +116,18 @@
}; };
/** /**
* Creer l'input
* @param hour
* @param day
* @returns {string}
*/
function createInputBox(hour, day) {
let dayFormat = moment(day, 'DD/MM/YYYY').format('DDMMYYYY');
return "<input type='checkbox' data-check=" + dayFormat + '_' + hour + " />"
}
/**
* Create table header for hours * Create table header for hours
* @returns {string} * @returns {string}
*/ */
...@@ -127,8 +135,25 @@ ...@@ -127,8 +135,25 @@
let $thead = $('<thead>'); let $thead = $('<thead>');
let $tr = $('<tr>'); let $tr = $('<tr>');
let html, theadFinal; let html, theadFinal;
let finalSortedTab = [];
// Permet de mettre un 'h' pour les heures/minutes
this.hours.forEach( (el, index) => {
if (el.split(':').length === 2) {
console.log(el.split(':'));
let test = el.split(':');
let final = test[0] + 'h' + test[1];
finalSortedTab.push(final);
} else {
finalSortedTab.push(el)
}
/*console.log(finalSortedTab.sort());*/
});
let hoursSorted = this.hours.sort(); let hoursSorted = finalSortedTab.sort();
for(let index in hoursSorted) { for(let index in hoursSorted) {
...@@ -164,6 +189,7 @@ ...@@ -164,6 +189,7 @@
for(let index in this.json[key]) { for(let index in this.json[key]) {
if(!this.hours.includes(this.json[key][index])) { if(!this.hours.includes(this.json[key][index])) {
this.hours.push(this.json[key][index]); this.hours.push(this.json[key][index]);
this.hours.sort();
} }
} }
} }
...@@ -215,44 +241,17 @@ ...@@ -215,44 +241,17 @@
} }
}; };
/**
* Generate JSON
* @param date
* @param heure
* @param isChecked
*/
this.createJSON = (date, heure, isChecked) => { this.createJSON = (date, heure, isChecked) => {
/*let json = {};
console.log(isChecked);
if (localStorage.getItem('test')) {
console.log('YEnA');
json = JSON.parse(localStorage.getItem('test'));
} else {
console.log('Empty');
json = {
date : '',
hour: []
};
}
console.log(json.date);
/!**
* Check si je suis lo
*!/
if ($.inArray(heure, json.hour) === -1) {
console.log('Jsuis pas encore lo');
json.date = date;
json.hour.push(heure);
}
localStorage.setItem('test', JSON.stringify(json));
console.log(json);*/
let json = {}; let json = {};
if (localStorage.getItem('test')) { if (localStorage.getItem('test')) {
console.log('YEnA');
json = JSON.parse(localStorage.getItem('test')); json = JSON.parse(localStorage.getItem('test'));
} }
...@@ -262,13 +261,43 @@ ...@@ -262,13 +261,43 @@
if (json[date] === undefined) { if (json[date] === undefined) {
json[date] = [ heure ]; json[date] = [ heure ];
} else { } else {
json[date].push(heure); if (isChecked) {
json[date].push(heure);
json[date].sort();
}
}
} else {
if (!isChecked) {
console.log('Je suis lo et pa check, alor jdegoge');
//Supprime l'entrée dans le JSON
let index = json[date].indexOf(heure);
if (index > -1) {
json[date].splice(index, 1);
}
//Supprime la clé dans le JSON si le tableau est vide
if (json[date].length === 0) {
console.log('Jsui vide lo');
delete json[date];
}
} }
} }
localStorage.setItem('test', JSON.stringify(json)); localStorage.setItem('test', JSON.stringify(json));
console.log(json); console.log(json);
let $input = $('<input type="hidden">');
//Check si l'input est créé
if ($('#jsonGenerate').length !== 0) {
$input.val(JSON.stringify(json));
} else {
$input.val(JSON.stringify(json)).attr('id', 'jsonGenerate');
$('#myTables').after($input);
}
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment