Commit 118703b9 authored by Mat's avatar Mat
Browse files

Info, Règle le déclenchement et l'affichage de modalRead

parent 0efe6d98
File mode changed from 100644 to 100755
......@@ -112,6 +112,7 @@ function buildRowInfo(jsonRow)
tr.appendChild(td6);
let td9 = document.createElement('td');
td9.appendChild(displayReadInfo(jsonRow));
td9.appendChild(displayEditInfo(jsonRow));
td9.appendChild(displayDeleteInfo(jsonRow));
tr.appendChild(td9);
......@@ -120,6 +121,53 @@ function buildRowInfo(jsonRow)
}
/*
* Affiche un bouton pour afficher le contenu de la rangée
* @param json object jsonRow
*/
function displayReadInfo(jsonRow)
{
let readBtn = buildReadBtn();
readBtn.dataset.target = ".read-info-modal";
readBtn.dataset.infoId = jsonRow.id;
readBtn.addEventListener('click', function()
{
let modal = document.querySelector('.read-info-modal');
let mTitle = modal.querySelector('h2#read-info');
mTitle.textContent = "Aperçu de l'actualité n°" + jsonRow.id;
let mBody = modal.querySelector('.modal-body');
let subtitle = jsonRow.subtitle ? '<h3>' + jsonRow.subtitle + '</h3>' : '';
let publiDate = (typeof jsonRow.posted_at !== 'undefined') ?
'<span>Publié le ' + formatStringDateTime(jsonRow.posted_at, true, true, false, false) + '</span>' : '';
mBody.innerHTML = '<div style="color: ' + jsonRow.color + ';">'
+ '<h2>' + jsonRow.title + '</h2>'
+ subtitle
+ publiDate
+ '<p>' + jsonRow.text + '</p>'
+ '</div>'
;
let mFooter = modal.querySelector('.modal-footer');
mFooter.childElementCount > 1 ?
mFooter.removeChild(mFooter.lastChild) : null ;
mFooter.appendChild(displayEditInfo(jsonRow));
mFooter.lastChild.classList.remove('btn-sm');
mFooter.lastChild.addEventListener('click', function() {
$('.read-info-modal').modal('hide'); // en jquery
});
});
return readBtn;
}
/*
* Affiche un bouton pour éditer une rangée
* @param json object jsonRow
......
......@@ -29,6 +29,15 @@ function createButton(callback)
/*
* Construit les boutons
*/
function buildReadBtn()
{
let btn = document.createElement('button');
btn.innerHTML = '<i class="fas fa-bars fa-fw"></i>';
btn.setAttribute('title', 'Voir');
btn.classList.add('btn', 'btn-dark', 'btn-sm', 'mb-1', 'mr-1');
btn.dataset.toggle = "modal";
return btn;
}
function buildEditBtn()
{
let btn = document.createElement('button');
......
......@@ -32,15 +32,15 @@ function getFrMonth(key, short = true)
}
}
function formatDate(date, weekWord = false, monthWord = false)
function formatDate(date, weekWord = false, monthWord = false, weekShort = true, monthShort = true)
{
let weekDay = '';
if (weekWord === true) {
weekDay = getFrDow(date.getDay()) + ' ';
weekDay = getFrDow(date.getDay(), weekShort) + ' ';
}
let month = '/' + formatNumber(date.getMonth()+1, 2) + '/';
if (monthWord === true) {
month = ' ' + getFrMonth(date.getMonth()) + ' ';
month = ' ' + getFrMonth(date.getMonth(), monthShort) + ' ';
}
return weekDay
+ formatNumber(date.getDate(), 2)
......@@ -68,13 +68,13 @@ function formatDateTimeISO(string)
}
/* string */
function formatStringDate(string)
function formatStringDate(string, weekWord = false, monthWord = false, weekShort = true, monthShort = true)
{
return formatDate(new Date(string), true, true);
return formatDate(new Date(string), weekWord, monthWord, weekShort, monthShort);
}
function formatStringDateTime(string)
function formatStringDateTime(string, weekWord = false, monthWord = false, weekShort = true, monthShort = true)
{
return formatStringDate(string) + ', à ' + formatTimeISO(string);
return formatStringDate(string, weekWord, monthWord, weekShort, monthShort) + ', à ' + formatTimeISO(string);
}
......
Supports Markdown
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