.. note:: **The information on this page is obsolete, incomplete or incorrect and left here only for reference and has not been ported to the new documentation wiki.** Please refer to the `TurboGears documentation wiki`_ for up-to-date documentation. .. _turbogears documentation wiki: http://docs.turbogears.org/
Tim Taylor Tool Library enables you to drag around Elements in lists and such.
The following block is the includes that are required (perhaps there's some general include or something but I was too lazy to look)
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/core.js"></script>
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/events.js"></script>
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/css.js"></script>
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/coordinates.js"></script>
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/drag.js"></script>
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/dragsort.js"></script>
<script language="JavaScript" type="text/javascript" src="/tg_static/js/tool-man/cookies.js"></script>
You need some Javascript to enable that dragging and that informs your controllers.
<script language="JavaScript" type="text/javascript">
var dragsort = ToolMan.dragsort()
var junkdrawer = ToolMan.junkdrawer()
window.onload = function() {
dragsort.makeListSortable(
document.getElementById("tracks"),
verticalOnly, saveOrder)
function verticalOnly(item) {
item.toolManDragGroup.verticalOnly()
}
function saveOrder(item) {
var group = item.toolManDragGroup
var list = group.element.parentNode
function dragend()
{
tracks = junkdrawer.serializeList(list)
loadJSONDoc('save?tracks=' + tracks)
}
group.register('dragend', dragend)
}
}
</script>
The saveOrder function does all the work, it gets a thing, serializes it and adds it as a paramter to a JSON call.
Then you need a snipplet of templae code that blows up what you're going to work with.
<body>
<ul id="tracks">
<li py:for="id, track_title in tracks"
py:content="track_title"
py:attrs="itemID=id"/>
</ul>
</body>
And finally the controller that does the a thing
@turbogears.expose() def save(self, tracklist, tracks): for reference in model.tracklist_reference.selectBy(tracklist=tracklist): model.tracklist_reference.delete(reference.id) for track in map(int, tracks.split('|')): model.tracklist_reference(tracklist=tracklist, track=track)
It deletes an associated tracklist and adds all the new references to a trackslist again. Note, I use the RestfullPath pattern for the Tracklist controller"