[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm lonparmset.pm

droeschl lon-capa-cvs-allow@mail.lon-capa.org
Tue, 11 Nov 2008 20:12:17 -0000


This is a MIME encoded message

--droeschl1226434337
Content-Type: text/plain

droeschl		Tue Nov 11 20:12:17 2008 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm lonhtmlcommon.pm 
  Log:
  Changes related to LON-CAPA redesign project.
  lonhtmlcommon.pm: 
      - added routine generate_menu() which generates the html markup for a LON-CAPA menu from an array.
        This serves the unification of LON-CAPA menus.
  
  lonparmset.pm:
      - moved the add_breadcrumb() call from handler to the appropriate subroutine.
      - removed checks of $parm_permission in handler, as it is checked in the main if-clause.
      - modified the underlying datastructure for menu creation in print_main_menu() so that generate_menu() can be applied.
      - replaced the markup creation in print_main_menu() with a call to generate_menu().
  
  
  
--droeschl1226434337
Content-Type: text/plain
Content-Disposition: attachment; filename="droeschl-20081111201217.txt"

Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.413 loncom/interface/lonparmset.pm:1.414
--- loncom/interface/lonparmset.pm:1.413	Thu Oct 23 14:26:17 2008
+++ loncom/interface/lonparmset.pm	Tue Nov 11 20:12:17 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.413 2008/10/23 14:26:17 bisitz Exp $
+# $Id: lonparmset.pm,v 1.414 2008/11/11 20:12:17 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -711,6 +711,15 @@
     my %loaditems = ('onunload' => "pclose()",
 		     'onload'   => "group_or_section('cgroup')",);
 
+    if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
+	     && (!$env{'form.dis'})) || ($env{'form.symb'})) {
+	&Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
+	    text=>"Problem Parameters"});
+    } else {
+	&Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
+	   text=>"Table Mode",
+	   help => 'Course_Setting_Parameters'});
+    }
     my $start_page = 
 	&Apache::loncommon::start_page('Set/Modify Course Parameters',
 				       &page_js(),
@@ -2079,6 +2088,8 @@
     my $r=shift;
     my $setoutput='';
 
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
+	text=>"Course Environment"});
     my $breadcrumbs = 
 	&Apache::lonhtmlcommon::breadcrumbs('Edit Course Environment');
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -3115,6 +3126,8 @@
 
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
+    	text=>"Overview Mode"});
     my $start_page = &Apache::loncommon::start_page('Set Parameters');
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
     $r->print(<<ENDOVER);
@@ -3275,6 +3288,8 @@
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
+	text=>"Overview Mode"});
     my $start_page=&Apache::loncommon::start_page('Modify Parameters');
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
     $r->print(<<ENDOVER);
@@ -3309,6 +3324,8 @@
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
+    	text=>"Clean Parameters"});
     my $start_page=&Apache::loncommon::start_page('Clean Parameters');
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
     $r->print(<<ENDOVER);
@@ -3392,6 +3409,8 @@
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
+    	text=>"Shifting Dates"});
     my $start_page=&Apache::loncommon::start_page('Shift Dates');
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
     $r->print(<<ENDOVER);
@@ -3417,6 +3436,8 @@
     my ($r) = @_;
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
+    	text=>"Shifting Dates"});
     my $start_page=&Apache::loncommon::start_page('Shift Dates');
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
     $r->print(<<ENDOVER);
