Dynamic menu
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 11 Oct 2012 15:34:58 +0000 (17:34 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 11 Oct 2012 15:34:58 +0000 (17:34 +0200)
apps/catalogue/templates/catalogue/menu.html
apps/catalogue/templatetags/catalogue_tags.py
apps/catalogue/views.py
apps/wolnelektury_core/static/js/base.js
apps/wolnelektury_core/templates/superbase.html

index 1a90b5c..72bf5e6 100644 (file)
@@ -1,32 +1,16 @@
-{% load i18n %}
-{% load tag_list from catalogue_tags %}
+{% load i18n static %}
 
 <ul id="menu">
 
 <ul id="menu">
+    {% for category, name, hash in categories %}
        <li class="hidden-box-wrapper menu">
        <li class="hidden-box-wrapper menu">
-               <a href="{% url catalogue %}#autorzy" class="hidden-box-trigger menu">
-                       <span class='mono'>{% trans "Authors" %}</span></a>
-               <div class="hidden-box">{% if author %}{% tag_list author %}{% endif %}</div>
-       </li>
-       <li class="hidden-box-wrapper menu">
-               <a href="{% url catalogue %}#gatunki" class="hidden-box-trigger menu">
-                       <span class='mono'>{% trans "Genres" %}</span></a>
-               <div class="hidden-box">{% if genre %}{% tag_list genre %}{% endif %}</div>
-       </li>
-       <li class="hidden-box-wrapper menu">
-               <a href="{% url catalogue %}#rodzaje" class="hidden-box-trigger menu">
-                       <span class='mono'>{% trans "Kinds" %}</span></a>
-               <div class="hidden-box">{% if kind %}{% tag_list kind %}{% endif %}</div>
-       </li>
-       <li class="hidden-box-wrapper menu">
-               <a href="{% url catalogue %}#epoki" class="hidden-box-trigger menu">
-                       <span class='mono'>{% trans "Epochs" %}</span></a>
-               <div class="hidden-box">{% if epoch %}{% tag_list epoch %}{% endif %}</div>
-       </li>
-       <li class="hidden-box-wrapper menu">
-               <a href="{% url catalogue %}#motywy" class="hidden-box-trigger menu">
-                       <span class='mono'>{% trans "Themes" %}</span></a>
-               <div class="hidden-box">{% if theme %}{% tag_list theme %}{% endif %}</div>
+               <a href="{% url catalogue %}#{{ hash }}" class="hidden-box-trigger menu load-menu">
+                       <span class='mono'>{{ name }}</span></a>
+               <div class="hidden-box" id="menu-{{ category }}">
+            <img src="{% static "img/indicator.gif" %}" alt="{% trans "Please wait…" %}" />
+        </div>
        </li>
        </li>
+    {% endfor %}
+
        <li class="menu">
                <a href="{% url book_list %}" class="menu">
                        <span class='mono'>{% trans "All books" %}</span></a>
        <li class="menu">
                <a href="{% url book_list %}" class="menu">
                        <span class='mono'>{% trans "All books" %}</span></a>
index 92827c1..8cf3acf 100644 (file)
@@ -404,11 +404,13 @@ def related_books(book, limit=6, random=1):
 
 @register.inclusion_tag('catalogue/menu.html')
 def catalogue_menu():
 
 @register.inclusion_tag('catalogue/menu.html')
 def catalogue_menu():
-    tags = Tag.objects.filter(
-            category__in=('author', 'epoch', 'genre', 'kind', 'theme')
-        ).exclude(book_count=0)
-    return split_tags(tags)
-    
+    return {'categories': [
+                ('author', _('Authors'), 'autorzy'),
+                ('genre', _('Genres'), 'gatunki'),
+                ('kind', _('Kinds'), 'rodzaje'),
+                ('epoch', _('Epochs'), 'epoki'),
+                ('theme', _('Themes'), 'autorzy'),
+        ]}
 
 
 @register.simple_tag
 
 
 @register.simple_tag
index cc56015..66036bf 100644 (file)
@@ -25,6 +25,7 @@ from ajaxable.utils import JSONResponse, AjaxableFormView
 from catalogue import models
 from catalogue import forms
 from catalogue.utils import split_tags, MultiQuerySet
 from catalogue import models
 from catalogue import forms
 from catalogue.utils import split_tags, MultiQuerySet
+from catalogue.templatetags.catalogue_tags import tag_list
 from pdcounter import models as pdcounter_models
 from pdcounter import views as pdcounter_views
 from suggest.forms import PublishingSuggestForm
 from pdcounter import models as pdcounter_models
 from pdcounter import views as pdcounter_views
 from suggest.forms import PublishingSuggestForm
@@ -43,8 +44,16 @@ def catalogue(request):
     categories = split_tags(tags)
     fragment_tags = categories.get('theme', [])
 
     categories = split_tags(tags)
     fragment_tags = categories.get('theme', [])
 
-    return render_to_response('catalogue/catalogue.html', locals(),
-        context_instance=RequestContext(request))
+    if request.is_ajax():
+        render_tag_list = lambda x: render_to_string(
+            'catalogue/tag_list.html', tag_list(x))
+        output = {'theme': render_tag_list(fragment_tags)}
+        for category, tags in categories.items():
+            output[category] = render_tag_list(tags)
+        return JSONResponse(output)
+    else:
+        return render_to_response('catalogue/catalogue.html', locals(),
+            context_instance=RequestContext(request))
 
 
 def book_list(request, filter=None, template_name='catalogue/book_list.html',
 
 
 def book_list(request, filter=None, template_name='catalogue/book_list.html',
index d43f1f2..9676d5b 100755 (executable)
@@ -59,6 +59,7 @@
 
                (function() {
                        var $current = null;
 
                (function() {
                        var $current = null;
+            var menu_loaded = false;
                        $('.hidden-box-wrapper').each(function() {
                                var $hidden = $('.hidden-box', this);
                                $('.hidden-box-trigger', this).click(function(event) {
                        $('.hidden-box-wrapper').each(function() {
                                var $hidden = $('.hidden-box', this);
                                $('.hidden-box-trigger', this).click(function(event) {
                                                $current && $current.hide('fast');
                                                $hidden.show('fast');
                                                $current = $hidden;
                                                $current && $current.hide('fast');
                                                $hidden.show('fast');
                                                $current = $hidden;
+                        if ($(this).hasClass('load-menu') && !menu_loaded) {
+                            $.ajax({
+                                url: '/katalog/',
+                                dataType: "json",
+                            }).done(function(data) {
+                                $.each(data, function(index, value) {
+                                    $('#menu-' + index).html(value);
+                                });
+                                menu_loaded = true;
+                            });
+                        }
                                        } 
                                });
                        });
                                        } 
                                });
                        });
index 423befb..b0067ac 100644 (file)
         <div id="main-content">
 
             <div id="nav-line">
         <div id="main-content">
 
             <div id="nav-line">
-               {% cache 300 catalogue-menu LANGUAGE_CODE %}
-                       {% catalogue_menu %}
-               {% endcache %}
+                {% catalogue_menu %}
 
             <div id="lang-menu" class="hoverget">
                 <span id='lang-button' class='mono hoverclick'>
 
             <div id="lang-menu" class="hoverget">
                 <span id='lang-button' class='mono hoverclick'>