diff --git a/HISTORY.rst b/HISTORY.rst
index dc9a4ac9a4..47c4633714 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -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)
================
diff --git a/mayan/apps/appearance/static/appearance/js/base.js b/mayan/apps/appearance/static/appearance/js/base.js
index 5be92bdef7..aaab24e581 100644
--- a/mayan/apps/appearance/static/appearance/js/base.js
+++ b/mayan/apps/appearance/static/appearance/js/base.js
@@ -15,6 +15,7 @@ jQuery(document).ready(function() {
var afterBaseLoad = function () {
MayanImage.intialize();
app.doToastrMessages();
+ app.setupAJAXperiodicWorkers();
app.setupAutoSubmit();
app.setupItemsSelector();
app.setupNewWindowAnchor();
diff --git a/mayan/apps/appearance/static/appearance/js/mayan_app.js b/mayan/apps/appearance/static/appearance/js/mayan_app.js
index 16c058bd39..2238e5fec8 100644
--- a/mayan/apps/appearance/static/appearance/js/mayan_app.js
+++ b/mayan/apps/appearance/static/appearance/js/mayan_app.js
@@ -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,
diff --git a/mayan/apps/appearance/templates/navigation/generic_link_instance.html b/mayan/apps/appearance/templates/navigation/generic_link_instance.html
index 965c674c7f..344ec4afe1 100644
--- a/mayan/apps/appearance/templates/navigation/generic_link_instance.html
+++ b/mayan/apps/appearance/templates/navigation/generic_link_instance.html
@@ -6,6 +6,12 @@
{% if link.disabled %}
{% if link.icon %}{% endif %}{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
{% else %}
- {% if link.icon %}{% endif %}{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
+ {% if link.icon %}{% endif %}{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
{% endif %}
{% endif %}
diff --git a/mayan/apps/events/links.py b/mayan/apps/events/links.py
index 182f2501e4..b54e0ac389 100644
--- a/mayan/apps/events/links.py
+++ b/mayan/apps/events/links.py
@@ -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'
)
diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py
index dbc66329d8..1a95e0cb8c 100644
--- a/mayan/apps/navigation/classes.py
+++ b/mayan/apps/navigation/classes.py
@@ -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