[LON-CAPA-cvs] cvs: rat /client extpickcode.html loncom/interface loncommon.pm londocs.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Sat, 07 Jul 2007 00:53:26 -0000


This is a MIME encoded message

--albertel1183769606
Content-Type: text/plain

albertel		Fri Jul  6 20:53:26 2007 EDT

  Modified files:              
    /loncom/interface	londocs.pm loncommon.pm 
    /rat/client	extpickcode.html 
  Log:
  - BUG#3487, make it possible to edit the location fo an external resource
  - improve paste buffer handling of ext resources and add ability to
      properly handle https:// style external resources
  - fix handling of : in paste buffer titles
  - some css tweaks
  
  
--albertel1183769606
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070706205326.txt"

Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.286 loncom/interface/londocs.pm:1.287
--- loncom/interface/londocs.pm:1.286	Tue Jul  3 20:21:42 2007
+++ loncom/interface/londocs.pm	Fri Jul  6 20:53:24 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.286 2007/07/04 00:21:42 albertel Exp $
+# $Id: londocs.pm,v 1.287 2007/07/07 00:53:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -908,9 +908,7 @@
     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
 
     while (@files) {
-	my $name = shift(@files);
-	my $url  = shift(@files);
-	#FIXME check if file exists before overwriting, might be restoring it
+	my ($name, $url, $residx) = @{ shift(@files) };
         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) 
 	     && ($caller eq 'londocs')
 	     && (!&Apache::lonnet::stat_file($url))) {
@@ -934,14 +932,16 @@
             }
         }
 	if ($url) {
-	    my $idx = &LONCAPA::map::getresidx($url);
-	    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
+	    if (!$residx) {
+		$residx = &LONCAPA::map::getresidx($url);
+		$LONCAPA::map::order[$#LONCAPA::map::order+1]=$residx;
+	    }
 	    my $ext = 'false';
 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
 	    $url  = &LONCAPA::map::qtunescape($url);
 	    $name = &LONCAPA::map::qtunescape($name);
-	    $LONCAPA::map::resources[$idx] = 
-		join ':', ($name, $url, $ext, 'normal', 'res');
+	    $LONCAPA::map::resources[$residx] = 
+		join(':', ($name, $url, $ext, 'normal', 'res'));
 	}
     }
     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
@@ -1199,6 +1199,8 @@
     if (&is_supplemental_title($title)) {
 	($title) = &parse_supplemental_title($title);
     }
