Commit ba06f3bc by Bence Dányi

webui: rewrite hardcoded urls

parent 32174835
...@@ -15,7 +15,7 @@ $(function() { ...@@ -15,7 +15,7 @@ $(function() {
$('.delete-template').click(function(e) { $('.delete-template').click(function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
delete_template_confirm($(this).data('id'), $(this).data('name')); delete_template_confirm($(this).data('url'), $(this).data('id'), $(this).data('name'));
}); });
$('.delete-key').click(function(e) { $('.delete-key').click(function(e) {
var id = $(this).data('id'); var id = $(this).data('id');
...@@ -97,7 +97,7 @@ $(function() { ...@@ -97,7 +97,7 @@ $(function() {
$('.try-template').click(function(e) { $('.try-template').click(function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
new_vm($(this).data('id')); new_vm($(this).data('url'));
}); });
$('.stop-vm').click(function(e) { $('.stop-vm').click(function(e) {
e.preventDefault(); e.preventDefault();
...@@ -135,7 +135,7 @@ $(function() { ...@@ -135,7 +135,7 @@ $(function() {
$('#modal-container .entry .summary').click(toggleDetails); $('#modal-container .entry .summary').click(toggleDetails);
}); });
$('#new-template-button').click(function() { $('#new-template-button').click(function() {
$.get('/ajax/templateWizard', function(data) { $.get($(this).data('url'), function(data) {
$('#modal-container').html(data); $('#modal-container').html(data);
}) })
$('#modal').show(); $('#modal').show();
...@@ -146,7 +146,7 @@ $(function() { ...@@ -146,7 +146,7 @@ $(function() {
var id=$(this).data('id'); var id=$(this).data('id');
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/ajax/templateEditWizard/'+id+'/', url: $(this).data('url'),
success: function(data){ success: function(data){
$('#modal').show(); $('#modal').show();
$('#modal-container').html(data); $('#modal-container').html(data);
...@@ -239,7 +239,7 @@ $(function() { ...@@ -239,7 +239,7 @@ $(function() {
e.stopPropagation(); e.stopPropagation();
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/ajax/shareEdit/' + $(this).data('id') + '/', url: $(this).data('url'),
success: function(data) { success: function(data) {
$('#modal').show(); $('#modal').show();
$('#modal-container').html(data); $('#modal-container').html(data);
...@@ -353,13 +353,11 @@ $(function() { ...@@ -353,13 +353,11 @@ $(function() {
* New VM * New VM
*/ */
function new_vm(template_id) { function new_vm(url) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/ajax/vm/new/' + template_id + '/', url: url,
success: function(data, b, xhrRequest) { success: function(data, b, xhrRequest) {
window.location.href = '/'; //xhrRequest.getResponseHeader("Location");
//alert(xhrRequest.getResponseHeader("Location"));
window.location.href = xhrRequest.getResponseHeader("Location"); window.location.href = xhrRequest.getResponseHeader("Location");
} }
}) })
...@@ -369,7 +367,7 @@ $(function() { ...@@ -369,7 +367,7 @@ $(function() {
* Template delete * Template delete
*/ */
function delete_template_confirm(id, name) { function delete_template_confirm(url, id, name) {
confirm_message = interpolate(gettext("Are you sure deleting this %s template?"), ["<strong>" + name + "</strong>"]) confirm_message = interpolate(gettext("Are you sure deleting this %s template?"), ["<strong>" + name + "</strong>"])
vm_confirm_popup(confirm_message, gettext("Delete"), function() { vm_confirm_popup(confirm_message, gettext("Delete"), function() {
delete_template(id) delete_template(id)
...@@ -379,10 +377,10 @@ $(function() { ...@@ -379,10 +377,10 @@ $(function() {
* Template delete * Template delete
*/ */
function delete_template(id) { function delete_template(url, id) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/ajax/template/delete/', url: url,
data: 'id=' + id, data: 'id=' + id,
dataType: 'json', dataType: 'json',
statusCode: { statusCode: {
...@@ -512,7 +510,7 @@ $(function() { ...@@ -512,7 +510,7 @@ $(function() {
var neptun = $(this).prev().val(); var neptun = $(this).prev().val();
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/ajax/group/' + $(this).data('id') + '/add/', url: $(this).data('url'),
data: 'neptun=' + neptun, data: 'neptun=' + neptun,
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
...@@ -534,13 +532,14 @@ $(function() { ...@@ -534,13 +532,14 @@ $(function() {
var timer; var timer;
return function(e) { return function(e) {
var val = $(this).val().split(' ')[0]; var val = $(this).val().split(' ')[0];
var that = this;
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(function() { timer = setTimeout(function() {
if (val.length < 1) return; if (val.length < 1) return;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: 'q=' + val, data: 'q=' + val,
url: '/ajax/group/autocomplete/', url: $(that).data('url'),
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
console.log(data); console.log(data);
...@@ -597,37 +596,25 @@ $(function() { ...@@ -597,37 +596,25 @@ $(function() {
var neptun = $(this).data('neptun'); var neptun = $(this).data('neptun');
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/ajax/group/' + $(this).data('gid') + '/remove/', url: $(this).data('url'),
data: 'neptun=' + neptun, data: 'neptun=' + neptun,
success: function(data) { success: function(data) {
$('#member-' + neptun).slideUp(700); $('#member-' + neptun).slideUp(700);
} }
}); });
}); });
/*$('#group-owners .remove').click(function(e) {
e.preventDefault();
e.stopPropagation();
var neptun = $(this).data('neptun');
$.ajax({
type: 'POST',
url: '/ajax/group/' + $(this).data('gid') + '/remove/',
data: 'neptun=' + neptun,
success: function(data) {
$('#member-' + neptun).slideUp(700);
}
});
});*/
$('#groups .delete').click(function(e) { $('#groups .delete').click(function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
var gid = $(this).data('id'); var gid = $(this).data('id');
var name = $(this).data('name'); var name = $(this).data('name');
var url = $(this).data('url');
vm_confirm_popup( vm_confirm_popup(
interpolate( interpolate(
gettext('Are you sure deleting <strong>%s</strong>'), [name]), gettext('Delete'), function() { gettext('Are you sure deleting <strong>%s</strong>'), [name]), gettext('Delete'), function() {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/ajax/group/delete/', url: url,
data: 'gid=' + gid, data: 'gid=' + gid,
success: function() { success: function() {
$('#group-' + gid).slideUp(700); $('#group-' + gid).slideUp(700);
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</div> </div>
{% endif %} {% endif %}
{% if not group %} {% if not group %}
<li id="new-template-button" class="entry new small-row"> <li id="new-template-button" class="entry new small-row" data-url="{% url one.views.ajax_template_wizard %}">
<div class="summary"> <div class="summary">
<div class="name">Új Sablon</div> <div class="name">Új Sablon</div>
<div class="clear"></div> <div class="clear"></div>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<div class="status">{{t.state}}</div> <div class="status">{{t.state}}</div>
<div class="actions"> <div class="actions">
{% if t.state == 'READY' %} {% if t.state == 'READY' %}
<a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}"> <a href="#" class="try-template-button" data-url="{% url new_vm_from_template template=t.id %}" title="{% trans "Try" %}">
<img src="{% static "icons/control.png" %}" alt="{% trans "Start" %}"/> <img src="{% static "icons/control.png" %}" alt="{% trans "Start" %}"/>
</a> </a>
<a href="#" class="template-share" data-id="{{t.id}}" data-gid="{{group.id}}" title="{% trans "Share" %}"> <a href="#" class="template-share" data-id="{{t.id}}" data-gid="{{group.id}}" title="{% trans "Share" %}">
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<form action="{% url one.views.vm_unshare i.id %}" method="post"> <form action="{% url one.views.vm_unshare i.id %}" method="post">
<span title="{{i.name}}">{{i.name|truncatechars:20}}</span> <span title="{{i.name}}">{{i.name|truncatechars:20}}</span>
({{i.get_running}}/{{i.instance_limit}}) {{i.type}} ({{i.get_running}}/{{i.instance_limit}}) {{i.type}}
<a href="#" class="edit" data-id="{{i.id}}"> <a href="#" class="edit" data-url="{% url ajax_share_edit_wizard id=i.id %}">
<img src="{% static "icons/pencil.png" %}" alt="{% trans "Edit" %}" title="{% trans "Edit" %}" /> <img src="{% static "icons/pencil.png" %}" alt="{% trans "Edit" %}" title="{% trans "Edit" %}" />
</a> </a>
{% csrf_token %} {% csrf_token %}
...@@ -47,11 +47,11 @@ ...@@ -47,11 +47,11 @@
{% endblock status %} {% endblock status %}
{% block actions %} {% block actions %}
<a href="#" class="edit-template" data-id="{{ t.id }}" title="{% trans "Edit" %}"> <a href="#" class="edit-template" title="{% trans "Edit" %}" data-url="{% url one.views.ajax_template_edit_wizard id=t.id %}">
<img src="{% static "icons/pencil.png" %}" alt="{% trans "Edit" %}" /> <img src="{% static "icons/pencil.png" %}" alt="{% trans "Edit" %}" />
</a> </a>
{% if t.state == 'READY' %} {% if t.state == 'READY' %}
<a href="#" class="try-template" data-id="{{t.id}}" title="{% trans "Try" %}"> <a href="#" class="try-template" data-url="{% url new_vm_from_template template=t.id %}" title="{% trans "Try" %}">
<img src="{% static "icons/control.png" %}" alt="{% trans "Start" %}"/> <img src="{% static "icons/control.png" %}" alt="{% trans "Start" %}"/>
</a> </a>
<!--<a href="#" title="{% trans "Edit" %}"> <!--<a href="#" title="{% trans "Edit" %}">
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<img src="{% static "icons/user-share.png" %}" alt="{% trans "Share" %}" /> <img src="{% static "icons/user-share.png" %}" alt="{% trans "Share" %}" />
</a> </a>
{% endif %} {% endif %}
<a href="#" class="delete-template" data-id="{{ t.id }}" data-name="{{ t.name }}" title="{% trans "Remove" %}"> <a href="#" class="delete-template" data-url="{% url one.views.ajax_template_delete %}" data-id="{{ t.id }}" data-name="{{ t.name }}" title="{% trans "Remove" %}">
<img src="{% static "icons/minus-circle.png" %}" alt="{% trans "Remove" %}" /> <img src="{% static "icons/minus-circle.png" %}" alt="{% trans "Remove" %}" />
</a> </a>
{% endblock actions %} {% endblock actions %}
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<small class="details">(<a href="{{ group.get_absolute_url }}">{% trans "More details" %}</a>)</small> <small class="details">(<a href="{{ group.get_absolute_url }}">{% trans "More details" %}</a>)</small>
</div> </div>
<div class="actions"> <div class="actions">
<a href="#" class="delete" data-id="{{group.id}}" data-name="{{group.name}}"> <a href="#" class="delete" data-url="{% url school.views.group_ajax_delete %}" data-id="{{group.id}}" data-name="{{group.name}}">
<img src="{% static "icons/minus-circle.png" %}" alt="{% trans "Delete" %}" title="{% trans "Delete" %}" /> <img src="{% static "icons/minus-circle.png" %}" alt="{% trans "Delete" %}" title="{% trans "Delete" %}" />
</a> </a>
<a href="#" class="hide-group" data-id="{{group.id}}"> <a href="#" class="hide-group" data-id="{{group.id}}">
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<div class="name">{% trans "Add user" %}</div> <div class="name">{% trans "Add user" %}</div>
<div id="new-member-form"> <div id="new-member-form">
<input type="text" placeholder="{% trans "User NEPTUN code" %}" /> <input type="text" placeholder="{% trans "User NEPTUN code" %}" />
<input type="submit" value="{% trans "Add user" %}" data-id="{{group.id}}"/> <input type="submit" value="{% trans "Add user" %}" data-url="{% url school.views.group_ajax_add_new_member gid=group.id %}"/>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="actions"> <div class="actions">
<a href="#" class="remove" data-gid="{{group.id}}" data-neptun="{{member.code}}"> <a href="#" class="remove" data-url="{% url school.views.group_ajax_remove_member gid=group.id %}" data-neptun="{{member.code}}">
<img src="{% static "icons/minus-circle.png" %}" alt="{% trans 'Remove' %}" /> <img src="{% static "icons/minus-circle.png" %}" alt="{% trans 'Remove' %}" />
</a> </a>
</div> </div>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
</div> </div>
<div class="details" id="new-owner-form"> <div class="details" id="new-owner-form">
<div class="container"> <div class="container">
<input type="text" placeholder="{% trans "Owner name/NEPTUN" %}" /> <input type="text" placeholder="{% trans "Owner name/NEPTUN" %}" data-url="{% url school.views.group_ajax_owner_autocomplete %}"/>
<div id="new-owner-autocomplete"></div> <div id="new-owner-autocomplete"></div>
</div> </div>
</div> </div>
......
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