Project

General

Profile

« Previous | Next » 

Revision 68cd4bba

Added by matanw about 7 years ago

fixes #14178 - Introduce patternfly toast notifications

View differences:

webpack/assets/javascripts/foreman_toast_notifications.js
import store from '../javascripts/react_app/redux';
import $ from 'jquery';
// to accommodate jnotify syntax
export function notify(message, type, sticky) {
let toast = {
message
};
if (type) {
toast.type = type;
}
if (sticky) {
toast.sticky = sticky;
}
showToast(toast);
}
function showToast(toast) {
store.dispatch(ToastActions.addToast(toast));
const isSticky = type => ['notice', 'success', 'info'].indexOf(type) === -1;
export function notify({message, type, link, sticky = isSticky(type)}) {
store.dispatch(ToastActions.addToast({
message,
type,
sticky,
link
}));
}
// to accommodate rails flash syntax
function importFlashMessagesFromRails() {
const notifications = $('#notifications').data().flash;
notifications.forEach(([type, message]) => {
// normalize rails flash names
if (type === 'danger') {
type = 'error';
}
showToast({
type,
message,
sticky: (type !== 'success')
});
$('#notifications').data().flash.forEach(([type, message]) => {
notify({message, type});
});
}
// load notifications from Rails on ContentLoad
$(document).on('ContentLoad', function () {
// to accommodate rails flash syntax
$(document).on('ContentLoad', () => {
store.dispatch(ToastActions.clearToasts());
importFlashMessagesFromRails();
});

Also available in: Unified diff