Commit 26b48bcc by Simon

Fix beug ajout de deux dates pareille et outputformat front

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