cda1904f5a784ef6a94ee2ad8cfbcc3c0d0d4bef chmalee Fri May 19 11:23:11 2023 -0700 Temporary commit generalizing the notification box diff --git src/hg/js/utils.js src/hg/js/utils.js index 85cf92e..26a8296 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -783,37 +783,73 @@ var sectionBegin = "'nonce-"; var sectionEnd = "'"; var ix = content.indexOf(sectionBegin); if (ix < 0) return ""; content = content.substring(ix+sectionBegin.length); ix = content.indexOf(sectionEnd); if (ix < 0) return ""; content = content.substring(0,ix); if (debug) alert('page nonce='+content); return content; } -function notifBoxShow() { +function notifBoxShow(cgiName, keyName) { /* move the notification bar div under '#TrackHeaderForm' */ - var notifEl = document.getElementById("notifBox"); + let lsKey = cgiName + "." + keyName; + var notifEl = document.getElementById(lsKey + "notifBox"); + // TODO: make a generic element for positioning this var parentEl = document.getElementById('TrackHeaderForm'); parentEl.appendChild(notifEl); notifEl.style.display = 'block'; - //document.getElementById('notifOK').onclick = notifBoxHide; +} + +function notifBoxSetup(cgiName, keyName, msg) { +/* Create a notification box if one hasn't been created, and + * add msg to the list of shown notifications. + * cgiName.keyName will be saved to localStorage in order to show + * or hide this notification. + * Must call notifBoxShow() in order to display the notification */ +// the key to save into localStorage +lsKey = cgiName + "." + keyName; +let notifBox = document.getElementById(lsKey+"notifBox"); +if (notifBox) { + notifBox.innerHTML += "<br>" + msg; +} else { + let newDiv = document.createElement("div"); + newDiv.style.display = "none"; + newDiv.style.width = "90%"; + newDiv.style.marginLeft = "100px"; + newDiv.id = lsKey+"notifBox"; + if (msg) { + newDiv.innerHTML = msg; + } + newDiv.innerHTML += "<div style='text-align:center'>"+ + "<button id='" + lsKey + "notifyHide'>Close</button> "+ + "<button id='" + lsKey + "notifyHideForever'>Don't show again</button>"+ + "</div>"; + document.body.appendChild(newDiv); + $("#"+lsKey+"notifyHide").click( function() { + $("#notifBox").remove(); + }); + $("#"+lsKey+"notifyHideForever").click( function() { + $("#notifBox").remove(); + localStorage.setItem("hgTracks.hideSpeedNotification", "1"); + }); + } } function warnBoxJsSetup() { // Sets up warnBox if not already established. This is duplicated from htmshell.c var html = ""; html += "<center>"; html += "<div id='warnBox' style='display:none;'>"; html += "<CENTER><B id='warnHead'></B></CENTER>"; html += "<UL id='warnList'></UL>"; html += "<CENTER><button id='warnOK'></button></CENTER>"; html += "</div></center>"; // GALT TODO either add nonce or move the showWarnBox and hideWarnBox to some universal javascript // file that is always included. Or consider if we can just dynamically define the functions