Extend updateStatusIcon() to set title too

All calls to updateStatusIcon() were followed by setting the title.
This commit is contained in:
Simon Rozman 2024-05-08 13:15:10 +02:00
parent d6e823ed7a
commit d15348ed50

View File

@ -73,9 +73,7 @@ class BesService {
* @param {Node} node DOM root node to proof
*/
proof(node) {
this.updateStatusIcon('bes-status-loading')
this.statusDiv.title = 'BesService je v procesu preverjanja pravopisa.'
this.updateStatusIcon('bes-status-loading', 'BesService je v procesu preverjanja pravopisa.')
this.recursiveProof(node)
// TODO: Check count in 'makrofinančno' case.
@ -83,13 +81,10 @@ class BesService {
(total, child) => total + child.matches.length,
0
)
if (count > 0) {
this.updateStatusIcon('bes-status-mistakes')
this.statusDiv.title = 'Število napak: ' + count
} else {
this.updateStatusIcon('bes-status-success')
this.statusDiv.title = 'V besedilu ni napak.'
}
if (count > 0)
this.updateStatusIcon('bes-status-mistakes', 'Število napak: ' + count)
else
this.updateStatusIcon('bes-status-success', 'V besedilu ni napak.')
}
/**
@ -136,8 +131,7 @@ class BesService {
await fetch(request, { signal })
.then(response => {
if (!response.ok) {
this.updateStatusIcon('bes-status-error')
this.statusDiv.title = 'Napaka pri preverjanju pravopisa.'
this.updateStatusIcon('bes-status-error', 'Napaka pri preverjanju pravopisa.')
throw new Error('Backend server response was not OK')
}
return response.json()
@ -196,8 +190,7 @@ class BesService {
})
.catch(error => {
if (error.name === 'AbortError') return
this.updateStatusIcon('bes-status-error')
this.statusDiv.title = 'Napaka pri preverjanju pravopisa.'
this.updateStatusIcon('bes-status-error', 'Napaka pri preverjanju pravopisa.')
throw new Error(
'Parsing backend server response failed: ' + error
)
@ -410,7 +403,13 @@ class BesService {
return { clientRects, highlights }
}
updateStatusIcon(status) {
/**
* Sets status icon style and title
*
* @param {String} status CSS class name to set status icon to
* @param {String} title Title of the status icon
*/
updateStatusIcon(status, title) {
const statuses = [
'bes-status-loading',
'bes-status-success',
@ -421,6 +420,7 @@ class BesService {
this.statusIcon.classList.remove(statusClass)
})
this.statusIcon.classList.add(status)
this.statusDiv.title = title
}
handleStatusClick(e, popup) {