Skip to content

Commit

Permalink
adding session-list riot tag
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscauley committed Nov 21, 2015
1 parent 55616be commit 5a5a352
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 43 deletions.
9 changes: 8 additions & 1 deletion course/models.py
Expand Up @@ -237,7 +237,8 @@ def as_json(self):
'instructor_name': self.get_instructor_name(),
'instructor_pk': self.user_id,
'course_id': self.course_id,
'enrolled_status': enrolled_status
'enrolled_status': enrolled_status,
'classtimes': [c.as_json for c in self.classtime_set.all()],
}
json = property(lambda self: dumps(self.as_json))
get_room = lambda self: self.course.room
Expand Down Expand Up @@ -349,6 +350,12 @@ def short_name(self):
description = cached_property(lambda self:self.session.course.description,name="description")
name = cached_property(lambda self: self.session.course.name,name="name")
room = cached_property(lambda self: self.session.course.room,name="room")
@property
def as_json(self):
return {
'start': str(self.start),
'end': str(self.end),
}
class Meta:
ordering = ("start",)

Expand Down
1 change: 1 addition & 0 deletions course/templates/course/_session_row.html
@@ -1,3 +1,4 @@
{#! DEPRACATED in favor of riot tag session-list #}
{% load txrx_tags %}
<div class="session well" id="s{{ session.id }}">
{% if request.user.is_superuser or request.user == session.user %}
Expand Down
44 changes: 17 additions & 27 deletions course/templates/course/detail.html
Expand Up @@ -70,7 +70,7 @@ <h2>Relevant files</h2>
{% if notify_course %}
<a href="{% url "clear_notification" "notify_course" request.user.id notify_course.id %}">
<button class="btn btn-danger">
Don't send me emails when this class is scheduled
Do not send me emails when this class is scheduled
</button>
</a>
{% else %}
Expand Down Expand Up @@ -101,31 +101,7 @@ <h2>Relevant files</h2>
<div style="clear: both;"></div>
</div>
<div class="col-xs-12 col-sm-4 col-md-3 pull-right" id="side">
<div class="SessionList">
{% if course.active_sessions %}
<h1 class="fee page_title">
{% if course.fee %}
${{ course.fee }}
{% else %}
Free
{% endif %}
</h1>
<h3>Upcoming Sessions:</h3>
{% endif %}
{% if "archive" in request.GET %}
{% for session in course.session_set.all|slice:"::-1" %}
{% include "course/_session_row.html" %}
{% endfor %}
{% else %}
{% for session in course.active_sessions %}
{% include "course/_session_row.html" %}
{% endfor %}
{% if request.user.is_superuser %}
<center><a href="?archive"><button class="btn-success btn">
View archived classes</button></a></center><br/>
{% endif %}
{% endif %}
</div>
<session-list></session-list>
<center>{% include "_social.html" with thing=course %}</center>
<br/>
<center><button class="btn btn-danger return_policy" onclick="$('.session_return_policy').toggle();return false;">
Expand Down Expand Up @@ -153,4 +129,18 @@ <h3>Upcoming Sessions:</h3>
</div>
{% endblock %}

{% block extrajs %}{% include "_comment_media.html" %}{% endblock %}
{% block extrajs %}
{% include "_comment_media.html" %}
<script type="riot/tag" src="/static/tags/course.tag"></script>
<script>
$(function() {
$.get(
'/classes/course_{{ course.id }}.json',
function(data) {
riot.mount('session-list',data);
},
"json"
)
});
</script>
{% endblock %}
3 changes: 2 additions & 1 deletion course/urls.py
Expand Up @@ -12,9 +12,10 @@

url(r'^$', 'classes.index'),
url(r'^(instructor|myclasses)/$','classes.user_ajax',name='user_ajax'),
url(r'^course_(\d+).json$','ajax.course_json'),

url(r'^toggle_enrollment/$', 'classes.toggle_enrollment'),
url(r'^rsvp/(\d+)/','classes.rsvp',name='rsvp'),
url(r'^u?n?rsvp/(\d+)/','classes.rsvp'),
url(r'^term/(\d+)/', 'classes.index'),
url(r'^ics/(all_classes).ics$','classes.ics_classes_all',name='ics_classes_all'),
url(r'^ics/(\d+)/([^/]+)/(my-classes).ics$','classes.ics_classes_user',name='ics_classes_user'),
Expand Down
9 changes: 9 additions & 0 deletions course/views/ajax.py
@@ -0,0 +1,9 @@
from django.http import HttpResponse
from django.shortcuts import get_object_or_404

from course.models import Course
import json

def course_json(request,course_id):
course = get_object_or_404(Course,id=course_id)
return HttpResponse(json.dumps(course.as_json))
2 changes: 1 addition & 1 deletion course/views/classes.py
Expand Up @@ -129,7 +129,7 @@ def rsvp(request,session_pk):
m = "You must be logged in to rsvp. Click the icon at the top right of the page to login or register"
return HttpResponse(json.dumps([0,m,session.full]))
enrollment,new = Enrollment.objects.get_or_create(user=request.user,session=session)
if "drop" in request.GET:
if "unrsvp" in request.path:
enrollment.delete()
q = 0
m = "You are no longer signed up for this."
Expand Down
13 changes: 5 additions & 8 deletions main/static/js/cart.js
Expand Up @@ -10,12 +10,8 @@ function showCart() {
$("#cart-modal").modal({width: 400, modal: true, minHight: 300});
}

function addClass(session_id) {
$(".SessionList .error").hide();
if (!session_id) { session_id = $("#session_selector").val(); }
if (!session_id) { $(".SessionList .error").show(); return; }
var session = window.SESSIONS_ON_PAGE[session_id];
addItem(session.name,session.fee,session_id);
function addClass(session) {
addItem(session.name,session.fee,session.id);
toggleCourses(session.name);
$("#cartModal").modal({show:true})
}
Expand Down Expand Up @@ -43,7 +39,8 @@ function toggleCourses(name) {
if ($(this).find(".itemName").text() == name) {
$(this).addClass("recentAdd");
}
})
});
riot.update('*');
}

