Commit a7bcad7d by Őry Máté

one: add create share

parent 62dd4060
......@@ -34,6 +34,8 @@ urlpatterns = patterns('',
url(r'^store/gui/$', 'store.views.gui', name='store_gui'),
url(r'^store/top/$', 'store.views.toplist', name='store_top'),
url(r'^ajax/templateWizard$', 'one.views.ajax_template_wizard', name='ajax_template_wizard'),
url(r'^ajax/share/(?P<id>\d+)$', 'one.views.ajax_share_wizard', name='ajax_share_wizard'),
url(r'^ajax/share/(?P<id>\d+)/(?P<gid>\d+)$', 'one.views.ajax_share_wizard', name='ajax_share_wizard'),
url(r'^ajax/template/delete/$', 'one.views.ajax_template_delete', name='ajax_template_delete'),
url(r'^ajax/template_name_unique/(?P<name>.*)$', 'one.views.ajax_template_name_unique', name='ajax_template_name_unique'),
url(r'^ajax/store/list$', 'store.views.ajax_listfolder', name='store_ajax_listfolder'),
......
......@@ -295,6 +295,23 @@
background-image: url(icons/computer--plus.png);
}
}
#new-share .type-summary, .share-type .value {
&.type-summary {
font-size: .8em;
text-align: right;
}
span {
background-position: left center;
background-repeat: no-repeat;
padding-left: 18px;
&.suspend{
background-image: url(icons/control-pause.png)
}
&.delete{
background-image: url(icons/minus-circle.png)
}
}
}
#template-wizard .size-summary, .type .value {
&.size-summary {
font-size: .8em;
......
......@@ -87,6 +87,13 @@ $(function() {
$('#shadow').click(function() {
$('#modal').hide();
})
$('.template-share').click(function(e) {
e.preventDefault(); e.stopPropagation();
$.get('/ajax/share/'+$(this).data('id'), function(data) {
$('#modal-container').html(data);
})
$('#modal').show();
});
$('#old-upload').click(function(e) {
e.preventDefault();
$(this).parent().parent().hide().parent().find('#old-upload-form').show();
......
......@@ -66,9 +66,13 @@
position: absolute;
}
}
input[type=text] {
input[type=text], input[type=number], select {
display: block;
float: right;
margin-top: 8px;
}
input[type=number] {
width: 4em;
}
textarea{
float: right;
......
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
<div class="contentblock" id="template">
<h2>{% trans "My templates" %}</h2>
<h2>{% trans "Templates" %}</h2>
<ul class="wm-list">
{% for t in mytemplates %}
<li class="wm" id="t{{t.id }}">
......@@ -11,7 +11,7 @@
<div class="actions">
<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="#" 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>
</div>
<div class="clear"></div>
</div>
......@@ -30,9 +30,8 @@
</div>
</li>
{% endfor %}
<!-- rgb(164, 179, 199) -->
{% if not mytemplates %}
{% if not mytemplates and not group %}
<div id="new-wm-tooltip">
<div id="new-wm-tooltip-container">
<p>
......@@ -45,12 +44,14 @@
</div>
</div>
{% endif %}
{% if not group %}
<li id="new-template-button" class="wm new">
<div class="summary">
<div class="name">Új Sablon</div>
<div class="clear"></div>
</div>
</li>
{% endif %}
{% if publictemplates %}
{% for t in publictemplates %}
<li class="wm" id="t{{t.id }}">
......@@ -58,7 +59,7 @@
<div class="name">{{t.name}}</div>
<div class="status">{{t.state}}</div>
<div class="actions">
<a href="#" 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 class="clear"></div>
</div>
......
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
<form action="/ajax/share/{{base.id}}" method="post" id="template-wizard">{% csrf_token %}
<div id="new-share" class="wizard">
<h2>{% blocktrans with t=base.name%}Sharing template: {{t}}{% endblocktrans %}</h2>
<p>{% trans "Choose a group" %}</p>
{% if not groups %}
<p class="hilight">{% trans "You have no groups." %}</p>
{% endif %}
<ul>
<li>
<label for="share-group">{% trans "Group" %}</label>
<select name="group"{% if not groups %} disabled=""{%endif%}>
<option value="" selected="" class="dummy">--</option>
{%for i in groups%}<option value="{{i.id}}">{{i.name}} ({{i.members.count}})</option>{%endfor%}
</select>
<div class="clear"></div>
</li>
</ul>
<div class="clear"></div>
<p>{% trans "Change the parameters as needed." %}</p>
<ul>
<li>
<label for="share-name">{% trans "Name of share" %}</label>
<input type="text" name="name" id="share-name" value="{{base.name}}" />
<div class="clear"></div>
</li>
<li class="li-share-type">
<label for="share-type">{% trans "Type" %}</label>
<ul class="radio">
{% for s in types %}
<li>
<label>
<input type="radio" name="type" value="{{s.id}}" id="share-type-{{s.id}}"
{% if s.default %}checked="checked"{% endif %} />
{{s.verbose_name}}
</label>
</li>
{% endfor %}
</ul>
{% for s in types %}
<p id="share-type-summary-{{s.id}}" class="type-summary clear"
{% if not s.default %}style="display:none"{% endif %}>
{{s.help_text}}
({% if s.suspend %}
<span class="suspend"
title="{% blocktrans with time=s.suspend %}Suspend after {{time}}.{%endblocktrans%}">
{{s.suspendx|timeuntil}}
</span>
{%endif%}{% if s.delete %}<span class="delete"
title="{% blocktrans with time=s.delete %}Delete after {{time}}.{%endblocktrans%}">
{{s.deletex|timeuntil}}</span>{%endif%})
</p>
{% endfor %}
<div class="clear"></div>
</li>
<li class="clear">
<label for="share-instance-limit">{% trans "Maximal count of instances" %}</label>
<input type="number" name="instance_limit" id="share-instance-limit" value="10" />
</li>
<li class="clear">
<label for="share-instance-limit">{% trans "Maximal count of instaces/user" %}</label>
<input type="number" name="per_user_limit" id="share-per-user-limit" value="1" />
</li>
<li style="border: none" class="clear">
<label for="share-description">{% trans "Description" %}</label>
<textarea name="description" id="share-description" style="text-align: left">{{base.description}}</textarea>
<div class="clear"></div>
</li>
</ul>
<nav>
<input type="reset" class="prev" value="{% trans "Cancel" %}" />
<input type="submit" value="{% trans "Share" %}" {% if not groups %} disabled=""{%endif%}/>
<div class="clear"></div>
</nav>
<script type="text/javascript">
$(function(){
if ("" == $(":selected this").val())
$('#new-share input[type=submit]').attr("disabled", "")
else
$('#new-share input[type=submit]').removeAttr("disabled")
$('#new-share select').change(function(e) {
if ("" == $(":selected this").val())
$('#new-share input[type=submit]').attr("disabled", "")
else
$('#new-share input[type=submit]').removeAttr("disabled")
})
$('#new-share nav .prev').click(function(){
$('#modal').hide();
})
$("#new-share input[name='type']").click(function(e){ /* TODO */
var v = $("#new-share input[name='type']:checked").val();
$("p.type-summary").hide();
$("#share-type-summary-" + v).show();
});
})
</script>
</div>
</form>
# -*- coding: utf-8 -*-
from datetime import datetime
from django.conf import settings
from datetime import timedelta as td
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib import messages
......@@ -132,6 +133,51 @@ class AjaxTemplateWizard(View):
}))
ajax_template_wizard = login_required(AjaxTemplateWizard.as_view())
class AjaxShareWizard(View):
def get(self, request, id, gid=None, *args, **kwargs):
types = TYPES_L
types[0]['default'] = True
for i, t in enumerate(types):
t['deletex'] = datetime.now() + td(seconds=1) + t['delete'] if t['delete'] else None
t['suspendx'] = datetime.now() + td(seconds=1) + t['suspend'] if t['suspend'] else None
types[i] = t
if gid:
gid = get_object_or_404(Group, id=gid)
return render_to_response('new-share.html', RequestContext(request,{
'base': get_object_or_404(Template, id=id),
'groups': request.user.person_set.all()[0].owned_groups.all(),
'types': types,
'group': gid,
}))
def post(self, request, id, gid=None, *args, **kwargs):
base = get_object_or_404(Template, id=id)
if base.owner != request.user and not base.public and not request.user.is_superuser:
raise PermissionDenied()
group = None
if gid:
group = get_object_or_404(Group, id=gid)
else:
group = get_object_or_404(Group, id=request.POST['group'])
if not group.owners.filter(user=request.user).exists():
raise PermissionDenied()
stype = request.POST['type']
if not stype in TYPES.keys():
raise PermissionDenied()
il = request.POST['instance_limit']
# TODO check quota
s = Share.objects.create(name=request.POST['name'], description=request.POST['description'],
type=stype, instance_limit=il, per_user_limit=request.POST['per_user_limit'],
group=group, template=base)
messages.success(request, _('Successfully shared %s.') % base)
return redirect('/')
ajax_share_wizard = login_required(AjaxShareWizard.as_view())
@require_POST
@login_required
def vm_saveas(request, vmid):
......
......@@ -51,10 +51,8 @@
</div>
</div>
<div class="boxes">
<div class="contentblock">
<h2>{% trans "Templates" %}</h2>
<ul class="wm-list">
<div id="new-wm-tooltip">
<div id="new-wm-tooltip" style="position:absolute">
<div id="new-wm-tooltip-container">
<p>
{% trans "This group has no shared templates." %}
......@@ -62,18 +60,9 @@
<p>
{% trans "Share one, and the group members can start their own virtual machine." %}
</p>
<div id="new-wm-tooltip-tail"></div>
<div id="new-wm-tooltip-tail"></div>
</div>
</div>
<li class="wm">
<div class="summary">
<div class="name">
{% trans "Share template" %}
</div>
<div class="clear"></div>
</div>
</li>
</ul>
</div>
{% include "box-templatelist.html" %}
</div>
{% endblock %}
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