Added (un)favourite buttons to other relevant places

Fixes issue #28

Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely 2012-08-25 17:03:08 +02:00
parent 293e1b24fc
commit 6747a48332
4 changed files with 99 additions and 65 deletions

View File

@ -0,0 +1,78 @@
/* TODO: The following two functions should also update the top-left profile
* box
*/
function favouriteOn()
{
var elem = $(this)
var topicSlug = elem.attr('id').replace(/^favourite-topic-button-/, '');
classList = elem.attr('class').split(/\s+/);
topicGroupSlug = null;
for (i in classList) {
if (classList[i].match(/^topicgroup-/)) {
topicGroupSlug = classList[i].replace(/^topicgroup-/, '');
break;
}
}
if (topicGroupSlug == null) {
return false;
}
url = Routing.generate('KekRozsakFrontBundle_forumFavouriteTopic', {
topicGroupSlug: topicGroupSlug,
topicSlug: topicSlug
});
$.ajax({
type: 'GET',
url: url
}).done(function() {
elem.html('[Kedvenc ikon]');
elem.removeClass('favourite-topic-button');
elem.addClass('unfavourite-topic-button');
elem.attr('id', 'unfavourite-topic-button-' + topicSlug);
elem.off('click.updateFav');
elem.on('click.updateFav', favouriteOff);
}).error(function() {
alert('Nem siker!');
});
}
function favouriteOff()
{
var elem = $(this)
var topicSlug = elem.attr('id').replace(/^unfavourite-topic-button-/, '');
classList = elem.attr('class').split(/\s+/);
topicGroupSlug = null;
for (i in classList) {
if (classList[i].match(/^topicgroup-/)) {
topicGroupSlug = classList[i].replace(/^topicgroup-/, '');
break;
}
}
if (topicGroupSlug == null) {
return false;
}
url = Routing.generate('KekRozsakFrontBundle_forumUnfavouriteTopic', {
topicGroupSlug: topicGroupSlug,
topicSlug: topicSlug
});
$.ajax({
type: 'GET',
url: url
}).done(function() {
elem.html('[Nem kedvenc ikon]');
elem.removeClass('unfavourite-topic-button');
elem.addClass('favourite-topic-button');
elem.attr('id', 'favourite-topic-button-' + topicSlug);
elem.off('click.updateFav');
elem.on('click.updateFav', favouriteOn);
}).error(function() {
alert('Nem siker!');
});
}
function setupFavButtons()
{
$('.favourite-topic-button').on('click.updateFav', favouriteOn);
$('.unfavourite-topic-button').on('click.updateFav', favouriteOff);
}
$(document).ready(setupFavButtons);

View File

@ -3,7 +3,16 @@
{% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %}
{% block title %} - Fórum - {{ topicGroup.title }} - {{ topic.title }}{% endblock %}
{% block content %}
<h3><a href="{{ path('KekRozsakFrontBundle_forumTopicGroupList') }}">Fórum</a> - <a href="{{ path('KekRozsakFrontBundle_forumTopicList', {slug: topicGroup.slug}) }}">{{ topicGroup.title }}</a> - {{ topic.title }}</h3>
<h3>
{% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %}
<span class="gomb unfavourite-topic-button topicgroup-{{ topicGroup.slug }}" id="unfavourite-topic-button-{{ topic.slug }}">[Kedvenc ikon]</span>
{% else %}
<span class="gomb favourite-topic-button topicgroup-{{ topicGroup.slug }}" id="favourite-topic-button-{{ topic.slug }}">[Nem kedvenc ikon]</span>
{% endif %}
<a href="{{ path('KekRozsakFrontBundle_forumTopicGroupList') }}">Fórum</a> -
<a href="{{ path('KekRozsakFrontBundle_forumTopicList', {slug: topicGroup.slug}) }}">{{ topicGroup.title }}</a> -
{{ topic.title }}
</h3>
<table class="post-lista">
<tbody>
<tr>

View File

