Commit 26b48bcc by Simon

Fix beug ajout de deux dates pareille et outputformat front

parent 954f2e70
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
this.json = null; this.json = null;
this.days = []; this.days = [];
this.hours = []; this.hours = [];
this.dateFormat = this.config.outputDateFormat || 'DD/MM/YYYY';
this.outputJson = {}; this.outputJson = {};
this.initLoad = () => { this.initLoad = () => {
...@@ -70,8 +71,8 @@ ...@@ -70,8 +71,8 @@
for(let index in this.days) { for(let index in this.days) {
let $tr = $('<tr>'); let $tr = $('<tr>');
let formatDateDay = moment(this.days[index], 'DD/MM/YYYY').locale('fr').format('dddd DD'); let formatDateDay = moment(this.days[index], this.dateFormat).locale('fr').format('dddd DD');
let formatDateMonth = moment(this.days[index], 'DD/MM/YYYY').locale('fr').format('MMMM'); let formatDateMonth = moment(this.days[index], this.dateFormat).locale('fr').format('MMMM');
html = $tr.append('<td><span class="date_format"><b>' + formatDateDay + '</b></span> ' + formatDateMonth + '</td>') html = $tr.append('<td><span class="date_format"><b>' + formatDateDay + '</b></span> ' + formatDateMonth + '</td>')
.append(this.createBodyContent(this.days[index])); .append(this.createBodyContent(this.days[index]));
...@@ -93,7 +94,7 @@ ...@@ -93,7 +94,7 @@
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>' + this.createInputBox(this.hours[key], index) + '</td>';
else else
html = '<td class="empty"></td>'; html = '<td class="empty"></td>';
...@@ -109,11 +110,11 @@ ...@@ -109,11 +110,11 @@
* @param day * @param day
* @returns {string} * @returns {string}
*/ */
function createInputBox(hour, day) { this.createInputBox = (hour, day) => {
let dayFormat = moment(day, 'DD/MM/YYYY').format('DDMMYYYY'); let dayFormat = moment(day, this.dateFormat).format('DDMMYYYY');
return "<label class='label_input'><input type='checkbox' data-check=" + dayFormat + '_' + hour + " /><span><i></i></span></label>" return "<label class='label_input'><input type='checkbox' data-check=" + dayFormat + '_' + hour + " /><span><i></i></span></label>"
} };
/** /**
* Create table header for hours * Create table header for hours
...@@ -328,8 +329,6 @@ ...@@ -328,8 +329,6 @@
this.createEvents(); this.createEvents();
this.initCSS(); this.initCSS();
console.log('OUTPUT', this.outputJson);
}; };
this.reinit = () => { this.reinit = () => {
...@@ -457,14 +456,12 @@ ...@@ -457,14 +456,12 @@
let $tbody = $('<tbody>'); let $tbody = $('<tbody>');
let html, tbodyFinal; let html, tbodyFinal;
console.log('this.json', this.json); if (!$.isEmptyObject(this.outputJson)) {
if (!$.isEmptyObject(this.json) || !$.isEmptyObject(this.outputJson)) {
for(let index in this.days) { for(let index in this.days) {
let $tr = $('<tr>'); let $tr = $('<tr>');
let formatDateDay = moment(this.days[index], 'DD/MM/YYYY').locale('fr').format('dddd DD'); let formatDateDay = moment(this.days[index], this.dateFormat).locale('fr').format('dddd DD');
let formatDateMonth = moment(this.days[index], 'DD/MM/YYYY').locale('fr').format('MMMM'); let formatDateMonth = moment(this.days[index], this.dateFormat).locale('fr').format('MMMM');
let date = this.days[index]; let date = this.days[index];
html = $tr.append('<td id="date"><span class="date_format"><b>' + formatDateDay + '</b> ' + formatDateMonth + '</span><div class="delete_row"><a href="#"><img src='+ CLOSEIMG +' /></a></div></td>') html = $tr.append('<td id="date"><span class="date_format"><b>' + formatDateDay + '</b> ' + formatDateMonth + '</span><div class="delete_row"><a href="#"><img src='+ CLOSEIMG +' /></a></div></td>')
...@@ -483,9 +480,7 @@ ...@@ -483,9 +480,7 @@
</span> </span>
</div> </div>
</td> `); </td> `);
} } else {
else {
let $tr = $('<tr>'); let $tr = $('<tr>');
html = $tr.append(`<td><div id="myDatepicker" class="input-group date" data-provide="datepicker"> html = $tr.append(`<td><div id="myDatepicker" class="input-group date" data-provide="datepicker">
...@@ -516,9 +511,9 @@ ...@@ -516,9 +511,9 @@
for(let key in this.hours) { for(let key in this.hours) {
if(this.outputJson[index] && this.outputJson[index].includes(this.hours[key])) if(this.outputJson[index] && this.outputJson[index].includes(this.hours[key]))
html = '<td>' + createInputBox(this.hours[key], index, true) + '</td>'; html = '<td>' + this.createInputBox(this.hours[key], index, true) + '</td>';
else else
html = '<td>' + createInputBox(this.hours[key], index, false) + '</td>'; html = '<td>' + this.createInputBox(this.hours[key], index, false) + '</td>';
$td.append(html); $td.append(html);
} }
...@@ -533,9 +528,8 @@ ...@@ -533,9 +528,8 @@
* @returns {string} * @returns {string}
*/ */
function createInputBox(hour, day, checked) { this.createInputBox = (hour, day, checked) => {
console.log('day', day); let dayFormat = moment(day, this.dateFormat).format('DDMMYYYY');
let dayFormat = moment(day, 'DD/MM/YYYY').format('DDMMYYYY');
let isChecked = checked ? 'checked' : ''; let isChecked = checked ? 'checked' : '';
let data = dayFormat + '_' + hour; let data = dayFormat + '_' + hour;
...@@ -606,7 +600,6 @@ ...@@ -606,7 +600,6 @@
*/ */
this.getDays = () => { this.getDays = () => {
this.days = Object.keys(this.json); this.days = Object.keys(this.json);
console.log('getDays',this.days);
}; };
/** /**
...@@ -628,7 +621,6 @@ ...@@ -628,7 +621,6 @@
*/ */
this.getJsonData = () => { this.getJsonData = () => {
let dataJson = $(this.config.input).val(); let dataJson = $(this.config.input).val();
console.log('getJSONDATA');
if(this.isJsonString(dataJson)){ if(this.isJsonString(dataJson)){
this.json = JSON.parse(dataJson); this.json = JSON.parse(dataJson);
...@@ -649,14 +641,11 @@ ...@@ -649,14 +641,11 @@
this.populateOutputJson = () => { this.populateOutputJson = () => {
for (let index in this.json) { for (let index in this.json) {
if (this.json[index].length === 0 ) { if (this.json[index].length === 0 ) {
console.log('PROUT');
this.addInOutputObject(index) this.addInOutputObject(index)
} }
for (let i in this.json[index]) { for (let i in this.json[index]) {
let dayFormat = moment(index, 'DD/MM/YYYY').format(this.dateFormat); let dayFormat = moment(index, this.dateFormat).format(this.dateFormat);
console.log('LO', [dayFormat, this.json[index][i]]);
this.addInOutputObject([dayFormat, this.json[index][i]] ) this.addInOutputObject([dayFormat, this.json[index][i]] )
} }
...@@ -714,8 +703,6 @@ ...@@ -714,8 +703,6 @@
let isChecked = $(e.target).is(':checked'); let isChecked = $(e.target).is(':checked');
if (isChecked) { if (isChecked) {
console.log('Pipa wesh', data);
this.addInOutputObject(data); this.addInOutputObject(data);
$(e.target).parent().parent().css('background', '#e2deef'); $(e.target).parent().parent().css('background', '#e2deef');
} else { } else {
...@@ -732,7 +719,6 @@ ...@@ -732,7 +719,6 @@
* @returns {boolean} * @returns {boolean}
*/ */
this.keyExist = (key) => { this.keyExist = (key) => {
console.log(key);
if (moment(key, this.dateFormat).format(this.dateFormat) === key) { if (moment(key, this.dateFormat).format(this.dateFormat) === key) {
if (this.days.indexOf(key) === -1) { if (this.days.indexOf(key) === -1) {
return true return true
...@@ -743,7 +729,7 @@ ...@@ -743,7 +729,7 @@
} }
} }
if (moment(key, 'HH:mm').format('HH:mm') === key) { if (moment(key, 'HH:mm').format('HH:mm') === key || moment(key, 'HH').format('HH') === key) {
if (this.hours.indexOf(key) === -1) { if (this.hours.indexOf(key) === -1) {
return true return true
} }
...@@ -763,14 +749,10 @@ ...@@ -763,14 +749,10 @@
//Force la fermeture du datePicker //Force la fermeture du datePicker
$('#myDatepicker').datepicker('hide'); $('#myDatepicker').datepicker('hide');
//let formatDateDay = moment(e.date).locale('fr').format('DDMMYYYY');
let formatDateOnSneFou = moment(e.date).locale('fr').format(this.dateFormat); let formatDateOnSneFou = moment(e.date).locale('fr').format(this.dateFormat);
console.log('formatDateOnSneFou dehors', formatDateOnSneFou);
if (this.keyExist(formatDateOnSneFou)) { if (this.keyExist(formatDateOnSneFou)) {
this.days.push(formatDateOnSneFou); this.days.push(formatDateOnSneFou);
console.log('formatDateOnSneFou dedans', formatDateOnSneFou);
this.addInOutputObject(formatDateOnSneFou); this.addInOutputObject(formatDateOnSneFou);
} }
...@@ -798,16 +780,18 @@ ...@@ -798,16 +780,18 @@
if (this.keyExist(goodHourFormat)) { if (this.keyExist(goodHourFormat)) {
this.hours.push(goodHourFormat); this.hours.push(goodHourFormat);
} }
} } else {
if (this.keyExist(e.time.value)) { if (this.keyExist(e.time.value)) {
//Ajout dans le bon format DD dans le tableau, supprime les 00 en trop //Ajout dans le bon format DD dans le tableau, supprime les 00 en trop
if (splitHour[1] === '00') { if (splitHour[1] === '00') {
if (this.keyExist(splitHour[0])) {
this.hours.push(splitHour[0]); this.hours.push(splitHour[0]);
}
} else { } else {
this.hours.push(e.time.value); this.hours.push(e.time.value);
} }
} }
}
this.hours.sort(function(a,b) { this.hours.sort(function(a,b) {
return moment(a, 'HH:mm') - moment(b, 'HH:mm'); return moment(a, 'HH:mm') - moment(b, 'HH:mm');
...@@ -875,7 +859,6 @@ ...@@ -875,7 +859,6 @@
* @param data * @param data
*/ */
this.addInOutputObject = (data) => { this.addInOutputObject = (data) => {
console.log('DATA', data);
if (typeof data === 'string') { if (typeof data === 'string') {
this.outputJson[data] = []; this.outputJson[data] = [];
} else { } else {
...@@ -899,8 +882,10 @@ ...@@ -899,8 +882,10 @@
* @param data * @param data
*/ */
this.removeInOutputObject = (data) => { this.removeInOutputObject = (data) => {
if (this.outputJson[data[0]]) { let dayFormat = moment(data[0], 'DDMMYYYY').format(this.dateFormat);
let output = this.outputJson[data[0]];
if (this.outputJson[dayFormat]) {
let output = this.outputJson[dayFormat];
let index = output.indexOf(data[1]); let index = output.indexOf(data[1]);
if (index !== -1) { if (index !== -1) {
......
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