Author: batiste.bieler
Date: Thu Feb 19 02:24:48 2009
New Revision: 354
Added:
trunk/pages/templates/admin/pages/page/sub_menu.html
Modified:
trunk/pages/admin/__init__.py
trunk/pages/admin/views.py
trunk/pages/media/pages/css/pages.css
trunk/pages/media/pages/javascript/change_list.js
trunk/pages/models.py
trunk/pages/templates/admin/pages/page/menu.html
trunk/pages/templatetags/pages_tags.py
Log:
Now the tree work in a more ajaxy way. It's quicker. Tree is collapsed by
default.
Modified: trunk/pages/admin/__init__.py
==============================================================================
--- trunk/pages/admin/__init__.py (original)
+++ trunk/pages/admin/__init__.py Thu Feb 19 02:24:48 2009
@@ -19,7 +19,7 @@
from pages.admin import widgets
from pages.admin.forms import PageForm
from pages.admin.utils import get_placeholders, get_connected_models
-from pages.admin.views import traduction, get_content, valid_targets_list,
\
+from pages.admin.views import traduction, get_content, sub_menu, \
change_status, modify_content
class PageAdmin(admin.ModelAdmin):
@@ -86,8 +86,8 @@
page_id, action, content_id, language_id = url.split('/')
return modify_content(request, unquote(page_id),
unquote(content_id),
unquote(language_id))
- elif url.endswith('/valid-targets-list'):
- return valid_targets_list(request, unquote(url[:-19]))
+ elif url.endswith('/sub-menu'):
+ return sub_menu(request, unquote(url[:-9]))
elif url.endswith('/move-page'):
return self.move_page(request, unquote(url[:-10]))
elif url.endswith('/change-status'):
@@ -163,14 +163,15 @@
additional_fieldsets.append((_('Content'), {'fields':
placeholder_fieldsets}))
- connected_fieldsets = []
+ # deactived for now, create bugs with page with same slug title
+ """connected_fieldsets = []
if obj:
for mod in get_connected_models():
for field_name, real_field_name, field in mod['fields']:
connected_fieldsets.append(field_name)
additional_fieldsets.append((_('Create a new linked ' +
- mod['model_name']), {'fields': connected_fieldsets}))
+ mod['model_name']), {'fields':
connected_fieldsets}))"""
given_fieldsets = list(self.declared_fieldsets)
@@ -222,7 +223,7 @@
form.base_fields['template'].initial = force_unicode(template)
# handle most of the logic of connected models
- if obj:
+ """if obj:
for mod in get_connected_models():
model = mod['model']
attributes = {'page': obj.id}
@@ -241,7 +242,7 @@
if validate_field:
for field_name, real_field_name, field in
mod['fields']:
- form.base_fields[field_name] = field
+ form.base_fields[field_name] = field"""
for placeholder in get_placeholders(request, template):
widget = self.get_widget(request, placeholder.widget)()
Modified: trunk/pages/admin/views.py
==============================================================================
--- trunk/pages/admin/views.py (original)
+++ trunk/pages/admin/views.py Thu Feb 19 02:24:48 2009
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, Http404
from django.contrib.admin.views.decorators import staff_member_required
@@ -67,3 +68,13 @@
query = Page.objects.valid_targets(page_id, request, perms)
return HttpResponse(",".join([str(p.id) for p in query]))
valid_targets_list = staff_member_required(valid_targets_list)
+
+def sub_menu(request, page_id):
+ """Render the children of the requested page"""
+ page = Page.objects.get(id=page_id)
+ pages = page.children.all()
+ has_permission = page.has_page_permission(request)
+ return "admin/pages/page/sub_menu.html", locals()
+
+sub_menu = staff_member_required(sub_menu)
+sub_menu = auto_render(sub_menu)
Modified: trunk/pages/media/pages/css/pages.css
==============================================================================
--- trunk/pages/media/pages/css/pages.css (original)
+++ trunk/pages/media/pages/css/pages.css Thu Feb 19 02:24:48 2009
@@ -60,20 +60,26 @@
overflow:hidden;
}
-a.collapse span{
+.expand-collapse span{
font-family: monospace;
+ font-size:16px;
+ margin:2px 4px;
}
-a.collapse span.collapsed{
+.expand-collapse .collapse {
display: none;
}
-a.collapsed span{
- display: none;
+.expand-collapse .expand {
+ display: inline;
}
-a.collapsed span.collapsed{
+.expanded .collapse {
display: inline;
+}
+
+.expanded .expand {
+ display: none;
}
.sidebar {
Modified: trunk/pages/media/pages/javascript/change_list.js
==============================================================================
--- trunk/pages/media/pages/javascript/change_list.js (original)
+++ trunk/pages/media/pages/javascript/change_list.js Thu Feb 19 02:24:48
2009
@@ -44,33 +44,19 @@
$(document).ready(function() {
- function initTreeCollapsing() {
- // TODO: this method for collapsing is too slow
- var col = $.cookie('tree_collapsed');
- if(col){
- col = col.split(',');
- }
- for(i in col) {
- // please keep that as fast as possible
- $('#c' + col[i]).addClass('collapsed');
- hide_children(col[i]);
- }
- }
- initTreeCollapsing();
-
- function save_collapsed() {
+ function save_expanded() {
var col = [];
- $('a.collapsed').each(function() {
+ $('a.expanded').each(function() {
col.push(this.id.substring(1));
});
// expire in 12 days
- $.cookie('tree_collapsed', col.join(','), {"expires":12});
+ $.cookie('tree_expanded', col.join(','), {"expires":12});
}
-
- function hide_children(id) {
+
+ function remove_children(id) {
$('.child-of-' + id).each(function() {
- this.style.display = 'none';
- hide_children(this.id.substring(9));
+ remove_children(this.id.substring(9));
+ $(this).remove();
});
}
@@ -82,15 +68,6 @@
});
}
- function show_children(id) {
- $('.child-of-' + id).each(function() {
- this.style.display='';
- if(!$('a.collapsed', this).length) {
- show_children(this.id.substring(9));
- }
- });
- }
-
var selected_page = false;
var action = false;
@@ -166,10 +143,12 @@
},
function(html) {
$('#changelist').html(html);
- initTreeCollapsing();
- $('#page-row-'+selected_page).addClass("selected");
var msg = $('<span>Successfully moved</span>');
- $($('#page-row-'+selected_page+"
td")[0]).append(msg);
+ var message_target = '#page-row-'+selected_page
+ if(!$(message_target).length)
+ message_target = '#page-row-'+target_id
+ $(message_target).addClass("selected");
+ $($(message_target+" td")[0]).append(msg);
msg.fadeOut(5000);
}
);
@@ -179,19 +158,22 @@
var query = $.query.set('target',
target_id).set('position', position).toString();
window.location.href += 'add/'+query;
}
- //selected_page = false;
return false;
}
- if(jtarget.hasClass("collapse")) {
+ if(jtarget.hasClass("expand-collapse")) {
var the_id = jtarget.attr('id').substring(1);
- jtarget.toggleClass('collapsed');
- if(jtarget.hasClass('collapsed')) {
- hide_children(the_id);
+ jtarget.toggleClass('expanded');
+ if(jtarget.hasClass('expanded')) {
+ $.get("/admin/pages/page/"+the_id+"/sub-menu/",
+ function(html) {
+ $('#page-row-'+the_id).after(html);
+ }
+ );
} else {
- show_children(the_id);
+ remove_children(the_id);
}
- save_collapsed();
+ save_expanded();
return false;
};
Modified: trunk/pages/models.py
==============================================================================
--- trunk/pages/models.py (original)
+++ trunk/pages/models.py Thu Feb 19 02:24:48 2009
@@ -246,6 +246,9 @@
for n in range(0, self.level):
level += ' '
return mark_safe(level + self.__unicode__())
+
+ def margin_level(self):
+ return self.level * 4 + 1
def __unicode__(self):
slug = self.slug()
Modified: trunk/pages/templates/admin/pages/page/menu.html
==============================================================================
--- trunk/pages/templates/admin/pages/page/menu.html (original)
+++ trunk/pages/templates/admin/pages/page/menu.html Thu Feb 19 02:24:48
2009
@@ -1,18 +1,19 @@
{% load pages_tags i18n adminmedia cache %}
{% if has_permission %}
-{% cache 10000 page_row_admin page.id %}
<tr id="page-row-{{ page.id }}" class="child-of-{{ page.parent_id }}">
-<td {% if level %}style="padding-left:{{level}}em"{% endif %}>
+<td style="padding-left:{{ page.margin_level }}em">
<span id="move-target-{{ page.id }}" class="move-target-container">
<a href="#" class="move-target left" title="{% trans "as left
sibling"%}"><img alt="" src="{%
admin_media_prefix %}img/admin/arrow-up.gif"/></a> |
<a href="#" class="move-target right" title="{% trans "as right
sibling"%}"><img alt="" src="{%
admin_media_prefix %}img/admin/arrow-down.gif"/></a></a> |
<a href="#" class="move-target first-child" title="{% trans "as
child"%}">↘</a>
</span>
- <a href="#" {% ifequal 0 children.count %}style="display: none"{%
endifequal %} id="c{{ page.id }}" class="collapse">
- <span class="collapsed">+</span>
- <span>-</span>
+ {% if page.children.count %}
+ <a href="#" class="expand-collapse {% if expanded %}expanded{%
endif %}" id="c{{ page.id }}">
+ <span class="expand">+</span>
+ <span class="collapse">-</span>
</a>
+ {% endif %}
<a href="{{ url }}{{ page.id }}/" class="changelink"
style="margin-right:1em;">{% show_content page "slug" %}</a>
</td>
<td>
@@ -49,9 +50,10 @@
{% endcache %}
</td>
</tr>
-{% endcache %}
{% endif %}
-{% for child in children %}
- {% pages_admin_menu child url level %}
-{% endfor %}
+{% if expanded %}
+ {% for child in children %}
+ {% pages_admin_menu child url level %}
+ {% endfor %}
+{% endif %}
Added: trunk/pages/templates/admin/pages/page/sub_menu.html
==============================================================================
--- (empty file)
+++ trunk/pages/templates/admin/pages/page/sub_menu.html Thu Feb 19
02:24:48 2009
@@ -0,0 +1,4 @@
+{% load pages_tags %}
+{% for page in pages %}
+ {% include "admin/pages/page/menu.html" %}
+{% endfor %}
\ No newline at end of file
Modified: trunk/pages/templatetags/pages_tags.py
==============================================================================
--- trunk/pages/templatetags/pages_tags.py (original)
+++ trunk/pages/templatetags/pages_tags.py Thu Feb 19 02:24:48 2009
@@ -53,6 +53,14 @@
"""Render the admin table of pages"""
request = context['request']
site = request.site
+
+ import urllib
+ if "tree_expanded" in request.COOKIES:
+ cookie_string = urllib.unquote(request.COOKIES['tree_expanded'])
+ if cookie_string:
+ ids = [int(id) for id in
urllib.unquote(request.COOKIES['tree_expanded']).split(',')]
+ if page.id in ids:
+ expanded = True
children = cache.get(Page.PAGE_CHILDREN_KEY % (page.id, site.id))
if children is None:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---