+    $url=~s{http(:|:)//https(:|:)//}{https$2//};
+
     &Apache::lonnet::appenv('docs.markedcopy_title' => $title,
 			    'docs.markedcopy_url'   => $url);
     delete($env{'form.markcopy'});
@@ -1214,15 +1216,17 @@
     $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');
 
     my $type;
-    if ($env{'docs.markedcopy_url'} =~ m{^/adm/wrapper/ext}) {
+    if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
 	$type = &mt('External Resource');
-	$r->print($type.': '.&Apache::map::qtescape($env{'docs.markedcopy_title'}));
+	$r->print($type.': '.
+		  &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
+		  &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
     }  else {
 	my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
 	my $type = &Apache::loncommon::filedescription($extension);
 	my $icon = '<img src="'.&Apache::loncommon::icon($extension).
 	    '" alt="" class="LC_icon" />';
-	$r->print($icon.$type.': '.  &parse_supplemental_title($env{'docs.markedcopy_title'}));
+	$r->print($icon.$type.': '.  &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
     }
     if ($container eq 'page') {
 	$r->print('
@@ -1344,8 +1348,8 @@
 	    
 	    if ($env{'form.pastemarked'}) {
 # paste resource to end of list
-                my $url=$env{'docs.markedcopy_url'};
-		my $title=$env{'docs.markedcopy_title'};
+                my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
+		my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
 # Maps need to be copied first
 		if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
 		    $title=&mt('Copy of').' '.$title;
@@ -1361,7 +1365,7 @@
 		}
 		$title = &LONCAPA::map::qtunescape($title);
 		my $ext='false';
-		if ($url=~/^http\:\/\//) { $ext='true'; }
+		if ($url=~m{^http(|s)://}) { $ext='true'; }
 		$url   = &LONCAPA::map::qtunescape($url);
 # Now insert the URL at the bottom
                 my $newidx=&LONCAPA::map::getresidx($url);
@@ -1435,13 +1439,11 @@
 # Group import/search
 	    if ($env{'form.importdetail'}) {
 		my @imports;
-#		&Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'});
 		foreach (split(/\&/,$env{'form.importdetail'})) {
 		    if (defined($_)) {
-			my ($name,$url)=split(/\=/,$_);
-			$name=&unescape($name);
-			$url=&unescape($url);
-			push @imports, $name, $url;
+			my ($name,$url,$residx)=
+			    map {&unescape($_)} split(/\=/,$_);
+			push(@imports, [$name, $url, $residx]);
 		    }
 		}
 # Store the changed version
@@ -1556,7 +1558,7 @@
 						$parseaction,$allfiles,
 						$codebase);
         my $ext='false';
-        if ($url=~/^http\:\/\//) { $ext='true'; }
+        if ($url=~m{^http://}) { $ext='true'; }
 	$url     = &LONCAPA::map::qtunescape($url);
         my $comment=$env{'form.comment'};
 	$comment = &LONCAPA::map::qtunescape($comment);
@@ -1856,7 +1858,9 @@
 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
 	}
     }
-    $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;
+    
+    my $orig_url = $url;
+    my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
 	my $symb=&Apache::lonnet::symbclean(
           &Apache::lonnet::declutter('uploaded/'.
@@ -1879,6 +1883,7 @@
 	    }
 	} elsif ($url=~m|^/ext/|) { 
 	    $url='/adm/wrapper'.$url;
+	    $external = 1;
 	}
         if (&Apache::lonnet::symbverify($symb,$url)) {
 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
@@ -1932,12 +1937,18 @@
 	$url.='pagepath='.&escape($pagepath).
 	    '&amp;pagesymb='.&escape($symb).$cpinfo;
     }
+    if ($external) {
+	my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
+	$external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
+    } else {
+	undef($external);
+    }
     $line.='
   <td class="LC_docs_entry_icon">
-    <a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>
+    '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
   </td>
   <td class="LC_docs_entry_title">
-    '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>')."
+    '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
   </td>";
     if (($allowed) && ($folder!~/^supplemental/)) {
  	my %lt=&Apache::lonlocal::texthash(
@@ -3068,7 +3079,13 @@
     }
     $r->print('</table>');
     if ($allowed) {
-	$r->print('<form method="post" name="extimport" action="/adm/coursedocs"><input type="hidden" name="title" /><input type="hidden" name="url" /><input type="hidden" name="useform" /></form>');
+	$r->print('
+<form method="post" name="extimport" action="/adm/coursedocs">
+  <input type="hidden" name="title" />
+  <input type="hidden" name="url" />
+  <input type="hidden" name="useform" />
+  <input type="hidden" name="residx" />
+</form>');
     }
   } else {
       unless ($upload_result eq 'phasetwo') {
@@ -3108,6 +3125,17 @@
 
 function makenewext(targetname) {
     this.document.forms.extimport.useform.value=targetname;
+    this.document.forms.extimport.title.value='';
+    this.document.forms.extimport.url.value='';
+    this.document.forms.extimport.residx.value='';
+    window.open('/adm/rat/extpickframe.html');
+}
+
+function edittext(targetname,residx,title,url) {
+    this.document.forms.extimport.useform.value=targetname;
+    this.document.forms.extimport.residx.value=residx;
+    this.document.forms.extimport.url.value=url;
+    this.document.forms.extimport.title.value=title;
     window.open('/adm/rat/extpickframe.html');
 }
 
@@ -3187,9 +3215,8 @@
     var title=this.document.forms.extimport.title.value;
     var url=this.document.forms.extimport.url.value;
     var form=this.document.forms.extimport.useform.value;
-    eval
-     ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
-    '";this.document.forms.'+form+'.submit();');
+    var residx=this.document.forms.extimport.residx.value;
+    eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
 }
 
 function changename(folderpath,index,oldtitle,container,pagesymb) {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.546 loncom/interface/loncommon.pm:1.547
--- loncom/interface/loncommon.pm:1.546	Fri Jul  6 05:02:03 2007
+++ loncom/interface/loncommon.pm	Fri Jul  6 20:53:24 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.546 2007/07/06 09:02:03 albertel Exp $
+# $Id: loncommon.pm,v 1.547 2007/07/07 00:53:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4437,7 +4437,7 @@
 
 table.LC_docs_documents {
   background: #BBBBBB;
-  border-size: 0px;
+  border-width: 0px;
   border-collapse: collapse;
 }
 
@@ -4480,6 +4480,11 @@
   color: #990000;
 }
 
+.LC_docs_reinit_warn,
+.LC_docs_ext_edit {
+  font-size: x-small;
+}
+
 .LC_docs_editor td.LC_docs_entry_title,
 .LC_docs_editor td.LC_docs_entry_icon {
   background: #FFFFBB;
Index: rat/client/extpickcode.html
diff -u rat/client/extpickcode.html:1.5 rat/client/extpickcode.html:1.6
--- rat/client/extpickcode.html:1.5	Sun Feb  1 16:47:22 2004
+++ rat/client/extpickcode.html	Fri Jul  6 20:53:26 2007
@@ -4,7 +4,7 @@
 The LearningOnline Network
 Pick External Resources
 //
-// $Id: extpickcode.html,v 1.5 2004/02/01 21:47:22 www Exp $
+// $Id: extpickcode.html,v 1.6 2007/07/07 00:53:26 albertel Exp $
 //
 // Copyright Michigan State University Board of Trustees
 //
@@ -29,9 +29,22 @@
 // http://www.lon-capa.org/
 //
 -->
+<head>
+  <script type="text/javascript">
+function initfields () {
+    if ( parent.opener.document.forms.extimport.title.value != '') {
+        document.forms.pick.exttitle.value =
+            parent.opener.document.forms.extimport.title.value;
+        document.forms.pick.exturl.value =
+            parent.opener.document.forms.extimport.url.value;
+	    
+    }
+}
 
-<body bgcolor="#FFFFBB">
-<form>
+  </script>
+</head>
+<body bgcolor="#FFFFBB" onload="javascript:initfields()">
+<form name="pick">
 <table>
 <tr><td bgcolor="#FFFF99">
 <input type="button" name="cancel" value="Choose"

--albertel1183769606--