From 058101b9414b331ec87c6d32c316b4301054415c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 14 Aug 2015 12:15:49 +0300 Subject: [PATCH] Can remove channels --- hc/front/urls.py | 3 +- hc/front/views.py | 16 ++++++++++- static/css/channels.css | 8 ++++++ static/js/channels.js | 12 +++++++- templates/front/channels.html | 38 +++++++++++++++++++++++++- templates/front/my_checks_desktop.html | 2 +- 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/hc/front/urls.py b/hc/front/urls.py index 623bf5af..b3b58a97 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -8,7 +8,7 @@ urlpatterns = [ url(r'^checks/([\w-]+)/name/$', views.update_name, name="hc-update-name"), url(r'^checks/([\w-]+)/timeout/$', views.update_timeout, name="hc-update-timeout"), url(r'^checks/([\w-]+)/email/$', views.email_preview), - url(r'^checks/([\w-]+)/remove/$', views.remove, name="hc-remove-check"), + url(r'^checks/([\w-]+)/remove/$', views.remove_check, name="hc-remove-check"), url(r'^checks/([\w-]+)/log/$', views.log, name="hc-log"), url(r'^pricing/$', views.pricing, name="hc-pricing"), url(r'^docs/$', views.docs, name="hc-docs"), @@ -16,6 +16,7 @@ urlpatterns = [ url(r'^channels/$', views.channels, name="hc-channels"), url(r'^channels/add/$', views.add_channel, name="hc-add-channel"), url(r'^channels/([\w-]+)/checks/$', views.channel_checks, name="hc-channel-checks"), + url(r'^channels/([\w-]+)/remove/$', views.remove_channel, name="hc-remove-channel"), url(r'^channels/([\w-]+)/verify/([\w-]+)/$', views.verify_email, name="hc-verify-email"), diff --git a/hc/front/views.py b/hc/front/views.py index a4c9f860..4c5ceae3 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -144,7 +144,7 @@ def email_preview(request, code): @login_required @uuid_or_400 -def remove(request, code): +def remove_check(request, code): assert request.method == "POST" check = Check.objects.get(code=code) @@ -251,3 +251,17 @@ def verify_email(request, code, token): return render(request, "front/verify_email_success.html") return render(request, "bad_link.html") + + +@login_required +@uuid_or_400 +def remove_channel(request, code): + assert request.method == "POST" + + channel = Channel.objects.get(code=code) + if channel.user != request.user: + return HttpResponseForbidden() + + channel.delete() + + return redirect("hc-channels") diff --git a/static/css/channels.css b/static/css/channels.css index 79011c4b..228d3140 100644 --- a/static/css/channels.css +++ b/static/css/channels.css @@ -67,3 +67,11 @@ table.channels-table > tbody > tr > th { .channel-row:hover .edit-checks { border: 1px dotted #AAA; } + +.channel-remove { + visibility: hidden; +} + +.channel-row:hover .channel-remove { + visibility: visible; +} \ No newline at end of file diff --git a/static/js/channels.js b/static/js/channels.js index 428183f9..8a39f72c 100644 --- a/static/js/channels.js +++ b/static/js/channels.js @@ -26,7 +26,6 @@ $(function() { return false; }); - var $cm = $("#checks-modal"); $cm.on("click", "#toggle-all", function() { var value = $(this).prop("checked"); @@ -35,4 +34,15 @@ $(function() { }); + $(".channel-remove").click(function() { + var $this = $(this); + + $("#remove-channel-form").attr("action", $this.data("url")); + $(".remove-channel-name").text($this.data("name")); + $('#remove-channel-modal').modal("show"); + + return false; + }); + + }); \ No newline at end of file diff --git a/templates/front/channels.html b/templates/front/channels.html index b3e8fc10..703bf295 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -9,6 +9,7 @@

Notification Channels

+ {% if channels %} @@ -41,11 +42,21 @@ {{ ch.checks.count }} of {{ num_checks }} + {% endfor %} + {% endif %} @@ -109,6 +119,32 @@ + + {% endblock %} {% block scripts %} diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html index c4de10be..5e7715af 100644 --- a/templates/front/my_checks_desktop.html +++ b/templates/front/my_checks_desktop.html @@ -79,7 +79,7 @@
  • Remove
  • Type Value + +
    Add Notification Channel @@ -71,7 +82,6 @@ -