CJVT updates August and September 2026
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* global $, axios, bootstrap, currentPagePath, initPagination, removeAllChildNodes, unsavedData, replaceContainer, isI18nReady, i18next, validator */
|
||||
/* global $, axios, bootstrap, currentPagePath, initPagination, removeAllChildNodes, unsavedData, replaceContainer, isI18nReady, i18next, validator, enableButton, disableButton, captureFormBaseline, isFormDirty, updateSaveButtonState, warnOnNameCollisionThenSubmit */
|
||||
|
||||
// const currentPagePath = location.pathname
|
||||
|
||||
@@ -113,11 +113,9 @@ function initAdmin() {
|
||||
|
||||
if (currentPagePath === '/admin/uporabniki/portal') {
|
||||
ce.formAddUser = document.getElementById('form-add-user')
|
||||
const userTable = document.getElementById('user-roles-table')
|
||||
const tableForm = document.getElementById('form-user-roles')
|
||||
userTable.addEventListener('change', enableButton)
|
||||
tableForm.addEventListener('input', () => updateSaveButtonState(tableForm))
|
||||
ce.formAddUser.addEventListener('submit', addUser)
|
||||
ce.formAddUser.addEventListener('input', enableButton)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(tableForm, dictSideMenu)
|
||||
async function addUser(event) {
|
||||
@@ -204,83 +202,7 @@ function initAdmin() {
|
||||
})
|
||||
}
|
||||
|
||||
if (currentPagePath === '/admin/slovarji') {
|
||||
const resultsListEl = document.getElementById('page-results')
|
||||
|
||||
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/listAllDictionaries?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 td5 = document.createElement('td')
|
||||
const td6 = document.createElement('td')
|
||||
const aEl = document.createElement('a')
|
||||
const imgEl = document.createElement('img')
|
||||
const spanEl = document.createElement('span')
|
||||
td1.textContent = result.id
|
||||
td2.textContent = result.name
|
||||
td3.textContent = result.status
|
||||
const timeCreated = new Date(result.timeCreated).toLocaleDateString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
)
|
||||
td4.textContent = timeCreated
|
||||
const timeModified = new Date(result.timeModified).toLocaleDateString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
)
|
||||
td5.textContent = timeModified
|
||||
aEl.classList.add('image-link')
|
||||
aEl.type = 'link'
|
||||
aEl.href = `/admin/slovarji/${result.id}/podatki`
|
||||
imgEl.src = '/images/u_edit-alt.svg'
|
||||
imgEl.alt = i18next.t('Uredi')
|
||||
spanEl.className = 'normal-gray ms-1'
|
||||
spanEl.textContent = i18next.t('Uredi')
|
||||
td6.append(aEl)
|
||||
aEl.append(imgEl, spanEl)
|
||||
rowEl.append(td1, td2, td3, td4, td5, td6)
|
||||
resultsListEl.appendChild(rowEl)
|
||||
})
|
||||
}
|
||||
}
|
||||
// /admin/slovarji sorting/pagination logic lives in dictionary-list-table.js.
|
||||
|
||||
if (
|
||||
/\/admin\/slovarji\/\d+\/podatki/.test(currentPagePath) ||
|
||||
@@ -291,24 +213,32 @@ function initAdmin() {
|
||||
const inputNewAuthorEl = document.getElementById('input-new-author')
|
||||
const inputNewAreaEl = document.getElementById('input-new-area')
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
$('.without-addition').on('change', enableButton)
|
||||
$('.without-addition').on('change', () => updateSaveButtonState(formEl))
|
||||
unsavedData(formEl, dictSideMenu)
|
||||
formEl.addEventListener('input', enableButton)
|
||||
formEl.addEventListener('input', () => updateSaveButtonState(formEl))
|
||||
if (imgTrashIcon !== null) {
|
||||
imgTrashIcon.forEach(el => el.addEventListener('click', deleteInput))
|
||||
}
|
||||
inputNewAuthorEl.addEventListener('click', () => {
|
||||
createNewAuthorInput(formEl)
|
||||
updateSaveButtonState(formEl)
|
||||
})
|
||||
inputNewAreaEl.addEventListener('click', () => {
|
||||
createNewAreaInput(formEl)
|
||||
updateSaveButtonState(formEl)
|
||||
})
|
||||
formEl.addEventListener('submit', event => {
|
||||
checkform()
|
||||
// checkform() // Stray call left over from consultancy pages' #select-cerif; this form has no such element.
|
||||
if (!event.target.checkValidity()) {
|
||||
event.preventDefault()
|
||||
event.target.classList.add('was-validated')
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
event.target.classList.add('was-validated')
|
||||
warnOnNameCollisionThenSubmit(event.target, {
|
||||
excludeDictionaryId: document.getElementById('dictionary-id').value
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -322,13 +252,11 @@ function initAdmin() {
|
||||
ce.domainLabelsForm = document.getElementById('dictionary-domain-labels')
|
||||
ce.domainLabelsForm.addEventListener('submit', secondaryDomainsToDb)
|
||||
const formAreas = document.getElementById('dictionary-domain-labels')
|
||||
formAreas.addEventListener('input', enableButton)
|
||||
formAreas.addEventListener('input', updateSecondaryDomainsButtonState)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(formAreas, dictSideMenu, secondaryDomainsToDb)
|
||||
const addAreaButtons = document.getElementById('add-area')
|
||||
addAreaButtons.addEventListener('click', enableButton)
|
||||
const useBtn = document.getElementById('modal-use-btn')
|
||||
useBtn.addEventListener('click', enableButton)
|
||||
useBtn.addEventListener('click', updateSecondaryDomainsButtonState)
|
||||
|
||||
async function secondaryDomainsToDb(event) {
|
||||
const data = secondaryDomainsForChange()
|
||||
@@ -423,9 +351,10 @@ function initAdmin() {
|
||||
ce.terminologyReviewCb = document.getElementById('terminology_review')
|
||||
ce.languageReviewCb = document.getElementById('language_review')
|
||||
ce.formDictUsers = document.getElementById('admin-dictionary-users')
|
||||
ce.formDictUsers.addEventListener('input', enableButton)
|
||||
ce.formDictUsers.addEventListener('input', () =>
|
||||
updateSaveButtonState(ce.formDictUsers)
|
||||
)
|
||||
ce.formAddUser = document.getElementById('form-add-user')
|
||||
ce.formAddUser.addEventListener('input', enableButton)
|
||||
ce.formAddUser.addEventListener('submit', addUser)
|
||||
checkUserRightsCb()
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
@@ -436,8 +365,6 @@ function initAdmin() {
|
||||
const arrAdminEls = Array.from(adminEl)
|
||||
arrAdminEls.forEach(el => el.addEventListener('click', () => countAdmins()))
|
||||
countAdmins()
|
||||
const publishSwitch = document.getElementById('publish-switch')
|
||||
publishSwitch.addEventListener('input', enableButton)
|
||||
|
||||
async function addUser(event) {
|
||||
event.preventDefault()
|
||||
@@ -457,19 +384,26 @@ function initAdmin() {
|
||||
|
||||
if (/\/admin\/uporabniki\/\d+\/urejanje/.test(currentPagePath)) {
|
||||
const formEditUser = document.getElementById('form-edit-user')
|
||||
formEditUser.addEventListener('input', enableButton)
|
||||
captureFormBaseline(formEditUser)
|
||||
formEditUser.addEventListener('input', () =>
|
||||
updateSaveButtonState(formEditUser)
|
||||
)
|
||||
}
|
||||
|
||||
if (currentPagePath === '/admin/nastavitve/portal') {
|
||||
const formAdminPortal = document.getElementById('admin-portal-settings')
|
||||
formAdminPortal.addEventListener('input', enableButton)
|
||||
formAdminPortal.addEventListener('input', () =>
|
||||
updateSaveButtonState(formAdminPortal)
|
||||
)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(formAdminPortal, dictSideMenu)
|
||||
}
|
||||
|
||||
if (currentPagePath === '/admin/nastavitve/slovarji') {
|
||||
const formAdminPortal = document.getElementById('admin-settings-dict')
|
||||
formAdminPortal.addEventListener('input', enableButton)
|
||||
formAdminPortal.addEventListener('input', () =>
|
||||
updateSaveButtonState(formAdminPortal)
|
||||
)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(formAdminPortal, dictSideMenu)
|
||||
}
|
||||
@@ -479,7 +413,9 @@ function initAdmin() {
|
||||
const { offsetMain } = window.adminElements
|
||||
offsetMain.addEventListener('click', handleClick)
|
||||
const formAdminPortal = document.getElementById('admin-settings-consult')
|
||||
formAdminPortal.addEventListener('input', enableButton)
|
||||
formAdminPortal.addEventListener('input', () =>
|
||||
updateSaveButtonState(formAdminPortal)
|
||||
)
|
||||
const dictSideMenu = document.querySelector('.admin-nav-content')
|
||||
unsavedData(formAdminPortal, dictSideMenu)
|
||||
}
|
||||
@@ -687,21 +623,17 @@ function checkConsultancyBtns() {
|
||||
|
||||
function deleteInput({ target }) {
|
||||
const element = target.closest('.added-field')
|
||||
const form = element.closest('form')
|
||||
const alertModal = new bootstrap.Modal(document.getElementById('alert-modal'))
|
||||
alertModal.toggle()
|
||||
const modalUseBtn = document.getElementById('modal-use-btn')
|
||||
modalUseBtn.addEventListener('click', () => {
|
||||
element.remove()
|
||||
alertModal.hide()
|
||||
enableButton()
|
||||
updateSaveButtonState(form)
|
||||
})
|
||||
}
|
||||
|
||||
function enableButton() {
|
||||
const disabledBtn = document.getElementById('disabled-submit-btn')
|
||||
disabledBtn.disabled = false
|
||||
}
|
||||
|
||||
function handleAreasClick({ target }) {
|
||||
const editRow = target.closest('.edit-row-btn')
|
||||
const deleteRow = target.closest('.delete-row-btn')
|
||||
@@ -717,11 +649,12 @@ function handleAreasClick({ target }) {
|
||||
}
|
||||
}
|
||||
if (deleteUserRow) {
|
||||
enableButton()
|
||||
const getRow = deleteUserRow.parentElement.parentElement
|
||||
const form = getRow.closest('form')
|
||||
const modalUseBtn = document.getElementById('modal-use-btn')
|
||||
modalUseBtn.addEventListener('click', () => {
|
||||
getRow.remove()
|
||||
updateSaveButtonState(form)
|
||||
})
|
||||
}
|
||||
if (deleteRow) {
|
||||
@@ -832,6 +765,7 @@ function handleAreasClick({ target }) {
|
||||
type: 'addArea'
|
||||
}
|
||||
secondaryDomainsForChange(data)
|
||||
updateSecondaryDomainsButtonState()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -875,6 +809,7 @@ function saveChanges(
|
||||
secondaryDomainsForChange(changed)
|
||||
}
|
||||
visibilityEl.disabled = true
|
||||
updateSecondaryDomainsButtonState()
|
||||
}
|
||||
|
||||
function initSecondaryDomainsForChange() {
|
||||
@@ -888,6 +823,18 @@ function initSecondaryDomainsForChange() {
|
||||
|
||||
const secondaryDomainsForChange = initSecondaryDomainsForChange()
|
||||
|
||||
// secondaryDomainsForChange 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 updateSecondaryDomainsButtonState() {
|
||||
const { domainLabelsForm } = window.adminElements
|
||||
if (isFormDirty(domainLabelsForm) || secondaryDomainsForChange().length > 0) {
|
||||
enableButton()
|
||||
} else {
|
||||
disableButton()
|
||||
}
|
||||
}
|
||||
|
||||
function initTempCounter() {
|
||||
let counter = 0
|
||||
return function (el) {
|
||||
@@ -919,6 +866,7 @@ function abortEditing(btnGrp, oldButtons, areaEl, translationEl) {
|
||||
translationEl.style.display = 'table-cell'
|
||||
const visibilityEl = getRow.querySelector('.form-check')
|
||||
visibilityEl.disabled = true
|
||||
updateSecondaryDomainsButtonState()
|
||||
}
|
||||
|
||||
function mobileMoveContent() {
|
||||
@@ -1188,8 +1136,9 @@ $('.summernote').summernote({
|
||||
const profileForm = document.getElementById('profileForm')
|
||||
|
||||
if (profileForm) {
|
||||
profileForm.addEventListener('input', e => {
|
||||
enableButton()
|
||||
captureFormBaseline(profileForm)
|
||||
profileForm.addEventListener('input', () => {
|
||||
updateSaveButtonState(profileForm)
|
||||
})
|
||||
|
||||
profileForm.addEventListener('submit', async e => {
|
||||
@@ -1216,7 +1165,11 @@ $('.summernote').summernote({
|
||||
return
|
||||
}
|
||||
|
||||
if (data.passwordOld && data.passwordNew && data.passwordNewRepeat) {
|
||||
if (data.passwordNew && data.passwordNewRepeat) {
|
||||
// passwordOld is intentionally not required here (it may legitimately be blank, e.g.
|
||||
// for an SSO-only account with no local password) - the server tells the user exactly
|
||||
// why it rejected the change (wrong old password, or no local password to change at
|
||||
// all), which is more useful than a generic "fill in all fields" notice.
|
||||
await handleUpdatePassword(data)
|
||||
} else if (location.pathname === '/spremeni-geslo') {
|
||||
// if missing the required data on endpoint /spremeni-geslo, notify!
|
||||
|
||||
Reference in New Issue
Block a user