Added 'user shelves' tool menu.
authorMarek Stępniowski <marek@stepniowski.com>
Fri, 5 Sep 2008 11:22:08 +0000 (13:22 +0200)
committerMarek Stępniowski <marek@stepniowski.com>
Fri, 5 Sep 2008 11:22:08 +0000 (13:22 +0200)
catalogue/urls.py
catalogue/views.py
media/css/master.css
media/js/catalogue.js
templates/base.html
templates/catalogue/user_shelves.html [new file with mode: 0644]

index d454fd4..12eaa47 100644 (file)
@@ -4,11 +4,13 @@ from django.conf.urls.defaults import *
 
 urlpatterns = patterns('catalogue.views',
     url(r'^$', 'main_page', name='main_page'),
 
 urlpatterns = patterns('catalogue.views',
     url(r'^$', 'main_page', name='main_page'),
-    url(r'^lektury/', 'book_list'),
-    url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/polki/', 'book_sets'),
-    url(r'^fragment/(?P<id>[0-9]+)/polki/', 'fragment_sets'),
-    url(r'^polki/nowa/$', 'new_set'),
-    url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/$', 'book_detail'),
+    url(r'^polki/$', 'user_shelves', name='user_shelves'),
+    url(r'^polki/(?P<slug>[a-zA-Z0-9-]+)/usun/$', 'delete_shelf', name='delete_shelf'),
+    url(r'^lektury/', 'book_list', name='book_list'),
+    url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/polki/', 'book_sets', name='book_shelves'),
+    url(r'^fragment/(?P<id>[0-9]+)/polki/', 'fragment_sets', name='fragment_shelves'),
+    url(r'^polki/nowa/$', 'new_set', name='new_set'),
+    url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/$', 'book_detail', name='book_detail'),
     url(r'^tags/$', 'tags_starting_with', name='hint'),
     url(r'^szukaj/$', 'search', name='search'),
     url(r'^(?P<tags>[a-zA-Z-/]+)/$', 'tagged_object_list', name='tagged_object_list'),
     url(r'^tags/$', 'tags_starting_with', name='hint'),
     url(r'^szukaj/$', 'search', name='search'),
     url(r'^(?P<tags>[a-zA-Z-/]+)/$', 'tagged_object_list', name='tagged_object_list'),
index 2719884..b3f2d5b 100644 (file)
@@ -221,8 +221,24 @@ 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)
     new_set_form = forms.NewSetForm(request.POST)
     if new_set_form.is_valid():
         new_set = new_set_form.save(request.user)
-        return HttpResponse('<p>Zestaw <strong>%s</strong> został utworzony</p>' % new_set)
+        return HttpResponse(u'<p>Zestaw <strong>%s</strong> został utworzony</p>' % new_set)
     
     return render_to_response('catalogue/book_sets.html', locals(),
             context_instance=RequestContext(request))
 
     
     return render_to_response('catalogue/book_sets.html', locals(),
             context_instance=RequestContext(request))
 
+
+@login_required
+@require_POST
+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>Zestaw <strong>%s</strong> został usunięty</p>' % user_set.name)
+    
+    
+@login_required
+def user_shelves(request):
+    shelves = models.Tag.objects.filter(category='set', user=request.user)
+    new_set_form = forms.NewSetForm()
+    return render_to_response('catalogue/user_shelves.html', locals(),
+            context_instance=RequestContext(request))
+
index da61511..a7b33e6 100644 (file)
@@ -343,6 +343,8 @@ em {
 /* ================ */
 /* = Modal Window = */
 /* ================ */
 /* ================ */
 /* = Modal Window = */
 /* ================ */
+.jqmOverlay { background-color: #000; }
+
 #set-window {
     position: absolute;
     display: none;
 #set-window {
     position: absolute;
     display: none;
@@ -366,9 +368,6 @@ em {
     padding: 1em;
 }
 
     padding: 1em;
 }
 
-.jqmOverlay { background-color: #000; }
-
-
 #login-register-window {
     position: absolute;
     display: none;
 #login-register-window {
     position: absolute;
     display: none;
@@ -397,6 +396,44 @@ em {
     padding: 1em;
 }
 
     padding: 1em;
 }
 
+#user-shelves-window {
+    position: absolute;
+    display: none;
+    width: 28em;
+    background-color: transparent;
+    margin-top: -0.5em;
+    margin-left: 1em;
+}
+
+#user-shelves-window div.header {
+    background-color: #FFF;
+    border-right: 0.3em solid #DDD;
+    width: 4em;
+    right: 0;
+    left: auto;
+    padding: 0.5em 1em 0.5em 1em;
+    float: right;
+    text-align: center;
+}
+
+#user-shelves-window div.target {
+    clear: both;
+    background-color: #FFF;
+    border-right: 0.3em solid #DDD;
+    border-bottom: 0.3em solid #DDD;
+    padding: 1em;
+}
+
+#user-shelves-window ul {
+    list-style: none;
+    padding: 0;
+}
+
+#user-shelves-window a.delete-shelf {
+    color: #900;
+    float: right;
+}
+
 /* ======================== */
 /* = Alphabetic book list = */
 /* ======================== */
 /* ======================== */
 /* = Alphabetic book list = */
 /* ======================== */
