Re-ordering of children and resources.

- Implement/activate re-ordering in standard children and resources
  listings
- Parent and (for resources) concept default order: ignore 'order' field
This commit is contained in:
Helmut Merz 2011-06-11 18:30:54 +02:00
parent b25af04e4c
commit e74d21bb7a
4 changed files with 50 additions and 11 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -280,7 +280,8 @@ class ConceptView(BaseView):
def getChildren(self, topLevelOnly=True, sort=True, noDuplicates=True):
form = self.request.form
if form.get('loops.viewName') == 'index.html' and self.editable:
#if form.get('loops.viewName') == 'index.html' and self.editable:
if self.editable:
self.registerDojoDnd()
if 'children_change_order' in form:
tokens = form.get('child_tokens')
@ -370,7 +371,24 @@ class ConceptView(BaseView):
for r in rels:
yield self.childViewFactory(r, self.request)
def reorderResources(self, tokens):
for r in self.context.getResourceRelations(sort=None):
token = ':'.join((util.getUidForObject(r.second),
util.getUidForObject(r.predicate)))
if token in tokens:
pos = tokens.index(token) + 1
if r.order != pos:
r.order = pos
def resources(self):
form = self.request.form
#if form.get('loops.viewName') == 'index.html' and self.editable:
if self.editable:
self.registerDojoDnd()
if 'resources_change_order' in form:
tokens = form.get('resources_tokens')
if tokens:
self.reorderResources(tokens)
from loops.browser.resource import ResourceRelationView
from loops.organize.personal.browser.filter import FilterView
fv = FilterView(self.context, self.request)

View file

@ -174,11 +174,13 @@
<metal:resources define-macro="conceptresources">
<div tal:attributes="class string:content-$level;
ondblclick python: item.openEditWindow('resources.html')"
tal:define="resources python: list(item.resources())"
tal:condition="resources">
<h2 i18n:translate="">Resources</h2>
<div tal:attributes="class string:content-$level;
ondblclick python: item.openEditWindow('resources.html')"
tal:define="resources python: list(item.resources())"
tal:condition="resources">
<h2 i18n:translate="">Resources</h2>
<form method="post"
tal:omit-tag="not:item/editable">
<table class="listing"
metal:define-macro="resources">
<tr tal:define="sortcol request/resources_sortcol|nothing;
@ -197,10 +199,13 @@
<th i18n:translate=""
tal:condition="view/showObjectActions">Info</th>
</tr>
<tbody withHandles="true" id="resources_list"
tal:attributes="dojoType python:item.editable and 'dojo.dnd.Source'">
<tal:items repeat="related resources">
<tal:item define="class python: repeat['related'].odd() and 'even' or 'odd';
description related/description">
<tr tal:attributes="class class">
<tr tal:attributes="class string:$class dojoDndItem dojoDndHandle;
id related/uniqueId">
<td tal:condition="item/showCheckboxes|nothing"
tal:define="uid related/uniqueId"
class="checkbox">
@ -242,12 +247,26 @@
style nothing"
tal:condition="view/showObjectActions">
<div metal:use-macro="views/node_macros/object_actions" />
<input type="hidden" name="resources_tokens:list"
tal:attributes="value related/uidToken" />
</td>
</tr>
</tal:item>
</tal:items>
</tbody>
</table>
</div>
<input type="submit" style="display: none"
name="resources_change_order" id="resources_change_order"
value="Save Changes"
i18n:attributes="value" />
<input type="hidden" name="loops.viewName" value="index.html" />
<script language="javascript">
dojo.subscribe('/dnd/drop', function(data) {
if (data.node.id == 'resources_list') {
dojo.byId('resources_change_order').style.display = ''}});
</script>
</form>
</div>
</metal:resources>

View file

@ -198,7 +198,8 @@ class Concept(Contained, Persistent):
predicates = predicates is None and ['*'] or predicates
relationships = [ConceptRelation(None, self, p) for p in predicates]
if sort == 'default':
sort = lambda x: (x.order, x.first.title.lower())
#sort = lambda x: (x.order, x.first.title.lower())
sort = lambda x: (x.first.title.lower())
rels = (r for r in getRelations(parent, self, relationships=relationships)
if canListObject(r.first, noSecurityCheck))
return sorted(rels, key=sort)

View file

@ -203,7 +203,8 @@ class Resource(Image, Contained):
obj = getMaster(self)
relationships = [ResourceRelation(None, obj, p) for p in predicates]
if sort == 'default':
sort = lambda x: (x.order, x.first.title.lower())
#sort = lambda x: (x.order, x.first.title.lower())
sort = lambda x: (x.first.title.lower())
rels = (r for r in getRelations(first=concept, second=obj,
relationships=relationships)
if canListObject(r.first, noSecurityCheck))