From: gfawcett Date: Wed, 25 Mar 2009 03:39:01 +0000 (+0000) Subject: Added action to move an item under a different heading. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=dcd4fb694c12094459923cf08517591ca601ac57;p=Syrup.git Added action to move an item under a different heading. It avoids cycles: no headings that are parents of themselves. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@217 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/static/menublocks.js b/conifer/static/menublocks.js index ec7b5ae..2d97d56 100644 --- a/conifer/static/menublocks.js +++ b/conifer/static/menublocks.js @@ -35,9 +35,9 @@ function doReorder() { $('#reorder_panel a').text($('#i18n-save-order').text()); reordering = true; } else { - $('.an_item').css({ marginTop: '3px' }); + $('.an_item').css({ marginTop: '4px' }); $('#ropanelmessage').remove(); - $('#reorder_panel a').text($('#i18n-reorder-items').text()); + $('#reorder_panel a').text('...'); $('.itemtree').sortable('destroy'); reordering = false; // get the LI item ids. Send them to the server. @@ -45,6 +45,7 @@ function doReorder() { var new_seq_string = Array.join(new_sequence, ','); $.post('reseq', {'new_order':new_seq_string}, function() { + $('#reorder_panel a').text($('#i18n-reorder-items').text()); alert($('#i18n-new-order-saved').text()); }); } diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index e2ad697..d5853bb 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -194,6 +194,11 @@ class Course(m.Model): def items(self): return self.item_set.all() + def headings(self): + """A list of all items which are headings.""" + #fixme, not sure 'title' is the best ordering. + return self.item_set.filter(item_type='HEADING').order_by('title') + def item_tree(self, subtree=None): """ Return a list, representing a tree of the course items, in diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index 5453b52..6452db9 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -46,6 +46,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'), (r'^course/(?P\d+)/reseq$', 'course_reseq'), (ITEM_PREFIX + r'reseq', 'item_heading_reseq'), + (ITEM_PREFIX + r'relocate/', 'item_relocate'), # move to new subheading # (r'^admin/terms/(?P\d+)/$', 'admin_term_edit'), # (r'^admin/terms/(?P\d+)/delete$', 'admin_term_delete'), # (r'^admin/terms/$', 'admin_term'), diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index ac79998..ac3162f 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -1150,3 +1150,31 @@ def item_heading_reseq(request, course_id, item_id): item = get_object_or_404(models.Item, pk=item_id, course__id=course_id) parent_heading = item return _reseq(request, course, parent_heading) + + +@instructors_only +def item_relocate(request, course_id, item_id): + """Move an item from its current subheading to another one.""" + course = get_object_or_404(models.Course, pk=course_id) + item = get_object_or_404(models.Item, pk=item_id, course__id=course_id) + if request.method != 'POST': + return g.render('item_relocate.xhtml', **locals()) + else: + newheading = int(request.POST['newheading']) + if newheading == 0: + new_parent = None + else: + new_parent = course.item_set.get(pk=newheading) + if item in new_parent.hierarchy(): + # then we would create a cycle. Bail out. + return g.render('simplemessage.xhtml', + title=_(_('Impossible item-move!')), + content=_('You cannot make an item a descendant of itself!')) + item.parent_heading = new_parent + item.save() + if new_parent: + return HttpResponseRedirect(new_parent.item_url('meta')) + else: + return HttpResponseRedirect(course.course_url()) + + diff --git a/conifer/templates/components/course.xhtml b/conifer/templates/components/course.xhtml index 80cf5f1..4cd3f0f 100644 --- a/conifer/templates/components/course.xhtml +++ b/conifer/templates/components/course.xhtml @@ -38,6 +38,9 @@ searchtext = _('search this course...') edit + + • put under heading + diff --git a/conifer/templates/item_add_heading.xhtml b/conifer/templates/item_add_heading.xhtml index 0fb19a6..8b9587a 100644 --- a/conifer/templates/item_add_heading.xhtml +++ b/conifer/templates/item_add_heading.xhtml @@ -11,7 +11,7 @@ course_title = '%s: %s (%s)' % (course.code, course.title, course.term) ${title} ${item_metadata_formset_header()}