[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface londocs.pm
raeburn
raeburn at source.lon-capa.org
Sun Mar 17 19:55:02 EDT 2013
raeburn Sun Mar 17 23:55:02 2013 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface londocs.pm
Log:
- For 2.11
- Backport 1.537.
-------------- next part --------------
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.484.2.28 loncom/interface/londocs.pm:1.484.2.29
--- loncom/interface/londocs.pm:1.484.2.28 Sun Mar 17 18:49:16 2013
+++ loncom/interface/londocs.pm Sun Mar 17 23:55:01 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.484.2.28 2013/03/17 18:49:16 raeburn Exp $
+# $Id: londocs.pm,v 1.484.2.29 2013/03/17 23:55:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1889,23 +1889,93 @@
my $valid_parameters_re = join('|',keys(%parameter_type));
# set parameters
sub update_parameter {
-
- return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
-
- my $which = $env{'form.changeparms'};
- my $idx = $env{'form.setparms'};
- if ($env{'form.'.$which.'_'.$idx}) {
- my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
- : 'yes';
- &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
- $parameter_type{$which});
- &remember_parms($idx,$which,'set',$value);
+ if ($env{'form.changeparms'} eq 'all') {
+ my (@allidx, at allmapidx,%allchecked,%currchecked);
+ %allchecked = (
+ 'hiddenresource' => {},
+ 'encrypturl' => {},
+ 'randompick' => {},
+ 'randomorder' => {},
+ );
+ foreach my $which (keys(%allchecked)) {
+ $env{'form.all'.$which} =~ s/,$//;
+ if ($which eq 'randompick') {
+ foreach my $item (split(/,/,$env{'form.all'.$which})) {
+ my ($res,$value) = split(/:/,$item);
+ if ($value =~ /^\d+$/) {
+ $allchecked{$which}{$res} = $value;
+ }
+ }
+ } else {
+ map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
+ }
+ }
+ my $haschanges = 0;
+ foreach my $res (@LONCAPA::map::order) {
+ my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
+ $name=&LONCAPA::map::qtescape($name);
+ $url=&LONCAPA::map::qtescape($url);
+ next unless ($name && $url);
+ my $is_map;
+ if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
+ $is_map = 1;
+ }
+ foreach my $which (keys(%allchecked)) {
+ if (($which eq 'randompick' || $which eq 'randomorder')) {
+ next if (!$is_map);
+ }
+ my $oldvalue = 0;
+ my $newvalue = 0;
+ if ($allchecked{$which}{$res}) {
+ $newvalue = $allchecked{$which}{$res};
+ }
+ my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
+ if ($which eq 'randompick') {
+ if ($current =~ /^(\d+)$/) {
+ $oldvalue = $1;
+ }
+ } else {
+ if ($current =~ /^yes$/i) {
+ $oldvalue = 1;
+ }
+ }
+ if ($oldvalue ne $newvalue) {
+ $haschanges = 1;
+ if ($newvalue) {
+ my $storeval = 'yes';
+ if ($which eq 'randompick') {
+ $storeval = $newvalue;
+ }
+ &LONCAPA::map::storeparameter($res,'parameter_'.$which,
+ $storeval,
+ $parameter_type{$which});
+ &remember_parms($res,$which,'set',$storeval);
+ } elsif ($oldvalue) {
+ &LONCAPA::map::delparameter($res,'parameter_'.$which);
+ &remember_parms($res,$which,'del');
+ }
+ }
+ }
+ }
+ return $haschanges;
} else {
- &LONCAPA::map::delparameter($idx,'parameter_'.$which);
+ return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
- &remember_parms($idx,$which,'del');
+ my $which = $env{'form.changeparms'};
+ my $idx = $env{'form.setparms'};
+ if ($env{'form.'.$which.'_'.$idx}) {
+ my $value = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
+ : 'yes';
+ &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
+ $parameter_type{$which});
+ &remember_parms($idx,$which,'set',$value);
+ } else {
+ &LONCAPA::map::delparameter($idx,'parameter_'.$which);
+
+ &remember_parms($idx,$which,'del');
+ }
+ return 1;
}
- return 1;
}
@@ -2167,7 +2237,7 @@
$r->print('</div>');
}
- my ($to_show,$output);
+ my ($to_show,$output, at allidx, at allmapidx);
&Apache::loncommon::start_data_table_count(); #setup a row counter
foreach my $res (@LONCAPA::map::order) {
@@ -2176,6 +2246,10 @@
$url=&LONCAPA::map::qtescape($url);
unless ($name) { $name=(split(/\//,$url))[-1]; }
unless ($name) { $idx++; next; }
+ push(@allidx,$res);
+ if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
+ push(@allmapidx,$res);
+ }
$output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
$coursenum,$coursedom,$crstype,
$pathitem,$supplementalflag,$container);
@@ -2206,8 +2280,48 @@
if ($folder !~ /^supplemental/) {
$to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
}
- $to_show .= &Apache::loncommon::end_data_table_header_row()
- .$output.' '
+ $to_show .= &Apache::loncommon::end_data_table_header_row();
+ if ($folder !~ /^supplemental/) {
+ my $idxlist = join(',', at allidx);
+ my $mapidxlist = join(',', at allmapidx);
+ if (@allidx > 0) {
+ my $path;
+ if ($env{'form.folderpath'}) {
+ $path =
+ &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+ }
+ $to_show .=
+ &Apache::loncommon::continue_data_table_row().
+ '<td colspan="5"> </td>'.
+ '<td colspan="4">'.
+ '<form action="/adm/coursedocs" method="post" name="togglemultchecks">'.
+ '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.&mt('Select:').' '.
+ '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick();" checked="checked" />'.&mt('single').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick();" />'.&mt('multiple').'</label></span></form>'.
+ '<div id="multiclick" style="display: none">'.
+ '<form action="/adm/coursedocs" method="post" name="cumulativechecks" onsubmit="return submitSettings(this);">'."\n".
+ '<fieldset><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n".
+ '<table><tr><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').'</span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');" />'.&mt('Randomly Pick').'<span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" /></span></td>'.
+ '</tr>'."\n".
+ '<tr><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')" />'.&mt('URL hidden').'</span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')" />'.&mt('Random Order').'</span></td></tr></table>'."\n".
+ '</fieldset>'.
+ '<input type="hidden" name="folderpath" value="'.$path.'" />'.
+ '<input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />'.
+ '<input type="hidden" name="allhiddenresource" value="" />'.
+ '<input type="hidden" name="allencrypturl" value="" />'.
+ '<input type="hidden" name="allrandompick" value="" />'.
+ '<input type="hidden" name="allrandomorder" value="" />'.
+ '<input type="hidden" name="allidx" value="'.$idxlist.'" />'.
+ '<input type="hidden" name="allmapidx" value="'.$mapidxlist.'" />'.
+ '<input type="hidden" name="changeparms" value="all" />'.
+ '<input type="submit" name="multiplesettings" value="'.&mt('Save settings below').'" />'.
+ '</form>'.
+ '</div>'.
+
+ '</td>'.
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ $to_show .= $output.' '
.&Apache::loncommon::end_data_table()
.'<br style="line-height:2px;" />'
.&Apache::loncommon::end_scrollbox();
@@ -2718,21 +2832,24 @@
if ($rpicknum) {
$rpckchk = ' checked="checked"';
}
- my $formname = 'edit_rpick_'.$orderidx;
+ my $formname = 'edit_randompick_'.$orderidx;
$rand_pick_text =
'<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
$form_common."\n".
-'<span class="LC_nobreak"><label><input type="checkbox" name="randpickon_'.$orderidx.'" id="rpick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="randompick_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" />';
+'<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
if ($rpicknum ne '') {
$rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
}
- $rand_pick_text .= '</span></form>';
+ $rand_pick_text .= '</span></span>'.
+ $form_end;
my $ro_set=
((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
+ my $formname = 'edit_rorder_'.$orderidx;
$rand_order_text =
-$form_start.
-$form_common.'
-<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="'."this.form.changeparms.value='randomorder';this.form.submit()".'" '.$ro_set.' /> '.&mt('Random Order').' </label></span></form>';
+'<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
+$form_common."\n".
+'<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder'".')"; '.$ro_set.' /> '.&mt('Random Order').' </label></span>'.
+$form_end;
}
} elsif ($supplementalflag && !$allowed) {
$url .= ($url =~ /\?/) ? '&':'?';
@@ -2806,16 +2923,18 @@
((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
my $hidtext=
((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
+ my $formhidden = 'edit_hiddenresource_'.$orderidx;
+ my $formurlhidden = 'edit_encrypturl_'.$orderidx;
$line.=(<<ENDPARMS);
<td class="LC_docs_entry_parameter">
- $form_start
+ <form action="/adm/coursedocs" method="post" name="$formhidden">
$form_common
- <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
+ <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'."'hiddenresource'".');" $hidtext /> $lt{'hd'}</label>
$form_end
<br />
- $form_start
+ <form action="/adm/coursedocs" method="post" name="$formurlhidden">
$form_common
- <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
+ <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'."'encrypturl'".');" $enctext /> $lt{'ec'}</label>
$form_end
</td>
<td class="LC_docs_entry_parameter">$rand_pick_text<br />
@@ -4921,34 +5040,154 @@
}
function updatePick(targetform,index,caller) {
- var pickitem = document.getElementById('rpick_'+index);
- var picknumitem = document.getElementById('rpicknum_'+index);
+ var pickitem;
+ var picknumitem;
+ var picknumtext;
+ if (index == 'all') {
+ pickitem = document.getElementById('randompickall');
+ picknumitem = document.getElementById('rpicknumall');
+ picknumtext = document.getElementById('rpicktextall');
+ } else {
+ pickitem = document.getElementById('randompick_'+index);
+ picknumitem = document.getElementById('rpicknum_'+index);
+ picknumtext = document.getElementById('randompicknum_'+index);
+ }
if (pickitem.checked) {
var picknum=prompt('$lt{"rpck"}',picknumitem.value);
if (picknum == '' || picknum == null) {
if (caller == 'check') {
pickitem.checked=false;
- return;
+ if (index == 'all') {
+ picknumtext.innerHTML = '';
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ checkForSubmit(targetform,'randompick');
+ }
}
} else {
picknum.toString();
var regexdigit=/^\\d+\$/;
if (regexdigit.test(picknum)) {
picknumitem.value = picknum;
- targetform.changeparms.value='randompick';
- targetform.submit();
+ if (index == 'all') {
+ picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativechecks,\\'all\\',\\'link\\');">'+picknum+'</a>';
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
+ checkForSubmit(targetform,'randompick');
+ }
} else {
if (caller == 'check') {
- pickitem.checked=false;
+ if (index == 'all') {
+ picknumtext.innerHTML = '';
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ pickitem.checked=false;
+ checkForSubmit(targetform,'randompick');
+ }
}
return;
}
}
} else {
- picknumitem.value = 0;
- targetform.changeparms.value='randompick';
- targetform.submit();
+ picknumitem.value = '';
+ picknumtext.innerHTML = '';
+ if (index == 'all') {
+ if (caller == 'link') {
+ propagateState(targetform,'rpicknum');
+ }
+ } else {
+ checkForSubmit(targetform,'randompick');
+ }
+ }
+}
+
+function propagateState(form,param) {
+ if (document.getElementById(param+'all')) {
+ var setcheck = 0;
+ var rpick = 0;
+ if (param == 'rpicknum') {
+ if (document.getElementById('randompickall')) {
+ if (document.getElementById('randompickall').checked) {
+ if (document.getElementById('rpicknumall')) {
+ rpick = document.getElementById('rpicknumall').value;
+ }
+ }
+ }
+ } else {
+ if (document.getElementById(param+'all').checked) {
+ setcheck = 1;
+ }
+ }
+ if ((param == 'encrypturl') || (param == 'hiddenresource')) {
+ var allidxlist = form.allidx.value;
+ if (allidxlist != '') {
+ var allidxs = allidxlist.split(',');
+ if (allidxs.length > 1) {
+ for (var i=0; i<allidxs.length; i++) {
+ if (document.getElementById(param+'_'+allidxs[i])) {
+ if (setcheck == 1) {
+ document.getElementById(param+'_'+allidxs[i]).checked = true;
+ } else {
+ document.getElementById(param+'_'+allidxs[i]).checked = false;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ var allmapidxlist = form.allmapidx.value;
+ if (allmapidxlist != '') {
+ var allmapidxs = allmapidxlist.split(',');
+ if (allmapidxs.length > 1) {
+ for (var i=0; i<allmapidxs.length; i++) {
+ var item = param+'_'+allmapidxs[i];
+ if (document.getElementById(item)) {
+ if (param == 'rpicknum') {
+ if (document.getElementById('randompick_'+allmapidxs[i])) {
+ if (document.getElementById('randompick_'+allmapidxs[i]).checked) {
+ document.getElementById(param+'_'+allmapidxs[i]).value = rpick;
+ if (rpick > 0) {
+ document.getElementById('randompicknum_'+allmapidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allmapidxs[i]+',\\''+allmapidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
+ } else {
+ document.getElementById('randompicknum_'+allmapidxs[i]).innerHTML = '';
+ }
+ }
+ }
+ } else {
+ if (setcheck == 1) {
+ document.getElementById(param+'_'+allmapidxs[i]).checked = true;
+ } else {
+ document.getElementById(param+'_'+allmapidxs[i]).checked = false;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
+ return;
+}
+
+function checkForSubmit(targetform,param) {
+ if (document.togglemultchecks.showmultpick.length) {
+ for (var i=0; i<document.togglemultchecks.showmultpick.length; i++) {
+ if (document.togglemultchecks.showmultpick[i].checked) {
+ if (document.togglemultchecks.showmultpick[i].value == 0) {
+ targetform.changeparms.value=param;
+ targetform.submit();
+ }
+ }
+ }
+ }
+ return;
}
function unselectInactive(nav) {
@@ -5055,6 +5294,68 @@
location.href=newurl;
}
+function submitSettings(form) {
+ var allidxlist = form.allidx.value;
+ form.allencrypturl.value = '';
+ form.allhiddenresource.value = '';
+ if (allidxlist != '') {
+ var allidxs = allidxlist.split(',');
+ if (allidxs.length > 1) {
+ for (var i=0; i<allidxs.length; i++) {
+ if (document.getElementById('hiddenresource_'+allidxs[i])) {
+ if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
+ form.allhiddenresource.value += allidxs[i]+',';
+ }
+ }
+ if (document.getElementById('encrypturl_'+allidxs[i])) {
+ if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
+ form.allencrypturl.value += allidxs[i]+',';
+ }
+ }
+ }
+ }
+ }
+ var allmapidxlist = form.allmapidx.value;
+ form.allrandompick.value = '';
+ form.allrandomorder.value = '';
+ if (allmapidxlist != '') {
+ var allmapidxs = allmapidxlist.split(',');
+ for (var i=0; i<allmapidxs.length; i++) {
+ var randompick = document.getElementById('randompick_'+allmapidxs[i]);
+ var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
+ var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
+ if ((randompick.checked) && (rpicknum.value != '')) {
+ form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
+ }
+ if (randorder.checked) {
+ form.allrandomorder.value += allmapidxs[i]+',';
+ }
+ }
+ }
+ form.submit();
+ return true;
+}
+
+function togglePick() {
+ var disp = 'none';
+ if (document.getElementById('multiclick')) {
+ var curr = document.getElementById('multiclick').style.display;
+ if (curr == 'none') {
+ disp='block';
+ }
+ document.getElementById('multiclick').style.display=disp;
+ }
+ if (document.getElementById('savemulti')) {
+ var curr = document.getElementById('save.multi').style.display;
+ if (curr == 'none') {
+ disp='inline';
+ }
+ document.getElementById('savemulti').style.display=disp;
+ }
+ resize_scrollbox('contentscroll','1','1');
+ return;
+}
+
ENDNEWSCRIPT
}
More information about the LON-CAPA-cvs
mailing list