@@ -3643,6 +3664,8 @@
 sub print_main_menu {
     my ($r,$parm_permission)=@_;
     #
+    $r->print(&header());
+    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Manager'));
     $r->print(<<ENDMAINFORMHEAD);
 <form method="post" enctype="multipart/form-data"
       action="/adm/parmset" name="studentform">
@@ -3654,84 +3677,88 @@
     my $mgr  = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
 
     my @menu =
-        ( { divider=>'Settings for Your Course',
-	  },
-          { text => 'Set Course Environment',
-	    action => 'crsenv',
-            permission => $parm_permission,
-            help => 'Course_Environment',
-            },
-          { text => 'Set Portfolio Metadata',
-	    action => 'setrestrictmeta',
-            permission => $parm_permission,
-            },
-	  { text => 'Manage Course Slots',
-	    url => '/adm/slotrequest?command=showslots',
-	    permission => $vgr,
-            },
-	  { text => 'Reset Student Access Times',
-	    url => '/adm/helper/resettimes.helper',
-	    permission => $mgr,
-            },
-
-          { text => 'Set Parameter Setting Default Actions',
-            action => 'setdefaults',
-            permission => $parm_permission,
-            },          
-	  { divider => 'New and Existing Parameter Settings for Your Resources',
-	    },
-          { text => 'Set/Modify Resource Parameters - Helper Mode',
-            url => '/adm/helper/parameter.helper',
-            permission => $parm_permission,
-            help => 'Parameter_Helper',
-            },
- 	  { text => 'Set/Modify Resource Parameters - Overview Mode',
-            action => 'newoverview',
-            permission => $parm_permission,
-            help => 'Parameter_Overview',
-            },
-          { text => 'Set/Modify Resource Parameters - Table Mode',
-            action => 'settable',
-            permission => $parm_permission,
-            help => 'Table_Mode',
-            },
-           { divider => 'Existing Parameter Settings for Your Resources',
-	  },
-	  { text => 'Modify Resource Parameters - Overview Mode',
-            action => 'setoverview',
-            permission => $parm_permission,
-            help => 'Parameter_Overview',
- 	    },          
-	  { text => 'Parameter Change Log and Course Blog Posting/User Notification',
-            action => 'parameterchangelog',
-            permission => $parm_permission,
-            },
+        ( { categorytitle=>'Settings for Your Course',
+	    items => [
+		  { linktext => 'Set Course Environment',
+		    url => '/adm/parmset?action=crsenv',
+		    permission => $parm_permission,
+		    help => 'Course_Environment',
+		    },
+		  { linktext => 'Set Portfolio Metadata',
+		    url => '/adm/parmset?action=setrestrictmeta',
+		    permission => $parm_permission,
+		    },
+		  { linktext => 'Manage Course Slots',
+		    url => '/adm/slotrequest?command=showslots',
+		    permission => $vgr,
+		    },
+		  { linktext => 'Reset Student Access Times',
+		    url => '/adm/helper/resettimes.helper',
+		    permission => $mgr,
+		    },
+
+		  { linktext => 'Set Parameter Setting Default Actions',
+		    url => '/adm/parmset?action=setdefaults',
+		    permission => $parm_permission,
+		    }]},          
+	  { categorytitle => 'New and Existing Parameter Settings for Your Resources',
+	    items => [
+		  { linktext => 'Set/Modify Resource Parameters - Helper Mode',
+		    url => '/adm/helper/parameter.helper',
+		    permission => $parm_permission,
+		    help => 'Parameter_Helper',
+		    },
+		  { linktext => 'Set/Modify Resource Parameters - Overview Mode',
+		    url => '/adm/parmset?action=newoverview',
+		    permission => $parm_permission,
+		    help => 'Parameter_Overview',
+		    },
+		  { linktext => 'Set/Modify Resource Parameters - Table Mode',
+		    url => '/adm/parmset?action=settable',
+		    permission => $parm_permission,
+		    help => 'Table_Mode',
+		    }]},
+           { categorytitle => 'Existing Parameter Settings for Your Resources',
+	     items => [
+		  { linktext => 'Modify Resource Parameters - Overview Mode',
+		    url => '/adm/parmset?action=setoverview',
+		    permission => $parm_permission,
+		    help => 'Parameter_Overview',
+		    },          
+		  { linktext => 'Parameter Change Log and Course Blog Posting/User Notification',
+		    url => '/adm/parmset?action=parameterchangelog',
+		    permission => $parm_permission,
+		    }]}
           );
-    my $menu_html = '';
-    foreach my $menu_item (@menu) {
-	if ($menu_item->{'divider'}) {
-	    $menu_html .= '<h3>'.&mt($menu_item->{'divider'}).'</h3>';
-	    next;
-	}
-        next if (! $menu_item->{'permission'});
-        $menu_html.='<p>';
-        $menu_html.='<span class="LC_parm_menu_item">';
-        if (exists($menu_item->{'url'})) {
-            $menu_html.=qq{<a href="$menu_item->{'url'}">};
-        } else {
-            $menu_html.=
-                qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
-        }
-        $menu_html.= &mt($menu_item->{'text'}).'</a></span>';
-        if (exists($menu_item->{'help'})) {
-            $menu_html.=
-                &Apache::loncommon::help_open_topic($menu_item->{'help'});
-        }
-        $menu_html.='</p>'.$/;
-    }
-    $r->print($menu_html);
+#---- Remove when done ----
+#    my $menu_html = '';
+#    foreach my $menu_item (@menu) {
+#	if ($menu_item->{'categorytitle'}) {
+#	    $menu_html .= '<h3>'.&mt($menu_item->{'categorytitle'}).'</h3>';
+#	    next;
+#	}
+#        next if (! $menu_item->{'permission'});
+#        $menu_html.='<p>';
+#        $menu_html.='<span class="LC_parm_menu_item">';
+#        if (exists($menu_item->{'url'})) {
+#            $menu_html.=qq{<a href="$menu_item->{'url'}">};
+#        } else {
+#            $menu_html.=
+#                qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
+#        }
+#        $menu_html.= &mt($menu_item->{'linktext'}).'</a></span>';
+#        if (exists($menu_item->{'help'})) {
+#            $menu_html.=
+#                &Apache::loncommon::help_open_topic($menu_item->{'help'});
+#        }
+#        $menu_html.='</p>'.$/;
+#    }
+# --------------------------
+
+    $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
     return;
 }
+
 ### Set portfolio metadata
 sub output_row {
     my ($r, $field_name, $field_text, $added_flag) = @_;
@@ -3793,6 +3820,8 @@
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
     $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
+    	text=>"Add Metadata Field"});
     &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>"/adm/parmset?action=setrestrictmeta",
               text=>"Restrict Metadata"},
