Commit 0c894790 by tarokkk

webui: added try-template-button

parent 55d80b6c
...@@ -18,6 +18,7 @@ urlpatterns = patterns('', ...@@ -18,6 +18,7 @@ urlpatterns = patterns('',
url(r'^login/$', 'school.views.login', name='login'), url(r'^login/$', 'school.views.login', name='login'),
url(r'^logout/$', 'school.views.logout', name='logout'), url(r'^logout/$', 'school.views.logout', name='logout'),
url(r'^vm/new/(?P<template>\d+)/$', 'one.views.vm_new', name='vm_new'), url(r'^vm/new/(?P<template>\d+)/$', 'one.views.vm_new', name='vm_new'),
url(r'^ajax/vm/new/(?P<template>\d+)/$', 'one.views.vm_new_ajax', name='vm_new_ajax'),
url(r'^vm/new/s(?P<share>\d+)/$', 'one.views.vm_new', name='vm_new'), url(r'^vm/new/s(?P<share>\d+)/$', 'one.views.vm_new', name='vm_new'),
url(r'^vm/show/(?P<iid>\d+)/$', 'one.views.vm_show', name='vm_show'), url(r'^vm/show/(?P<iid>\d+)/$', 'one.views.vm_show', name='vm_show'),
url(r'^vm/delete/(?P<iid>\d+)/$', 'one.views.vm_delete', name='vm_delete'), url(r'^vm/delete/(?P<iid>\d+)/$', 'one.views.vm_delete', name='vm_delete'),
......
...@@ -52,6 +52,10 @@ $(function() { ...@@ -52,6 +52,10 @@ $(function() {
e.stopPropagation(); e.stopPropagation();
}); });
} }
$('.try-template-button').click(function(e) {
e.preventDefault(); e.stopPropagation();
new_vm($(this).data('id') );
});
$('.stop-vm-button').click(function(e) { $('.stop-vm-button').click(function(e) {
e.preventDefault(); e.stopPropagation(); e.preventDefault(); e.stopPropagation();
stop_vm($(this).data('id'), $(this).data('name')); stop_vm($(this).data('id'), $(this).data('name'));
...@@ -203,7 +207,7 @@ $(function() { ...@@ -203,7 +207,7 @@ $(function() {
type: 'POST', type: 'POST',
url: '/vm/' + state + '/' + id + '/', url: '/vm/' + state + '/' + id + '/',
success: function(data, b, c) { success: function(data, b, c) {
if ( state == "resume" ){ if ( state == "resume"){
window.location.href = '/vm/show/'+id+"/"; window.location.href = '/vm/show/'+id+"/";
} }
else { else {
...@@ -212,6 +216,19 @@ $(function() { ...@@ -212,6 +216,19 @@ $(function() {
} }
}) })
} }
/**
* New VM
*/
function new_vm(template_id) {
$.ajax({
type: 'POST',
url: 'ajax/vm/new/' + template_id + '/',
success: function(data, b, xhrRequest) {
window.location.href = xhrRequest.getResponseHeader("Location");
//alert(xhrRequest.getResponseHeader("Location"));
}
})
}
/** /**
* Template delete * Template delete
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
<div class="name">{{t.name}}</div> <div class="name">{{t.name}}</div>
<div class="status">{{t.state}}</div> <div class="status">{{t.state}}</div>
<div class="actions"> <div class="actions">
<a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}">
<img src="static/icons/control.png" alt="{% trans "Start" %}"/></a>
<a href="#" title="{% trans "Edit" %}"><img src="/static/icons/pencil.png" alt="{% trans "Edit" %}" /></a> <a href="#" title="{% trans "Edit" %}"><img src="/static/icons/pencil.png" alt="{% trans "Edit" %}" /></a>
<a href="#" class="delete-template-button" data-id="{{ t.id }}" data-name="{{ t.name }}" title="{% trans "Remove" %}"><img src="/static/icons/minus-circle.png" alt="{% trans "Remove" %}" /></a> <a href="#" class="delete-template-button" data-id="{{ t.id }}" data-name="{{ t.name }}" title="{% trans "Remove" %}"><img src="/static/icons/minus-circle.png" alt="{% trans "Remove" %}" /></a>
<a href="#" class="template-share" data-id="{{t.id}}" title="{% trans "Share" %}"><img src="static/icons/user-share.png" alt="{% trans "Share" %}" /></a> <a href="#" class="template-share" data-id="{{t.id}}" title="{% trans "Share" %}"><img src="static/icons/user-share.png" alt="{% trans "Share" %}" /></a>
...@@ -59,6 +61,8 @@ ...@@ -59,6 +61,8 @@
<div class="name">{{t.name}}</div> <div class="name">{{t.name}}</div>
<div class="status">{{t.state}}</div> <div class="status">{{t.state}}</div>
<div class="actions"> <div class="actions">
<a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}">
<img src="static/icons/control.png" alt="{% trans "Start" %}"/></a>
<a href="#" class="template-share" data-id="{{t.id}}" {%if group%}data-gid="{{group.id}}"{%endif%} title="{% trans "Share" %}"><img src="static/icons/user-share.png" alt="{% trans "Share" %}" /></a> <a href="#" class="template-share" data-id="{{t.id}}" {%if group%}data-gid="{{group.id}}"{%endif%} title="{% trans "Share" %}"><img src="static/icons/user-share.png" alt="{% trans "Share" %}" /></a>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
......
...@@ -6,7 +6,7 @@ from django.contrib.auth.decorators import login_required ...@@ -6,7 +6,7 @@ from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.core import signing from django.core import signing, urlresolvers
from django.core.mail import mail_managers, send_mail from django.core.mail import mail_managers, send_mail
from django.db import transaction from django.db import transaction
from django.forms import ModelForm, Textarea from django.forms import ModelForm, Textarea
...@@ -115,7 +115,7 @@ def vm_credentials(request, iid): ...@@ -115,7 +115,7 @@ def vm_credentials(request, iid):
vm = get_object_or_404(Instance, pk=iid, owner=request.user) vm = get_object_or_404(Instance, pk=iid, owner=request.user)
return render_to_response('vm-credentials.html', RequestContext(request, { 'i' : vm })) return render_to_response('vm-credentials.html', RequestContext(request, { 'i' : vm }))
except: except:
return HttpResponse(_("Could not get Virtual Machine credentials."), code=404) return HttpResponse(_("Could not get Virtual Machine credentials."), status=404)
messages.error(request, _('Failed to power off virtual machine.')) messages.error(request, _('Failed to power off virtual machine.'))
class AjaxTemplateWizard(View): class AjaxTemplateWizard(View):
...@@ -189,10 +189,12 @@ def vm_saveas(request, vmid): ...@@ -189,10 +189,12 @@ def vm_saveas(request, vmid):
messages.success(request, _("Template is being saved...")) messages.success(request, _("Template is being saved..."))
return redirect(inst) return redirect(inst)
def vm_new_ajax(request, template ):
return vm_new(request, template, redir=False)
@require_POST @require_POST
@login_required @login_required
def vm_new(request, template=None, share=None): def vm_new(request, template=None, share=None, redir=True):
base = None base = None
extra = None extra = None
if template: if template:
...@@ -215,10 +217,15 @@ def vm_new(request, template=None, share=None): ...@@ -215,10 +217,15 @@ def vm_new(request, template=None, share=None):
#Gány quota #Gány quota
if share == None or (share != None and share.get_running() < share.instance_limit) or extra: if share == None or (share != None and share.get_running() < share.instance_limit) or extra:
i = Instance.submit(base, request.user, extra=extra, share=share) i = Instance.submit(base, request.user, extra=extra, share=share)
return redirect(i) if redir:
return redirect(i)
else:
response = HttpResponse("Created", status=201)
response['Location'] = i.get_absolute_url()
return response
except Exception as e: except Exception as e:
logger.error('Failed to create virtual machine.' + unicode(e)) logger.error('Failed to create virtual machine.' + unicode(e))
messages.error(request, _('Failed to create virtual machine.')) messages.error(request, _('Failed to create virtual machine.')+unicode(e))
return redirect('/') return redirect('/')
class VmListView(ListView): class VmListView(ListView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment