{% extends "site_base.html" %}

{% load i18n %}
{% load threadedcommentstags %}

{% load tribe_tags %}
{% load gravatar %}
{% load project_tags %}
{% load blog_tags %}
{% load wiki %}
{% load voting_tags %} 
{% load extra_voting_tags %}

{% load in_filter %}
{% load extra_tagging_tags %}


{% block head_title %}{% blocktrans %}Tags{% endblocktrans %}{% endblock %}

{% block body %}
    <p><span class="warning">Note</span>: this is an <b>experimental</b> feature that is subject to massive change at any time.</p>

    <h1>{% trans "All Photos Matching " %}<i>"{{ tag }}"</i></h1>

    {% if phototags %}
        <div class="thumb-row clearfix">
        {% for photo in phototags %}
                <div class="gallery-photo-thumb">
                    <a href="/photos/details/{{ photo.id }}/"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a><br />
                    from <a href="{% url profiles.views.profile photo.member.username %}">{{ photo.member.username }}</a><br />
                    <img src="/site_media/comment.png" border="0" class="noborder" align="absmiddle" /><a href="/photos/details/{{ photo.id }}/">{% get_comment_count for photo as commentcount %} {{ commentcount }} Comments</a>
                    <br />
                    Viewed {{ photo.view_count }} Times
                </div>
        {% endfor %}
        </div>
    {% else %}
        No photos matching tag.
    {% endif %}

    {% if bookmarktags %}
        {% scores_for_objects bookmarktags as score_dict %}

        <h1>All Bookmarks Matching <i>{{ tag }}</i></h1>
        <table class="bookmarks" width="100%">
            {% for bookmark in bookmarktags %}
                <tr class="{% cycle odd,even %}">
                    <td class="meta">
                        <div class="avatar">{% gravatar bookmark.bookmark.adder 40 %}</div>
                        <div class="details"><a href="{% url profiles.views.profile bookmark.bookmark.adder.username %}">{{ bookmark.bookmark.adder }}</a></div>
                        {{ bookmark.bookmark.added|date }}
                    </td>
                    
                    <td>
                        <h2><a href="{{ bookmark.bookmark.url }}">{{ bookmark.bookmark.description }}</a></h2>
                        <div class="url">{% if bookmark.bookmark.get_favicon_url %}<img src="{{ bookmark.bookmark.get_favicon_url }}" width="16" height="16" /> {% endif %}{{ bookmark.bookmark.url }}</div>
                        <div class="body">{{ bookmark.bookmark.note|linebreaks }}</div>
                        <div class="tags">{% show_tag_counts bookmark.bookmark.all_tags_with_counts %}</div>
                    </td>
                </tr>
            {% endfor %}
        </table>

    {% else %}
        No bookmarks matching tag.
    {% endif %}


    <h1>{% trans "All Blog Posts Matching " %}<i>"{{ tag }}"</i></h1>

    {% if alltags %}
        <p>{% trans "These are blog posts from everyone:" %}</p>
        {% for blog_post in alltags %}
            {% show_blog_post blog_post %}
        {% endfor %}
    {% else %}
        No blog posts matching tag.
    {% endif %}

    <h1>{% blocktrans %}All Projects Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>

    <dl>
        {% for project in project_tags %}
            {% show_project project %}
        {% endfor %}
    </dl>

    <h1>{% blocktrans %}All Project Topics Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>

    {% for topic in project_topic_tags %}
        {% show_project_topic topic %}
    {% endfor %}

    <h1>{% blocktrans %}All Project Tasks Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>

    {% for task in project_task_tags %}
        {% show_task task %}
    {% endfor %}

    <h1>{% blocktrans %}All Tribes Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>

    <dl>
        {% for tribe in tribe_tags %}
            {% show_tribe tribe %}
        {% endfor %}
    </dl>

    <h1>{% blocktrans %}All Tribe Topics Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>

    {% for topic in tribe_topic_tags %}
        {% show_tribe_topic topic %}
    {% endfor %}

    <h1>{% blocktrans %}All Wiki Articles Matching <i>{{ tag }}</i>{% endblocktrans %}</h1>

    <table class="topics">
        {% for article in wiki_article_tags %}
            {% show_teaser article %}
        {% endfor %}
    </table>


{% endblock %}


{% block extra_body %}
    <script>
        function vote(bookmark_id, direction) {
            $.post(bookmark_id + '/' + direction + 'vote/', function(data) {
                var jsonResult = eval('(' + data + ')');
                var new_score = jsonResult.score.score;
                $('#bookmark_' + bookmark_id + '_score').text(new_score + ' point' + (new_score == 1 ? '': 's'));
            });
            if (direction == 'up') {
                $('#up_' + bookmark_id).replaceWith('<a id="up_' + bookmark_id + '" href="#" onclick="return false;"><img src="/site_media/up_mod.png"/>');
                $('#down_' + bookmark_id).replaceWith('<a id="down_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'clear\'); return false;"><img src="/site_media/down_grey.png"/>');
            }
            else if (direction == 'down') {
                $('#up_' + bookmark_id).replaceWith('<a id="up_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'clear\'); return false;"><img src="/site_media/up_grey.png"/>');
                $('#down_' + bookmark_id).replaceWith('<a id="down_' + bookmark_id + '" href="#" onclick="return false;"><img src="/site_media/down_mod.png"/>');
            }
            else { // clear
                $('#up_' + bookmark_id).replaceWith('<a id="up_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'up\'); return false;"><img src="/site_media/up_grey.png"/>');
                $('#down_' + bookmark_id).replaceWith('<a id="down_' + bookmark_id + '" href="#" onclick="vote(' + bookmark_id + ', \'down\'); return false;"><img src="/site_media/down_grey.png"/>');
            }
        }
    </script>
{% endblock %}
