[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm
banghart
lon-capa-cvs@mail.lon-capa.org
Fri, 13 Oct 2006 00:20:20 -0000
banghart Thu Oct 12 20:20:20 2006 EDT
Modified files:
/loncom/interface lonparmset.pm
Log:
Work toward ordering added metadata. It doesn't work yet.
Saving work in progress.
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.339 loncom/interface/lonparmset.pm:1.340
--- loncom/interface/lonparmset.pm:1.339 Sat Oct 7 16:02:16 2006
+++ loncom/interface/lonparmset.pm Thu Oct 12 20:20:19 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.339 2006/10/07 20:02:16 banghart Exp $
+# $Id: lonparmset.pm,v 1.340 2006/10/13 00:20:19 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3215,6 +3215,90 @@
}
return ($output);
}
+sub order_meta_fields {
+ my ($r)=@_;
+ my $idx = 1;
+ 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'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata Fields'));
+ if ($env{'form.storeorder'}) {
+ my $newpos = $env{'form.newpos'} - 1;
+ my $currentpos = $env{'form.currentpos'} - 1;
+ my @neworder = ();
+ my @oldorder = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
+ my $i;
+
+ if ($newpos>$currentpos) {
+ # moving stuff up
+ for ($i=0;$i<$currentpos;$i++) {
+ $neworder[$i]=$oldorder[$i];
+ }
+ for ($i=$currentpos;$i<$newpos;$i++) {
+ $neworder[$i]=$oldorder[$i+1];
+ }
+ $neworder[$newpos]=$oldorder[$currentpos];
+ for ($i=$newpos+1;$i<=$#oldorder;$i++) {
+ $neworder[$i]=$oldorder[$i];
+ }
+ } else {
+ # moving stuff down
+ for ($i=0;$i<$newpos;$i++) {
+ $neworder[$i]=$oldorder[$i];
+ }
+ $neworder[$newpos]=$oldorder[$currentpos];
+ for ($i=$newpos+1;$i<$currentpos+1;$i++) {
+ $neworder[$i]=$oldorder[$i-1];
+ }
+ for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
+ $neworder[$i]=$oldorder[$i];
+ }
+ }
+ my $ordered_fields = join ",", @neworder;
+ my $put_result = &Apache::lonnet::put('environment',
+ {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
+
+
+
+
+
+ $r->print($env{'form.currentpos'}.' becomes '.$env{'form.newpos'});
+ }
+ my $fields = &get_added_meta_fieldnames();
+ my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
+ if (!@fields_in_order) {
+ # no order found, pick sorted order then create metadata.addedorder key.
+ foreach my $key (sort keys %$fields) {
+ push @fields_in_order, $key;
+ my $ordered_fields = join ",", @fields_in_order;
+ my $put_result = &Apache::lonnet::put('environment',
+ {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
+ }
+ }
+ $r->print('<table>');
+ my $num_fields = scalar(@fields_in_order);
+ foreach my $key (@fields_in_order) {
+ $r->print('<tr><td>');
+ $r->print('<form method="post" action="">');
+ $r->print('<select name="newpos" onChange="this.form.submit()">');
+ for (my $i = 1;$i le $num_fields;$i ++) {
+ if ($i eq $idx) {
+ $r->print('<option value="'.$i.'" SELECTED>('.$i.')</option>');
+ } else {
+ $r->print('<option value="'.$i.'">'.$i.'</option>');
+ }
+ }
+ $r->print('</select></td><td>');
+ $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
+ $r->print('<input type="hidden" name="storeorder" value="true" />');
+ $r->print('</form>');
+ $r->print($$fields{$key}.'</td></tr>');
+ $idx ++;
+ }
+ $r->print('</table>');
+
+ return 'ok';
+}
sub addmetafield {
my ($r)=@_;
$r->print(&Apache::loncommon::start_page('Add Metadata Field'));
@@ -3328,6 +3412,10 @@
<form method="post" action="/adm/parmset?action=addmetadata" name="form">
<input type="submit" name="restrictmeta" value="Add a Metadata Field">
</form>
+ </form><br />
+ <form method="post" action="/adm/parmset?action=ordermetadata" name="form">
+ <input type="submit" name="restrictmeta" value="Order Metadata Fields">
+ </form>
ENDenv
$r->print(&Apache::loncommon::end_page());
return 'ok';
@@ -3335,7 +3423,6 @@
##################################################
sub get_added_meta_fieldnames {
my %fields;
- my ($default_fields) = @_;
foreach my $key(%env) {
if ($key =~ m/\.metadata\.(.+)\.added$/) {
my $field_name = $1;
@@ -3807,6 +3894,10 @@
&Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
text=>"Add Metadata Field"});
&addmetafield($r);
+ } elsif ($env{'form.action'} eq 'ordermetadata' && $parm_permission) {
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
+ text=>"Add Metadata Field"});
+ &order_meta_fields($r);
} elsif ($env{'form.action'} eq 'setrestrictmeta' && $parm_permission) {
&Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
text=>"Restrict Metadata"});