From 6747a4833273ad187b106138cd185e0f30761058 Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Sat, 25 Aug 2012 17:03:08 +0200 Subject: [PATCH] Added (un)favourite buttons to other relevant places Fixes issue #28 Signed-off-by: Gergely Polonkai --- .../FrontBundle/Resources/public/js/forum.js | 78 +++++++++++++++++++ .../Resources/views/Forum/postList.html.twig | 11 ++- .../views/Forum/topicGroupList.html.twig | 9 ++- .../Resources/views/Forum/topicList.html.twig | 66 +--------------- 4 files changed, 99 insertions(+), 65 deletions(-) create mode 100644 src/KekRozsak/FrontBundle/Resources/public/js/forum.js diff --git a/src/KekRozsak/FrontBundle/Resources/public/js/forum.js b/src/KekRozsak/FrontBundle/Resources/public/js/forum.js new file mode 100644 index 0000000..e4b9a86 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/public/js/forum.js @@ -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); diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/postList.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/postList.html.twig index 40dfb05..646e141 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/postList.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/postList.html.twig @@ -3,7 +3,16 @@ {% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %} {% block title %} - Fórum - {{ topicGroup.title }} - {{ topic.title }}{% endblock %} {% block content %} -

Fórum - {{ topicGroup.title }} - {{ topic.title }}

+

+{% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %} + [Kedvenc ikon] +{% else %} + [Nem kedvenc ikon] +{% endif %} + Fórum - + {{ topicGroup.title }} - + {{ topic.title }} +

diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig index b91fa22..4a162e6 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicGroupList.html.twig @@ -36,7 +36,14 @@ {% if topicGroup.topics|length > 0 %} {% for topic in topicGroup.topics %} - + @@ -51,64 +52,3 @@ Ebben a témakörben nincsenek témák. {% endif %} {% endblock content %} - -{% block bottomscripts %} - -{% endblock bottomscripts %} \ No newline at end of file
[ikon] + [ikon] +{% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %} + [Kedvenc ikon] +{% else %} + [Nem kedvenc ikon] +{% endif %} + {{ topic.title }} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig index 69e3513..842627a 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Forum/topicList.html.twig @@ -27,10 +27,11 @@ {% for topic in topicGroup.topics %}
+ [ikon] {% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %} - [Kedvenc ikon] + [Kedvenc ikon] {% else %} - [Nem kedvenc ikon] + [Nem kedvenc ikon] {% endif %} {{ topic.title }}