function applyFilters(that) {
Expand Down Expand Up @@ -73,7 +70,7 @@ function rsvp(session_id,url) {
row.removeClass("loading");
row.find(".RsvpLink").removeClass("attending");
if (data[0]>0) {
row.find(".RsvpLink").addClass("attending");
row.find(".RsvpLink").addClass("attending");
}
$(".class-enrollment").hide();
},
Expand Down
10 changes: 5 additions & 5 deletions main/static/less/course.less
Expand Up @@ -13,7 +13,7 @@
&.enrolled { background: #A9CEE0; }
}

.course, .SessionList .session {
.course, session-list .session {
&:hover {
background: fade(@brand-primary,20);
}
Expand Down Expand Up @@ -84,7 +84,7 @@
}
}

.SessionList, event-list {
session-list, event-list {
position: relative;
.fee {
border-color: transparent;
Expand Down Expand Up @@ -193,7 +193,7 @@
#unscheduled-courses .price { display: none; }

@media (max-width: @screen-xs-max) {
.SessionList .fee {
session-list .fee {
float: right;
font-size: 24px;
line-height: 1;
Expand All @@ -218,7 +218,7 @@
}
}

.SessionList {
session-list {
.RsvpLink, .EnrollLink {
text-align: center;
}
Expand Down Expand Up @@ -315,7 +315,7 @@
cursor: help;
}

.SessionList {
session-list {
.add { display: inline-block; }
.view-cart, .add-to-cart, .rsvp, .unrsvp {
font-size: 12px;
Expand Down
76 changes: 76 additions & 0 deletions main/static/tags/course.tag
Expand Up @@ -64,3 +64,79 @@
</a>
</div>
</course-list>

<session-list>
<div class="session well" id="s{ id }" each={ opts.active_sessions }>
<a if={ parent.user.is_superuser || instructor_pk == parent.user.id }
href="/classes/instructor_session/{ id }/" class="instructor-link fa fa-edit"></a>
<a if={ parent.user.is_superuser } href="/admin/course/session/{ id }/"
class="admin-link fa fa-pencil-square"></a>
<div class="date" each={ classtimes }>
{ moment.format("ddd MMM D") } { start_time } - { end_time }
</div>
<div class="instructor">with { instructor_name }</div>
<b class="full" if={ closed_status == 'full' }>This session is full</b>
<div if={ !closed_status }>
<button class="btn btn-primary" onclick={ parent.add } if={ fee && !incart }>
Add this session to cart</button>
<button class="btn btn-primary fa fa-shopping-cart" onclick={ parent.viewCart } if={ fee && incart }>
View Cart</button>
<button class="btn btn-success rsvp" onclick={ parent.rsvp } if={ !fee && rsvpd }>
RSVP for this event</button>
<button class="btn btn-danger unrsvp" onclick={ parent.unrsvp } if={ !fee && !rsvpd }>
Cancel RSVP</button>
</div>
</div>

this.user = window.TXRX.user;
var that = this;
add(e) {
addClass(e.item);
}
viewCart(e) {
$("#cartModal").modal({show:true});
}
function _rsvp(e,url) {
var target = document.getElementById("s"+e.id);
target.setAttribute("ur-loading","loading");
$.get(
url,
function(data) {
target.removeAttribute("ur-loading","loading");
window.TXRX.user.rsvps[e.item.id] = data.quantity;
that.update();
},
"json"
);
}
rsvp(e) {
var url = "/classes/rsvp/"+e.item.id+"/";
_rsvp(e,url);
}
unrsvp(e) {
var url = "/classes/unrsvp/"+e.item.id+"/";
_rsvp(e,url);
}
function showSmartTime(moment) {
if (moment.minutes() == 0) {
if (moment.hours() == 0) { return "midnight" }
if (moment.hours() == 12) { return "noon" }
return moment.format("ha")
}
return moment.format("h:mma")
}
this.on("update",function() {
uR.forEach(this.opts.active_sessions,function(session) {
if (window.location.search.indexOf("overbook="+session.id) != -1) { session.closed_status = ""; }
session.rsvpd = window.TXRX.user.enrollments[session.id];
session.incart = !!window.simpleCart.items[session.id];
session.fee = that.opts.fee;
uR.forEach(session.classtimes,function(classtime) {
classtime.moment = moment(classtime.start);
classtime.start_time = showSmartTime(classtime.moment);
classtime.end_moment = moment(classtime.end);
classtime.end_time = showSmartTime(classtime.end_moment);
});
});
});
</session-list>
2 changes: 2 additions & 0 deletions user/views.py
Expand Up @@ -5,6 +5,7 @@
from django.template.response import TemplateResponse

from .models import User, UserCheckin
from event.models import RSVP
from course.models import Enrollment
from geo.models import Room
from tool.models import Criterion, UserCriterion, Permission
Expand Down Expand Up @@ -49,6 +50,7 @@ def user_json(request):
'is_toolmaster': request.user.is_toolmaster,
'is_staff': request.user.is_staff,
'is_superuser': request.user.is_superuser,
'enrollments': {e.session_id:e.quantity for e in request.user.enrollment_set.all()},
})
}
return TemplateResponse(request,"user.json",values)
Expand Down

0 comments on commit 5a5a352

Please sign in to comment.