--- loncom/interface/portfolio.pm 2013/04/11 14:59:49 1.240
+++ loncom/interface/portfolio.pm 2013/04/12 17:21:09 1.241
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.240 2013/04/11 14:59:49 bisitz Exp $
+# $Id: portfolio.pm,v 1.241 2013/04/12 17:21:09 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -639,9 +639,9 @@ sub display_file {
}
sub done {
- my ($message,$url)=@_;
- unless (defined $message) {
- $message='Done';
+ my ($linktext,$url)=@_;
+ unless (defined $linktext) {
+ $linktext='Return to directory';
}
my %anchor_fields = (
'showversions' => $env{'form.showversions'},
@@ -650,7 +650,8 @@ sub done {
'symb' => $env{'form.symb'},
'mode' => $env{'form.mode'}
);
- my $result = '
'.&make_anchor($url,\%anchor_fields,&mt($message)).'
';
+ my $result = &Apache::lonhtmlcommon::actionbox(
+ [&make_anchor($url,\%anchor_fields,&mt($linktext))]);
return $result;
}
@@ -662,8 +663,12 @@ sub delete {
my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
my ($uname,$udom) = &get_name_dom($group);
if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
- $r->print(&mt('The file is locked and cannot be deleted.').'
');
- $r->print(&done('Back',$url));
+ $r->print(
+ ''
+ .&mt('The file is locked and cannot be deleted.')
+ .'
'
+ .&done(undef,$url)
+ );
} else {
if (scalar(@files)) {
&open_form($r,$url);
@@ -684,18 +689,21 @@ sub delete_confirmed {
my $port_path = &get_port_path();
my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
$uname);
+ my @msg;
foreach my $delete_file (@files) {
- $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
- $env{'form.currentpath'}.
- $delete_file);
+ $result =
+ &Apache::lonnet::removeuserfile(
+ $uname,$udom,$port_path.
+ $env{'form.currentpath'}.
+ $delete_file);
if ($result ne 'ok') {
- $r->print(''
- .&mt('An error occurred ([_1]) while trying to delete [_2].'
- ,$result,&display_file(undef, $delete_file))
- .'
');
+ push(@msg, &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while trying to delete [_2].'
+ ,$result,&display_file(undef, $delete_file)),1));
} else {
- $r->print(&mt('File: [_1] deleted.',
- &display_file(undef,$delete_file)));
+ push(@msg, &Apache::lonhtmlcommon::confirm_success(
+ &mt('File: [_1] deleted.'
+ ,&display_file(undef,$delete_file))));
my $file_name = $env{'form.currentpath'}.$delete_file;
$file_name = &prepend_group($file_name);
my %access_controls =
@@ -711,23 +719,24 @@ sub delete_confirmed {
&Apache::lonnet::modify_access_controls($file_name,\%changes,
$udom,$uname);
if ($outcome ne 'ok') {
- $r->print('
'.&mt("An error occurred ([_1]) while ".
- "trying to delete access controls for the file.",$outcome).
- '
');
+ push(@msg, &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while '.
+ 'trying to delete access controls for the file.',$outcome),1));
} else {
if ($deloutcome eq 'ok') {
- $r->print('
'.&mt('Access controls also deleted for the file.').'
');
+ push(@msg, &mt('Access controls also deleted for the file.')); # FIXME: Does the user really need this message?
} else {
- $r->print(''.'
'.
- &mt("An error occurred ([_1]) while ".
- "trying to delete access controls for the file.",$deloutcome).
- '
');
+ push(@msg, &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while '.
+ 'trying to delete access controls for the file.'
+ ,$deloutcome),1));
}
}
}
}
}
}
+ $r->print(&Apache::loncommon::confirmwrapper(join('
',@msg)));
$r->print(&done(undef,$url));
}
@@ -747,12 +756,15 @@ sub delete_dir_confirmed {
my $port_path = &get_port_path();
my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
$directory_name);
-
+
if ($result ne 'ok') {
- $r->print(''
- .&mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
- ,$result,$directory_name)
- .'
');
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
+ ,$result,$directory_name),1)));
+ $r->print(&done(undef,$url));
+ return;
} else {
# now remove from recent
&Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
@@ -763,6 +775,10 @@ sub delete_dir_confirmed {
}
$env{'form.currentpath'} = $directory_name;
}
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('Directory successfully deleted'))));
$r->print(&done(undef,$url));
}
@@ -772,7 +788,11 @@ sub rename {
my ($uname,$udom) = &get_name_dom($group);
$file_name = &prepend_group($file_name);
if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
- $r->print("The file is locked and cannot be renamed.
");
+ $r->print(
+ ''
+ .&mt('The file is locked and cannot be renamed.')
+ .'
'
+ );
$r->print(&done(undef,$url));
} else {
&open_form($r,$url);
@@ -787,13 +807,32 @@ sub rename_confirmed {
my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
my ($uname,$udom) = &get_name_dom($group);
my $port_path = &get_port_path();
+
+ # Display warning in case of filename cleaning has changed the filename
+ if ($filenewname ne $env{'form.filenewname'}) {
+ $r->print(
+ ''
+ .&mt('Invalid characters')
+ .'
'
+ .&mt('The new filename was changed from [_1] to [_2].'
+ ,''.&display_file('',$env{'form.filenewname'}).''
+ ,''.&display_file('',$filenewname).'')
+ .'
'
+ );
+
+ }
+
+ # Filename empty?
if ($filenewname eq '') {
- $r->print(''.
- &mt("Error: no valid filename was provided to rename to.").
- '
');
- $r->print(&done(undef,$url));
- return;
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('Error: no valid filename was provided to rename to.'),1)));
+ $r->print(&done(undef,$url));
+ return;
}
+
+ # Rename the file
my $chg_access;
my $result=
&Apache::lonnet::renameuserfile($uname,$udom,
@@ -802,18 +841,20 @@ sub rename_confirmed {
if ($result eq 'ok') {
$chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
} else {
- $r->print(''.
- &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
- ,$result,&display_file(),&display_file('',$filenewname))
- .'
');
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
+ ,$result,&display_file(),&display_file('',$filenewname))
+ ,1)));
+ $r->print(&done(undef,$url));
return;
}
- if ($filenewname ne $env{'form.filenewname'}) {
- $r->print(&mt("The new filename was changed from:
[_1] to [_2]",
- ''.&display_file('',$env{'form.filenewname'}).'',
- ''.&display_file('',$filenewname).''));
- }
$r->print($chg_access);
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('File successfully renamed'))));
$r->print(&done(undef,$url));
}
@@ -878,7 +919,13 @@ sub display_access {
my $aclcount = keys(%access_controls);
my ($header,$info);
if ($action eq 'chgaccess') {
- $header = ''.&mt('Allowing others to retrieve file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'
';
+ $header =
+ ''
+ .&mt('Allowing others to retrieve file: [_1]'
+ ,''
+ .$port_path.$env{'form.currentpath'}.$env{'form.access'}
+ .'')
+ .'
';
$info .= &mt('Access to this file by others can be set to be one or more of the following types: public, passphrase-protected or conditional.');
$info .= '
- '.&mt('Public files are available to anyone without the need for login.');
$info .= '
- '.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
@@ -1083,8 +1130,8 @@ sub update_access {
}
}
my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
- $r->print('
'.&mt('Allowing others to retrieve file: [_1]',
- $port_path.$file_name).'
'."\n");
+ $r->print(''.&mt('Allowing others to retrieve file: [_1]',
+ ''.$port_path.$file_name.'').'
'."\n");
$file_name = &prepend_group($file_name);
my ($uname,$udom) = &get_name_dom($group);
my ($errors,$outcome,$deloutcome,$new_values,$translation);
@@ -1184,9 +1231,11 @@ sub update_access {
'currentpath' => $env{'form.currentpath'},
'access' => $env{'form.selectfile'}
);
- $r->print('
'.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
+ my @actions;
+ push(@actions, &make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
delete $anchor_fields{'access'};
- $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory')));
+ push(@actions, &make_anchor($url,\%anchor_fields,&mt('Return to directory')));
+ $r->print('
'.&Apache::lonhtmlcommon::actionbox(\@actions));
}
return;
}
@@ -1949,10 +1998,14 @@ sub upload {
my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formname.'.filename'});
my ($state,$msg);
if ($fname eq '') {
- my $msg = &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
'so after eliminating special characters there was nothing left.',
- ''.$env{'form.uploaddoc.filename'}.'');
- $r->print($msg.&done('Back',$url));
+ ''.$env{'form.uploaddoc.filename'}.''),1)));
+
+ $r->print(&done(undef,$url));
return;
}
my $disk_quota = &get_quota($group);
@@ -1969,7 +2022,7 @@ sub upload {
if ($state eq 'will_exceed_quota'
|| $state eq 'file_locked'
|| $state eq 'zero_bytes') {
- $r->print($msg.&done('Back',$url));
+ $r->print($msg.&done(undef,$url));
return;
}
@@ -2065,14 +2118,20 @@ $group_elem
END
} else {
- $r->print(''.&mt('An error occurred ([_1]) while trying to upload [_2].'
- ,$result,&display_file(undef,$fname)).'
');
- $r->print(&done('Back',$url));
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while trying to upload [_2].'
+ ,$result,&display_file(undef,$fname)),1)));
+ $r->print(&done(undef,$url));
}
} elsif ($result !~ m|^/uploaded/|) {
- $r->print(''.&mt('An error occurred ([_1]) while trying to upload [_2].'
- ,$result,&display_file(undef,$fname)).'
');
- $r->print(&done('Back',$url));
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while trying to upload [_2].'
+ ,$result,&display_file(undef,$fname)),1)));
+ $r->print(&done(undef,$url));
} else {
if (!&suppress_embed_prompt()) {
if ($mimetype eq 'text/html') {
@@ -2080,11 +2139,14 @@ END
&print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
return;
} else {
- $r->print(''.&mt('Completed upload of the file.').'
'.
- &mt('No embedded items identified.').'
');
+ $r->print(''.&mt('No embedded items identified.').'
');
}
}
}
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('File successfully uploaded'))));
$r->print(&done(undef,$url));
}
return;
@@ -2154,7 +2216,7 @@ sub overwrite {
my $msg = &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
'so after eliminating special characters there was nothing left.',
''.$env{'form.filename'}.'');
- $r->print($msg.&done('Back',$url));
+ $r->print($msg.&done(undef,$url));
return;
}
$env{'form.'.$formname.'.filename'} = $fname;
@@ -2165,8 +2227,8 @@ sub overwrite {
\%allfiles,\%codebase,undef,undef,undef,
undef,undef,undef,\$mimetype);
if ($result !~ m|^/uploaded/|) {
- $r->print(''.&mt('An error occurred ([_1]) while trying to overwrite [_2].'
- ,$result,&display_file(undef,$fname)).'
');
+ $r->print(''.&mt('An error occurred ([_1]) while trying to overwrite [_2].'
+ ,$result,&display_file(undef,$fname)).'
');
$r->print(&after_overwrite(&mt('Back'),$url));
} else {
if ($mode eq 'parse') {
@@ -2224,7 +2286,7 @@ sub lock_info {
$filetext = ''.$env{'form.lockinfo'}.
' (group: '.$group.')';
} else {
- $filetext = ''.$file_name.'';
+ $filetext = ''.$file_name.'';
}
my $title =''.&Apache::lonnet::gettitle($$array_item[0]).
@@ -2247,20 +2309,36 @@ sub lock_info {
}
}
}
- $r->print(&done(&mt('Back'),$url));
+ $r->print(&done(undef,$url));
return 'ok';
}
sub createdir {
my ($r,$url,$group)=@_;
my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
+ # Display warning in case of directory name cleaning has changed the directory name
+ if ($newdir ne $env{'form.newdir'}) {
+ $r->print(
+ ''
+ .&mt('Invalid characters')
+ .'
'
+ .&mt('The new directory name was changed from [_1] to [_2].'
+ ,''.$env{'form.newdir'}.''
+ ,''.$newdir.'')
+ .'
'
+ );
+ }
+
+ # Directory name empty?
if ($newdir eq '') {
- $r->print(''.
- &mt("Error: no directory name was provided.").
- '
');
- $r->print(&done(undef,$url));
- return;
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('Error: no directory name was provided.'),1)));
+ $r->print(&done(undef,$url));
+ return;
}
+
my $portfolio_root = &get_portfolio_root();
my ($dirlistref,$listerror) = &get_dir_list($portfolio_root,undef,$group);
my $found_file = 0;
@@ -2272,26 +2350,32 @@ sub createdir {
}
}
}
- if ($found_file){
- $r->print(''
- .&mt('Unable to create a directory named [_1].',''.$newdir.'')
- .' '.&mt('A file or directory by that name already exists.').'
');
+ if ($found_file) {
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('Unable to create a directory named [_1].'
+ ,''.$newdir.''),1)
+ .'
'.&mt('A file or directory by that name already exists.')));
} else {
my ($uname,$udom) = &get_name_dom($group);
my $port_path = &get_port_path();
my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
$port_path.$env{'form.currentpath'}.$newdir);
if ($result ne 'ok') {
- $r->print(''
- .&mt('An error occurred ([_1]) while trying to create a new directory [_2].'
- ,$result,&display_file())
- .'
');
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('An error occurred ([_1]) while trying to create a new directory [_2].'
+ ,$result,&display_file()),1)));
+
+ } else {
+ $r->print(
+ &Apache::loncommon::confirmwrapper(
+ &Apache::lonhtmlcommon::confirm_success(
+ &mt('Directory successfully created'))));
}
}
- if ($newdir ne $env{'form.newdir'}) {
- $r->print(&mt('The new directory name was changed from [_1] to [_2].'
- ,''.$env{'form.newdir'}.'',''.$newdir.''));
- }
$r->print(&done(undef,$url));
}
@@ -2621,10 +2705,14 @@ sub handler {
}
}
if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
- $r->print('');
- $r->print(&mt('No file was selected to upload.').' ');
- $r->print(&mt('To upload a file, click Browse... and select a file, then click Upload.'));
- $r->print('');
+ $r->print(
+ ''
+ .&mt('No file was selected to upload.')
+ .'<
'
+ .&mt('To upload a file, click [_1]Browse...[_2] and select a file, then click [_1]Upload[_2].'
+ ,'','')
+ .'
'
+ );
}
if ($env{'form.meta'}) {
&open_form($r,$url);