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!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// TODO Remove no-console ignore rule once things are out of rapid dev phase.
|
||||
/* eslint no-console: 0 */
|
||||
/* global axios, initPagination, i18next */
|
||||
/* global axios, initPagination, i18next, DateUtils */
|
||||
const pageURL = location.pathname
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
@@ -10,9 +10,12 @@ window.addEventListener('load', () => {
|
||||
function initComments() {
|
||||
const ce = {}
|
||||
window.commentElements = ce
|
||||
ce.updatePager = initPagination('pagination', onPageChange)
|
||||
ce.commentsCountEl = document.getElementById('comments-count')
|
||||
ce.commentsContainerEl = document.getElementById('comments-container')
|
||||
if (!ce.commentsContainerEl) {
|
||||
return
|
||||
}
|
||||
ce.updatePager = initPagination('pagination', onCommentsPageChange)
|
||||
ce.commentForm = document.getElementById('comment-form')
|
||||
ce.commentReplyForm = document.getElementById('comment-reply-form')
|
||||
ce.commentMessageInput = document.getElementById('comment-message-input')
|
||||
@@ -37,15 +40,6 @@ function initComments() {
|
||||
ce.commentReplyInput.addEventListener('input', autoGrow)
|
||||
// ce.commentMessageInput.addEventListener('keydown', normalizeTextAreaSize)
|
||||
|
||||
window.commentSetting = {}
|
||||
window.commentSetting.localeOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}
|
||||
|
||||
if (ce.commentMessageInput && ce.commentReplyInput) {
|
||||
ce.commentMessageInput.originalHeight = window.getComputedStyle(
|
||||
ce.commentMessageInput
|
||||
@@ -154,7 +148,6 @@ function renderCommentCount(commentCount) {
|
||||
|
||||
function appendComment(comment) {
|
||||
const { commentsContainerEl, commentDiv } = window.commentElements
|
||||
const { localeOptions } = window.commentSetting
|
||||
|
||||
const {
|
||||
message,
|
||||
@@ -164,9 +157,7 @@ function appendComment(comment) {
|
||||
quote
|
||||
} = comment
|
||||
|
||||
let tstamp = new Date(timeCreated).toLocaleTimeString('sl-SL', localeOptions)
|
||||
|
||||
tstamp = `• ${tstamp}`
|
||||
const tstamp = `• ${DateUtils.formatDateTime(timeCreated)}`
|
||||
const divText = document.createElement('div')
|
||||
const divTextComment = document.createElement('div')
|
||||
const divRow = document.createElement('div')
|
||||
@@ -230,12 +221,7 @@ function appendComment(comment) {
|
||||
timeCreated
|
||||
} = quote
|
||||
|
||||
let tstamp = new Date(timeCreated).toLocaleTimeString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
)
|
||||
|
||||
tstamp = `• ${tstamp}`
|
||||
const tstamp = `• ${DateUtils.formatDateTime(timeCreated)}`
|
||||
|
||||
const quoteText = document.createElement('div')
|
||||
const imgQuotemarks = document.createElement('img')
|
||||
@@ -411,7 +397,6 @@ function prepareReplyForm(repliedCommentData) {
|
||||
window.scrollTo(0, document.body.scrollHeight)
|
||||
const { commentForm, commentReplyForm, commentQuoteId, replyFormContainer } =
|
||||
window.commentElements
|
||||
const { localeOptions } = window.commentSetting
|
||||
|
||||
commentQuoteId.value = quoteId
|
||||
|
||||
@@ -439,12 +424,7 @@ function prepareReplyForm(repliedCommentData) {
|
||||
quoteAuthorLastNameEl.textContent = quoteAuthorLastName
|
||||
quotePreview.appendChild(quoteAuthorLastNameEl)
|
||||
|
||||
let tstamp = new Date(quotetimeCreated).toLocaleTimeString(
|
||||
'sl-SL',
|
||||
localeOptions
|
||||
)
|
||||
|
||||
tstamp = `• ${tstamp}`
|
||||
const tstamp = `• ${DateUtils.formatDateTime(quotetimeCreated)}`
|
||||
const quotetimeCreatedEl = document.createElement('p')
|
||||
quotetimeCreatedEl.className = 'comment-quote-time-created'
|
||||
quotetimeCreatedEl.textContent = tstamp
|
||||
@@ -569,10 +549,10 @@ function checkButton(type) {
|
||||
}
|
||||
|
||||
async function changeEntryCommentSection() {
|
||||
await onPageChange()
|
||||
await onCommentsPageChange()
|
||||
}
|
||||
|
||||
async function onPageChange(newPage) {
|
||||
async function onCommentsPageChange(newPage) {
|
||||
const { updatePager } = window.commentElements
|
||||
try {
|
||||
let { page, numberOfAllPages } = await displayComments(newPage)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* global $, bootstrap, handleDomainsClickForConsultancy, initPagination, inputFieldsChecker, currentPagePath,
|
||||
axios, nthParent, tooltipListWOL, tooltipTriggerList, removeAllChildNodes, i18next */
|
||||
axios, nthParent, tooltipListWOL, tooltipTriggerList, removeAllChildNodes, i18next, DateUtils */
|
||||
|
||||
/*
|
||||
author: Miha Stele, 2022
|
||||
@@ -463,10 +463,14 @@ const initialPage = +new URL(location).searchParams.get('p') || 1
|
||||
|
||||
let updatePager
|
||||
try {
|
||||
updatePager = initPagination('pagination', onPageChange, initialPage)
|
||||
updatePager = initPagination(
|
||||
'pagination',
|
||||
onConsultancyEntriesPageChange,
|
||||
initialPage
|
||||
)
|
||||
} catch (e) {}
|
||||
|
||||
async function onPageChange(newPage) {
|
||||
async function onConsultancyEntriesPageChange(newPage) {
|
||||
const receivedPageNumber = await changePage(newPage)
|
||||
updateUrlAndHistory(receivedPageNumber)
|
||||
}
|
||||
@@ -541,6 +545,7 @@ function renderResults(resultsMarkup) {
|
||||
const wrapper = document.createElement('div')
|
||||
wrapper.innerHTML = resultsMarkup
|
||||
resultsListEl.appendChild(wrapper)
|
||||
DateUtils.applyTimestamps(wrapper)
|
||||
}
|
||||
|
||||
function updateUrlAndHistory(page) {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
const dateLocaleByLang = {
|
||||
sl: 'sl-SI',
|
||||
en: 'en-GB'
|
||||
}
|
||||
|
||||
const dateOnlyOptions = { day: '2-digit', month: '2-digit', year: 'numeric' }
|
||||
const timeOnlyOptions = { hour: '2-digit', minute: '2-digit' }
|
||||
const dateTimeOptions = { ...dateOnlyOptions, ...timeOnlyOptions }
|
||||
|
||||
function getDateLocale() {
|
||||
const lang = document.documentElement.lang || 'sl'
|
||||
return dateLocaleByLang[lang] || dateLocaleByLang.sl
|
||||
}
|
||||
|
||||
function toDateOrNull(value) {
|
||||
const date = value instanceof Date ? value : new Date(value)
|
||||
return isNaN(date.getTime()) ? null : date
|
||||
}
|
||||
|
||||
function formatDate(value) {
|
||||
const date = toDateOrNull(value)
|
||||
return date ? date.toLocaleDateString(getDateLocale(), dateOnlyOptions) : ''
|
||||
}
|
||||
|
||||
function formatTime(value) {
|
||||
const date = toDateOrNull(value)
|
||||
return date ? date.toLocaleTimeString(getDateLocale(), timeOnlyOptions) : ''
|
||||
}
|
||||
|
||||
function formatDateTime(value) {
|
||||
const date = toDateOrNull(value)
|
||||
return date ? date.toLocaleString(getDateLocale(), dateTimeOptions) : ''
|
||||
}
|
||||
|
||||
// Scans `root` (defaults to the whole document) for elements carrying a
|
||||
// data-timestamp attribute and fills them in using the browser's own
|
||||
// timezone. Call this again after injecting server-rendered HTML fragments
|
||||
// (e.g. AJAX-paginated results), since it only runs automatically once on
|
||||
// page load.
|
||||
function applyTimestamps(root) {
|
||||
const scope = root || document
|
||||
scope.querySelectorAll('[data-timestamp]').forEach(el => {
|
||||
const date = toDateOrNull(el.getAttribute('data-timestamp'))
|
||||
if (!date) return
|
||||
|
||||
const datePart = el.querySelector('[data-timestamp-part="date"]')
|
||||
const timePart = el.querySelector('[data-timestamp-part="time"]')
|
||||
|
||||
if (datePart || timePart) {
|
||||
if (datePart) datePart.textContent = formatDate(date)
|
||||
if (timePart) timePart.textContent = formatTime(date)
|
||||
} else if (el.getAttribute('data-timestamp-format') === 'date') {
|
||||
el.textContent = formatDate(date)
|
||||
} else {
|
||||
el.textContent = formatDateTime(date)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
window.DateUtils = {
|
||||
formatDate,
|
||||
formatTime,
|
||||
formatDateTime,
|
||||
applyTimestamps
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => applyTimestamps())
|
||||
@@ -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
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/* globals axios, i18next */
|
||||
|
||||
const exportForm = document.forms['dictionary-export']
|
||||
|
||||
exportForm.addEventListener('submit', async event => {
|
||||
event.preventDefault()
|
||||
|
||||
const payload = Object.fromEntries(new FormData(event.target))
|
||||
|
||||
try {
|
||||
await axios.post(event.target.action, payload)
|
||||
// TODO This (page refresh) is a temporary hack. Replace with proper UI updating logic.
|
||||
location.reload()
|
||||
} 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.')
|
||||
}
|
||||
|
||||
alert(message)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,291 @@
|
||||
/* global $, axios, i18next, isI18nReady, initSelect2, initPagination, removeAllChildNodes, currentPagePath, DateUtils, bindKeys, setVisibleAdvancedSearch */
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
/* global isAdvancedSearchButtonPressedOddTimes:writable */
|
||||
|
||||
// Sorting, pagination, searching and filtering shared by /admin/slovarji and /ogled-virov.
|
||||
const PAGE_CONFIG = {
|
||||
'/admin/slovarji': {
|
||||
apiUrl: '/api/v1/dictionaries/listAllDictionaries',
|
||||
rowActionHref: id => `/admin/slovarji/${id}/podatki`,
|
||||
rowActionIcon: '/images/u_edit-alt.svg',
|
||||
rowActionLabelKey: 'Uredi'
|
||||
},
|
||||
'/ogled-virov': {
|
||||
apiUrl: '/api/v1/dictionaries/listAllViewableDictionaries',
|
||||
rowActionHref: id => `/ogled-virov/${id}/podatki`,
|
||||
rowActionIcon: '/images/eye.svg',
|
||||
rowActionLabelKey: 'Podatki'
|
||||
}
|
||||
}
|
||||
|
||||
const pageConfig = PAGE_CONFIG[currentPagePath]
|
||||
|
||||
if (pageConfig) {
|
||||
;(function () {
|
||||
const SORT_COLUMNS = [
|
||||
'id',
|
||||
'name',
|
||||
'status',
|
||||
'timeCreated',
|
||||
'timeModified'
|
||||
]
|
||||
|
||||
const resultsListEl = document.getElementById('page-results')
|
||||
const headerButtons = {
|
||||
id: document.getElementById('sortById'),
|
||||
name: document.getElementById('sortByName'),
|
||||
status: document.getElementById('sortByStatus'),
|
||||
timeCreated: document.getElementById('sortByTimeCreated'),
|
||||
timeModified: document.getElementById('sortByTimeModified')
|
||||
}
|
||||
const headerIcons = {
|
||||
id: document.getElementById('idImg'),
|
||||
name: document.getElementById('nameImg'),
|
||||
status: document.getElementById('statusImg'),
|
||||
timeCreated: document.getElementById('timeCreatedImg'),
|
||||
timeModified: document.getElementById('timeModifiedImg')
|
||||
}
|
||||
|
||||
const searchInput = document.getElementById('dict-name-search')
|
||||
const searchBtn = document.getElementById('search-dictionaries')
|
||||
const applyFiltersBtn = document.getElementById('apply-filters')
|
||||
const clearFiltersBtn = document.getElementById('clear-filters')
|
||||
|
||||
const initialParams = new URL(location).searchParams
|
||||
let currentPage = +initialParams.get('p') > 0 ? +initialParams.get('p') : 1
|
||||
let sortBy = SORT_COLUMNS.includes(initialParams.get('sort'))
|
||||
? initialParams.get('sort')
|
||||
: 'id'
|
||||
let sortDir = initialParams.get('dir') === 'asc' ? 'asc' : 'desc'
|
||||
let nameQuery = initialParams.get('q') || ''
|
||||
let primaryDomainIds = initialParams.getAll('pd')
|
||||
let secondaryDomainIds = initialParams.getAll('sd')
|
||||
let languageIds = initialParams.getAll('lang')
|
||||
let statuses = initialParams.getAll('status')
|
||||
let latestRequestId = 0
|
||||
|
||||
const updatePager = initPagination('pagination', onPageChange, currentPage)
|
||||
|
||||
bindSortHeaderListeners()
|
||||
bindFilterListeners()
|
||||
initFilterSelect2()
|
||||
bindKeys('#dict-name-search')
|
||||
if (
|
||||
primaryDomainIds.length ||
|
||||
secondaryDomainIds.length ||
|
||||
languageIds.length ||
|
||||
statuses.length
|
||||
) {
|
||||
// scripts.js unconditionally force-closes the panel on every page load
|
||||
// (setVisibleAdvancedSearch(false), run once #advanced-search exists),
|
||||
// which would otherwise override the server-rendered "open" state from
|
||||
// the Pug `class` condition on #admin-dict-filter-panel. Explicitly
|
||||
// reopen it here (this file loads after scripts.js) and keep the
|
||||
// shared open/close counter in sync so the *next* click closes it.
|
||||
isAdvancedSearchButtonPressedOddTimes = true
|
||||
setVisibleAdvancedSearch(true)
|
||||
}
|
||||
window.addEventListener('popstate', onPopState)
|
||||
|
||||
function bindSortHeaderListeners() {
|
||||
SORT_COLUMNS.forEach(column => {
|
||||
headerButtons[column].addEventListener('click', () =>
|
||||
onSortClick(column)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function onSortClick(column) {
|
||||
if (sortBy === column) {
|
||||
sortDir = sortDir === 'asc' ? 'desc' : 'asc'
|
||||
} else {
|
||||
sortBy = column
|
||||
sortDir = 'asc'
|
||||
}
|
||||
currentPage = 1
|
||||
updateSortIndicators()
|
||||
await fetchAndRender()
|
||||
}
|
||||
|
||||
function updateSortIndicators() {
|
||||
SORT_COLUMNS.forEach(column => {
|
||||
const icon = headerIcons[column]
|
||||
if (column === sortBy) {
|
||||
icon.classList.remove('invisible')
|
||||
icon.src =
|
||||
sortDir === 'asc'
|
||||
? '/images/arrow_drop_up.svg'
|
||||
: '/images/arrow_drop_down.svg'
|
||||
} else {
|
||||
icon.classList.add('invisible')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function onPageChange(newPage) {
|
||||
currentPage = newPage
|
||||
await fetchAndRender()
|
||||
}
|
||||
|
||||
function initFilterSelect2() {
|
||||
isI18nReady.then(t => {
|
||||
initSelect2('.select-admin-domain-primary', t('Področje'))
|
||||
initSelect2('.select-admin-domain-secondary', t('Podpodročje'))
|
||||
initSelect2('.select-admin-language', t('Jezik'))
|
||||
initSelect2('.select-admin-status', t('Status'))
|
||||
})
|
||||
}
|
||||
|
||||
function bindFilterListeners() {
|
||||
// Opening/closing #admin-dict-filter-panel itself is handled globally
|
||||
// by scripts.js (initAdvancedSearch('#advanced-search')), since the
|
||||
// panel reuses the #advanced-search id and .advanced-search-root class
|
||||
// from /slovarji's advanced-search dropdown.
|
||||
searchBtn.addEventListener('click', onApplyFilters)
|
||||
searchInput.addEventListener('keydown', event => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault()
|
||||
onApplyFilters()
|
||||
}
|
||||
})
|
||||
applyFiltersBtn.addEventListener('click', onApplyFilters)
|
||||
clearFiltersBtn.addEventListener('click', onClearFilters)
|
||||
}
|
||||
|
||||
async function onApplyFilters() {
|
||||
nameQuery = searchInput.value.trim()
|
||||
primaryDomainIds = $('#filter-domain-primary').val() || []
|
||||
secondaryDomainIds = $('#filter-domain-secondary').val() || []
|
||||
languageIds = $('#filter-language').val() || []
|
||||
statuses = $('#filter-status').val() || []
|
||||
currentPage = 1
|
||||
await fetchAndRender()
|
||||
}
|
||||
|
||||
async function onClearFilters() {
|
||||
nameQuery = ''
|
||||
primaryDomainIds = []
|
||||
secondaryDomainIds = []
|
||||
languageIds = []
|
||||
statuses = []
|
||||
syncFilterControls()
|
||||
currentPage = 1
|
||||
await fetchAndRender()
|
||||
}
|
||||
|
||||
function syncFilterControls() {
|
||||
searchInput.value = nameQuery
|
||||
$('#filter-domain-primary').val(primaryDomainIds).trigger('change')
|
||||
$('#filter-domain-secondary').val(secondaryDomainIds).trigger('change')
|
||||
$('#filter-language').val(languageIds).trigger('change')
|
||||
$('#filter-status').val(statuses).trigger('change')
|
||||
}
|
||||
|
||||
async function fetchAndRender(updateHistory = true) {
|
||||
// Guards against out-of-order responses: if a newer request has been
|
||||
// issued (e.g. rapid sort-click then back-navigation) by the time this
|
||||
// one resolves, its response is stale and must not overwrite the UI.
|
||||
const requestId = ++latestRequestId
|
||||
try {
|
||||
const { page, numberOfAllPages, results } = await getData(
|
||||
currentPage
|
||||
)
|
||||
if (requestId !== latestRequestId) return
|
||||
currentPage = page
|
||||
removeAllChildNodes(resultsListEl)
|
||||
renderResults(results)
|
||||
updatePager(page, numberOfAllPages)
|
||||
if (updateHistory) updateUrlAndHistory()
|
||||
} catch (error) {
|
||||
if (requestId !== latestRequestId) return
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
function buildQueryParams(page) {
|
||||
const params = new URLSearchParams()
|
||||
params.set('p', page)
|
||||
params.set('sort', sortBy)
|
||||
params.set('dir', sortDir)
|
||||
if (nameQuery) params.set('q', nameQuery)
|
||||
primaryDomainIds.forEach(id => params.append('pd', id))
|
||||
secondaryDomainIds.forEach(id => params.append('sd', id))
|
||||
languageIds.forEach(id => params.append('lang', id))
|
||||
statuses.forEach(value => params.append('status', value))
|
||||
return params
|
||||
}
|
||||
|
||||
async function getData(page) {
|
||||
const url = `${pageConfig.apiUrl}?${buildQueryParams(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')
|
||||
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 = statusLabel(result.status)
|
||||
td4.textContent = DateUtils.formatDateTime(result.timeCreated)
|
||||
td5.textContent = DateUtils.formatDateTime(result.timeModified)
|
||||
aEl.classList.add('image-link')
|
||||
aEl.type = 'link'
|
||||
aEl.href = pageConfig.rowActionHref(result.id)
|
||||
imgEl.src = pageConfig.rowActionIcon
|
||||
imgEl.alt = i18next.t(pageConfig.rowActionLabelKey)
|
||||
spanEl.className = 'normal-gray ms-1'
|
||||
spanEl.textContent = i18next.t(pageConfig.rowActionLabelKey)
|
||||
td6.append(aEl)
|
||||
aEl.append(imgEl, spanEl)
|
||||
rowEl.append(td1, td2, td3, td4, td5, td6)
|
||||
resultsListEl.appendChild(rowEl)
|
||||
})
|
||||
}
|
||||
|
||||
function statusLabel(status) {
|
||||
if (status === 'closed') return i18next.t('zaprt')
|
||||
if (status === 'reviewed') return i18next.t('v predogledu')
|
||||
return i18next.t('odprt')
|
||||
}
|
||||
|
||||
function updateUrlAndHistory() {
|
||||
const newUrl = new URL(location)
|
||||
newUrl.search = buildQueryParams(currentPage).toString()
|
||||
history.pushState(null, '', newUrl)
|
||||
}
|
||||
|
||||
function onPopState() {
|
||||
const params = new URL(location).searchParams
|
||||
currentPage = +params.get('p') > 0 ? +params.get('p') : 1
|
||||
sortBy = SORT_COLUMNS.includes(params.get('sort'))
|
||||
? params.get('sort')
|
||||
: 'id'
|
||||
sortDir = params.get('dir') === 'asc' ? 'asc' : 'desc'
|
||||
nameQuery = params.get('q') || ''
|
||||
primaryDomainIds = params.getAll('pd')
|
||||
secondaryDomainIds = params.getAll('sd')
|
||||
languageIds = params.getAll('lang')
|
||||
statuses = params.getAll('status')
|
||||
updateSortIndicators()
|
||||
syncFilterControls()
|
||||
fetchAndRender(false)
|
||||
}
|
||||
})()
|
||||
}
|
||||
@@ -1,7 +1,22 @@
|
||||
/* global captureFormBaseline, isFormDirty */
|
||||
|
||||
const nameForm = document.getElementById('extraction-name')
|
||||
captureFormBaseline(nameForm)
|
||||
|
||||
const nameEl = document.getElementById('name')
|
||||
nameEl.addEventListener('input', enableButton)
|
||||
nameEl.addEventListener('input', updateButtonState)
|
||||
|
||||
function updateButtonState() {
|
||||
if (isFormDirty(nameForm)) enableButton()
|
||||
else disableButton()
|
||||
}
|
||||
|
||||
function enableButton() {
|
||||
const disabledBtn = document.getElementById('mpbtn')
|
||||
disabledBtn.classList.remove('disabled')
|
||||
}
|
||||
|
||||
function disableButton() {
|
||||
const disabledBtn = document.getElementById('mpbtn')
|
||||
disabledBtn.classList.add('disabled')
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* global axios, removeAllChildNodes, bootstrap, i18next */
|
||||
/* global axios, removeAllChildNodes, bootstrap, i18next, DateUtils */
|
||||
|
||||
const fileUploadContainerEl = document.getElementById('upload-files-container')
|
||||
const fileUploadForm = document.forms['upload-files']
|
||||
@@ -180,10 +180,7 @@ function updateFileListEl(fileListEl, { status, fileStats, index }) {
|
||||
sizeEl.textContent = fileStats.size
|
||||
|
||||
const dateEl = fileListEl.querySelector('.file-date-modified')
|
||||
const formattedDate = new Date(fileStats.timeModified).toLocaleDateString(
|
||||
'sl-SL'
|
||||
)
|
||||
dateEl.textContent = formattedDate
|
||||
dateEl.textContent = DateUtils.formatDate(fileStats.timeModified)
|
||||
|
||||
const successImgEl = document.createElement('img')
|
||||
successImgEl.src = '/images/valid.svg'
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/* global $, axios, bootstrap, i18next */
|
||||
/* global $, axios, bootstrap, i18next, exactTagMatcher */
|
||||
|
||||
$('.pick-multiple').select2()
|
||||
$('.enter-multiple').select2({
|
||||
tags: true
|
||||
tags: true,
|
||||
matcher: exactTagMatcher
|
||||
})
|
||||
|
||||
const editStopTermsLink = document.getElementById('edit-stop-terms')
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Clears the fixed #offset-padding header out of the way of the page content
|
||||
// below it, for pages with no side menu (mirrors the same logic each
|
||||
// page-specific script - admin.js, dictionaries.js, help.js, etc. - already
|
||||
// duplicates for its own page).
|
||||
|
||||
window.addEventListener('load', adjustOffsetBy)
|
||||
window.addEventListener('resize', adjustOffsetBy)
|
||||
|
||||
function adjustOffsetBy() {
|
||||
const fixedTopSection = document.getElementById('fixed-top-section')
|
||||
const offsetMain = document.getElementById('offset-main')
|
||||
const offsetHeaderPadding = document.getElementById('offset-padding')
|
||||
if (!fixedTopSection || !offsetMain) return
|
||||
|
||||
if (document.body.clientWidth < 1200) {
|
||||
if (offsetHeaderPadding !== null) offsetMain.style.paddingTop = `0px`
|
||||
} else if (offsetHeaderPadding !== null) {
|
||||
const referenceHeight = fixedTopSection.offsetHeight
|
||||
const offsetHeaderHeight = offsetHeaderPadding.offsetHeight
|
||||
offsetMain.style.paddingTop = `${referenceHeight + offsetHeaderHeight}px`
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/* global axios, i18next */
|
||||
|
||||
function displayError(errorElementId, 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.')
|
||||
}
|
||||
|
||||
const errorElement = document.querySelector(`#${errorElementId}`)
|
||||
errorElement.textContent = message
|
||||
errorElement.style.visibility = 'visible'
|
||||
}
|
||||
|
||||
function bindAjaxForm(formId, errorElementId) {
|
||||
const form = document.querySelector(`#${formId}`)
|
||||
if (!form) return
|
||||
|
||||
form.addEventListener('submit', async event => {
|
||||
event.preventDefault()
|
||||
|
||||
const data = {}
|
||||
new FormData(form).forEach((value, key) => {
|
||||
data[key] = value
|
||||
})
|
||||
|
||||
try {
|
||||
await axios.post(form.action, data)
|
||||
window.location = '/'
|
||||
} catch (error) {
|
||||
displayError(errorElementId, error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
bindAjaxForm('create-profile-form', 'create-profile-error')
|
||||
bindAjaxForm('convert-account-form', 'convert-account-error')
|
||||
@@ -1,9 +1,4 @@
|
||||
// Note to myself: please optimize and remove the redundacy of the code written in multiple classes to achieve the same result as this
|
||||
|
||||
const focusOnCompletePromtBase = queryInput => {
|
||||
queryInput.focus()
|
||||
queryInput.select()
|
||||
}
|
||||
/* global focusOnCompletePromtBase */
|
||||
|
||||
// Tradeoff: Declare a variable for the element to reduce duplication?
|
||||
const inputQuery = document.querySelector('#search-query')
|
||||
|
||||
@@ -898,14 +898,47 @@ if (registerSwithcButton) {
|
||||
}
|
||||
|
||||
{
|
||||
let unsaved = false
|
||||
const formBaselines = new WeakMap()
|
||||
|
||||
function serializeFormState(form) {
|
||||
return new URLSearchParams(new FormData(form)).toString()
|
||||
}
|
||||
|
||||
function captureFormBaseline(form) {
|
||||
formBaselines.set(form, serializeFormState(form))
|
||||
}
|
||||
|
||||
function isFormDirty(form) {
|
||||
const baseline = formBaselines.get(form)
|
||||
if (baseline == null) return false
|
||||
return serializeFormState(form) !== baseline
|
||||
}
|
||||
|
||||
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 updateSaveButtonState(form) {
|
||||
if (isFormDirty(form)) enableButton()
|
||||
else disableButton()
|
||||
}
|
||||
|
||||
function unsavedData(form, sideMenu, ajaxFunction) {
|
||||
form.addEventListener('input', () => {
|
||||
unsaved = true
|
||||
})
|
||||
$('.without-addition').on('change.select2', () => {
|
||||
unsaved = true
|
||||
})
|
||||
captureFormBaseline(form)
|
||||
sideMenu.addEventListener('click', () =>
|
||||
handleMenuClick(form, event, ajaxFunction)
|
||||
)
|
||||
@@ -914,7 +947,7 @@ if (registerSwithcButton) {
|
||||
/* SELECT 2 */
|
||||
|
||||
function evaluateAlerModalTarget(pf, form, ajaxFunction) {
|
||||
if (unsaved) {
|
||||
if (isFormDirty(form)) {
|
||||
event.preventDefault()
|
||||
openUnsavedMixin(form, pf, ajaxFunction)
|
||||
}
|
||||
@@ -950,8 +983,64 @@ if (registerSwithcButton) {
|
||||
)
|
||||
}
|
||||
|
||||
function warnOnNameCollisionThenSubmit(form, { excludeDictionaryId } = {}) {
|
||||
const fieldNames = ['nameSl', 'nameSlShort', 'nameEn']
|
||||
const params = {}
|
||||
let anyChanged = false
|
||||
|
||||
fieldNames.forEach(name => {
|
||||
const input = form.querySelector(`[name="${name}"]`)
|
||||
if (!input) return
|
||||
const changed = input.value !== input.defaultValue
|
||||
if (changed) anyChanged = true
|
||||
if (input.value && (!excludeDictionaryId || changed)) {
|
||||
params[name] = input.value
|
||||
}
|
||||
})
|
||||
|
||||
if (excludeDictionaryId && !anyChanged) {
|
||||
form.submit()
|
||||
return
|
||||
}
|
||||
if (excludeDictionaryId) params.excludeDictionaryId = excludeDictionaryId
|
||||
|
||||
axios
|
||||
.get('/api/v1/dictionaries/check-name-collision', { params })
|
||||
.then(({ data }) => {
|
||||
if (!data.collision) {
|
||||
form.submit()
|
||||
return
|
||||
}
|
||||
const modal = new bootstrap.Modal(
|
||||
document.getElementById('name-collision-warning')
|
||||
)
|
||||
modal.show()
|
||||
const acceptBtnId = excludeDictionaryId
|
||||
? 'modal-rename-btn'
|
||||
: 'modal-create-btn'
|
||||
document
|
||||
.getElementById(acceptBtnId)
|
||||
.addEventListener('click', () => form.submit(), { once: true })
|
||||
})
|
||||
}
|
||||
|
||||
/* SELECT 2 */
|
||||
|
||||
// select2's default matcher does substring + diacritic-insensitive comparison,
|
||||
// which blocks entering tags like "scar" after "scarf" or "gloš" after "glos".
|
||||
// Use exact comparison instead for free-text tag fields.
|
||||
function exactTagMatcher(params, data) {
|
||||
if ($.trim(params.term) === '') {
|
||||
return data
|
||||
}
|
||||
|
||||
if (typeof data.text === 'undefined') {
|
||||
return null
|
||||
}
|
||||
|
||||
return data.text.toUpperCase() === params.term.toUpperCase() ? data : null
|
||||
}
|
||||
|
||||
function initSelect2(querySelector, placeholder) {
|
||||
$(querySelector).select2({
|
||||
// allowClear: true,
|
||||
@@ -1042,7 +1131,8 @@ if (registerSwithcButton) {
|
||||
|
||||
$('.multiple').select2({
|
||||
minimumResultsForSearch: Infinity,
|
||||
tags: true
|
||||
tags: true,
|
||||
matcher: exactTagMatcher
|
||||
})
|
||||
|
||||
$('.without-addition').select2({
|
||||
@@ -1065,7 +1155,8 @@ if (registerSwithcButton) {
|
||||
$('.without-dropdown').select2({
|
||||
minimumResultsForSearch: Infinity,
|
||||
tags: true,
|
||||
dropdownCssClass: 'hide-dropdown'
|
||||
dropdownCssClass: 'hide-dropdown',
|
||||
matcher: exactTagMatcher
|
||||
})
|
||||
} catch (e) {
|
||||
// console.log(e)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/* global axios, bootstrap */
|
||||
|
||||
const contactAuthorsForm = document.querySelector('#contact-authors-form')
|
||||
|
||||
if (contactAuthorsForm) {
|
||||
contactAuthorsForm.addEventListener('submit', async event => {
|
||||
event.preventDefault()
|
||||
if (!contactAuthorsForm.checkValidity()) {
|
||||
event.stopPropagation()
|
||||
contactAuthorsForm.classList.add('was-validated')
|
||||
return
|
||||
}
|
||||
|
||||
const payload = Object.fromEntries(new FormData(event.target))
|
||||
const res = await axios.post(event.target.action, payload)
|
||||
|
||||
if (res.status === 201) {
|
||||
contactAuthorsForm.reset()
|
||||
contactAuthorsForm.classList.remove('was-validated')
|
||||
|
||||
const infoModal = document.getElementById('contact-authors-response')
|
||||
if (infoModal) {
|
||||
const responseModal = new bootstrap.Modal(infoModal)
|
||||
responseModal.toggle()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user