@@ -3878,6 +3907,8 @@
 }
 sub addmetafield {
     my ($r)=@_;
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
+    	text=>"Add Metadata Field"});
     $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -3928,6 +3959,8 @@
     my $output;
     my $item_num;
     my $put_result;
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
+    	text=>"Restrict Metadata"});
     $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -4035,6 +4068,8 @@
 sub defaultsetter {
     my ($r) = @_;
 
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
+    	text=>"Set Defaults"});
     my $start_page = 
 	&Apache::loncommon::start_page('Parameter Setting Default Actions');
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
@@ -4267,6 +4302,8 @@
 
 sub parm_change_log {
     my ($r)=@_;
+    &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
+	text=>"Parameter Change Log"});
     $r->print(&Apache::loncommon::start_page('Parameter Change Log'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
 
@@ -4447,11 +4484,10 @@
 
     &reset_caches();
 
-    if ($r->header_only) {
-	&Apache::loncommon::content_type($r,'text/html');
-	$r->send_http_header;
-	return OK;
-    }
+    &Apache::loncommon::content_type($r,'text/html');
+    $r->send_http_header;
+    return OK if $r->header_only;
+
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 					    ['action','state',
                                              'pres_marker',
@@ -4475,12 +4511,6 @@
     my $exists = &check_for_course_info();
 
     if ($env{'request.course.id'} &&  $parm_permission && $exists) {
-
-        # Start Page
-        &Apache::loncommon::content_type($r,'text/html');
-        $r->send_http_header;
-
-
         #
         # Main switch on form.action and form.state, as appropriate
         #
@@ -4488,64 +4518,34 @@
         #  the table mode
         if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
 	     && (!$env{'form.dis'})) || ($env{'form.symb'})) {
-            &Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
-						    text=>"Problem Parameters"});
 	    &assessparms($r);
-
         } elsif (! exists($env{'form.action'})) {
-            $r->print(&header());
-            $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Manager'));
             &print_main_menu($r,$parm_permission);
-        } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
-						    text=>"Course Environment"});
+        } elsif ($env{'form.action'} eq 'crsenv') {
             &crsenv($r); 
-        } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
-						    text=>"Overview Mode"});
+        } elsif ($env{'form.action'} eq 'setoverview') {
 	    &overview($r);
-	} elsif ($env{'form.action'} eq 'addmetadata' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
-						    text=>"Add Metadata Field"});
+	} elsif ($env{'form.action'} eq 'addmetadata') {
 	    &addmetafield($r);
-	} elsif ($env{'form.action'} eq 'ordermetadata' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
-						    text=>"Add Metadata Field"});
+	} elsif ($env{'form.action'} eq 'ordermetadata') {
 	    &order_meta_fields($r);
-        } elsif ($env{'form.action'} eq 'setrestrictmeta' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
-						    text=>"Restrict Metadata"});
+        } elsif ($env{'form.action'} eq 'setrestrictmeta') {
 	    &setrestrictmeta($r);
-        } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
-						    text=>"Overview Mode"});
+        } elsif ($env{'form.action'} eq 'newoverview') {
 	    &newoverview($r);
-        }  elsif ($env{'form.action'} eq 'setdefaults' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
-						    text=>"Set Defaults"});
+        } elsif ($env{'form.action'} eq 'setdefaults') {
 	    &defaultsetter($r);
-	} elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
-						    text=>"Table Mode",
-						    help => 'Course_Setting_Parameters'});
+	} elsif ($env{'form.action'} eq 'settable') {
 	    &assessparms($r);
-        } elsif ($env{'form.action'} eq 'parameterchangelog' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
-						    text=>"Parameter Change Log"});
+        } elsif ($env{'form.action'} eq 'parameterchangelog') {
 	    &parm_change_log($r);
-        } elsif ($env{'form.action'} eq 'cleanparameters' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
-						    text=>"Clean Parameters"});
+        } elsif ($env{'form.action'} eq 'cleanparameters') {
 	    &clean_parameters($r);
-        } elsif ($env{'form.action'} eq 'dateshift1' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
-                                                    text=>"Shifting Dates"});
+        } elsif ($env{'form.action'} eq 'dateshift1') {
             &date_shift_one($r);
-        } elsif ($env{'form.action'} eq 'dateshift2' && $parm_permission) {
-            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
-                                                    text=>"Shifting Dates"});
+        } elsif ($env{'form.action'} eq 'dateshift2') {
             &date_shift_two($r);
-	} elsif ($env{'form.action'} eq 'categorizecourse' && $parm_permission) {
+	} elsif ($env{'form.action'} eq 'categorizecourse') {
             &assign_course_categories($r);
         } 
     } else {
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.182 loncom/interface/lonhtmlcommon.pm:1.183
--- loncom/interface/lonhtmlcommon.pm:1.182	Tue Oct  7 10:13:58 2008
+++ loncom/interface/lonhtmlcommon.pm	Tue Nov 11 20:12:17 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.182 2008/10/07 10:13:58 foxr Exp $
+# $Id: lonhtmlcommon.pm,v 1.183 2008/11/11 20:12:17 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2004,6 +2004,59 @@
     return $scripttag;
 }
 
