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 %} -
[ikon] | ++ [ikon] +{% if app.user.userData and app.user.userData.isFavouriteForumTopic(topic) %} + | +{% else %} + +{% 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) %} - | + {% else %} - + {% endif %}{{ topic.title }} | @@ -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