From 26a04c48ad657e44da8fc43ea96e695655c54249 Mon Sep 17 00:00:00 2001 From: Dányi Bence <madbence@gmail.com> Date: Wed, 20 Feb 2013 16:15:22 +0100 Subject: [PATCH] webui: implement vm-rename feature (ajax) --- cloud/urls.py | 3 +++ one/static/script/cloud.js | 12 +++++++++++- one/views.py | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cloud/urls.py b/cloud/urls.py index b2021f6..8d3df96 100644 --- a/cloud/urls.py +++ b/cloud/urls.py @@ -80,6 +80,9 @@ urlpatterns = patterns('', url(r'^ajax/vm/status/(?P<iid>\d+)$', 'one.views.vm_ajax_instance_status', name='vm_ajax_instance_status'), + url(r'^ajax/vm/rename/(?P<iid>\d+)/$', + 'one.views.vm_ajax_rename', + name='vm_ajax_rename'), url(r'^language/(?P<lang>[-A-Za-z]+)/$', 'school.views.language', name='language'), url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), diff --git a/one/static/script/cloud.js b/one/static/script/cloud.js index 86b0954..b878f5a 100644 --- a/one/static/script/cloud.js +++ b/one/static/script/cloud.js @@ -56,7 +56,17 @@ $(function() { $('#vm-' + id + '-name').find('input[type=submit]').click(function(f) { f.preventDefault(); f.stopPropagation(); - alert($(this).prev().val()); + var newName = $(this).prev().val(); + $.ajax({ + type: 'POST', + data: 'name=' + newName, + dataType: 'json', + url: '/ajax/vm/rename/' + id + '/', + success: function(data) { + $('#vm-' + id + '-name-details').show(); + $('#vm-' + id + '-name').html(data.name); + } + }); }) }); $('.try-template-button').click(function(e) { diff --git a/one/views.py b/one/views.py index b1c7653..3e30def 100644 --- a/one/views.py +++ b/one/views.py @@ -295,6 +295,13 @@ def vm_ajax_instance_status(request, iid): inst.update_state() return HttpResponse(json.dumps({'booting': not inst.active_since, 'state': inst.state})) +@login_required +def vm_ajax_rename(request, iid): + inst = get_object_or_404(Instance, id=iid, owner=request.user) + inst.name = request.POST['name'] + inst.save() + return HttpResponse(json.dumps({'name': inst.name})) + def boot_token(request, token): try: id = signing.loads(token, salt='activate') -- libgit2 0.26.0