Added action to move an item under a different heading.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Wed, 25 Mar 2009 03:39:01 +0000 (03:39 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Wed, 25 Mar 2009 03:39:01 +0000 (03:39 +0000)
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

conifer/static/menublocks.js
conifer/syrup/models.py
conifer/syrup/urls.py
conifer/syrup/views.py
conifer/templates/components/course.xhtml
conifer/templates/item_add_heading.xhtml

index ec7b5ae..2d97d56 100644 (file)
@@ -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());
                   });
     }
index e2ad697..d5853bb 100644 (file)
@@ -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
index 5453b52..6452db9 100644 (file)
@@ -46,6 +46,7 @@ urlpatterns = patterns('conifer.syrup.views',
     (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'),
     (r'^course/(?P<course_id>\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<term_id>\d+)/$', 'admin_term_edit'),
 #     (r'^admin/terms/(?P<term_id>\d+)/delete$', 'admin_term_delete'),
 #     (r'^admin/terms/$', 'admin_term'),
index ac79998..ac3162f 100644 (file)
@@ -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())
+        
+        
index 80cf5f1..4cd3f0f 100644 (file)
@@ -38,6 +38,9 @@ searchtext = _('search this course...')
        <span py:if="edit">
          &bull; <a href="${item.item_url('edit/')}">edit</a>
        </span>
+       <span py:if="edit">
+         &bull; <a href="${item.item_url('relocate/')}">put under heading</a>
+       </span>
       </span>
       <!-- !to show a full tree, uncomment the following: -->
       <!-- ${show_tree(subs, edit)} -->
index 0fb19a6..8b9587a 100644 (file)
@@ -11,7 +11,7 @@ course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
   <head>
     <title>${title}</title>
     <script type="text/javascript">
-      $(function() {$('input[@name="title"]').focus();});
+      $(function() {$('input[name="title"]').focus();});
     </script>
     ${item_metadata_formset_header()}
   </head>