From 77f2454e3cc1b1c1480e1e46ae2646cd7bc771d6 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Fri, 15 Sep 2017 17:20:42 +0530 Subject: [PATCH] remove error msg on successful termination --- .../hosting/js/virtual_machine_detail.js | 18 ++++++++++-------- hosting/views.py | 7 ++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index df401ebe..47080cd4 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -1,14 +1,16 @@ function VMTerminateStatus($container, url) { - $.get(url) - .done(function(data) { + $.ajax({ + url: url, + dataType: 'json', + success: function(data) { + VMTerminateSuccess($container, data); + }, + error: function() { setTimeout(function(){ VMTerminateStatus($container, url); }, 4000); - }) - .fail(function(data) { - VMTerminateSuccess($container, data) - window.location.reload(true); - }); + } + }); } function VMTerminateActive($container, altText) { @@ -25,6 +27,7 @@ function VMTerminateSuccess($container, data) { $container.addClass('terminate-success') .find('.vm-item-lg').text(data.text); $container.find('.btn').remove(); + window.location = data.redirect; } function VMTerminateFail($container, data, text) { @@ -50,7 +53,6 @@ $(document).ready(function() { console.log("success", data); if (data.status == true) { VMTerminateSuccess($container, data); - window.location = data.redirect; } else { if ('text' in data) { VMTerminateFail($container, data, text); diff --git a/hosting/views.py b/hosting/views.py index 77c4b8dc..072ada8e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -926,9 +926,14 @@ class VirtualMachineView(LoginRequiredMixin, View): if self.request.is_ajax(): storage = messages.get_messages(request) storage.used = True - raise Http404() + return HttpResponse( + json.dumps({'redirect': self.get_success_url()}), + content_type="application/json" + ) else: return redirect(reverse('hosting:virtual_machines')) + elif self.request.is_ajax(): + return HttpResponse() try: serializer = VirtualMachineSerializer(vm) context = {