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