Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'jquerymobile'

  • Loading branch information...
commit d66e710ca9becdf19d03930e12e37cefeca83063 2 parents 718e9cc + d57046b
@patrickbaumann patrickbaumann authored
View
0  example/manage.py 100755 → 100644
File mode changed
View
132 geocamTalk/templates/geocamTalk/base.html
@@ -1,32 +1,126 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="utf-8">
<title>
{% block title %}
GeoCam Talk
{% endblock %}
</title>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
- <script src="http://jquery.malsup.com/media/jquery.media.js?v.92"></script>
+ <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
+ <link rel="stylesheet" href="/resources/css/jquery.mobile.css" />
+ <link rel="stylesheet" href="/resources/css/site.css" />
+ <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
+ <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
+ <script type="text/javascript">
+ $(document).bind("mobileinit", function () {
+ //$.mobile.ajaxEnabled = true;
+ $.extend($.mobile, {
+ ajaxFormsEnabled: false/*,
+ ajaxEnabled: false*/
+ });
+ });
+ var running_timestamp = {{ timestamp }};
+ var new_message_count = {{ user.profile.getUnreadMessageCount }};
+
+ var updateFunction = function() {
+ var url = '{% url geocamTalk.views.feed_messages %}';
+
+ url += '?since=' + running_timestamp;
+ $.getJSON(url, function(data) {
+ var html_str = "";
+ for (var i in data['ms']) {
+ var msg = data['ms'][i];
+ var pk = msg['messageId'];
+ var content = msg['content'];
+ var has_geolocation = msg['hasGeolocation'];
+ var authorUsername = msg['authorUsername'];
+ var authorFullname = msg['authorFullname'];
+ {% if recipient %}
+ authorFullname = '<a href="{% url geocamTalk.views.message_list recipient.username %}/' +authorUsername+ '">' +authorFullname+ '</a>' ;
+ {% endif %}
+
+ var msgDate = new Date (msg['contentTimestamp']);
+ var content_timestamp =
+ msgDate.getDate() + "/" + msgDate.getMonth() + "/" + msgDate.getFullYear()
+ + " " + msgDate.getHours() + ":" + msgDate.getMinutes();
+
+ html_str += '<li id="message_'+pk+'"><p id="message_'+pk+'_header">';
+ html_str += 'On '+content_timestamp+' '+authorFullname;
+ if (has_geolocation == true) {
+ html_str += '<a href="#" data-rel="dialog" data-transition="pop" data-inline="true" data-role="button" data-icon="geoCam-map" data-iconpos="notext" title="Map Info" data-theme="c" class="ui-btn ui-btn-inline ui-btn-icon-notext ui-btn-corner-all ui-shadow ui-btn-up-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Map Info</span><span class="ui-icon ui-icon-geoCam-map ui-icon-shadow"></span></span></a>';
+ }
+ html_str += '</p>';
+ html_str += '<p id="message_'+pk+'_content">'+content+'</p>';
+ html_str += '</li>';
+ }
+
+ running_timestamp = data['ts'];
+ new_message_count += data['msgCnt'];
+
+ $('div[data-role="page"]').each(function() {
+ $(this).find('#message_list').prepend(html_str);
+ $(this).find('#new_message_count').html(new_message_count);
+ });
+
+ if (new_message_count > 0
+ && $('div[data-role="page"]').find('#clear_link').length == 0) {
+ var link = $('<a href="#" id="clear_link" data-role="button" data-inline="true" data-theme="c" class="ui-btn ui-btn-inline ui-btn-corner-all ui-shadow ui-btn-up-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Clear Received Messages</span></span></a>');
+ link.click(function() {
+ $.get('{% url geocamTalk.views.clear_messages %}', function(data) {
+ $('div[data-role="page"]').each(function() {
+ $(this).find('#clear_link').remove();
+ $(this).find('#new_message_count').html(0);
+ });
+ running_timestamp = data['ts'];
+ });
+ });
+ $('div[data-role="page"]').find('#new_message_link').after(link);
+ }
+ });
+ }
+ $('div').live('pagebeforeshow', function(event, ui){
+ $('a.media').media( { width: 300, height: 20 } );
+ updateFunction();
+ });
+ setInterval(updateFunction, 60 * 10 * 1000); // 10 minutes
+ </script>
+ <script src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"></script>
+ <script src="http://jquery.malsup.com/media/jquery.media.js?v.92"></script>
{% block css %}{% endblock %}
</head>
<body>
- <header>
- {% if user.is_authenticated %}
- <a id="my_messages_link" href="{% url geocamTalk.views.message_list user.username%}">My Messages (<span id="new_message_count">{{user.profile.getUnreadMessageCount}}</span>)</a> |
- <a href="{% url geocamTalk.views.message_list%}">All Messages</a> | Hello {% firstof user.first_name user.username %}
- <a href="/accounts/logout/">Logout</a>
- {% else %}
- <a href="/accounts/login/">Login</a>
- {% endif %}
- </header>
- <content>
- {% block content %}
- {% endblock %}
- </content>
- <footer>
- </footer>
- {% block js %}
- {% endblock %}
+ <div id="bodydiv" data-role="page" data-theme="c">
+ <header>
+ <div data-role="header">
+ <h1>{% block pagetitle %}GeoCam Talk{% endblock %}</h1>
+ <a href="/talk/messages" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
+ <div data-role="navbar">
+ <ul id="bigsigh">
+ <li><a id="my_messages_link" href="{% url geocamTalk.views.message_list user.username%}">My Messages (<span id="new_message_count">{{user.profile.getUnreadMessageCount}}</span>)</a></li>
+ <li><a href="{% url geocamTalk.views.message_list%}">All Messages</a></li>
+ <li><a href="{% url geocamTalk.views.message_map %}">Talk Map</a></li>
+ </ul>
+ </div>
+ </div>
+ </header>
+ <content>
+ <div data-role="content">
+ <a id="new_message_link" href="{% url geocamTalk.views.create_message %}" data-role="button" data-inline="true">New Message</a>
+ {% block content %}
+ {% endblock %}
+ </div>
+ </content>
+ <footer>
+ <div data-role="footer" class="ui-bar">
+ {% if user.is_authenticated %}
+ <a href="/accounts/logout/" class="ui-btn-right">Logout {% firstof user.first_name user.username %}</a>
+ {% else %}
+ <a href="/accounts/login/">Login</a>
+ {% endif %}
+ </div>
+ </footer>
+ {% block js %} {% endblock %}
+ </div>
</body>
</html>
View
15 geocamTalk/templates/geocamTalk/details.html
@@ -0,0 +1,15 @@
+<div data-role="page">
+<img src="http://maps.google.com/maps/api/staticmap?markers={{ message.latitude }},{{ message.longitude }}&zoom=14&size=320x400&sensor=false" />
+<!--center={{ message.latitude }},{{ message.longitude }}-->
+<dl>
+ <dt>Latitude</dt>
+ <dd>{{ message.latitude }}</dd>
+ <dt>Longitude</dt>
+ <dd>{{ message.longitude }}</dd>
+ <dt>Altitude</dt>
+ <dd>{{ message.altitude }}</dd>
+ <dt>Accuracy</dt>
+ <dd>{{ message.accuracy }}</dd>
+</dl>
+<a href="docs-dialogs.html" data-role="button" data-inline="true" data-icon="check" data-rel="back" data-theme="c">Okay</a>
+</div>
View
55 geocamTalk/templates/geocamTalk/map.html
@@ -0,0 +1,55 @@
+{% extends "geocamTalk/base.html" %}
+
+{% block js %}
+<script>
+ $('#bodydiv').live('pageshow', function(event) {
+ createMap({{ first_geolocation.0 }},{{ first_geolocation.1 }});
+ });
+
+function createMap(latitude, longitude) {
+ var latlng = new google.maps.LatLng( latitude,longitude );
+ var myOptions = {
+ zoom: 12,
+ center: latlng,
+ mapTypeControl: false,
+ navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+
+ var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
+
+ var messages =
+ [{% for m in gc_msg %}{% if m.has_geolocation %}
+ {marker:null,latitude:{{m.latitude}},longitude:{{m.longitude}},pk:{{m.pk}}},
+ {% endif %}
+ {% endfor %}];
+
+ $(messages).each(function(i,msg){
+ var pos = new google.maps.LatLng(msg.latitude,msg.longitude);
+ msg.marker = new google.maps.Marker({position:pos,map:map});
+ });
+
+ var infoWindow = new google.maps.InfoWindow();
+ $(messages).each(function(i, msg) {
+ google.maps.event.addListener(msg.marker,"click", function() {
+ infoWindow.close();
+ $.getJSON("talk/messages/details/" + msg.pk + ".json", function(data) {
+ var messageHtml = "<strong>" + data['authorFullname'] + "</strong><br />"
+ + "<span>" + data['contentTimestamp'] + "</span>"
+ + "<p>" + data['content'] + "</p>"
+ infoWindow.setContent(messageHtml);
+ });
+ infoWindow.open(map, msg.marker);
+ });
+ });
+
+ google.maps.event.trigger(map,'resize');
+ }
+
+</script>
+{% endblock %}
+
+{% block content %}
+<section id="map_canvas" style="width: 320px; height: 400px">
+</section>
+{% endblock %}
View
93 geocamTalk/templates/geocamTalk/message_list.html
@@ -31,9 +31,10 @@
{% endif %}
</h1>
<div id="messages">
-<dl id="message_list">
+<ul id="message_list">
{% for m in gc_msg %}
- <dt id="message_{{m.pk}}">
+ <li id="message_{{m.pk}}">
+ <p id="message_{{m.pk}}_header">
On {{ m.get_date_string }}
{% if recipient %}
<a href="{% url geocamTalk.views.message_list recipient.username m.author.username %}">
@@ -41,91 +42,19 @@
{% else %}
{{ m.get_author_string}}
{% endif %}
- said
- {% if m.has_geolocation %}<img src="/resources/map.png" />{%endif%}
+ {% if m.has_geolocation %}<a href="{% url geocamTalk.views.message_details m.pk %}" data-rel="dialog" data-transition="pop" data-inline="true" data-role="button" data-icon="geoCam-map" data-iconpos="notext">Map Info</a>{%endif%}
{% if m.has_audio %}
<a class="media" href="{{m.audio_file.url}}"></a>
- {%endif%}
- </dt>
- <dd id="message_{{m.pk}}_content">
- <p>{{ m.content}}</p>
- </dd>
+ {%endif%}
+ </p>
+ <p id="message_{{m.pk}}_content">
+ {{ m.content}}
+ </p>
+ </li>
{% endfor %}
-</dl>
-
-<a href="{% url geocamTalk.views.create_message %}">New Message</a>
+</ul>
</div>
{% endblock %}
{% block js %}
-<script>
- $(document).ready(function() {
- $('a.media').media( { width: 300, height: 20 } );
- var running_timestamp = {{ timestamp }};
- var new_message_count = {{ user.profile.getUnreadMessageCount }};
-
- var updateFunction = function(){
- // messagefeed.json looks like this:
- // [{"content": "The hospital is full, no more beds...", "content_timestamp": "02/19 21:35:52", "has_geolocation": -122.4048743, "author": "Adam Grant"},
- // {"content": "Casualties are littering the streets!", "content_timestamp": "02/19 21:35:29", "has_geolocation": -122.4048743, "author": "Adam Grant"},
- // {"content": "Some crazy stuff is happening in this neighborhood.", "content_timestamp": "02/19 21:34:46", "has_geolocation": -122.4048743, "author": "Adam Grant"}]
- {% if author %}
- var url = '{% url geocamTalk.views.feed_messages recipient.username author.username %}';
- {% else %}
- {% if recipient %}
- var url = '{% url geocamTalk.views.feed_messages recipient.username %}';
- {% else %}
- var url = '{% url geocamTalk.views.feed_messages %}';
- {% endif %}
- {% endif %}
- url = url + '?since=' + running_timestamp;
- $.getJSON(url, function(data) {
- var html_str = "";
- for (var i in data['ms']) {
- var msg = data['ms'][i];
- var pk = msg['messageId'];
- var content = msg['content'];
- var content_timestamp = msg['contentTimestamp']; // TODO: convert this to a string
- var has_geolocation = msg['hasGeolocation'];
- var authorUsername = msg['authorUsername'];
- var authorFullname = msg['authorFullname']
- {% if recipient %}
- authorFullname = '<a href="{% url geocamTalk.views.message_list recipient.username %}/' +authorUsername+ '">' +authorFullname+ '</a>' ;
- {% endif %}
-
- html_str += '<dt id="message_'+pk+'">';
- html_str += 'On '+content_timestamp+' '+authorFullname+' said';
- if (has_geolocation == true) {
- html_str += '<img src="/resources/map.png" />';
- }
- html_str += '</dt>';
- html_str += '<dd id="message_'+pk+'_content">';
- html_str += '<p>'+content+'</p>';
- html_str += '</dd>';
- }
- $('#message_list').prepend(html_str);
- running_timestamp = data['ts'];
- new_message_count += data['msgCnt'];
- $('#new_message_count').html(new_message_count);
-
- if (new_message_count > 0 && $('#clear_link').length == 0)
- {
- var span = '<span id="stupidfix">&nbsp;</span>';
- var link = $('<a id="clear_link" href="#">(Clear)</a>');
- link.click(function() {
- $.get('{% url geocamTalk.views.clear_messages %}', function() {
- new_message_count = 0;
- $('#new_message_count').html(new_message_count);
- $('#clear_link').remove();
- $('#stupidfix').remove();
- });
- });
- $('#my_messages_link').after(link).after(span);
- }
- });
- };
- updateFunction();
- setInterval(updateFunction, 3*1000);
- });
-</script>
{% endblock %}
View
6 geocamTalk/urls.py
@@ -18,7 +18,9 @@
url(r'messages/clear', 'clear_messages',
name='talk_clear_messages'),
url(r'messages/details/(?P<message_id>\d+).json', 'message_details_json',
- name="talk_message_details_json"),
+ name="talk_message_details_json"),
+ url(r'messages/details/(?P<message_id>\d+)$', 'message_details',
+ name="talk_message_details"),
url(r'messages/(?P<recipient_username>[^ ]+)/(?P<author_username>[^ ]+).json', 'feed_messages',
name="talk_message_list_to_from_json"),
url(r'messages/(?P<recipient_username>[^ ]+).json', 'feed_messages',
@@ -31,4 +33,6 @@
name="talk_message_list_author"),
url(r'messages', 'message_list',
name="talk_message_list_all"),
+ url(r'map', 'message_map',
+ name="talk_message_map"),
)
View
44 geocamTalk/views.py
@@ -5,7 +5,7 @@
# __END_LICENSE__
from django.shortcuts import render_to_response, get_object_or_404
-from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404,\
+from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404, \
HttpResponseBadRequest
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
@@ -20,6 +20,20 @@
from django.db.models import Q, Count
import json
+def get_first_geolocation(messages):
+ """ return the first geotagged message lat and long as tuple """
+ try:
+ return [(m.latitude, m.longitude) for m in messages if m.has_geolocation()][0]
+ except:
+ return ()
+
+@login_required
+def message_map(request):
+ messages = TalkMessage.getMessages()
+ return render_to_response('geocamTalk/map.html',
+ dict(gc_msg=messages,
+ first_geolocation=get_first_geolocation(messages)),
+ context_instance=RequestContext(request))
@login_required
def clear_messages(request):
@@ -27,7 +41,7 @@ def clear_messages(request):
profile.last_viewed_mymessages = TalkMessage.getLargestMessageId()
profile.save()
- return HttpResponse(status=200)
+ return HttpResponse(json.dumps({'ts': TalkMessage.getLargestMessageId()}))
@login_required
def message_list(request, recipient_username=None, author_username=None):
@@ -47,9 +61,9 @@ def message_list(request, recipient_username=None, author_username=None):
profile.last_viewed_mymessages = timestamp
profile.save()
- return render_to_response('geocamTalk/message_list.html',
- dict(gc_msg=TalkMessage.getMessages(recipient,author),
- recipient=recipient,
+ return render_to_response('geocamTalk/message_list.html',
+ dict(gc_msg=TalkMessage.getMessages(recipient, author),
+ recipient=recipient,
author=author,
timestamp=timestamp),
context_instance=RequestContext(request))
@@ -89,11 +103,19 @@ def message_details_json(request, message_id):
else:
message = get_object_or_404(TalkMessage, pk=message_id)
return HttpResponse(json.dumps(message.getJson()))
-
+
+@login_required
+def message_details(request, message_id):
+ message = get_object_or_404(TalkMessage, pk=message_id)
+
+ return render_to_response('geocamTalk/details.html',
+ {'message':message},
+ context_instance=RequestContext(request))
+
@login_required
def index(request):
return render_to_response('geocamTalk/home.html',
- dict(),
+ dict(),
context_instance=RequestContext(request))
@login_required
@@ -116,7 +138,7 @@ def create_message(request):
else:
form = GeocamTalkForm()
return render_to_response('geocamTalk/message_form.html',
- dict(form=form),
+ dict(form=form),
context_instance=RequestContext(request))
@@ -155,9 +177,9 @@ def create_message_json(request):
message = TalkMessage.fromJson(messageDict)
if "audio" in request.FILES:
- filename = "%s%s.mp4" % (message.author, message.content_timestamp.strftime("%H%M%S"))
+ filename = "%s%s.mp4" % (message.author, message.content_timestamp.strftime("%H%M%S"))
file_content = ContentFile(request.FILES['audio'].read())
- file_format = os.path.splitext( request.FILES['audio'].name)[-1]
+ file_format = os.path.splitext(request.FILES['audio'].name)[-1]
message.audio_file.save(filename, file_content)
try:
print message
@@ -176,4 +198,4 @@ def create_message_json(request):
else:
return HttpResponseServerError()
else:
- return HttpResponseForbidden()
+ return HttpResponseForbidden()
View
0  revisions/__init__.py 100755 → 100644
File mode changed
View
0  revisions/admin.py 100755 → 100644
File mode changed
View
0  revisions/managers.py 100755 → 100644
File mode changed
View
0  revisions/middleware.py 100755 → 100644
File mode changed
View
0  revisions/models.py 100755 → 100644
File mode changed
View
0  revisions/shortcuts.py 100755 → 100644
File mode changed
View
0  revisions/tests/__init__.py 100755 → 100644
File mode changed
View
0  revisions/tests/admin.py 100755 → 100644
File mode changed
View
0  revisions/tests/fixtures/asides_scenario.json 100755 → 100644
File mode changed
View
0  revisions/tests/fixtures/fancy_revisions_scenario.json 100755 → 100644
File mode changed
View
0  revisions/tests/fixtures/revisions_scenario.json 100755 → 100644
File mode changed
View
0  revisions/tests/fixtures/trashable_scenario.json 100755 → 100644
File mode changed
View
0  revisions/tests/fixtures/users.json 100755 → 100644
File mode changed
View
0  revisions/tests/models.py 100755 → 100644
File mode changed
View
0  revisions/tests/tests.py 100755 → 100644
File mode changed
View
0  revisions/tests/urls.py 100755 → 100644
File mode changed
View
0  revisions/views.py 100755 → 100644
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.