[open-ils-commits] r217 - in servres/trunk/conifer: static syrup templates templates/components (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 24 23:39:04 EDT 2009


Author: gfawcett
Date: 2009-03-24 23:39:01 -0400 (Tue, 24 Mar 2009)
New Revision: 217

Modified:
   servres/trunk/conifer/static/menublocks.js
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/urls.py
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/components/course.xhtml
   servres/trunk/conifer/templates/item_add_heading.xhtml
Log:
Added action to move an item under a different heading.

It avoids cycles: no headings that are parents of themselves.


Modified: servres/trunk/conifer/static/menublocks.js
===================================================================
--- servres/trunk/conifer/static/menublocks.js	2009-03-25 02:52:37 UTC (rev 216)
+++ servres/trunk/conifer/static/menublocks.js	2009-03-25 03:39:01 UTC (rev 217)
@@ -35,9 +35,9 @@
 	$('#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 @@
 	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());
 		   });
     }

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-03-25 02:52:37 UTC (rev 216)
+++ servres/trunk/conifer/syrup/models.py	2009-03-25 03:39:01 UTC (rev 217)
@@ -194,6 +194,11 @@
     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

Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py	2009-03-25 02:52:37 UTC (rev 216)
+++ servres/trunk/conifer/syrup/urls.py	2009-03-25 03:39:01 UTC (rev 217)
@@ -46,6 +46,7 @@
     (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'),

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-03-25 02:52:37 UTC (rev 216)
+++ servres/trunk/conifer/syrup/views.py	2009-03-25 03:39:01 UTC (rev 217)
@@ -1150,3 +1150,31 @@
     item = get_object_or_404(models.Item, pk=item_id, course__id=course_id)
     parent_heading = item
     return _reseq(request, course, parent_heading)
+
+
+ at 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())
+        
+        

Modified: servres/trunk/conifer/templates/components/course.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/course.xhtml	2009-03-25 02:52:37 UTC (rev 216)
+++ servres/trunk/conifer/templates/components/course.xhtml	2009-03-25 03:39:01 UTC (rev 217)
@@ -38,6 +38,9 @@
 	<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)} -->

Modified: servres/trunk/conifer/templates/item_add_heading.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_heading.xhtml	2009-03-25 02:52:37 UTC (rev 216)
+++ servres/trunk/conifer/templates/item_add_heading.xhtml	2009-03-25 03:39:01 UTC (rev 217)
@@ -11,7 +11,7 @@
   <head>
     <title>${title}</title>
     <script type="text/javascript">
-      $(function() {$('input[@name="title"]').focus();});
+      $(function() {$('input[name="title"]').focus();});
     </script>
     ${item_metadata_formset_header()}
   </head>



More information about the open-ils-commits mailing list