CJVT updates August and September 2026
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* global $, axios, bootstrap, currentPagePath, initPagination, removeAllChildNodes, unsavedData, replaceContainer, i18next */
|
||||
/* global $, axios, bootstrap, currentPagePath, initPagination, removeAllChildNodes, unsavedData, replaceContainer, i18next, DateUtils, captureFormBaseline, isFormDirty, updateSaveButtonState, enableButton, disableButton, warnOnNameCollisionThenSubmit */
|
||||
|
||||
// Temporary workaround (use of currentPagePath).
|
||||
|
||||
@@ -11,6 +11,7 @@ let queryBattery = ''
|
||||
function initDictionaries() {
|
||||
const ce = {}
|
||||
window.dictionaryElements = ce
|
||||
let confirmedVersionId = 'latest-version'
|
||||
ce.textDescription = document.getElementById('text-description')
|
||||
ce.headerTitle = document.getElementById('site-header-title')
|
||||
ce.fixedTopSection = document.getElementById('fixed-top-section')
|
||||
@@ -23,10 +24,7 @@ function initDictionaries() {
|
||||
mobileMoveContent()
|
||||
adjustOffsetBy()
|
||||
window.onscroll = hideAndShowHeader
|
||||
if (
|
||||
/\/slovarji\/\d+\/podatki/.test(currentPagePath) ||
|
||||
currentPagePath === '/slovarji/nov'
|
||||
) {
|
||||
if (currentPagePath === '/slovarji/nov') {
|
||||
ce.inputNewAuthor = document.getElementById('input-new-author')
|
||||
ce.inputNewArea = document.getElementById('input-new-area')
|
||||
}
|
||||
@@ -66,8 +64,12 @@ function initDictionaries() {
|
||||
checkLanguages()
|
||||
if (!event.target.checkValidity()) {
|
||||
event.preventDefault()
|
||||
event.target.classList.add('was-validated')
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
event.target.classList.add('was-validated')
|
||||
warnOnNameCollisionThenSubmit(event.target)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,6 +80,7 @@ function initDictionaries() {
|
||||
ce.dictionaryStructureForm = document.getElementById(
|
||||
'form-dictionary-structure'
|
||||
)
|
||||
captureFormBaseline(ce.dictionaryStructureForm)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(ce.dictionaryStructureForm, dictSideMenu)
|
||||
ce.checkLanguageGroup = document.getElementById('language-group')
|
||||
@@ -92,10 +95,13 @@ function initDictionaries() {
|
||||
'synonym-language-subgroup'
|
||||
)
|
||||
|
||||
// jquery event listener for a select2 field
|
||||
$('.multiple').on('change', enableButton)
|
||||
$('#languages-input').on('select2:select select2:unselect', () =>
|
||||
updateSaveButtonState(ce.dictionaryStructureForm)
|
||||
)
|
||||
|
||||
ce.dictionaryStructureForm.addEventListener('input', enableButton)
|
||||
ce.dictionaryStructureForm.addEventListener('input', () =>
|
||||
updateSaveButtonState(ce.dictionaryStructureForm)
|
||||
)
|
||||
ce.definitionCheckBox = document.getElementById('definition-check-box')
|
||||
ce.submitDictionaryBtn = document.getElementById('submit-dictionary-btn')
|
||||
ce.checkLanguageGroup.addEventListener('click', checkBoxLanguageChecker)
|
||||
@@ -111,54 +117,14 @@ function initDictionaries() {
|
||||
})
|
||||
}
|
||||
|
||||
if (/\/slovarji\/\d+\/podatki/.test(currentPagePath)) {
|
||||
ce.descriptionDictionaryForm = document.getElementById(
|
||||
'form-dictionary-description'
|
||||
)
|
||||
ce.descriptionDictionaryForm.addEventListener('input', enableButton)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(ce.descriptionDictionaryForm, dictSideMenu)
|
||||
ce.inputElements = document.querySelectorAll('input')
|
||||
ce.imgTrashIcon = document.querySelectorAll('.delete-author-btn')
|
||||
ce.inputElements.forEach(el => el.addEventListener('input', enableButton))
|
||||
ce.inputElements.forEach(el => el.addEventListener('change', enableButton))
|
||||
ce.inputNewAuthor.addEventListener('click', () => {
|
||||
addField(ce.descriptionDictionaryForm, ce.inputNewAuthor)
|
||||
})
|
||||
ce.inputNewAuthor.addEventListener('click', enableButton)
|
||||
ce.inputNewArea.addEventListener('click', () => {
|
||||
createNewAreaInput(ce.descriptionDictionaryForm)
|
||||
})
|
||||
ce.inputNewArea.addEventListener('click', enableButton)
|
||||
if (ce.imgTrashIcon !== null) {
|
||||
ce.imgTrashIcon.forEach(el => el.addEventListener('click', deleteField))
|
||||
ce.imgTrashIcon.forEach(el => el.addEventListener('click', enableButton))
|
||||
}
|
||||
|
||||
// jquery event listener for select2 fields
|
||||
$('.without-addition').on('change', enableButton)
|
||||
$('.multiple').on('change', enableButton)
|
||||
|
||||
// JQuery for summernote text editor
|
||||
$('.summernote').on('summernote.change', enableButton)
|
||||
|
||||
ce.descriptionDictionaryForm.addEventListener('submit', event => {
|
||||
// checkform()
|
||||
if (!event.target.checkValidity()) {
|
||||
event.preventDefault()
|
||||
}
|
||||
event.target.classList.add('was-validated')
|
||||
})
|
||||
}
|
||||
|
||||
if (/\/slovarji\/\d+\/uvoz\/datoteka/.test(currentPagePath)) {
|
||||
ce.fileUploadInput = document.getElementById('upload')
|
||||
const btnImportEl = document.getElementById('button-import')
|
||||
btnImportEl.addEventListener('click', () => ce.fileUploadInput.click())
|
||||
const fileUploadInputValue = ce.fileUploadInput.value
|
||||
const chosenFile = document.getElementById('chosen-file')
|
||||
const fileTypeSelectionContainer = document.getElementById(
|
||||
'file-type-selection'
|
||||
const fileFormatSelectionContainer = document.getElementById(
|
||||
'file-format-selection'
|
||||
)
|
||||
ce.fileImportForm = document.getElementById('file-import-form')
|
||||
|
||||
@@ -173,10 +139,19 @@ function initDictionaries() {
|
||||
}
|
||||
})
|
||||
|
||||
fileTypeSelectionContainer.addEventListener(
|
||||
'change',
|
||||
updateAcceptedFileTypes
|
||||
)
|
||||
fileFormatSelectionContainer.addEventListener('change', () => {
|
||||
updateAcceptedFileTypes()
|
||||
updateEntryStatusAvailability()
|
||||
})
|
||||
updateEntryStatusAvailability()
|
||||
|
||||
function updateEntryStatusAvailability() {
|
||||
const isJsonFormat =
|
||||
ce.fileImportForm.importFileFormat.value === 'json_term_candidates'
|
||||
for (const radio of ce.fileImportForm.entryStatus) {
|
||||
radio.disabled = isJsonFormat
|
||||
}
|
||||
}
|
||||
|
||||
ce.fileImportForm.addEventListener('submit', submitFormMultipart)
|
||||
|
||||
@@ -187,74 +162,25 @@ function initDictionaries() {
|
||||
|
||||
await axios.post(event.target.action, payload)
|
||||
|
||||
alert(i18next.t('SLOVAR UVOŽEN'))
|
||||
showImportResponseModal(i18next.t('SLOVAR UVOŽEN'))
|
||||
onPageChange(1)
|
||||
} catch (error) {
|
||||
alert(i18next.t('NAPAKA V UVOZU'))
|
||||
showImportResponseModal(i18next.t('NAPAKA V UVOZU'))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const resultsListEl = document.getElementById('page-results')
|
||||
const dictionaryId = document.getElementById('dictionary-id').value
|
||||
|
||||
const updatePager = initPagination('pagination', onPageChange)
|
||||
|
||||
async function onPageChange(newPage) {
|
||||
try {
|
||||
const { page, numberOfAllPages, results } = await getDataForPage(
|
||||
newPage
|
||||
)
|
||||
removeAllChildNodes(resultsListEl)
|
||||
renderResults(results)
|
||||
updatePager(page, numberOfAllPages)
|
||||
} catch (error) {
|
||||
let message = i18next.t('Prišlo je do napake.')
|
||||
if (error.response?.data) {
|
||||
message = error.response.data
|
||||
} else if (error.request) {
|
||||
message = i18next.t('Strežnik ni dosegljiv. Poskusite kasneje.')
|
||||
}
|
||||
alert(message)
|
||||
updatePager()
|
||||
}
|
||||
}
|
||||
|
||||
async function getDataForPage(page) {
|
||||
const url = `/api/v1/dictionaries/${dictionaryId}/showImportFromFileForm?p=${page}`
|
||||
const { data } = await axios.get(url)
|
||||
return data
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
const localeOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}
|
||||
results.forEach(result => {
|
||||
const rowEl = document.createElement('tr')
|
||||
const td1 = document.createElement('td')
|
||||
const td2 = document.createElement('td')
|
||||
const td3 = document.createElement('td')
|
||||
const td4 = document.createElement('td')
|
||||
const date = new Date(result.time_started).toLocaleDateString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
)
|
||||
td1.textContent = date
|
||||
td2.textContent = result.file_format
|
||||
td3.textContent = result.count_valid_entries
|
||||
td4.textContent = result.status
|
||||
rowEl.append(td1, td2, td3, td4)
|
||||
resultsListEl.appendChild(rowEl)
|
||||
})
|
||||
}
|
||||
function showImportResponseModal(message) {
|
||||
const modalEl = document.getElementById('import-response-modal')
|
||||
modalEl.querySelector('#response-modal-text').textContent = message
|
||||
new bootstrap.Modal(modalEl).toggle()
|
||||
}
|
||||
|
||||
const IMPORT_STATUS_KEYS = {
|
||||
'in progress': 'importStatusInProgress',
|
||||
error: 'importStatusError',
|
||||
done: 'importStatusDone'
|
||||
}
|
||||
}
|
||||
|
||||
if (/\/slovarji\/\d+\/izvoz/.test(currentPagePath)) {
|
||||
const resultsListEl = document.getElementById('page-results')
|
||||
const dictionaryId = document.getElementById('dictionary-id').value
|
||||
|
||||
@@ -281,44 +207,174 @@ function initDictionaries() {
|
||||
}
|
||||
|
||||
async function getDataForPage(page) {
|
||||
const url = `/api/v1/dictionaries/${dictionaryId}/showExportToFileForm?p=${page}`
|
||||
const url = `/api/v1/dictionaries/${dictionaryId}/showImportFromFileForm?p=${page}`
|
||||
const { data } = await axios.get(url)
|
||||
return data
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
const localeOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}
|
||||
results.forEach(result => {
|
||||
const rowEl = document.createElement('tr')
|
||||
const td1 = document.createElement('td')
|
||||
const td2 = document.createElement('td')
|
||||
const td3 = document.createElement('td')
|
||||
const td4 = document.createElement('td')
|
||||
const date = new Date(result.time_created).toLocaleDateString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
td1.textContent = DateUtils.formatDateTime(result.time_started)
|
||||
td2.textContent = result.file_format
|
||||
td3.textContent = result.count_entries
|
||||
td4.textContent = i18next.t(IMPORT_STATUS_KEYS[result.status])
|
||||
rowEl.append(td1, td2, td3, td4)
|
||||
resultsListEl.appendChild(rowEl)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (/\/slovarji\/\d+\/izvoz/.test(currentPagePath)) {
|
||||
const EXPORT_POLL_INTERVAL_MS = 2000
|
||||
const EXPORT_POLL_MAX_ATTEMPTS = 150 // ~5 minutes, then give up quietly
|
||||
|
||||
const exportForm = document.forms['dictionary-export']
|
||||
|
||||
exportForm.addEventListener('submit', async event => {
|
||||
event.preventDefault()
|
||||
|
||||
const payload = Object.fromEntries(new FormData(event.target))
|
||||
payload.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
|
||||
try {
|
||||
await axios.post(event.target.action, payload)
|
||||
pollExportsUntilFinished()
|
||||
} catch (error) {
|
||||
let message = i18next.t('Prišlo je do napake.')
|
||||
if (error.response) {
|
||||
message = error.response.data
|
||||
} else if (error.request) {
|
||||
message = i18next.t('Strežnik ni dosegljiv. Poskusite kasneje.')
|
||||
}
|
||||
showExportResponseModal(message)
|
||||
}
|
||||
})
|
||||
|
||||
function showExportResponseModal(message) {
|
||||
const modalEl = document.getElementById('export-response-modal')
|
||||
modalEl.querySelector('#response-modal-text').textContent = message
|
||||
new bootstrap.Modal(modalEl).toggle()
|
||||
}
|
||||
|
||||
async function pollExportsUntilFinished(
|
||||
remainingAttempts = EXPORT_POLL_MAX_ATTEMPTS
|
||||
) {
|
||||
if (remainingAttempts <= 0) return
|
||||
const results = await onPageChange(1)
|
||||
const stillProcessing = results?.some(
|
||||
result => result.status === 'pending' || result.status === 'in progress'
|
||||
)
|
||||
if (stillProcessing) {
|
||||
setTimeout(
|
||||
() => pollExportsUntilFinished(remainingAttempts - 1),
|
||||
EXPORT_POLL_INTERVAL_MS
|
||||
)
|
||||
td1.textContent = date
|
||||
}
|
||||
}
|
||||
|
||||
const EXPORT_STATUS_KEYS = {
|
||||
pending: 'exportStatusPending',
|
||||
'in progress': 'exportStatusInProgress',
|
||||
failed: 'exportStatusFailed'
|
||||
}
|
||||
|
||||
const resultsListEl = document.getElementById('page-results')
|
||||
const dictionaryId = document.getElementById('dictionary-id').value
|
||||
|
||||
const updatePager = initPagination('pagination', onPageChange)
|
||||
|
||||
async function onPageChange(newPage) {
|
||||
try {
|
||||
const { page, numberOfAllPages, results } = await getDataForPage(
|
||||
newPage
|
||||
)
|
||||
removeAllChildNodes(resultsListEl)
|
||||
renderResults(results)
|
||||
updatePager(page, numberOfAllPages)
|
||||
return results
|
||||
} catch (error) {
|
||||
let message = i18next.t('Prišlo je do napake.')
|
||||
if (error.response?.data) {
|
||||
message = error.response.data
|
||||
} else if (error.request) {
|
||||
message = i18next.t('Strežnik ni dosegljiv. Poskusite kasneje.')
|
||||
}
|
||||
alert(message)
|
||||
updatePager()
|
||||
}
|
||||
}
|
||||
|
||||
async function getDataForPage(page) {
|
||||
const url = `/api/v1/dictionaries/${dictionaryId}/showExportToFileForm?p=${page}`
|
||||
const { data } = await axios.get(url)
|
||||
return data
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
results.forEach(result => {
|
||||
const rowEl = document.createElement('tr')
|
||||
const td1 = document.createElement('td')
|
||||
const td2 = document.createElement('td')
|
||||
const td3 = document.createElement('td')
|
||||
const td4 = document.createElement('td')
|
||||
td1.textContent = DateUtils.formatDateTime(result.time_created)
|
||||
td2.textContent = result.export_file_format
|
||||
td3.textContent = result.entry_count
|
||||
if (result.status === 'finished') {
|
||||
const wrapperEl = document.createElement('div')
|
||||
wrapperEl.className = 'd-flex align-items-center'
|
||||
|
||||
const aEl = document.createElement('a')
|
||||
aEl.href = `/slovarji/export-download/${result.id}`
|
||||
aEl.textContent = i18next.t('Shrani')
|
||||
aEl.className = 'btn btn-primary'
|
||||
td4.append(aEl)
|
||||
} else td4.textContent = ''
|
||||
wrapperEl.append(aEl)
|
||||
|
||||
const deleteImgEl = document.createElement('img')
|
||||
deleteImgEl.src = '/images/red-trash-icon.svg'
|
||||
deleteImgEl.alt = i18next.t('Izbriši')
|
||||
const deleteBtnEl = document.createElement('button')
|
||||
deleteBtnEl.type = 'button'
|
||||
deleteBtnEl.className = 'p-0 table-button-grp delete-row-btn ms-3'
|
||||
deleteBtnEl.setAttribute('data-bs-target', '#alert-modal')
|
||||
deleteBtnEl.setAttribute('data-bs-toggle', 'modal')
|
||||
deleteBtnEl.dataset.exportId = result.id
|
||||
deleteBtnEl.append(deleteImgEl)
|
||||
wrapperEl.append(deleteBtnEl)
|
||||
|
||||
td4.append(wrapperEl)
|
||||
} else td4.textContent = i18next.t(EXPORT_STATUS_KEYS[result.status])
|
||||
|
||||
rowEl.append(td1, td2, td3, td4)
|
||||
resultsListEl.appendChild(rowEl)
|
||||
})
|
||||
}
|
||||
|
||||
resultsListEl.addEventListener('click', handleExportResultsClick)
|
||||
|
||||
function handleExportResultsClick({ target }) {
|
||||
const deleteBtn = target.closest('.delete-row-btn')
|
||||
if (!deleteBtn) return
|
||||
|
||||
const rowEl = deleteBtn.closest('tr')
|
||||
const exportId = deleteBtn.dataset.exportId
|
||||
|
||||
document.getElementById('modal-use-btn').onclick = async () => {
|
||||
try {
|
||||
await axios.delete(
|
||||
`/api/v1/dictionaries/${dictionaryId}/export/${exportId}`
|
||||
)
|
||||
rowEl.remove()
|
||||
} catch {
|
||||
showExportResponseModal(i18next.t('Prišlo je do napake.'))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (/\/slovarji\/\d+\/vsebina/.test(currentPagePath)) {
|
||||
@@ -340,7 +396,7 @@ function initDictionaries() {
|
||||
ce.selectAllDates = document.querySelectorAll('input[name=date]')
|
||||
ce.classicOverview = document.getElementById('classic-overview')
|
||||
// ce.selectedOverview = document.getElementById('selected-date-overview')
|
||||
ce.btnSaveIcon = document.getElementById('btn-save-icon')
|
||||
ce.btnSaveIcon = document.getElementById('disabled-submit-btn')
|
||||
ce.filterCheckBoxes = document.querySelectorAll('.indeterminate-cbox')
|
||||
ce.showFilterBtn = document.getElementById('show-filter')
|
||||
ce.explanationField = document.getElementById('explanation-field')
|
||||
@@ -363,7 +419,10 @@ function initDictionaries() {
|
||||
ce.clearSearchInput = document.querySelector('.clear-search-input')
|
||||
ce.collapsablePart = document.querySelectorAll('.collapsable-entry-part')
|
||||
ce.scrollEl = document.querySelector('.content-nav-content')
|
||||
$('.multiple').on('select2:select', enableButton)
|
||||
$('.multiple, .without-dropdown').on(
|
||||
'select2:select select2:unselect',
|
||||
onFormEdited
|
||||
)
|
||||
ce.collapsablePart.forEach(el => {
|
||||
el.addEventListener('hide.bs.collapse', () =>
|
||||
changePageContent('collapse-hidden')
|
||||
@@ -415,16 +474,16 @@ function initDictionaries() {
|
||||
ce.showDates.addEventListener('click', () =>
|
||||
changePageContent(ce.showDates.id)
|
||||
)
|
||||
ce.selectAllDates.forEach(el =>
|
||||
el.addEventListener('click', () => showSelectedDateData(el))
|
||||
)
|
||||
ce.filterCheckBoxes.forEach(el =>
|
||||
el.addEventListener('click', () => indeterminateTheBox(el))
|
||||
)
|
||||
ce.showFilterBtn.addEventListener('click', () =>
|
||||
changePageContent(ce.showFilterBtn.getAttribute('aria-expanded'))
|
||||
)
|
||||
ce.formEditContent.addEventListener('input', enableButton)
|
||||
ce.formEditContent.addEventListener('input', onFormEdited)
|
||||
document
|
||||
.getElementById('alert-modal')
|
||||
.addEventListener('hidden.bs.modal', onFormEdited)
|
||||
ce.resizeFields = document.querySelectorAll('.explanation-field')
|
||||
if (ce.resizeFields.length) {
|
||||
ce.resizeFields.forEach(el =>
|
||||
@@ -436,26 +495,30 @@ function initDictionaries() {
|
||||
ce.resizeFields.forEach(el => el.dispatchEvent(eventText))
|
||||
const mcBtnsGrp = document.querySelectorAll('.mc-buttons-group')
|
||||
if (mcBtnsGrp.length) {
|
||||
mcBtnsGrp.forEach(e => e.addEventListener('click', enableButton))
|
||||
mcBtnsGrp.forEach(e => e.addEventListener('click', onFormEdited))
|
||||
}
|
||||
if (ce.newHeadwordGroupBtn)
|
||||
ce.newHeadwordGroupBtn.addEventListener('click', createHeadword)
|
||||
if (ce.newConnectionBtn)
|
||||
ce.newConnectionBtn.addEventListener('click', () =>
|
||||
ce.newConnectionBtn.addEventListener('click', () => {
|
||||
addConnectionField(ce.formEditContent, ce.newConnectionBtn)
|
||||
)
|
||||
onFormEdited()
|
||||
})
|
||||
if (ce.newImageBtn)
|
||||
ce.newImageBtn.addEventListener('click', () =>
|
||||
ce.newImageBtn.addEventListener('click', () => {
|
||||
addField(ce.formEditContent, ce.newImageBtn)
|
||||
)
|
||||
onFormEdited()
|
||||
})
|
||||
if (ce.newAudioBtn)
|
||||
ce.newAudioBtn.addEventListener('click', () =>
|
||||
ce.newAudioBtn.addEventListener('click', () => {
|
||||
addField(ce.formEditContent, ce.newAudioBtn)
|
||||
)
|
||||
onFormEdited()
|
||||
})
|
||||
if (ce.newVideoBtn)
|
||||
ce.newVideoBtn.addEventListener('click', () =>
|
||||
ce.newVideoBtn.addEventListener('click', () => {
|
||||
addField(ce.formEditContent, ce.newVideoBtn)
|
||||
)
|
||||
onFormEdited()
|
||||
})
|
||||
ce.statusEditEl.addEventListener('change', () => checkIfValid())
|
||||
ce.termInputField.addEventListener('input', () => checkIfValid())
|
||||
if (ce.definitionField !== null)
|
||||
@@ -532,7 +595,6 @@ function initDictionaries() {
|
||||
}
|
||||
}
|
||||
|
||||
let unsaved = false
|
||||
ce.deleteEntryBtn.addEventListener('click', handleClick)
|
||||
// Ajax render entry data
|
||||
const messageContainer = document.querySelectorAll('.message-container')
|
||||
@@ -549,7 +611,7 @@ function initDictionaries() {
|
||||
const versionEl = target.closest('.date-element')
|
||||
const deleteEntryEl = target.closest('#delete-entry')
|
||||
if (term) {
|
||||
if (unsaved) {
|
||||
if (isFormDirty(window.dictionaryElements.formEditContent)) {
|
||||
const modalUseBtn = document.getElementById('modal-use-btn')
|
||||
const modalCnclBtn = document.getElementById('modal-cancel-btn')
|
||||
const modalMain = document.getElementById('alert-text')
|
||||
@@ -571,7 +633,6 @@ function initDictionaries() {
|
||||
updateEntry(event, termId)
|
||||
renderTermData(termId, event)
|
||||
activateMe(term)
|
||||
disableButton()
|
||||
term.classList.add('selected-term-btn')
|
||||
modalUseBtn.textContent = okBtnText
|
||||
modalCnclBtn.textContent = cnclBtnTxt
|
||||
@@ -581,7 +642,6 @@ function initDictionaries() {
|
||||
const termId = term.getAttribute('data-term-id')
|
||||
renderTermData(termId, event)
|
||||
activateMe(term)
|
||||
disableButton()
|
||||
term.classList.add('selected-term-btn')
|
||||
modalUseBtn.textContent = okBtnText
|
||||
modalCnclBtn.textContent = cnclBtnTxt
|
||||
@@ -591,7 +651,6 @@ function initDictionaries() {
|
||||
const termId = term.getAttribute('data-term-id')
|
||||
renderTermData(termId, event)
|
||||
activateMe(term)
|
||||
disableButton()
|
||||
term.classList.add('selected-term-btn')
|
||||
}
|
||||
}
|
||||
@@ -637,9 +696,16 @@ function initDictionaries() {
|
||||
const info = new FormData(formEditContent)
|
||||
info.append('isPublishedEl', isPublishedEl)
|
||||
loadPreview(info)
|
||||
updateSaveButtonState(formEditContent)
|
||||
showSelectedDateData()
|
||||
confirmedVersionId = versionId
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
alert('Prišlo je do napake.')
|
||||
const confirmedRadio = document.querySelector(
|
||||
`input[name="date"][value="${confirmedVersionId}"]`
|
||||
)
|
||||
if (confirmedRadio) confirmedRadio.checked = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,7 +732,7 @@ function initDictionaries() {
|
||||
loadPreview(info)
|
||||
changeVersionList(data.entry.versions)
|
||||
setLatestVersion(data.entry)
|
||||
ce.formEditContent.addEventListener('input', () => (unsaved = true))
|
||||
confirmedVersionId = 'latest-version'
|
||||
formEditContent.dataset.entryId = entryId
|
||||
formEditContent.action = '/api/v1/entries/update'
|
||||
previewBtnEl.disabled = false
|
||||
@@ -679,9 +745,18 @@ function initDictionaries() {
|
||||
deleteEntry.disabled = false
|
||||
changeCollapsedContent()
|
||||
checkIfValid()
|
||||
unsaved = false
|
||||
captureFormBaseline(formEditContent)
|
||||
if (!ce.btnSaveIcon.classList.contains('saved-entry-btn')) {
|
||||
disableButton()
|
||||
ce.btnSaveIcon.textContent = i18next.t('Shrani')
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
alert('Prišlo je do napake.')
|
||||
const confirmedRadio = document.querySelector(
|
||||
`input[name="date"][value="${confirmedVersionId}"]`
|
||||
)
|
||||
if (confirmedRadio) confirmedRadio.checked = true
|
||||
} finally {
|
||||
resizeFields.forEach(el => autoResize(el))
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
@@ -690,11 +765,6 @@ function initDictionaries() {
|
||||
|
||||
function insertTermData(entryId, data, vAuthor) {
|
||||
const { newConnectionBtn } = window.dictionaryElements
|
||||
const localeOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
}
|
||||
const termName = document.getElementById('term-name')
|
||||
const domainsSecondary = $('#domain-secondary')
|
||||
const label = document.getElementById('explanation-field')
|
||||
@@ -733,10 +803,9 @@ function initDictionaries() {
|
||||
linkRow
|
||||
)
|
||||
if (data.entry.time_modified) {
|
||||
const dateModified = new Date(
|
||||
latestVersionLabel.textContent = DateUtils.formatDate(
|
||||
data.entry.time_modified
|
||||
).toLocaleDateString('sl-SL', localeOptions)
|
||||
latestVersionLabel.textContent = dateModified
|
||||
)
|
||||
}
|
||||
if (entryId)
|
||||
for (let i = 0; i < termIdText.length; i++) {
|
||||
@@ -798,7 +867,7 @@ function initDictionaries() {
|
||||
}
|
||||
})
|
||||
}
|
||||
if (data.entry.links) {
|
||||
if (data.entry.links && linkRow) {
|
||||
data.entry.links.forEach((el, index) => {
|
||||
if (index > 0) {
|
||||
addConnectionField(ce.formEditContent, newConnectionBtn, el)
|
||||
@@ -902,10 +971,13 @@ function initDictionaries() {
|
||||
payload.set('entryId', entryId)
|
||||
try {
|
||||
saveBtn.textContent = i18next.t('Shranjujem ...')
|
||||
saveBtn.disabled = true
|
||||
await axios.post(ce.formEditContent.action, payload)
|
||||
spinnerEl.classList.remove('d-none')
|
||||
saveBtn.classList.add('saved-entry-btn')
|
||||
saveBtn.disabled = false
|
||||
saveBtn.textContent = i18next.t('Shranjeno')
|
||||
captureFormBaseline(ce.formEditContent)
|
||||
if (id != null) entryId = id
|
||||
ajaxSideMenu(entryId)
|
||||
} catch (error) {
|
||||
@@ -916,16 +988,21 @@ function initDictionaries() {
|
||||
message = i18next.t('Strežnik ni dosegljiv. Poskusite kasneje.')
|
||||
}
|
||||
messageContainer.textContent = message
|
||||
updateSaveButtonState(ce.formEditContent)
|
||||
saveBtn.textContent = i18next.t('Shrani')
|
||||
}
|
||||
} else {
|
||||
event.preventDefault()
|
||||
const payload = new URLSearchParams(new FormData(ce.formEditContent))
|
||||
try {
|
||||
saveBtn.textContent = i18next.t('Shranjujem ...')
|
||||
saveBtn.disabled = true
|
||||
const res = await axios.post(ce.formEditContent.action, payload)
|
||||
spinnerEl.classList.remove('d-none')
|
||||
saveBtn.classList.add('saved-entry-btn')
|
||||
saveBtn.disabled = false
|
||||
saveBtn.textContent = i18next.t('Shranjeno')
|
||||
captureFormBaseline(ce.formEditContent)
|
||||
let entryId = res.data.entryId
|
||||
if (id != null) entryId = id
|
||||
ajaxSideMenu(entryId)
|
||||
@@ -937,6 +1014,8 @@ function initDictionaries() {
|
||||
message = i18next.t('Strežnik ni dosegljiv. Poskusite kasneje.')
|
||||
}
|
||||
messageContainer.textContent = message
|
||||
updateSaveButtonState(ce.formEditContent)
|
||||
saveBtn.textContent = i18next.t('Shrani')
|
||||
} finally {
|
||||
changePageContent('first')
|
||||
}
|
||||
@@ -1069,11 +1148,10 @@ function initDictionaries() {
|
||||
ce.domainLabelsForm.addEventListener('submit', domainLabelsToDb)
|
||||
const addAreaBtn = document.getElementById('add-area')
|
||||
addAreaBtn.addEventListener('click', () => subareasContent(noSubareas))
|
||||
addAreaBtn.addEventListener('click', enableButton)
|
||||
const formLabes = document.getElementById('dictionary-domain-labels')
|
||||
formLabes.addEventListener('input', enableButton)
|
||||
formLabes.addEventListener('input', updateDomainLabelsButtonState)
|
||||
const useBtn = document.getElementById('modal-use-btn')
|
||||
useBtn.addEventListener('click', enableButton)
|
||||
useBtn.addEventListener('click', updateDomainLabelsButtonState)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(ce.domainLabelsForm, dictSideMenu, domainLabelsToDb)
|
||||
async function domainLabelsToDb(event) {
|
||||
@@ -1305,6 +1383,9 @@ function adjustOffsetBy() {
|
||||
|
||||
function hideAndShowHeader() {
|
||||
const { textDescription, headerTitle } = window.dictionaryElements
|
||||
// Pages without the side-menu structure (e.g. /slovarji, /svetovanje)
|
||||
// don't have #site-header-title/#text-description - nothing to show/hide.
|
||||
if (!textDescription || !headerTitle) return
|
||||
if (!/\/slovarji\/\d+\/vsebina/.test(currentPagePath)) {
|
||||
if (document.documentElement.scrollTop < 50) {
|
||||
textDescription.style.display = 'block'
|
||||
@@ -1323,11 +1404,22 @@ function mobileMoveContent() {
|
||||
const secondaryButton = document.querySelector('.header-btn-secondary')
|
||||
const primaryButton = document.querySelector('.header-btn')
|
||||
const siteHeading = document.getElementById('site-heading')
|
||||
const siteHeadingTextContent = siteHeading.textContent
|
||||
const navTitle = document.getElementById('nav-title')
|
||||
const headerContainerRight = document.querySelector(
|
||||
'.header-container-divider-right'
|
||||
)
|
||||
// Pages without the side-menu structure (e.g. /slovarji, /svetovanje)
|
||||
// don't have these elements - nothing to reposition/show-hide there.
|
||||
if (
|
||||
!adminNavMobileEl ||
|
||||
!mobileRightHolder ||
|
||||
!siteHeading ||
|
||||
!navTitle ||
|
||||
!headerContainerRight
|
||||
) {
|
||||
return
|
||||
}
|
||||
const siteHeadingTextContent = siteHeading.textContent
|
||||
if (document.body.clientWidth <= 1200) {
|
||||
if (secondaryButton) {
|
||||
mobileRightHolder.appendChild(secondaryButton)
|
||||
@@ -1552,6 +1644,9 @@ function checkBoxLanguageChecker() {
|
||||
synonymLanguageSubgroup.classList.add('disabled-input')
|
||||
definitionCheckBox.classList.add('disabled-input')
|
||||
}
|
||||
|
||||
const { dictionaryStructureForm } = window.dictionaryElements
|
||||
if (dictionaryStructureForm) updateSaveButtonState(dictionaryStructureForm)
|
||||
}
|
||||
|
||||
function checkBoxDefinitionChecker() {
|
||||
@@ -1566,22 +1661,9 @@ function checkBoxDefinitionChecker() {
|
||||
}
|
||||
}
|
||||
|
||||
function enableButton() {
|
||||
const disabledBtn = document.getElementById('disabled-submit-btn')
|
||||
disabledBtn.disabled = false
|
||||
if (disabledBtn.classList.contains('saved-entry-btn')) {
|
||||
disabledBtn.classList.remove('saved-entry-btn')
|
||||
disabledBtn.textContent = 'Shrani'
|
||||
}
|
||||
}
|
||||
|
||||
function disableButton() {
|
||||
const disabledBtn = document.getElementById('disabled-submit-btn')
|
||||
disabledBtn.disabled = true
|
||||
if (disabledBtn.classList.contains('saved-entry-btn')) {
|
||||
disabledBtn.classList.remove('saved-entry-btn')
|
||||
disabledBtn.textContent = 'Shrani'
|
||||
}
|
||||
function onFormEdited() {
|
||||
updateSaveButtonState(window.dictionaryElements.formEditContent)
|
||||
window.dictionaryElements.btnSaveIcon.textContent = i18next.t('Shrani')
|
||||
}
|
||||
|
||||
function changePageContent(el) {
|
||||
@@ -1680,9 +1762,6 @@ function changePageContent(el) {
|
||||
selectAllDates.forEach(el => (el.checked = false))
|
||||
showDates.firstChild.src = '/images/fi_blue-calendar.svg'
|
||||
showDates.id = 'show-dates'
|
||||
btnSaveIcon.firstChild.src = '/images/fi_save.svg'
|
||||
btnSaveIcon.children[1].textContent = 'Shrani'
|
||||
btnSaveIcon.id = 'btn-save-icon'
|
||||
break
|
||||
case 'new-entry-btn': {
|
||||
// formEditContent.reset()
|
||||
@@ -1728,13 +1807,16 @@ function changePageContent(el) {
|
||||
const messageContainer = document.querySelectorAll('.message-container')
|
||||
messageContainer.forEach(el => el.classList.add('d-none'))
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
selectedEntry.classList.remove('selected-term-btn')
|
||||
if (selectedEntry) selectedEntry.classList.remove('selected-term-btn')
|
||||
$('.multiple').val(null).trigger('change')
|
||||
$('.without-dropdown').val(null).trigger('change')
|
||||
// editBtnEl.click()
|
||||
// termInputField.addEventListener('focus', () =>
|
||||
// showMCButtons(termInputField, 'link')
|
||||
// )
|
||||
captureFormBaseline(formEditContent)
|
||||
disableButton()
|
||||
btnSaveIcon.textContent = i18next.t('Shrani')
|
||||
termInputField.focus()
|
||||
termInputField.click()
|
||||
|
||||
@@ -1786,7 +1868,7 @@ function changePageContent(el) {
|
||||
editBtnEl.click()
|
||||
termInputField.focus()
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
selectedEntry.classList.remove('selected-term-btn')
|
||||
if (selectedEntry) selectedEntry.classList.remove('selected-term-btn')
|
||||
editBtnEl.click()
|
||||
responseModal.toggle()
|
||||
duplicateEntry.disabled = true
|
||||
@@ -1977,7 +2059,7 @@ function loadPreview(info) {
|
||||
}
|
||||
} else changeClasses(previewLinkedTerms, 'hide')
|
||||
|
||||
if (foreignTerm) {
|
||||
if (foreignTerm.length) {
|
||||
listForeignTerm.forEach(el => (el.textContent = ''))
|
||||
foreignTerm.forEach(el => {
|
||||
if (listForeignTerm.length) {
|
||||
@@ -1997,7 +2079,7 @@ function loadPreview(info) {
|
||||
else changeClasses(el.parentElement.parentElement, 'hide')
|
||||
})
|
||||
}
|
||||
if (foreignDef) {
|
||||
if (foreignDef.length) {
|
||||
listForeignDefinitions.forEach(el => (el.textContent = ''))
|
||||
foreignDef.forEach(el => {
|
||||
if (listForeignDefinitions.length) {
|
||||
@@ -2015,7 +2097,7 @@ function loadPreview(info) {
|
||||
})
|
||||
}
|
||||
|
||||
if (foreignSyn) {
|
||||
if (foreignSyn.length) {
|
||||
listForeignSynonyms.forEach(el => (el.textContent = ''))
|
||||
foreignSyn.forEach(el => {
|
||||
if (listForeignSynonyms.length) {
|
||||
@@ -2038,7 +2120,7 @@ function loadPreview(info) {
|
||||
|
||||
const languageContainers = document.querySelectorAll('.preview-one-language')
|
||||
const langLine = document.querySelector('.start-line')
|
||||
if (languageContainers) {
|
||||
if (languageContainers.length) {
|
||||
const arrLang = Array.from(languageContainers)
|
||||
arrLang.forEach(el => {
|
||||
const arrChildren = Array.from(el.children)
|
||||
@@ -2046,12 +2128,14 @@ function loadPreview(info) {
|
||||
el.classList.add('d-none')
|
||||
} else el.classList.remove('d-none')
|
||||
})
|
||||
if (
|
||||
arrLang.filter(el => el.classList.contains('d-none')).length >=
|
||||
arrLang.length
|
||||
) {
|
||||
langLine.classList.add('d-none')
|
||||
} else langLine.classList.remove('d-none')
|
||||
if (langLine) {
|
||||
if (
|
||||
arrLang.filter(el => el.classList.contains('d-none')).length >=
|
||||
arrLang.length
|
||||
) {
|
||||
langLine.classList.add('d-none')
|
||||
} else langLine.classList.remove('d-none')
|
||||
}
|
||||
}
|
||||
changeCollapsedContent()
|
||||
}
|
||||
@@ -2080,11 +2164,6 @@ function changeVersionList(versions) {
|
||||
el.remove()
|
||||
}
|
||||
})
|
||||
const localeOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
}
|
||||
if (versions.length) {
|
||||
versions
|
||||
.slice()
|
||||
@@ -2100,11 +2179,7 @@ function changeVersionList(versions) {
|
||||
dateLabel.dataset.bsPlacement = 'bottom'
|
||||
dateLabel.dataset.bsToggle = 'tooltip'
|
||||
dateLabel.dataset.bsHtml = 'true'
|
||||
const date = new Date(el.version_time).toLocaleDateString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
)
|
||||
dateLabel.textContent = date
|
||||
dateLabel.textContent = DateUtils.formatDate(el.version_time)
|
||||
dateRadio.id = `date${el.version}`
|
||||
dateRadio.value = `${el.version}`
|
||||
dateLabel.htmlFor = `date${el.version}`
|
||||
@@ -2150,15 +2225,14 @@ function setLatestVersion(data) {
|
||||
}
|
||||
|
||||
function removeOldMedia(images, audio, video) {
|
||||
if (images !== null || audio !== null || video !== null) {
|
||||
const media = [images, audio, video]
|
||||
media.forEach(el => {
|
||||
const arrChildren = Array.from(el.childNodes)
|
||||
arrChildren.forEach(el => {
|
||||
el.remove()
|
||||
})
|
||||
const media = [images, audio, video]
|
||||
media.forEach(el => {
|
||||
if (!el) return
|
||||
const arrChildren = Array.from(el.childNodes)
|
||||
arrChildren.forEach(el => {
|
||||
el.remove()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function changeClasses(el, elClass) {
|
||||
@@ -2199,14 +2273,9 @@ function letsScroll(btn) {
|
||||
}
|
||||
}
|
||||
|
||||
function showSelectedDateData(date) {
|
||||
function showSelectedDateData() {
|
||||
const { btnSaveIcon } = window.dictionaryElements
|
||||
|
||||
// classicOverview.classList.add('d-none')
|
||||
// selectedOverview.classList.remove('d-none')
|
||||
btnSaveIcon.firstChild.src = '/images/u_redo.svg'
|
||||
btnSaveIcon.children[1].textContent = i18next.t('Obnovi')
|
||||
btnSaveIcon.id = 'redo-action'
|
||||
btnSaveIcon.textContent = i18next.t('Obnovi')
|
||||
}
|
||||
|
||||
function indeterminateTheBox(checkbox) {
|
||||
@@ -2615,6 +2684,7 @@ function handleAreasClick({ target }) {
|
||||
type: 'addArea'
|
||||
}
|
||||
domainLabelsForChange(data)
|
||||
updateDomainLabelsButtonState()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2746,6 +2816,7 @@ function abortEditing(btnGrp, oldButtons, areaEl) {
|
||||
areaEl.style.display = 'table-cell'
|
||||
const visibilityEl = getRow.querySelector('.form-check')
|
||||
visibilityEl.disabled = true
|
||||
updateDomainLabelsButtonState()
|
||||
}
|
||||
|
||||
function saveChanges(btnGrp, inputArea, oldButtons, tDataArea) {
|
||||
@@ -2774,6 +2845,7 @@ function saveChanges(btnGrp, inputArea, oldButtons, tDataArea) {
|
||||
domainLabelsForChange(changed)
|
||||
}
|
||||
visibilityEl.disabled = true
|
||||
updateDomainLabelsButtonState()
|
||||
}
|
||||
|
||||
function initDomainLabelsForChange() {
|
||||
@@ -2787,6 +2859,18 @@ function initDomainLabelsForChange() {
|
||||
|
||||
const domainLabelsForChange = initDomainLabelsForChange()
|
||||
|
||||
// domainLabelsForChange tracks add/edit/delete of a row separately from the
|
||||
// form's own fields (added rows have no submittable inputs of their own),
|
||||
// so dirty-checking here needs both: the form itself, and this queue.
|
||||
function updateDomainLabelsButtonState() {
|
||||
const { domainLabelsForm } = window.dictionaryElements
|
||||
if (isFormDirty(domainLabelsForm) || domainLabelsForChange().length > 0) {
|
||||
enableButton()
|
||||
} else {
|
||||
disableButton()
|
||||
}
|
||||
}
|
||||
|
||||
function initTempCounter() {
|
||||
let counter = 0
|
||||
return function (el) {
|
||||
@@ -2810,14 +2894,16 @@ function deleteContentData(
|
||||
) {
|
||||
const addedFields = document.querySelectorAll('.added-field')
|
||||
if (addedFields.length) addedFields.forEach(el => el.remove())
|
||||
if (domainLabels) domainLabels.val(null).trigger('change')
|
||||
if (domainLabels) domainLabels.empty().trigger('change')
|
||||
if (synonym) synonym.val(null).trigger('change')
|
||||
if (synonym) synonym.empty().trigger('change')
|
||||
if (listForeignTerms) $('.foreign-term-el').val(null).trigger('change')
|
||||
if (listForeignTerms) $('.foreign-term-el').empty().trigger('change')
|
||||
if (listForeignSynonyms) $('.foreign-synonym-el').val(null).trigger('change')
|
||||
if (listForeignSynonyms) $('.foreign-synonym-el').empty().trigger('change')
|
||||
if (domainLabels.length) domainLabels.val(null).trigger('change')
|
||||
if (domainLabels.length) domainLabels.empty().trigger('change')
|
||||
if (synonym.length) synonym.val(null).trigger('change')
|
||||
if (synonym.length) synonym.empty().trigger('change')
|
||||
if (listForeignTerms.length) $('.foreign-term-el').val(null).trigger('change')
|
||||
if (listForeignTerms.length) $('.foreign-term-el').empty().trigger('change')
|
||||
if (listForeignSynonyms.length)
|
||||
$('.foreign-synonym-el').val(null).trigger('change')
|
||||
if (listForeignSynonyms.length)
|
||||
$('.foreign-synonym-el').empty().trigger('change')
|
||||
if (images) images.value = ''
|
||||
if (audio) audio.value = ''
|
||||
if (video) video.value = ''
|
||||
@@ -2827,7 +2913,7 @@ function deleteContentData(
|
||||
linkType.value = 'related'
|
||||
linkText.value = ''
|
||||
}
|
||||
if (listForeignDefinitions) {
|
||||
if (listForeignDefinitions.length) {
|
||||
const foreignDefinitionsFields = document.querySelectorAll(
|
||||
'.foreign-definition-el'
|
||||
)
|
||||
@@ -2923,8 +3009,10 @@ $('.summernote').summernote({
|
||||
function updateAcceptedFileTypes() {
|
||||
const { fileImportForm, fileUploadInput } = window.dictionaryElements
|
||||
|
||||
const selectedFileFormat = fileImportForm.importFileFormat.value
|
||||
fileUploadInput.accept = `.${selectedFileFormat}`
|
||||
const selectedFileFormatRadio = fileImportForm.querySelector(
|
||||
'input[name="importFileFormat"]:checked'
|
||||
)
|
||||
fileUploadInput.accept = `.${selectedFileFormatRadio.dataset.extension}`
|
||||
}
|
||||
|
||||
// Activate BS5 tooltips
|
||||
|
||||
Reference in New Issue
Block a user