remove error msg on successful termination

This commit is contained in:
Arvind Tiwari 2017-09-15 17:20:42 +05:30
parent 0c3f605735
commit 77f2454e3c
2 changed files with 16 additions and 9 deletions

View file

@ -1,14 +1,16 @@
function VMTerminateStatus($container, url) { function VMTerminateStatus($container, url) {
$.get(url) $.ajax({
.done(function(data) { url: url,
dataType: 'json',
success: function(data) {
VMTerminateSuccess($container, data);
},
error: function() {
setTimeout(function(){ setTimeout(function(){
VMTerminateStatus($container, url); VMTerminateStatus($container, url);
}, 4000); }, 4000);
}) }
.fail(function(data) { });
VMTerminateSuccess($container, data)
window.location.reload(true);
});
} }
function VMTerminateActive($container, altText) { function VMTerminateActive($container, altText) {
@ -25,6 +27,7 @@ function VMTerminateSuccess($container, data) {
$container.addClass('terminate-success') $container.addClass('terminate-success')
.find('.vm-item-lg').text(data.text); .find('.vm-item-lg').text(data.text);
$container.find('.btn').remove(); $container.find('.btn').remove();
window.location = data.redirect;
} }
function VMTerminateFail($container, data, text) { function VMTerminateFail($container, data, text) {
@ -50,7 +53,6 @@ $(document).ready(function() {
console.log("success", data); console.log("success", data);
if (data.status == true) { if (data.status == true) {
VMTerminateSuccess($container, data); VMTerminateSuccess($container, data);
window.location = data.redirect;
} else { } else {
if ('text' in data) { if ('text' in data) {
VMTerminateFail($container, data, text); VMTerminateFail($container, data, text);

View file

@ -926,9 +926,14 @@ class VirtualMachineView(LoginRequiredMixin, View):
if self.request.is_ajax(): if self.request.is_ajax():
storage = messages.get_messages(request) storage = messages.get_messages(request)
storage.used = True storage.used = True
raise Http404() return HttpResponse(
json.dumps({'redirect': self.get_success_url()}),
content_type="application/json"
)
else: else:
return redirect(reverse('hosting:virtual_machines')) return redirect(reverse('hosting:virtual_machines'))
elif self.request.is_ajax():
return HttpResponse()
try: try:
serializer = VirtualMachineSerializer(vm) serializer = VirtualMachineSerializer(vm)
context = { context = {