7

I am trying to get a Bootstrap Notify alert to remain visible until the user dismisses it, without it auto-closing. To do this, according to my understanding of the documentation, I set the delay setting to 0. This is my JS file that is included after bootstrap-notify.js:

$(function () {
    var alertTemplate = $("#notify-template").html();
    $.notifyDefaults({ target: "_self" }, { type: "warning", delay: 0, template: alertTemplate });
});

var toasterNotify = function (alertTitle, alertMessage, alertUrl) {
    alertUrl = alertUrl || "#";
    $.notify({ title: alertTitle, message: alertMessage, url: alertUrl }, { delay: 0 });
}

This toasterNotify function works exactly as expected when I call it directly from a click event on a button in the view, but when it's called from a SignalR callback from the server, as below, the alert closes almost instantly as soon as it appears:

var hubProxy = $.connection.applicationHub;
hubProxy.client.alertNewClaim = function (model) {
    toasterNotify(model.SourceFullName, model.Message);
};

EDIT:

I have figured out that the controller action involved pushes the SignalR message to the client just before returning a view result. So the client immediately receives the SignalR message and displays the alert, only to have the page refreshed by the returned view, removing the alert quickly. I still have no idea yet how to work around this.

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • tr to reproduce the error somewhere where we can see and debug it . or if your page is live then provide a link – J Santosh Oct 09 '15 at 10:41
  • "pushes the SignalR message to the client just before returning a view result" << don't return the view / refresh the page. The current page's JS can't (reasonably) do anything if the page is refreshed. Sounds like the `SingnalR` message can contain a URL (if it's different from the current one) - send that from your server to `toasterNotify` as 3rd param. Once the user clicks the modal, they will go to that URL (I believe - based on the docs I read here: http://bootstrap-notify.remabledesigns.com/). Don't go to `#` though - that won't reload your view - use the documents current location. – pherris Oct 09 '15 at 15:59
  • I think what your trying to accomplish can only be done with a single page app - I assume your using a multi page .NET MVC app where in between actions the complete page is refreshed. Can you inject the JS server side in some sort of view, why does it need to come from `signalR` – Marty Oct 09 '15 at 16:14

1 Answers1

0

My hacky workaround for this has been to en-queue the message to the DB before sending it, on the controller side, then have the client query for messages not marked as 'dismissed' on every page load. So, the user will see the message on every page they visit, forever, until they click the 'close' button on the message, which results in a request being sent to a Messaging controller to mark that message as 'dismissed'.

ProfK
  • 49,207
  • 121
  • 399
  • 775