Permalink
Browse files

Add in demos of data-timeout and data-interval

  • Loading branch information...
1 parent f0037ec commit e5f31142dbafc18762cff3a7206098fe7445f204 @paltman paltman committed Jul 23, 2013
Showing with 39 additions and 3 deletions.
  1. +7 −0 demo/templates/_status.html
  2. +5 −1 demo/templates/homepage.html
  3. +4 −2 demo/urls.py
  4. +23 −0 demo/views.py
@@ -0,0 +1,7 @@
+<div class="alert alert-info hide">
+ You have created <strong>{{ count }}</strong> tasks so far.
+</div>
+
+<script type="text/javascript">
+ $(".alert").fadeIn();
+</script>
@@ -9,16 +9,20 @@
{% block topbar_base %}{% endblock %}
{% block body %}
+ <div class="alert hide"></div>
<div class="row">
<div class="span4"></div>
- <div class="span4">
+ <div class="span4" data-timeout="5000" data-url="{% url "status" %}">
<h1>Tasks</h1>
<p class="lead">
A sample tasks app to demonstrate how to use
<a href="https://github.com/eldarion/eldarion-ajax/">
eldarion-ajax
</a>
</p>
+ <p class="lead" data-interval="1000" data-url="{% url "total_count" %}" data-replace-inner="#total-count">
+ There have been <span id="total-count">{{ total_count }}</span> tasks added by everyone.
+ </p>
<form class="form-inline ajax" method="post" action="{% url "task_add" %}" data-append="#tasks">
{% csrf_token %}
<div class="input-append">
View
@@ -6,14 +6,16 @@
admin.autodiscover()
-urlpatterns = patterns("",
+urlpatterns = patterns(
+ "",
url(r"^$", "demo.views.home", name="home"),
url(r"^tasks/(?P<pk>\d+)/done/$", "demo.views.mark_done", name="task_mark_done"),
url(r"^tasks/(?P<pk>\d+)/undone/$", "demo.views.mark_undone", name="task_mark_undone"),
url(r"^tasks/completed/$", "demo.views.complete_count_fragment", name="task_complete_count_fragment"),
url(r"^tasks/add/$", "demo.views.add", name="task_add"),
url(r"^tasks/(?P<pk>\d+)/delete/$", "demo.views.delete", name="task_delete"),
-
+ url(r"^status/$", "demo.views.status", name="status"),
+ url(r"^total-count/$", "demo.views.total_count", name="total_count"),
url(r"^admin/", include(admin.site.urls)),
url(r"^account/", include("account.urls")),
)
View
@@ -11,6 +11,28 @@
from demo.models import Task
+def status(request):
+ data = {
+ "fragments": {
+ ".alert": render_to_string(
+ "_status.html",
+ RequestContext(request, {
+ "count": Task.objects.filter(
+ session__session_key=request.session.session_key
+ ).count()
+ })
+ )
+ }
+ }
+ return HttpResponse(json.dumps(data), content_type="application/json")
+
+
+def total_count(request):
+ return HttpResponse(json.dumps({
+ "html": Task.objects.count()
+ }), content_type="application/json")
+
+
def home(request):
if not request.session.exists(request.session.session_key):
request.session.create()
@@ -19,6 +41,7 @@ def home(request):
"tasks": Task.objects.filter(
session__session_key=request.session.session_key
),
+ "total_count": Task.objects.count(),
"done_count": Task.objects.filter(
session__session_key=request.session.session_key,
done=True

0 comments on commit e5f3114

Please sign in to comment.