From 108c9cc4636b04f4ba3f0edd67c26acbdca36984 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Thu, 11 Sep 2008 16:37:17 +0200 Subject: [PATCH] Added user shelves column to main page. --- apps/catalogue/forms.py | 4 +++ apps/catalogue/views.py | 17 +++++++++--- wolnelektury/media/css/master.css | 21 +++++++++++---- wolnelektury/media/js/catalogue.js | 27 +++++++++++++------ wolnelektury/templates/base.html | 2 +- .../templates/catalogue/main_page.html | 23 ++++++++++++++-- .../templates/catalogue/user_shelves.html | 4 +-- 7 files changed, 77 insertions(+), 21 deletions(-) diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index 279ec7193..e20adbadc 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -39,6 +39,10 @@ class ObjectSetsForm(forms.Form): class NewSetForm(forms.Form): name = forms.CharField(max_length=50, required=True) + + def __init__(self, *args, **kwargs): + super(NewSetForm, self).__init__(*args, **kwargs) + self.fields['name'].widget.attrs['title'] = u'nazwa nowej półki' def save(self, user, commit=True): name = self.cleaned_data['name'] diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 72055f780..3b9f31d16 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -71,6 +71,8 @@ def tags_starting_with(request): def main_page(request): if request.user.is_authenticated(): + shelves = models.Tag.objects.filter(category='set', user=request.user) + new_set_form = forms.NewSetForm() extra_where = '((NOT catalogue_tag.category = "set" AND catalogue_tag.main_page = 1) OR catalogue_tag.user_id = %d)' % request.user.id else: extra_where = 'NOT catalogue_tag.category = "set" AND catalogue_tag.main_page = 1' @@ -80,6 +82,7 @@ def main_page(request): categories = split_tags(tags) form = forms.SearchForm() + return render_to_response('catalogue/main_page.html', locals(), context_instance=RequestContext(request)) @@ -222,7 +225,11 @@ def new_set(request): new_set_form = forms.NewSetForm(request.POST) if new_set_form.is_valid(): new_set = new_set_form.save(request.user) - return HttpResponse(u'

Półka %s została utworzona

' % new_set) + + if request.is_ajax(): + return HttpResponse(u'

Półka %s została utworzona

' % new_set) + else: + return HttpResponseRedirect('/') return render_to_response('catalogue/book_sets.html', locals(), context_instance=RequestContext(request)) @@ -233,9 +240,13 @@ def new_set(request): def delete_shelf(request, slug): user_set = get_object_or_404(models.Tag, slug=slug, category='set', user=request.user) user_set.delete() - return HttpResponse(u'

Półka %s została usunięta

' % user_set.name) - + if request.is_ajax(): + return HttpResponse(u'

Półka %s została usunięta

' % user_set.name) + else: + return HttpResponseRedirect('/') + + @login_required def user_shelves(request): shelves = models.Tag.objects.filter(category='set', user=request.user) diff --git a/wolnelektury/media/css/master.css b/wolnelektury/media/css/master.css index 41d81810b..d2fc0fc16 100644 --- a/wolnelektury/media/css/master.css +++ b/wolnelektury/media/css/master.css @@ -173,8 +173,13 @@ p .ac_input { margin: 0 0 2.5em 0; } +#tags-description { + color: #777; + margin: 0 0.5em -0.75em 0.5em; +} + #main-page #tags-list { - margin-right: 29em; + margin-right: 33%; } #categories-list ul, #themes-list ul { @@ -236,9 +241,9 @@ p .ac_input { /* ============== */ #propaganda { float: right; - width: 27em; + width: 30%; margin: 0; - padding: 1em; + padding: 2em 1em 1em; } @@ -460,16 +465,22 @@ p .ac_input { padding: 1em; } -#user-shelves-window ul { +.shelf-list { list-style: none; padding: 0; } -#user-shelves-window a.delete-shelf { +.shelf-list a.delete-shelf { color: #900; float: right; } +.shelf-list a.delete-shelf:active, .shelf-list a.delete-shelf:hover { + color: #FFF; + background-color: #900; + text-decoration: none; +} + /* ======================== */ /* = Alphabetic book list = */ /* ======================== */ diff --git a/wolnelektury/media/js/catalogue.js b/wolnelektury/media/js/catalogue.js index ad5a7c2c8..58021fee8 100644 --- a/wolnelektury/media/js/catalogue.js +++ b/wolnelektury/media/js/catalogue.js @@ -1,6 +1,6 @@ (function($) { $(function() { - $('#id_q').labelify({labelledClass: 'blur'}); + $('form input').labelify({labelledClass: 'blur'}); target = $('#login-register-window div.target'); @@ -80,7 +80,7 @@ $('#login-register-window').jqm({ target: target[0], overlay: 60, - trigger: '#login-register-link', + trigger: '.login-register-link', onShow: function(hash) { var offset = $(hash.t).offset(); hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top}); @@ -89,6 +89,17 @@ } }); + $('.delete-shelf').click(function() { + var link = $(this); + var shelf_name = $('.visit-shelf', link.parent()).text(); + if (confirm('Czy na pewno usunąć półkę ' + shelf_name + '?')) { + $.post(link.attr('href'), function(data, textStatus) { + link.parent().remove(); + }); + } + return false; + }); + $('#user-shelves-window').jqm({ ajax: '@href', target: $('#user-shelves-window div.target')[0], @@ -101,8 +112,6 @@ hash.w.show(); }, onLoad: function(hash) { - var shelf_name = $('a.visit-shelf', this).html(); - $('form', hash.w).ajaxForm({ target: $('#user-shelves-window div.target'), success: function() { setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000) } @@ -116,11 +125,13 @@ location.href = $('a.visit-shelf', this).attr('href'); }); - $('.delete-shelf').click(function() { + $('.delete-shelf').click(function() { + var link = $(this); + var shelf_name = $('.visit-shelf', link.parent()).text(); + console.log(shelf_name); if (confirm('Czy na pewno usunąć półkę ' + shelf_name + '?')) { - $.post($(this).attr('href'), function(data, textStatus) { - $('#user-shelves-window div.target').html(data); - setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000); + $.post(link.attr('href'), function(data, textStatus) { + link.parent().remove(); }); } return false; diff --git a/wolnelektury/templates/base.html b/wolnelektury/templates/base.html index 8c8f1c68b..ff40f4113 100644 --- a/wolnelektury/templates/base.html +++ b/wolnelektury/templates/base.html @@ -30,7 +30,7 @@ | Wyloguj

{% else %} -

Zaloguj się / Załóż konto

+

{% endif %}
diff --git a/wolnelektury/templates/catalogue/main_page.html b/wolnelektury/templates/catalogue/main_page.html index f6e45a301..a1418ce96 100644 --- a/wolnelektury/templates/catalogue/main_page.html +++ b/wolnelektury/templates/catalogue/main_page.html @@ -13,10 +13,29 @@
+

↓ Przeglądaj lektury według wybranych kategorii i motywów ↓

Twoje półki z lekturami

-

Stwórz własny zestaw lektur!

-

Aby zarządzać swoimi półkami musisz się zalogować.

+ {% if user.is_authenticated %} + {% if shelves %} + + {% else %} +

Nie posiadasz żadnych półek. Jeśli chcesz, możesz utworzyć półkę poniżej.

+ {% endif %} +
+
+
    +
  1. {{ new_set_form.name }}
  2. +
+
+ {% else %} +

Stwórz własny zestaw lektur!

+

Aby zarządzać swoimi półkami musisz się .

+ {% endif %}
diff --git a/wolnelektury/templates/catalogue/user_shelves.html b/wolnelektury/templates/catalogue/user_shelves.html index 88e73150d..7f6ce5538 100644 --- a/wolnelektury/templates/catalogue/user_shelves.html +++ b/wolnelektury/templates/catalogue/user_shelves.html @@ -1,4 +1,4 @@ -

Moje półki

+

Twoje półki z lekturami

{% if shelves %}
    {% for shelf in shelves %} @@ -11,6 +11,6 @@
      -
    1. {{ new_set_form.name }}
    2. +
    3. {{ new_set_form.name }}
    \ No newline at end of file -- 2.20.1