@ -36,7 +36,14 @@
{% if topicGroup.topics|length > 0 %}
{% for topic in topicGroup.topics %}
<tr class="{{ cycle(['odd', 'even'], loop.index0) }}">
<td>[ikon]</td>
<td>
[ikon]
{% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %}
<span class="gomb unfavourite-topic-button topicgroup-{{ topic.topicGroup.slug }}" id="unfavourite-topic-button-{{ topic.slug }}">[Kedvenc ikon]</span>
{% else %}
<span class="gomb favourite-topic-button topicgroup-{{ topic.topicGroup.slug }}" id="favourite-topic-button-{{ topic.slug }}">[Nem kedvenc ikon]</span>
{% endif %}
</td>
<td><a href="{{ path('KekRozsakFrontBundle_forumPostList', {topicGroupSlug: topicGroup.slug, topicSlug: topic.slug}) }}">{{ topic.title }}</a></td>
<td></td>
<td>

View File

@ -27,10 +27,11 @@
{% for topic in topicGroup.topics %}
<tr class="{{ cycle(['odd', 'even'], loop.index0) }}">
<td>
[ikon]
{% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %}
<span class="gomb unfavourite-topic-button" id="unfavourite-topic-button-{{ topic.slug }}">[Kedvenc ikon]</span>
<span class="gomb unfavourite-topic-button topicgroup-{{ topicGroup.slug }}" id="unfavourite-topic-button-{{ topic.slug }}">[Kedvenc ikon]</span>
{% else %}
<span class="gomb favourite-topic-button" id="favourite-topic-button-{{ topic.slug }}">[Nem kedvenc ikon]</span>
<span class="gomb favourite-topic-button topicgroup-{{ topicGroup.slug }}" id="favourite-topic-button-{{ topic.slug }}">[Nem kedvenc ikon]</span>
{% endif %}
</td>
<td><a href="{{ path('KekRozsakFrontBundle_forumPostList', { topicGroupSlug: topicGroup.slug, topicSlug: topic.slug }) }}">{{ topic.title }}</a></td>
@ -51,64 +52,3 @@
Ebben a témakörben nincsenek témák.
{% endif %}
{% endblock content %}
{% block bottomscripts %}
<script type="text/javascript">
{# TODO: The following two functions should also update the top-left profile
# box
#}
function favouriteOn()
{
var self = $(this)
var topicSlug = self.attr('id').replace(/^favourite-topic-button-/, '');
url = Routing.generate('KekRozsakFrontBundle_forumFavouriteTopic', {
topicGroupSlug: '{{ topicGroup.slug }}',
topicSlug: topicSlug
});
$.ajax({
type: 'GET',
url: url
}).done(function() {
self.html('[Kedvenc ikon]');
self.removeClass('favourite-topic-button');
self.addClass('unfavourite-topic-button');
self.attr('id', 'unfavourite-topic-button-' + topicSlug);
self.off('click.updateFav');
self.on('click.updateFav', favouriteOff);
}).error(function() {
alert('Nem siker!');
});
}
function favouriteOff()
{
var self = $(this)
var topicSlug = self.attr('id').replace(/^unfavourite-topic-button-/, '');
url = Routing.generate('KekRozsakFrontBundle_forumUnfavouriteTopic', {
topicGroupSlug: '{{ topicGroup.slug }}',
topicSlug: topicSlug
});
$.ajax({
type: 'GET',
url: url
}).done(function() {
self.html('[Nem kedvenc ikon]');
self.removeClass('unfavourite-topic-button');
self.addClass('favourite-topic-button');
self.attr('id', 'favourite-topic-button-' + topicSlug);
self.off('click.updateFav');
self.on('click.updateFav', favouriteOn);
}).error(function() {
alert('Nem siker!');
});
}
function setupFavButtons()
{
$('.favourite-topic-button').on('click.updateFav', favouriteOn);
$('.unfavourite-topic-button').on('click.updateFav', favouriteOff);
}
$(document).ready(setupFavButtons);
</script>
{% endblock bottomscripts %}