+##############################################
+##############################################
+
+# generate_menu
+#
+# Generates html markup for a menu. 
+#
+# Inputs:
+# An array of following structure:
+#   ({	categorytitle => 'Categorytitle',
+#	items => [
+#		    {	linktext    =>	'Text to be displayed',
+#			url	    =>	'URL the link is pointing to, i.e. /adm/site?action=dosomething',
+#			permission  =>	'Contains permissions as returned from lonnet::allowed(),
+#					 must evaluate to true in order to activate the link',
+#			help	    =>	'Name of the corresponding helpfile',
+#			linktitle   =>	'Description of the link (used for title tag)'
+#		    },
+#		    ...
+#		]
+#   }, 
+#   ...
+#   )
+#
+# Outputs: A scalar containing the html markup for the menu.
+
+# ---- Remove when done ----
+# This routine is part of the redesign of LON-CAPA and it's 
+# subject to change during this project.
+# Don't rely on its current functionality as it might be 
+# changed or removed.
+# --------------------------
+
+sub generate_menu {
+    my @menu = @_;
+    my $menu_html = '';
+
+    foreach my $category (@menu) { #FIXME: insert appropriate classnames for styles when they're finished.
+	$menu_html .='<div class=""><h3 class="">'.$category->{'categorytitle'}.'</h3><ul class="">';
+	foreach my $item (@{ $category->{items} }) {
+	    next if (! $item->{'permission'});
+	    $menu_html .= '<li class="">'.
+			    qq{<a href="$item->{'url'}" title="$item->{'linktitle'}">}.
+			    &mt($item->{'linktext'}).'</a>';
+	    if (exists($item->{'help'})) {
+		$menu_html .= &Apache::loncommon::help_open_topic($item->{'help'});
+	    }
+	    $menu_html .= '</li>';
+	}
+	$menu_html .= '</div>';
+    }
+    return $menu_html;
+}
 
 
 1;

--droeschl1226434337--