Permalink
Browse files

fixed issue with clear not clearing all pages and resetting back to p…

…revious number
  • Loading branch information...
1 parent 4947915 commit 77981778f3952dee2a0411b955616e595440664a @ahsteele ahsteele committed Apr 14, 2011
Showing with 72 additions and 72 deletions.
  1. +71 −0 geocamTalk/templates/geocamTalk/base.html
  2. +1 −72 geocamTalk/templates/geocamTalk/message_list.html
@@ -21,6 +21,77 @@
});
});
</script>
+ <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(){
+ {% 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 += '<a data-rel="dialog" data-transition="pop" data-inline="true" data-role="button" data-icon="geoCam-map" data-iconpos="notext">Map Info</a>';
+ }
+ html_str += '</dt>';
+ html_str += '<dd id="message_'+pk+'_content">';
+ html_str += '<p>'+content+'</p>';
+ html_str += '</dd>';
+ }
+
+ $.mobile.activePage.page().find('#message_list').prepend(html_str);
+ running_timestamp = data['ts'];
+ new_message_count += data['msgCnt'];
+
+ $.mobile.pageContainer.find('div[data-role="page"]').each(function(i) {
+ $(this).find('#new_message_count').html(new_message_count);
+ });
+
+ if (new_message_count > 0
+ && $.mobile.activePage.page().find('#clear_link').length == 0) {
+ var link = $('<li><a id="clear_link" href="#">(Clear)</a></li>');
+ link.click(function() {
+ $.get('{% url geocamTalk.views.clear_messages %}', function() {
+ new_message_count = 0;
+
+ $.mobile.pageContainer.find('div[data-role="page"]').each(function(i) {
+ $(this).find('#new_message_count').html(0);
+ $(this).find('#clear_link').remove();
+ });
+ });
+ });
+ $.mobile.activePage.page().find('#my_messages_link').parent().after(link);
+ }
+ });
+ };
+ updateFunction();
+ setInterval(updateFunction, 3 *1000);
+ });
+ </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 %}
@@ -58,76 +58,5 @@
{% 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 += '<a data-rel="dialog" data-transition="pop" data-inline="true" data-role="button" data-icon="geoCam-map" data-iconpos="notext">Map Info</a>';
- }
- html_str += '</dt>';
- html_str += '<dd id="message_'+pk+'_content">';
- html_str += '<p>'+content+'</p>';
- html_str += '</dd>';
- }
-
- $.mobile.activePage.page().find('#message_list').prepend(html_str);
- running_timestamp = data['ts'];
- new_message_count += data['msgCnt'];
- $.mobile.activePage.page().find('#new_message_count').html(new_message_count);
-
- if (new_message_count > 0
- && $.mobile.activePage.page().find('#clear_link').length == 0)
- {
- //var span = '<span id="stupidfix">&nbsp;</span>';
- var link = $('<li><a id="clear_link" href="#">(Clear)</a></li>');
- link.click(function() {
- $.get('{% url geocamTalk.views.clear_messages %}', function() {
- new_message_count = 0;
- $.mobile.activePage.page().find('#new_message_count').html(new_message_count);
- $.mobile.activePage.page().find('#clear_link').remove();
- });
- });
- $.mobile.activePage.page().find('#my_messages_link').parent().after(link);//.after(span);
- //alert($('#bigSigh'));//.listview('refresh');
- }
- });
- };
- updateFunction();
- setInterval(updateFunction, 3*1000);
- });
-</script>
+
{% endblock %}

0 comments on commit 7798177

Please sign in to comment.