code reformating

This commit is contained in:
Arvind Tiwari 2017-09-15 00:57:59 +05:30
parent 8402fd4fd3
commit a935871722
2 changed files with 56 additions and 68 deletions

View file

@ -1,54 +1,52 @@
$(document).ready(function() {
$( document ).ready(function() {
$('#confirm-cancel').on('click', '.btn-ok', function(e) {
var url = $('#virtual_machine_cancel_form').attr('action');
var $container = $('#terminate-VM');
var $btn = $container.find('.btn');
var text = $container.find('.vm-item-lg').text();
var altText = $container.attr('data-alt');
$container.find('.alert-danger').addClass('hide');
$container.addClass('processing')
.find('.vm-item-lg').attr('class', '')
.addClass('vm-item-lg vm-color-failed')
.text(altText);
$btn.prop('disabled', true);
$('#confirm-cancel').modal('hide');
$.post(url)
.done(function(data) {
console.log("success", data);
if (data.status == true) {
$container.addClass('terminate-success')
.find('.vm-item-lg').text(data.text);
$btn.remove();
window.location = data.redirect;
} else {
$container.addClass('terminate-fail')
.find('.vm-item-lg').text(text);
$container.find('.btn').prop('disabled', false);
$container.find('.alert-danger').text(data.text).removeClass('hide');
}
})
.fail(function(data) {
$container.addClass('terminate-fail')
.find('.vm-item-lg').text(text);
$container.find('.btn').prop('disabled', false);
$container.find('.alert-danger').removeClass('hide');
})
.always(function(data) {
$container.removeClass('processing');
});
});
$('#confirm-cancel').on('click', '.btn-ok', function(e) {
var url = $('#virtual_machine_cancel_form').attr('action');
var $container = $('#terminate-VM');
var $btn = $container.find('.btn');
var text = $container.find('.vm-item-lg').text();
var altText = $container.attr('data-alt');
$container.find('.alert-danger').addClass('hide');
$container.addClass('processing')
.find('.vm-item-lg').attr('class', '')
.addClass('vm-item-lg vm-color-failed')
.text(altText);
$btn.prop('disabled', true);
$('#confirm-cancel').modal('hide');
$.post(url)
.done(function(data) {
console.log( "success" , data);
if (data.status == true) {
$container.addClass('terminate-success')
.find('.vm-item-lg').text(data.text);
$btn.remove();
window.location = data.redirect;
}
else {
$container.addClass('terminate-fail')
.find('.vm-item-lg').text(text);
$container.find('.btn').prop('disabled', false);
$container.find('.alert-danger').text(data.text).removeClass('hide');
}
})
.fail(function(data) {
$container.addClass('terminate-fail')
.find('.vm-item-lg').text(text);
$container.find('.btn').prop('disabled', false);
$container.find('.alert-danger').removeClass('hide');
})
.always(function(data) {
$container.removeClass('processing');
});
});
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
$('.nav-tabs a').click(function (e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
window.location.hash = this.hash;
$('html,body').scrollTop(scrollmem);
});
$('.nav-tabs a').click(function(e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
window.location.hash = this.hash;
$('html,body').scrollTop(scrollmem);
});
});

View file

@ -957,6 +957,14 @@ class VirtualMachineView(LoginRequiredMixin, View):
response['text'] = ugettext(
'Error terminating VM') + opennebula_vm_id
else:
for t in range(150):
try:
manager.get_vm(self.kwargs.get('pk'))
except BaseException:
break
else:
sleep(2)
context = {
'vm': vm_data,
'base_url': "{0}://{1}".format(self.request.scheme,
@ -973,28 +981,10 @@ class VirtualMachineView(LoginRequiredMixin, View):
}
email = BaseEmail(**email_data)
email.send()
# messages.error(
# request,
# _('VM %(VM_ID)s terminated successfully') % {
# 'VM_ID': opennebula_vm_id}
# )
t = 0
while True:
if t < 150:
t += 1
try:
manager.get_vm(self.kwargs.get('pk'))
except BaseException:
break
else:
sleep(2)
else:
break
response['status'] = True
response['redirect'] = self.get_success_url()
response['text'] = ugettext('Terminated')
return HttpResponse(
json.dumps(response),
content_type="application/json"