allow fixed ordering of concept children in standard listing via drag and drop

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@4189 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2011-02-13 17:42:47 +00:00
parent 551351d59c
commit fdaf31bd79
3 changed files with 49 additions and 10 deletions

View file

@ -690,6 +690,11 @@ class BaseView(GenericView, I18NView):
#cm.register('css', identifier='dojo.css', position=1, #cm.register('css', identifier='dojo.css', position=1,
# resourceName='ajax.dojo/dojo/resources/dojo.css', media='all') # resourceName='ajax.dojo/dojo/resources/dojo.css', media='all')
def registerDojoDnd(self):
self.registerDojo()
jsCall = 'dojo.require("dojo.dnd.Source")'
self.controller.macros.register('js-execute', jsCall, jsCall=jsCall)
def registerDojoDialog(self): def registerDojoDialog(self):
self.registerDojo() self.registerDojo()
jsCall = 'dojo.require("dijit.Dialog")' jsCall = 'dojo.require("dijit.Dialog")'

View file

@ -269,7 +269,23 @@ class ConceptView(BaseView):
instance.view = self instance.view = self
return instance return instance
def reorderChildren(self, tokens):
for r in self.context.getChildRelations(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 getChildren(self, topLevelOnly=True, sort=True, noDuplicates=True): def getChildren(self, topLevelOnly=True, sort=True, noDuplicates=True):
form = self.request.form
if form.get('loops.viewName') == 'index.html' and self.editable:
self.registerDojoDnd()
if 'children_change_order' in form:
tokens = form.get('child_tokens')
if tokens:
self.reorderChildren(tokens)
cm = self.loopsRoot.getConceptManager() cm = self.loopsRoot.getConceptManager()
hasType = cm.getTypePredicate() hasType = cm.getTypePredicate()
params = self.params params = self.params

View file

@ -97,12 +97,14 @@
<metal:children define-macro="conceptchildren"> <metal:children define-macro="conceptchildren">
<div tal:attributes="class string:content-$level; <div tal:attributes="class string:content-$level;
ondblclick python: item.openEditWindow('configure.html')" ondblclick python: item.openEditWindow('configure.html')"
tal:define="children python: list(item.unique(item.children()))" tal:define="children python: list(item.unique(item.children()))"
tal:condition="children"> tal:condition="children">
<h2 i18n:translate="" <h2 i18n:translate=""
tal:condition="show_headline|python:True">Children</h2> tal:condition="show_headline|python:True">Children</h2>
<form method="post"
tal:omit-tag="not:item/editable">
<table class="listing"> <table class="listing">
<tr> <tr>
<th i18n:translate="">Title</th> <th i18n:translate="">Title</th>
@ -112,16 +114,18 @@
<th i18n:translate="" <th i18n:translate=""
tal:condition="view/showObjectActions">Info</th> tal:condition="view/showObjectActions">Info</th>
</tr> </tr>
<tbody withHandles="true" id="children_list"
tal:attributes="dojoType python:item.editable and 'dojo.dnd.Source'">
<tal:items repeat="related children"> <tal:items repeat="related children">
<tal:item define="class python: repeat['related'].odd() and 'even' or 'odd'; <tal:item define="class python: repeat['related'].odd() and 'even' or 'odd';
description related/description; description related/description;
predicate related/predicateTitle; predicate related/predicateTitle;
info python: ' | '.join( info python: ' | '.join(
t for t in (description, predicate) if t)"> t for t in (description, predicate) if t)">
<tr tal:attributes="class class"> <tr tal:attributes="class string:$class dojoDndItem dojoDndHandle;
id related/uniqueId">
<td valign="top"> <td valign="top">
<a href="#" <a tal:attributes="href python: view.getUrlForTarget(related);
tal:attributes="href python: view.getUrlForTarget(related);
title info"> title info">
<span tal:replace="related/title">Resource Title</span> <span tal:replace="related/title">Resource Title</span>
</a> </a>
@ -136,12 +140,26 @@
style nothing" style nothing"
tal:condition="view/showObjectActions"> tal:condition="view/showObjectActions">
<div metal:use-macro="views/node_macros/object_actions" /> <div metal:use-macro="views/node_macros/object_actions" />
<input type="hidden" name="child_tokens:list"
tal:attributes="value related/uidToken" />
</td> </td>
</tr> </tr>
</tal:item> </tal:item>
</tal:items> </tal:items>
</tbody>
</table> </table>
</div> <input type="submit" style="display: none"
name="children_change_order" id="children_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 == 'children_list') {
dojo.byId('children_change_order').style.display = ''}});
</script>
</form>
</div>
</metal:children> </metal:children>