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']
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'
categories = split_tags(tags)
form = forms.SearchForm()
+
return render_to_response('catalogue/main_page.html', locals(),
context_instance=RequestContext(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>Półka <strong>%s</strong> została utworzona</p>' % new_set)
+
+ if request.is_ajax():
+ return HttpResponse(u'<p>Półka <strong>%s</strong> została utworzona</p>' % new_set)
+ else:
+ return HttpResponseRedirect('/')
return render_to_response('catalogue/book_sets.html', locals(),
context_instance=RequestContext(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>Półka <strong>%s</strong> została usunięta</p>' % user_set.name)
-
+ if request.is_ajax():
+ return HttpResponse(u'<p>Półka <strong>%s</strong> została usunięta</p>' % user_set.name)
+ else:
+ return HttpResponseRedirect('/')
+
+
@login_required
def user_shelves(request):
shelves = models.Tag.objects.filter(category='set', user=request.user)
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 {
/* ============== */
#propaganda {
float: right;
- width: 27em;
+ width: 30%;
margin: 0;
- padding: 1em;
+ padding: 2em 1em 1em;
}
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 = */
/* ======================== */
(function($) {
$(function() {
- $('#id_q').labelify({labelledClass: 'blur'});
+ $('form input').labelify({labelledClass: 'blur'});
target = $('#login-register-window div.target');
$('#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});
}
});
+ $('.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],
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) }
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;
| <a href="{% url logout %}?next={{ request.get_full_path }}">Wyloguj</a>
</p>
{% else %}
- <p><a href="{% url login %}" id="login-register-link">Zaloguj się / Załóż konto</a></p>
+ <p><a href="{% url login %}" class="login-register-link">Zaloguj się / Załóż konto</a></p>
{% endif %}
</div>
<div class="clearboth"></div>
</form>
<div id="intro">
+ <p id="tags-description">↓ Przeglądaj lektury według wybranych kategorii i motywów ↓</p>
<div id="propaganda">
<h2>Twoje półki z lekturami</h2>
- <p>Stwórz własny zestaw lektur!</p>
- <p>Aby zarządzać swoimi półkami musisz się <a id="login-register-link" href="#">zalogować</a>.</p>
+ {% if user.is_authenticated %}
+ {% if shelves %}
+ <ul class="shelf-list">
+ {% for shelf in shelves %}
+ <li><a href="{% url delete_shelf shelf.slug %}" class="delete-shelf">usuń</a> <a href="{{ shelf.get_absolute_url }}" class="visit-shelf">{{ shelf.name }}</a></li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <p>Nie posiadasz żadnych półek. Jeśli chcesz, możesz utworzyć półkę poniżej.</p>
+ {% endif %}
+ <hr />
+ <form action="{% url catalogue.views.new_set %}" method="post" accept-charset="utf-8" class="cuteform">
+ <ol>
+ <li>{{ new_set_form.name }} <input type="submit" value="Utwórz półkę"/></li>
+ </ol>
+ </form>
+ {% else %}
+ <p>Stwórz własny zestaw lektur!</p>
+ <p>Aby zarządzać swoimi półkami musisz się <a class="login-register-link" href="#">zalogować</a>.</p>
+ {% endif %}
</div>
<div id="tags-list">
<div id="categories-list">
-<h2>Moje półki</h2>
+<h2>Twoje półki z lekturami</h2>
{% if shelves %}
<ul class="shelf-list">
{% for shelf in shelves %}
<hr />
<form action="{% url catalogue.views.new_set %}" method="post" accept-charset="utf-8" class="cuteform">
<ol>
- <li>{{ new_set_form.name }} <input type="submit" value="Utwórz nową półkę"/></li>
+ <li>{{ new_set_form.name }} <input type="submit" value="Utwórz półkę"/></li>
</ol>
</form>
\ No newline at end of file