نمایش بلادرنگ اعلامی به تمام کاربران در هنگام درج یک رکورد جدید به صورت notification
نویسنده: سیروان عفیفی
تاریخ: ۱۳۹۳/۱۰/۱۲ ۱۳:۴۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
PM> Install-Package toastr
toastr.info("نمایش یک پیام - info");
toastr.success("نمایش یک پیام - success");
toastr.error("نمایش یک پیام - error");
toastr.warning("نمایش یک پیام - warning");
toastr.success("نمایش یک پیام - success", "عنوان"); toastr.options = {
tapToDismiss: true,
toastClass: 'toast',
containerId: 'toast-container',
debug: false,
showMethod: 'fadeIn', //fadeIn, slideDown, and show are built into jQuery
showDuration: 300,
showEasing: 'swing', //swing and linear are built into jQuery
onShown: undefined,
hideMethod: 'fadeOut',
hideDuration: 1000,
hideEasing: 'swing',
onHidden: undefined,
extendedTimeOut: 1000,
iconClasses: {
error: 'toast-error',
info: 'toast-info',
success: 'toast-success',
warning: 'toast-warning'
},
iconClass: 'toast-info',
positionClass: 'toast-top-right',
timeOut: 5000, // Set timeOut and extendedTimeOut to 0 to make it sticky
titleClass: 'toast-title',
messageClass: 'toast-message',
target: 'body',
closeHtml: '<button>×</button>',
newestOnTop: true,
preventDuplicates: false,
progressBar: false
}; public class NotificationHub : Hub
{
private readonly IProductService _productService;
public NotificationHub(IProductService productService)
{
_productService = productService;
}
public void SendNotification()
{
Clients.Others.ShowNotification(_productService.GetLastProduct());
}
} var notify = $.connection.notificationHub;
notify.client.showNotification = function (data) {
toastr.info("رکورد جدیدی ثبت گردید جهت نمایش اینجا کلیک کنید");
};
$.connection.hub.start().done(function () {
@{
if (ViewBag.NotifyUsers)
{
<text>notify.server.sendNotification();</text>
}
}
}); var positionClasses = {
topRight: 'toast-top-right',
bottomRight: 'toast-bottom-right',
bottomLeft: 'toast-bottom-left',
topLeft: 'toast-top-left',
topCenter: 'toast-top-center',
bottomCenter: 'toast-bottom-center'
};
var notify = $.connection.notificationHub;
notify.client.showNotification = function (data) {
toastr.options = {
showDuration: 300,
positionClass: positionClasses.bottomRight,
onclick: function () {
$('#table tr:last').after("<tr>" +
"<td>" + data.Title + "</td>" +
"<td>" + data.Description + "</td>" +
"<td>" + data.Price + "</td>" +
"<td>" + data.Category + "</td>" +
"<td> </td>" +
"</tr>");
}
};
toastr.info("رکورد جدیدی ثبت گردید جهت نمایش اینجا کلیک کنید");
};
$.connection.hub.start().done(function () {
@{
if (ViewBag.NotifyUsers)
{
<text>notify.server.sendNotification();</text>
}
}
}); onclick: function () {
$('#table tr:last').after("<tr>" +
"<td>" + data.Title + "</td>" +
"<td>" + data.Description + "</td>" +
"<td>" + data.Price + "</td>" +
"<td>" + data.Category + "</td>" +
"<td> </td>" +
"</tr>");
} data {Id: 12, Title: "Item1", Description: "Des", Price: 100000, Category: 0}