Event API & User Event view

This commit is contained in:
Martin Bauer
2013-06-18 22:49:01 +02:00
parent 111fce5d91
commit 0ce7dc2f25
9 changed files with 309 additions and 4 deletions

View File

@@ -0,0 +1,175 @@
{% extends "website/base.html" %}
{% load sekizai_tags staticfiles %}
<!-- No Feature slider -->
{% block feature_slider %}
{% endblock %}
<!-- Static Navbar at top -->
{% block navbar_options %} navbar navbar-inverse navbar-static-top {% endblock %}
{% block content %}
{% addtoblock "js" %}
<script>
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
crossDomain: false, // obviates need for sameOrigin test
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
function setEventButtonStatus( button, status ) {
others = button.siblings();
all = button.add( button.siblings() );
all.removeClass("btn-danger").
removeClass("btn-warning").
removeClass("btn-success").
removeClass("btn-info");
others.addClass("btn-info");
if ( status === "Yes" ) {
button.addClass("btn-success");
}
else if ( status === "No" ) {
button.addClass("btn-danger");
}
else if ( status === "?" ) {
button.addClass("btn-warning");
}
}
function putStatus( button, status ) {
p = button.parent();
putObject = [ { "event": p.data("event-id"),
"musician": p.data("username"),
"status": status } ];
request = $.ajax( {
type: "PUT",
url: "/eventParticipation/" + p.data("username") + "/" + p.data("event-id"),
contentType: "application/json",
data: JSON.stringify(putObject)
});
setEventButtonStatus( button, status );
//request.done(function(jqXHR, textStatus) {
// setEventButtonStatus( button, status )
//});
}
$(function(){
$(".event-status-yes").click(function () {
putStatus( $(this), "Yes" );
});
$(".event-status-no").click(function () {
putStatus( $(this), "No" );
});
$(".event-status-dontknow").click(function () {
putStatus( $(this), "?" );
});
});
</script>
{% endaddtoblock %}
<div class="container">
<div class="row">
<div class="row-fluid eventTable">
<div class="span12">
<h2>Termine</h2>
<div class="box-content">
<table class="table table-striped">
<thead>
<tr>
<th id='eventTitle'>Termin</th>
<th id='date' >Datum</th>
<th id='time' >Uhrzeit</th>
<th id='place' >Ort</th>
<th id='status' >Status ändern</th>
<th id='comment' >Kommentar</th>
</tr>
</thead>
<tbody>
{% for event in events %}
<tr>
<td class="center"> <a href="{{ event.pk }}"> {{ event.title }} </a> </td>
<td class="center"> {{ event.date }} </td>
<td class="center"> {{ event.time }} </td>
<!-- <td class="center"> {{ event.location }} </td> -->
<td class="center"> Ort </td>
<td class="center">
<div class="btn-group event-status-select" data-event-id="{{event.pk}}" data-username="{{user.username}}" >
<button class="btn event-status-yes {% if event.participation.status == "Yes" %} btn-success {% else %} btn-info {% endif %}">
<i class="icon-ok-sign icon-white"></i>
</button>
<button class="btn event-status-dontknow {% if event.participation.status == "?" %} btn-warning {% else %} btn-info {% endif %}">
<i class="icon-question-sign icon-white "></i>
</button>
<button class="btn event-status-no {% if event.participation.status == "No" %} btn-danger {% else %} btn-info {% endif %}">
<i class="icon-remove-sign icon-white"></i>
</button>
</div>
</td>
<td>
<div class="input-append">
<input id="appendedInputButton" size="16" type="text" value="{{ event.participation.comment }}" ><button class="btn" type="button">OK</button>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
</div>
</div>
{% endblock %}