index bdceb1a..d403a70 100644 (file)
                 hash.w.show();
             }
         });
                 hash.w.show();
             }
         });
-        $('#login-register-window').labelify({labelledClass: 'blur'});
+        
+        $('#user-shelves-window').jqm({
+            ajax: '@href',
+            target: $('#user-shelves-window div.target')[0],
+            overlay: 60,
+            trigger: '#user-shelves-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});
+                $('div.header', hash.w).css({width: $(hash.t).width()});
+                hash.w.show();
+            },
+            onLoad: function(hash) { 
+                $('form', hash.w).ajaxForm({
+                    target: $('#user-shelves-window div.target'),
+                    success: function() { setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000) }
+                });
+                
+                $('ul.shelf-list li', hash.w).hover(function() {
+                    $(this).css({background: '#EEE', cursor: 'pointer'});
+                }, function() {
+                    $(this).css({background: 'transparent'});
+                }).click(function() {
+                    location.href = $('a.visit-shelf', this).attr('href');
+                });
+                
+                $('.delete-shelf').click(function() { 
+                    $.post($(this).attr('href'), function(data, textStatus) {
+                        $('#user-shelves-window div.target').html(data);
+                        setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000);
+                    });
+                    return false;
+                });
+            }
+        });
     });
 })(jQuery)
\ No newline at end of file
     });
 })(jQuery)
\ No newline at end of file
index aa0f01c..8c8f1c6 100644 (file)
@@ -23,7 +23,7 @@
                 {% if user.is_authenticated %}
                     <p>
                         Zalogowany jako <strong>{{ user.username }}</strong>
                 {% if user.is_authenticated %}
                     <p>
                         Zalogowany jako <strong>{{ user.username }}</strong>
-                        | <a href="#" id="user-sets-link">Moje półki</a>
+                        | <a href="{% url user_shelves %}" id="user-shelves-link">Moje półki</a>
                         {% if user.is_staff %}
                         | <a href="/admin/">Administracja</a>
                         {% endif %}
                         {% if user.is_staff %}
                         | <a href="/admin/">Administracja</a>
                         {% endif %}
                 </form>
             </div>
         </div>
                 </form>
             </div>
         </div>
+        <div id="user-shelves-window">
+            <div class="header"><a href="#" class="jqmClose">Zamknij</a></div>
+            <div class="target">
+                <p><img src="/media/img/indicator.gif" alt="*"/> Ładowanie</p>
+            </div>
+        </div>
     </body>
 </html>
     </body>
 </html>
diff --git a/templates/catalogue/user_shelves.html b/templates/catalogue/user_shelves.html
new file mode 100644 (file)
index 0000000..44517c5
--- /dev/null
@@ -0,0 +1,15 @@
+<h2>Moje półki</h2>
+{% 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 nową półkę"/></li>
+</ol>