Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions Resources/public/js/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function enableMode(mode, lexikTranslationId, locales, url, csrfToken) {
document.getElementById('inputContent-' + lexikTranslationId + '-' + locales[i]).style.display = 'block';
}
} else if (mode == 'view') {

let update = false;

editButton.style.display = 'block';
deleteButton.style.display = 'block';
saveButton.style.display = 'none';
Expand All @@ -30,14 +33,18 @@ function enableMode(mode, lexikTranslationId, locales, url, csrfToken) {
var newValue = document.getElementById('inputContent-' + lexikTranslationId + '-' + locales[i]).value;

if (oldValue !== newValue) {
saveUpdatedLexikTranslations(lexikTranslationId, locales[i], newValue, url, csrfToken);
update = true;
document.getElementById('content-' + lexikTranslationId + '-' + locales[i]).innerText = newValue;
}

document.getElementById('content-' + lexikTranslationId + '-' + locales[i]).style.display = 'block';
document.getElementById('inputContent-' + lexikTranslationId + '-' + locales[i]).style.display = 'none';
document.getElementById('btnDelete-' + lexikTranslationId + '-' + locales[i]).style.display = 'none';
document.getElementById('btnKeyDelete-' + lexikTranslationId).style.display = 'none';
}
if (update) {
saveUpdatedLexikTranslations(lexikTranslationId, locales[i], url, csrfToken);
}
} else if (mode == 'delete') {
editButton.style.display = 'none';
deleteButton.style.display = 'none';
Expand All @@ -49,11 +56,9 @@ function enableMode(mode, lexikTranslationId, locales, url, csrfToken) {
}
}

function saveUpdatedLexikTranslations(lexikTranslationId, locale, newValue, url, csrfToken) {
function saveUpdatedLexikTranslations(lexikTranslationId, locale, url, csrfToken) {
let params = [];

document.getElementById('inputContent-' + lexikTranslationId + '-' + locale).value = newValue;
document.getElementById('content-' + lexikTranslationId + '-' + locale).innerText = newValue;
var saveButton = document.getElementById('saveButton-' + lexikTranslationId);
var trElement = saveButton.closest('tr.content');
var tdElements = trElement.querySelectorAll('td');
Expand Down Expand Up @@ -416,7 +421,7 @@ function constructHtmlTr(item) {
</td>
${Object.keys(item).filter(key => key !== '_id' && key !== '_domain' && key !== '_key').map(locale => `
<td>
<span id="content-${item._id}-${locale}" class="locale">${item[locale]}</span>
<span id="content-${item._id}-${locale}" class="locale">${escapeHtml(item[locale])}</span>
<div>
<textarea id="inputContent-${item._id}-${locale}" name="column.index" class="form-control" style="display: none">${item[locale]}</textarea>
</div>
Expand Down Expand Up @@ -449,6 +454,16 @@ function constructHtmlTr(item) {
return tr;
}

function escapeHtml(unsafe)
{
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}

function displayNoTranslations()
{
let div =
Expand All @@ -457,4 +472,4 @@ function displayNoTranslations()
</div>`;

return div;
}
}