Skip to content

Instantly share code, notes, and snippets.

@sharvit
Last active March 8, 2018 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharvit/f18336eab8e46795dac09e1380a9611c to your computer and use it in GitHub Desktop.
Save sharvit/f18336eab8e46795dac09e1380a9611c to your computer and use it in GitHub Desktop.
Foreman toast-notifications readme

Toast Notifications

Types

['error', 'warning', 'success', 'info']
// deprecated-types
['notice']

Create notification from the server

Available in all application-controllers

error "This is an error message"
warning "This is a warning message"
success "This is a success message"
info "This is an info message"

# deprecated!!! will use success type
notice "This is n notice message"

Create notification from the server with Action

error "This is an error message", link: { text: 'action', href: 'https://theforeman.org' }
warning "This is a warning message", link: { text: 'action', href: 'https://theforeman.org' }
success "This is a success message", link: { text: 'action', href: 'https://theforeman.org' }
info "This is an info message", link: { text: 'action', href: 'https://theforeman.org' }

From the client

// getting the API object in the browser
window.tfm.toastNotifications

Clear

Clear all the toast notifications from the view

window.tfm.toastNotifications.clear();

Notify

Creates a toast notification

Simple toasts

window.tfm.toastNotifications.notify({
  message: 'This is an error message',
  type: 'error',
})
window.tfm.toastNotifications.notify({
  message: 'This is a warning message',
  type: 'warning',
})
window.tfm.toastNotifications.notify({
  message: 'This is a success message',
  type: 'success',
})
window.tfm.toastNotifications.notify({
  message: 'This is an info message',
  type: 'info',
})

Override the default sticky behavior

window.tfm.toastNotifications.notify({
  message: 'This is an error message',
  type: 'error',
  sticky: false,
})
window.tfm.toastNotifications.notify({
  message: 'This is a warning message',
  type: 'warning',
  sticky: false,
})
window.tfm.toastNotifications.notify({
  message: 'This is a success message',
  type: 'success',
  sticky: true,
})
window.tfm.toastNotifications.notify({
  message: 'This is an info message',
  type: 'info',
  sticky: true,
})

Use Actions

window.tfm.toastNotifications.notify({
  message: 'This is an error message',
  type: 'error',
  link: { children: 'Click to fix!', href: 'https://theforeman.org' }
})
window.tfm.toastNotifications.notify({
  message: 'This is a warning message',
  type: 'warning',
  link: { children: 'Read more', href: 'https://theforeman.org' }
})
window.tfm.toastNotifications.notify({
  message: 'This is a success message',
  type: 'success',
  link: { children: 'Undo', href: 'https://theforeman.org' }
})
window.tfm.toastNotifications.notify({
  message: 'This is an info message',
  type: 'info',
  link: { children: 'Redo', href: 'https://theforeman.org' }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment