--- loncom/homework/edit.pm 2014/11/28 18:23:03 1.152 +++ loncom/homework/edit.pm 2023/03/27 18:41:06 1.157 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # edit mode helpers # -# $Id: edit.pm,v 1.152 2014/11/28 18:23:03 raeburn Exp $ +# $Id: edit.pm,v 1.157 2023/03/27 18:41:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -134,10 +134,11 @@ package Apache::edit; use strict; use Apache::lonnet; +use Apache::loncommon; use HTML::Entities(); use Apache::lonlocal; use lib '/home/httpd/lib/perl/'; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); # Global Vars @@ -164,12 +165,9 @@ sub tag_start { $description=&mt(&Apache::lonxml::description($token)); if (!$description) { $description="<$tag>"; } } - $result.= &start_table($token)."<tr><td>$description</td> - <td>".&mt('Delete?').' '. - &deletelist($target,$token) - ."</td> - <td>". - &insertlist($target,$token); + $result.= &start_table($token)."<tr><td>".&Apache::loncommon::insert_folding_button(). + " $description</td><td>".&mt('Delete?')." ".&deletelist($target,$token). + "</td><td>".&insertlist($target,$token); #<td>". # &movebuttons($target,$token). # "</tr><tr><td colspan=\"3\">\n"; @@ -232,7 +230,10 @@ sub end_table { return $result; } -sub start_spanning_row { return '<tr><td colspan="5" bgcolor="#F0F0F0">';} +sub start_spanning_row { + return '<tr name="foldblock_'.$Apache::lonxml::curdepth. + '" style="visibility: \'\'"><td colspan="5" bgcolor="#F0F0F0">'; +} sub start_row { return '<tr><td bgcolor="#DDDDDD">'; } sub end_row { return '</td></tr>'; } @@ -788,12 +789,14 @@ sub element_change_detection { sub submit_ask_anyway { my ($extra_action) = @_; - return ' onclick="still_ask=true;'.$extra_action.'" '; + my $resource = &Apache::loncommon::escape_single($env{'request.ambiguous'}); + return ' onclick="saveScrollPosition(\''.$resource.'\');still_ask=true;'.$extra_action.';" '; } sub submit_dont_ask { my ($extra_action) = @_; - return ' onclick="is_submit=true;'.$extra_action.'" '; + my $resource = &Apache::loncommon::escape_single($env{'request.ambiguous'}); + return ' onclick="saveScrollPosition(\''.$resource.'\');is_submit=true;'.$extra_action.';" '; } sub js_update_linknum { @@ -1193,52 +1196,166 @@ sub deletecoorddata { &Apache::lonnet::delenv('imagechoice.'); } +#----------------------------------------------------- browse and search links +sub browse_or_search { + my ($id,$mode,$titleid,$only,$crsonly,$usesearch) = @_; + my $output; + my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url(); + if ($cnum) { + my $form = 'lonhomework'; + my ($element,$bretitleelement,$srchtitleelement); + $element = &get_element($id,$mode); + my %lt = &Apache::lonlocal::texthash ( + uacf => 'Use a course file', + uanf => 'Use a new file', + impo => 'Import', + sear => 'Search', + sefi => 'Select File', + upfi => 'Upload File', + dire => 'Directory', + news => 'New sub-directory', + empd => 'No suitable resources found', + ); + my ($importcrsres,$uploadfile,$allonly); + if ($only) { + $allonly = $only; + if ($crsonly) { + $allonly .= ','.$crsonly; + } + } elsif ($crsonly) { + $allonly = $crsonly; + } + my ($numdirs,$pickfile) = + &Apache::loncommon::import_crsauthor_form('coursepath_'.$element,'coursefile_'.$element,undef,$allonly,$element); + $importcrsres=(<<CRSRES); + <fieldset id="importcrsresform_$element" style="display:inline;"> + <legend>$lt{'uacf'}</legend> + <div id="hascrsres_$element" style="padding:0;clear:both;margin:0;border:0;display:none;"> + <p> + $pickfile + </p><p> + <input type="button" name="crsres_$element" value="$lt{'sefi'}" onclick="updateCrsFile(this.form,'$element');" /> + </p> + </div> + <div id="nocrsres_$element" style="padding:0;clear:both;margin:0;border:0display:none;"> + <p> + $lt{'empd'} + </p> + </div> + </fieldset> +CRSRES + my %subdirs; + my $toppath="/priv/$cdom/$cnum"; + my $exclude = &Apache::lonnet::priv_exclude(); + &Apache::lonnet::recursedirs(1,1,'',$exclude,'',0,$toppath,'',\%subdirs); + my $numcrsdirs = keys(%subdirs); + my $pickdir = $lt{'dire'}.'<select name="crsauthorpath_'.$element.'">'."\n". + '<option value="/">/</option>'."\n"; + if ($numcrsdirs) { + foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n"; + } + } + $pickdir .= '</select><br />'; + my $uploadfile =(<<CRSUPL); + <fieldset id="uploadcrsresform_$element" style="display:inline;"> + <legend>$lt{'uanf'}</legend> + <p> + $pickdir + <span class="LC_nobreak">$lt{'news'}? + <label><input type="radio" name="newsubdir_$element" value="0" onclick="toggleNewsubdir(this.form,'$element');" checked="checked" />No</label> + + <label><input type="radio" name="newsubdir_$element" value="1" onclick="toggleNewsubdir(this.form,'$element');" />Yes</label> + </span><span id="newsubdir_$element"></span> + <input type="hidden" name="newsubdirname_$element" id="newsubdirname_$element" value="" autocomplete="off" /> + </p> + <input type="file" id="uploadcrsres_$element" name="uploadcrsres_$element" size="40" /> + <input type="hidden" id="crsuploadto_$element" name="filename_$element" value="$ENV{'REQUEST_URI'}" /> + <input type="submit" id="crsupload_$element" class="LC_uploadcrsres" value="$lt{'upfi'}" /> + <iframe id="crsupload_target_$element" name="crsupload_target_$element" src="" style="width:0px;height:0px;border:0px"></iframe> + </fieldset> +CRSUPL + if ($titleid) { + $bretitleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; + $srchtitleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; + } else { + $bretitleelement=",'$only'"; + } + $output = '<a href="javascript:toggleChooser(document.'.$form.",'$element'".');">'. + &mt('Choose File').'</a>'. + '<div id="chooser_'.$element.'" style="display:none" class="LC_left_float">'. + '<fieldset><legend>'.&mt('Choose File').'</legend>'. + '<label><input type="radio" name="chooser_'.$element.'" value="crsres" onclick="toggleCrsFile(this.form,'."'$element'".')" />'.$lt{'uacf'}.'</label> '. + '<label><input type="radio" name="chooser_'.$element.'" value="upload" onclick="toggleCrsUpload(this.form,'."'$element'".')" />'.$lt{'uanf'}.'</label> '. + '<label><input type="radio" name="chooser_'.$element.'" value="import" onclick="toggleResImport(this.form,'."'$element'".');openbrowser('."'$form','$element'$bretitleelement)".'" />'.$lt{'impo'}.'</label>'; + if ($usesearch) { + $output .= ' <label><input type="radio" name="chooser_'.$element.'" value="search" onclick="opensearcher('."'$form','$element'$srchtitleelement".')" />'.$lt{'sear'}.'</label>'; + } + $output .= '<div id="chooser_'.$element.'_crsres" style="display:none">'. + $importcrsres. + '</div>'. + '<div id="chooser_'.$element.'_upload" style="display:none">'. + $uploadfile. + '</div>'. + '</fieldset></div>'; + + } else { + $output = &browse($id, $mode, $titleid, $only); + if ($usesearch) { + $output .= ' '.&search($id, $mode, $titleid); + } + } + return $output; +} + #----------------------------------------------------- browse sub browse { # insert a link to call up the filesystem browser (lonindexer) my ($id, $mode, $titleid, $only) = @_; + my %lt = &Apache::lonlocal::texthash ( + se => 'Select', + ); my $form = 'lonhomework'; - my $element; - if (! defined($mode) || $mode eq 'attribute') { - $element = &escape("$id\_$Apache::lonxml::curdepth"); - } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag> - $element = &escape('homework_edit_'. - $Apache::lonxml::curdepth); - } + my $element = &get_element($id,$mode); my $titleelement; if ($titleid) { $titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; } else { $titleelement=",'$only'"; } - my $result = <<"ENDBUTTON"; -<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a> + return <<"ENDBUTTON"; +<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>$lt{'se'}</a> ENDBUTTON - return $result; } -#----------------------------------------------------- browse +#----------------------------------------------------- search sub search { # insert a link to call up the filesystem browser (lonindexer) my ($id, $mode, $titleid) = @_; my $form = 'lonhomework'; - my $element; - if (! defined($mode) || $mode eq 'attribute') { - $element = &escape("$id\_$Apache::lonxml::curdepth"); - } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag> - $element = &escape('homework_edit_'. - $Apache::lonxml::curdepth); - } + my $element = &get_element($id,$mode); my $titleelement; if ($titleid) { $titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'"; } + my $linktext = &mt('Search'); my $result = <<"ENDBUTTON"; -<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a> +<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>$linktext</a> ENDBUTTON return $result; } +sub get_element { + my ($id,$mode) = @_; + my $element; + if (! defined($mode) || $mode eq 'attribute') { + $element = &escape("$id\_$Apache::lonxml::curdepth"); + } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag> + $element = &escape('homework_edit_'. + $Apache::lonxml::curdepth); + } + return $element; +} 1; __END__