Add periodic AJAX workers to update the value of the notifications link.
Signed-off-by: Eric Riggs <ericriggs42@gmail.com>
This commit is contained in:
committed by
Roberto Rosario
parent
5704c21d56
commit
5b3285c006
@@ -27,6 +27,7 @@ Next (2018-XX-XX)
|
||||
- Remove the unused scrollable_content internal feature.
|
||||
- Remove unused animate.css package.
|
||||
- Add page loading indicator.
|
||||
- Add periodic AJAX workers to update the value of the notifications link.
|
||||
|
||||
2.8 (2018-02-27)
|
||||
================
|
||||
|
||||
@@ -15,6 +15,7 @@ jQuery(document).ready(function() {
|
||||
var afterBaseLoad = function () {
|
||||
MayanImage.intialize();
|
||||
app.doToastrMessages();
|
||||
app.setupAJAXperiodicWorkers();
|
||||
app.setupAutoSubmit();
|
||||
app.setupItemsSelector();
|
||||
app.setupNewWindowAnchor();
|
||||
|
||||
@@ -52,6 +52,35 @@ App.tagResultTemplate = function (tag) {
|
||||
|
||||
// Instance methods
|
||||
|
||||
App.prototype.AJAXperiodicWorker = function (options) {
|
||||
var app = this;
|
||||
|
||||
$.ajax({
|
||||
complete: function() {
|
||||
setTimeout(app.AJAXperiodicWorker, options.interval, options);
|
||||
},
|
||||
success: function(data) {
|
||||
options.element.text(data[options.attributeName]);
|
||||
},
|
||||
url: options.APIURL
|
||||
});
|
||||
}
|
||||
|
||||
App.prototype.setupAJAXperiodicWorkers = function () {
|
||||
var app = this;
|
||||
|
||||
$('a[data-apw-url]').each(function() {
|
||||
var $this = $(this);
|
||||
|
||||
app.AJAXperiodicWorker({
|
||||
attributeName: $this.data('apw-attribute'),
|
||||
APIURL: $this.data('apw-url'),
|
||||
element: $this,
|
||||
interval: $this.data('apw-interval'),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
App.prototype.doToastrMessages = function () {
|
||||
toastr.options = {
|
||||
'closeButton': true,
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
{% if link.disabled %}
|
||||
<a class="{% if link_classes %}{{ link_classes }} {% else %}btn {% if 'dangerous' in link.tags %}btn-danger{% else %}btn-primary{% endif %} btn-xs{% endif %} {% if link.active %}{{ link_class_active }}{% endif %} {% if 'new_window' in link.tags %}new_window{% endif %} disabled" disabled='disabled' style="cursor: default;" href="#">{% if link.icon %}<i class="hidden-xs hidden-sm hidden-md {{ link.icon }}"></i>{% endif %}{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}</a>{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
|
||||
{% else %}
|
||||
<a class="{% if link_classes %}{{ link_classes }} {% else %}btn {% if 'dangerous' in link.tags %}btn-danger{% else %}btn-primary{% endif %} btn-xs{% endif %} {% if link.active %}{{ link_class_active }}{% endif %} {% if 'new_window' in link.tags %}new_window{% endif %}" href="{{ link.url }}">{% if link.icon %}<i class="hidden-xs hidden-sm hidden-md {{ link.icon }}"></i>{% endif %}{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}</a>{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
|
||||
<a
|
||||
class="{% if link_classes %}{{ link_classes }} {% else %}btn {% if 'dangerous' in link.tags %}btn-danger{% else %}btn-primary{% endif %} btn-xs{% endif %} {% if link.active %}{{ link_class_active }}{% endif %} {% if 'new_window' in link.tags %}new_window{% endif %}"
|
||||
{% for key,value in link.html_data.items %}
|
||||
data-{{ key }}={{ value }}
|
||||
{% endfor %}
|
||||
|
||||
href="{{ link.url }}">{% if link.icon %}<i class="hidden-xs hidden-sm hidden-md {{ link.icon }}"></i>{% endif %}{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}</a>{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
@@ -68,6 +68,9 @@ link_user_events = Link(
|
||||
view='events:user_events'
|
||||
)
|
||||
link_user_notifications_list = Link(
|
||||
icon='fa fa-bell', text=get_notification_count,
|
||||
html_data={
|
||||
'apw-attribute': 'count', 'apw-interval': '5000',
|
||||
'apw-url': '/api/notifications/'
|
||||
}, icon='fa fa-bell', text=get_notification_count,
|
||||
view='events:user_notifications_list'
|
||||
)
|
||||
|
||||
@@ -37,6 +37,10 @@ class ResolvedLink(object):
|
||||
def description(self):
|
||||
return self.link.description
|
||||
|
||||
@property
|
||||
def html_data(self):
|
||||
return self.link.html_data
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
return self.link.icon
|
||||
@@ -244,8 +248,8 @@ class Menu(object):
|
||||
|
||||
class Link(object):
|
||||
def __init__(self, text, view=None, args=None, condition=None,
|
||||
conditional_disable=None, description=None, icon=None,
|
||||
icon_class=None, keep_query=False, kwargs=None,
|
||||
conditional_disable=None, description=None, html_data=None,
|
||||
icon=None, icon_class=None, keep_query=False, kwargs=None,
|
||||
permissions=None, permissions_related=None,
|
||||
remove_from_query=None, tags=None,
|
||||
url=None):
|
||||
@@ -254,6 +258,7 @@ class Link(object):
|
||||
self.condition = condition
|
||||
self.conditional_disable = conditional_disable
|
||||
self.description = description
|
||||
self.html_data = html_data
|
||||
self.icon = icon
|
||||
self.icon_class = icon_class
|
||||
self.keep_query = keep_query
|
||||
|
||||
Reference in New Issue
Block a user