Huge change, removed Status class and all "alert" messages are now shown as BS toast() and are via the DB and handled async in the F/E in jscript via Ajax. Fixed BUG-113 where toasts() were repeating. Removed many of the explicit alert messages (other than errors) and hooked {New|Finish}Job to consistently send messages to the F/E. Other messages (F/E without a job, like save settings) now use this model as well. Finally converted most of the older POST responses to formal json
This commit is contained in:
@@ -1,30 +1,31 @@
|
||||
// global
|
||||
var next_toast_id=1
|
||||
|
||||
function NewToast(data)
|
||||
{
|
||||
console.log(data)
|
||||
// make new div, include data.alert as background colour, and data.message as toast body
|
||||
d_id='st' + String(next_toast_id)
|
||||
// toast "id" is based on msg_id, for any persistent/long-lived msg's we will try to reshow them
|
||||
// dont bother, if it already exists it is visible, just move on
|
||||
d_id='st' + String(data.id)
|
||||
if( $('#'+d_id).length !== 0 )
|
||||
return
|
||||
// make new div, include data.level as background colour, and data.message as toast body
|
||||
div='<div id="' + d_id + '"'
|
||||
if( data.persistent === true )
|
||||
div+=' data-bs-autohide="false"'
|
||||
if( data.job_id !== undefined )
|
||||
div+=' job_id=' + String(data.job_id)
|
||||
div +=' class="toast hide align-items-center border-0'
|
||||
if( data.alert == "success" || data.alert == "danger" )
|
||||
if( data.level == "success" || data.level == "danger" )
|
||||
div += ' text-white'
|
||||
div += ' bg-' + data.alert
|
||||
div += `" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
div += ' bg-' + data.level + '" '
|
||||
if( data.level == "success" )
|
||||
div += 'data-bs-delay="2000" '
|
||||
div += `role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
<font size="1.5em">
|
||||
`
|
||||
div += data.message
|
||||
div += ' </div>'
|
||||
div += ' </font></div>'
|
||||
if( data.cant_close !== true )
|
||||
{
|
||||
div += ' <button type="button" class="btn-close me-2 m-auto'
|
||||
if( data.alert === "success" || data.alert === "danger" )
|
||||
if( data.level === "success" || data.level === "danger" )
|
||||
div += ' btn-close-white'
|
||||
div += ' " data-bs-dismiss="toast" aria-label="Close"></button>'
|
||||
}
|
||||
@@ -35,9 +36,6 @@ function NewToast(data)
|
||||
// insert this as the first element in the status_container
|
||||
$('#status_container').prepend(div)
|
||||
|
||||
// make sure we have a new id for next toast
|
||||
next_toast_id++
|
||||
|
||||
return d_id
|
||||
}
|
||||
|
||||
@@ -45,20 +43,13 @@ function NewToast(data)
|
||||
// can reuse any that are hidden, OR, create a new one by appending as needed (so we can have 2+ toasts on screen)
|
||||
function StatusMsg(st)
|
||||
{
|
||||
console.log('StatusMsg' + st )
|
||||
el=NewToast(st)
|
||||
$('#' + el ).toast("show")
|
||||
// if there is a job_id, then clear the message for it or it will be picked up again on reload
|
||||
// BUT, we dont want to do this immediately, should hook on close, but for
|
||||
// now, we will do this to get a first pass working
|
||||
if( st.job_id !== undefined )
|
||||
{
|
||||
console.log( 'set hidden.bs.toast handler for: ' + st.job_id )
|
||||
$('#' + el).on( 'hidden.bs.toast',
|
||||
function() {
|
||||
$.ajax( { type: 'POST', url: '/clearmsgforjob/'+st.job_id, success: function(data) { console.log('cleared job id' )} } )
|
||||
} )
|
||||
}
|
||||
// clear message only when toast is hidden (either timeout OR user clicks close btn)
|
||||
$('#' + el).on( 'hidden.bs.toast',
|
||||
function() {
|
||||
$.ajax( { type: 'POST', url: '/clearmsg/'+st.id, success: function(data) {} } )
|
||||
} )
|
||||
}
|
||||
|
||||
// this will make the active jobs badge red with a > 0 value, or navbar colours
|
||||
|
||||
Reference in New Issue
Block a user