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

banghart lon-capa-cvs@mail.lon-capa.org
Tue, 18 Jan 2005 02:18:29 -0000


This is a MIME encoded message

--banghart1106014709
Content-Type: text/plain

banghart		Mon Jan 17 21:18:29 2005 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  	Saving work. Still approaching meta data.
  
  
--banghart1106014709
Content-Type: text/plain
Content-Disposition: attachment; filename="banghart-20050117211829.txt"

Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.70 loncom/interface/portfolio.pm:1.71
--- loncom/interface/portfolio.pm:1.70	Mon Jan 17 20:27:09 2005
+++ loncom/interface/portfolio.pm	Mon Jan 17 21:18:29 2005
@@ -206,7 +206,191 @@
             <input type="hidden" name="currentpath" value="'.$current_path.'" />
     </form>');
 }
-
+sub prettyinput {
+    my ($type,$value,$fieldname,$formname,
+	$relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
+    if (! defined($size)) {
+        $size = 80;
+    }
+    # Language
+    if ($type eq 'language') {
+	return &Apache::lonmeta::selectbox($fieldname,
+			  $value,
+			  \&Apache::loncommon::languagedescription,
+			  (&Apache::loncommon::languageids)).
+                              &relatedfield(0,$relatedsearchflag,$relatedsep);
+    }
+    # Copyright
+    if ($type eq 'copyright') {
+	return &Apache::lonmeta::selectbox($fieldname,
+			  $value,
+			  \&Apache::loncommon::copyrightdescription,
+			  (&Apache::loncommon::copyrightids)).
+                              &relatedfield(0,$relatedsearchflag,$relatedsep);
+    }
+    # Source Copyright
+    if ($type eq 'sourceavail') {
+	return &Apache::lonmeta::selectbox($fieldname,
+			  $value,
+			  \&Apache::loncommon::source_copyrightdescription,
+			  (&Apache::loncommon::source_copyrightids)).
+                              &relatedfield(0,$relatedsearchflag,$relatedsep);
+    }
+    # Gradelevels
+    if (($type eq 'lowestgradelevel') ||
+	($type eq 'highestgradelevel')) {
+	return &Apache::loncommon::select_level_form($value,$fieldname).
+            &relatedfield(0,$relatedsearchflag,$relatedsep);
+    }
+    # Obsolete
+    if ($type eq 'obsolete') {
+	return '<input type="checkbox" name="'.$fieldname.'"'.
+	    ($value?' checked="1"':'').' />'.
+            &relatedfield(0,$relatedsearchflag,$relatedsep); 
+    }
+    # Obsolete replacement file
+    if ($type eq 'obsoletereplacement') {
+	return '<input type="text" name="'.$fieldname.
+	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
+	    "('".$formname."','".$fieldname."'".
+	    ",'')\">".&mt('Select').'</a>'.
+            &relatedfield(0,$relatedsearchflag,$relatedsep); 
+    }
+    # Customdistribution file
+    if ($type eq 'customdistributionfile') {
+	return '<input type="text" name="'.$fieldname.
+	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
+	    "('".$formname."','".$fieldname."'".
+	    ",'rights')\">".&mt('Select').'</a>'.
+            &relatedfield(0,$relatedsearchflag,$relatedsep); 
+    }
+    # Source Customdistribution file
+    if ($type eq 'sourcerights') {
+	return '<input type="text" name="'.$fieldname.
+	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
+	    "('".$formname."','".$fieldname."'".
+	    ",'rights')\">".&mt('Select').'</a>'.
+            &relatedfield(0,$relatedsearchflag,$relatedsep); 
+    }
+    # Dates
+    if (($type eq 'creationdate') ||
+	($type eq 'lastrevisiondate')) {
+	return 
+            &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
+            &relatedfield(0,$relatedsearchflag,$relatedsep);
+    }
+    # No pretty input found
+    $value=~s/^\s+//gs;
+    $value=~s/\s+$//gs;
+    $value=~s/\s+/ /gs;
+    $value=~s/\"/\&quot\;/gs;
+    return 
+        '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
+        'value="'.$value.'" />'.
+        &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
+                      $relatedvalue); 
+}
+
+sub relatedfield {
+    my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
+    if (! $relatedsearchflag) { 
+        return '';
+    }
+    if (! defined($relatedsep)) {
+        $relatedsep=' ';
+    }
+    if (! $show) {
+        return $relatedsep.'&nbsp;';
+    }
+    return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
+	($relatedvalue?' checked="1"':'').' />';
+}
+
+
+# The field names
+sub fieldnames {
+    return &Apache::lonlocal::texthash
+        (
+         'title' => 'Title',
+         'author' =>'Author(s)',
+         'authorspace' => 'Author Space',
+         'modifyinguser' => 'Last Modifying User',
+         'subject' => 'Subject',
+         'keywords' => 'Keyword(s)',
+         'notes' => 'Notes',
+         'abstract' => 'Abstract',
+         'lowestgradelevel' => 'Lowest Grade Level',
+         'highestgradelevel' => 'Highest Grade Level',
+         'standards' => 'Standards',
+         'mime' => 'MIME Type',
+         'language' => 'Language',
+         'creationdate' => 'Creation Date',
+         'lastrevisiondate' => 'Last Revision Date',
+         'owner' => 'Publisher/Owner',
+         'copyright' => 'Copyright/Distribution',
+         'customdistributionfile' => 'Custom Distribution File',
+         'sourceavail' => 'Source Available',
+         'sourcerights' => 'Source Custom Distribution File',
+         'obsolete' => 'Obsolete',
+         'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
+         'count'      => 'Network-wide number of accesses (hits)',
+         'course'     => 'Network-wide number of courses using resource',
+         'course_list' => 'Network-wide courses using resource',
+         'sequsage'      => 'Number of resources using or importing resource',
+         'sequsage_list' => 'Resources using or importing resource',
+         'goto'       => 'Number of resources that follow this resource in maps',
+         'goto_list'  => 'Resources that follow this resource in maps',
+         'comefrom'   => 'Number of resources that lead up to this resource in maps',
+         'comefrom_list' => 'Resources that lead up to this resource in maps',
+         'clear'      => 'Material presented in clear way',
+         'depth'      => 'Material covered with sufficient depth',
+         'helpful'    => 'Material is helpful',
+         'correct'    => 'Material appears to be correct',
+         'technical'  => 'Resource is technically correct', 
+         'avetries'   => 'Average number of tries till solved',
+         'stdno'      => 'Total number of students who have worked on this problem',
+         'difficulty' => 'Degree of difficulty',
+         'disc'       => 'Degree of discrimination',
+	 'dependencies' => 'Resources used by this resource',
+         );
+}
+
+sub edit_meta_data {
+    my ($r,$uri) = @_;
+    # Construction Space Call
+    # Header
+    my $disuri=$uri;
+    my $fn=&Apache::lonnet::filelocation('',$uri);
+    $disuri=~s/^\/\~/\/priv\//;
+    $disuri=~s/\.meta$//;
+    my $target=$uri;
+    $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
+    $target=~s/\.meta$//;
+        $r->print('<script language="JavaScript">'.
+                  &Apache::loncommon::browser_and_searcher_javascript().
+                  '</script>');
+        my %lt=&fieldnames();
+	my $output;
+    foreach ('author','title','subject','keywords','abstract','notes',
+             'copyright','customdistributionfile','language',
+             'standards',
+             'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
+             'obsolete','obsoletereplacement') {
+        if (defined($ENV{'form.new_'.$_})) {
+            $Apache::lonpublisher::metadatafields{$_}=
+                $ENV{'form.new_'.$_};
+        }
+        if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
+            $Apache::lonpublisher::metadatafields{'copyright'}=
+                'default';
+        }
+        $output.=('<p>'.$lt{$_}.': '.
+                  &prettyinput($_,
+			   $Apache::lonpublisher::metadatafields{$_},
+			   'new_'.$_,'defaultmeta').'</p>');
+    }
+    return $output;
+}
 sub open_form {
     my ($r)=@_;
     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
@@ -521,6 +705,7 @@
 	}
     if ($ENV{'form.meta'}) {
         &open_form($r);
+        $r->print(&edit_meta_data($r, $ENV{'form.currentpath'}.$ENV{'form.selectfile'}));
         $r->print('Edit the meta data<br />');
         &close_form($r);
     }

--banghart1106014709--