CJVT updates August and September 2026
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user