diff --git a/manager/templatetags/manager.py b/manager/templatetags/manager.py index 4c8edd9..df45343 100644 --- a/manager/templatetags/manager.py +++ b/manager/templatetags/manager.py @@ -25,6 +25,10 @@ def directUserOrgas(user): def directOrgaString(user): return ", ".join(str(orga) for orga in directUserOrgas(user)) +@register.simple_tag +def directOrgaAjax(user): + return "[" + ",".join(str(orga.id) for orga in directUserOrgas(user)) + "]" + @register.simple_tag(takes_context=True) def userOrgas(context): return directUserOrgas(context.request.user) @@ -52,3 +56,7 @@ def userNets(context): @register.simple_tag def netOrgaString(network): return ", ".join(str(orga) for orga in network.organization.all()) + +@register.simple_tag +def netOrgaAjax(network): + return "[" + ",".join(str(orga.id) for orga in network.organization.all()) + "]" diff --git a/static/js/devices.js b/static/js/devices.js index 16729b9..717ce7e 100644 --- a/static/js/devices.js +++ b/static/js/devices.js @@ -188,6 +188,16 @@ function showorgas() { window.history.pushState("", "", "/organizations/"); }; +function filtertables() { + orga_id = $("#orgaselect option:selected").val(); + $("tbody tr").each(function(i, row) + { + if ($.inArray(parseInt(orga_id, "10"), $(row).data('orga')) !== -1) $(row).show(); + else $(row).hide(); + }); + +}; + var page = document.location.pathname.substring(1, document.location.pathname.lastIndexOf('/')); if (page == "users") showusers(); else if (page == "wifi") showwifi(); @@ -195,8 +205,14 @@ else if (page == "networks") shownets(); else if (page == "organizations") showorgas(); else showdevices(); +filtertables(); + $("div[id$='-indicator']").each(function() { device_id = this.id.split("-")[0]; updateStatus(device_id); setInterval(updateStatus, 10000, device_id); }); + +$("#orgaselect").on('change', function() { + filtertables(); +}); diff --git a/templates/manager/index.html b/templates/manager/index.html index 30e5110..9697691 100644 --- a/templates/manager/index.html +++ b/templates/manager/index.html @@ -3,7 +3,7 @@ {% load manager %} {% block content %} -
Organization: {% orgaString %}
+Organization: {% userOrgas as orgas %}{% if orgas|length > 1 %}{% else %}{% orgaString %}{% endif %}
User: {{ user.first_name }} {{ user.last_name }} ({{ user.username }})