Added toastr for notifications (with legacy support for the HTML alerts)
This commit is contained in:
parent
76eec051d3
commit
a015c74c47
|
@ -18,6 +18,7 @@
|
|||
"jquery": "~2.1.0",
|
||||
"vegas": "~1.3.4",
|
||||
"jquery-pjax": "~1.8.1",
|
||||
"nprogress": "~0.1.3"
|
||||
"nprogress": "~0.1.3",
|
||||
"toastr": "~2.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ module.exports = (grunt) ->
|
|||
"static_components/js/icheck.min.js",
|
||||
"static_components/js/jquery-pjax.js",
|
||||
"static_components/js/nprogress.js",
|
||||
"static_components/js/toastr.js",
|
||||
"shelfzilla/themes/bootflat/static/js/main.full.js",
|
||||
]
|
||||
dest: "shelfzilla/themes/bootflat/static/js/site.js"
|
||||
|
@ -62,6 +63,7 @@ module.exports = (grunt) ->
|
|||
"static_components/css/bootstrap.min.css",
|
||||
"static_components/css/bootflat.min.css",
|
||||
"static_components/css/nprogress.css",
|
||||
"static_components/css/toastr.css",
|
||||
]
|
||||
dest: "shelfzilla/themes/bootflat/static/css/style.css"
|
||||
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
NProgress.start()
|
||||
|
||||
window._updateMessages = false
|
||||
window.updateMessages = ->
|
||||
window.updateMessagesHtml = ->
|
||||
$.pjax
|
||||
url: '/messages/'
|
||||
container: '[data-pjax-container="messages"]'
|
||||
push: false
|
||||
window._updateMessages = false
|
||||
|
||||
window.updateMessages = ->
|
||||
$.getJSON "/messages/?format=json", (data) ->
|
||||
for message in data
|
||||
toastr[message.extra_tags](message.message)
|
||||
window._updateMessages = false
|
||||
|
||||
# Document ready
|
||||
$ ->
|
||||
NProgress.inc(0.3)
|
||||
# Background
|
||||
|
@ -40,6 +47,9 @@ $ ->
|
|||
if elem.is('[pjax-messages]')
|
||||
window._updateMessages = true
|
||||
|
||||
# Update messages
|
||||
window.updateMessages()
|
||||
|
||||
# Tooltips
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import json
|
||||
from django.views.generic import View as DjangoView
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponse
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
class View(DjangoView):
|
||||
|
@ -17,7 +20,29 @@ class View(DjangoView):
|
|||
|
||||
class MessagesView(View):
|
||||
template = 'contrib/messages.html'
|
||||
formats = ['html', 'json']
|
||||
|
||||
def get(self, request):
|
||||
ctx = RequestContext(request, {})
|
||||
return render_to_response(self.template, context_instance=ctx)
|
||||
format = 'html'
|
||||
if 'format' in request.GET and request.GET['format'] in self.formats:
|
||||
format = request.GET['format']
|
||||
|
||||
if format == 'html':
|
||||
ctx = RequestContext(request, {})
|
||||
result = render_to_response(self.template, context_instance=ctx)
|
||||
elif format == 'json':
|
||||
messages_json = []
|
||||
for message in messages.get_messages(request):
|
||||
messages_json.append(
|
||||
{
|
||||
"level": message.level,
|
||||
"message": message.message,
|
||||
"extra_tags": message.tags,
|
||||
}
|
||||
)
|
||||
result = HttpResponse(
|
||||
json.dumps(messages_json),
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
return result
|
||||
|
|
Reference in New Issue