diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index c878310..81846a1 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -1069,4 +1069,8 @@ li.item .notify_badge { font-size: 14px; font-style: italic; cursor: text; +} + +.btn:focus, .btn:active:focus, .btn.active:focus, .btn.focus, .btn:active.focus, .btn.active.focus { + outline: none; } \ No newline at end of file diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index f554f67..97ed386 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -534,6 +534,18 @@ a.add-row { background: #FFFFFF; } +.btn_unfav { + color: #FF0000 !important; +} + +.btn_fav { + color: #BBBBBB !important; +} + +.btn:not(.btn-raised):not(.btn-link):focus, .btn:not(.btn-raised):not(.btn-link):hover, .input-group-btn .btn:not(.btn-raised):not(.btn-link):focus, .input-group-btn .btn:not(.btn-raised):not(.btn-link):hover { + background-color: initial; +} + @media(max-width: 768px) { .navbar .navbar-nav .dropdown .dropdown-menu li > a { color: #333333 !important; diff --git a/amadeus/static/js/main.js b/amadeus/static/js/main.js index 263d617..9151f83 100755 --- a/amadeus/static/js/main.js +++ b/amadeus/static/js/main.js @@ -14,7 +14,9 @@ $(function () { height: 200 }); - $('[data-toggle="tooltip"]').tooltip(); + $('[data-toggle="tooltip"]').tooltip({ + trigger: 'hover' + }); //Dropdown menu collapse $('.dropdown-accordion').on('click', 'a[data-toggle="collapse"]', function (event) { diff --git a/mural/templates/mural/_view.html b/mural/templates/mural/_view.html index d36aa97..6fe2ed7 100644 --- a/mural/templates/mural/_view.html +++ b/mural/templates/mural/_view.html @@ -25,7 +25,7 @@ {% endif %} - diff --git a/mural/templates/mural/list.html b/mural/templates/mural/list.html index 0acc23f..653d414 100644 --- a/mural/templates/mural/list.html +++ b/mural/templates/mural/list.html @@ -102,5 +102,28 @@ return false; }); } + + function favorite(btn) { + var action = btn.data('action'), + url = btn.data('url'); + + $.ajax({ + url: url, + data: {'action': action}, + dataType: 'json', + success: function (response) { + if (action == 'favorite') { + btn.switchClass("btn_fav", "btn_unfav", 250, "easeInOutQuad"); + btn.data('action', 'unfavorite'); + } else { + btn.switchClass("btn_unfav", "btn_fav", 250, "easeInOutQuad"); + btn.data('action', 'favorite'); + } + + btn.attr('data-original-title', response.label); + } + }); + + } {% endblock %} \ No newline at end of file diff --git a/mural/templatetags/mural_filters.py b/mural/templatetags/mural_filters.py index 3806944..5b58394 100644 --- a/mural/templatetags/mural_filters.py +++ b/mural/templatetags/mural_filters.py @@ -19,4 +19,18 @@ def fav_label(post, user): if MuralFavorites.objects.filter(post = post, user = user).exists(): return _('Unfavorite') - return _('Favorite') \ No newline at end of file + return _('Favorite') + +@register.filter(name = 'fav_action') +def fav_action(post, user): + if MuralFavorites.objects.filter(post = post, user = user).exists(): + return "unfavorite" + + return "favorite" + +@register.filter(name = 'fav_class') +def fav_class(post, user): + if MuralFavorites.objects.filter(post = post, user = user).exists(): + return "btn_unfav" + + return "btn_fav" \ No newline at end of file diff --git a/mural/urls.py b/mural/urls.py index af3fb15..58efae5 100644 --- a/mural/urls.py +++ b/mural/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), url(r'^create_gen/$', views.GeneralCreate.as_view(), name='create_general'), url(r'^render_post/([\w_-]+)/$', views.render_gen_post, name='render_post_general'), + url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), ] \ No newline at end of file diff --git a/mural/views.py b/mural/views.py index eaa054b..52b3197 100644 --- a/mural/views.py +++ b/mural/views.py @@ -6,6 +6,7 @@ from django.template.loader import render_to_string from django.core.urlresolvers import reverse, reverse_lazy from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.decorators import login_required from django.db.models import Q, Count from channels import Group @@ -13,7 +14,7 @@ import json from users.models import User -from .models import GeneralPost, CategoryPost, SubjectPost, MuralVisualizations +from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites from .forms import GeneralPostForm class GeneralIndex(LoginRequiredMixin, generic.ListView): @@ -103,3 +104,17 @@ def render_gen_post(request, post): html = render_to_string("mural/_view.html", context, request) return JsonResponse({'message': _('Your post was published successfully!'), 'view': html}) + +@login_required +def favorite(request, post): + action = request.GET.get('action', '') + post = get_object_or_404(Mural, id = post) + + if action == 'favorite': + MuralFavorites.objects.create(post = post, user = request.user) + + return JsonResponse({'label': _('Unfavorite')}) + else: + MuralFavorites.objects.filter(post = post, user = request.user).delete() + + return JsonResponse({'label': _('Favorite')}) \ No newline at end of file -- libgit2 0.21.2