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

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 04 Jul 2006 20:50:52 -0000


This is a MIME encoded message

--raeburn1152046252
Content-Type: text/plain

raeburn		Tue Jul  4 16:50:52 2006 EDT

  Modified files:              
    /loncom/interface	loncoursegroups.pm 
  Log:
  Client side javascript and server side perl to enforce group portfolio quota constraints dictated by course quota limit.  Updates to messages displayed when creation of folder hierarchy or setting of hide parameter(s) is unsuccessful.
  
  
--raeburn1152046252
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060704165052.txt"

Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.36 loncom/interface/loncoursegroups.pm:1.37
--- loncom/interface/loncoursegroups.pm:1.36	Sun Jul  2 13:08:42 2006
+++ loncom/interface/loncoursegroups.pm	Tue Jul  4 16:50:52 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.36 2006/07/02 17:08:42 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.37 2006/07/04 20:50:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -368,7 +368,7 @@
     my @member_changes = ('deletion','expire','activate','reenable',
                           'changefunc','changepriv');
     my ($groupname,$description,$startdate,$enddate,$granularity,$specificity,
-        $quota);
+        $quota,$validate_script);
 
     if (defined($env{'form.groupname'})) {
         $groupname = $env{'form.groupname'};
@@ -727,11 +727,51 @@
             }
         }
     }
- 
+
+    if (($action eq 'create' && $state eq 'pick_name') || 
+        ($action eq 'modify' && $state eq 'change_settings')) {
+        my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,\%stored);
+        my $space_trim = '/^\s*|\s*\$/g,""';
+        my $float_check = '/^([0-9]*\.?[0-9]*)$/';
+        $validate_script = '
+    var newquota = document.'.$state.'.quota.value;
+    newquota.replace('.$space_trim.');
+    if (newquota == "" ) {
+        document.'.$state.'.quota.value = 0;
+        newquota = 0;       
+    }
+    var maxposs = '.$maxposs.';
+    if (newquota > maxposs) {
+        alert("The file repository quota you entered for this group ("+newquota+" Mb) exceeds the maximum possible ("+maxposs+" Mb). Please enter a smaller number.");
+        return;
+    }
+    var re_quota = '.$float_check.';
+    var check_quota = newquota.match(re_quota);
+    if (check_quota == null) {
+        alert("The quota you entered contains invalid characters, the quota should only include numbers, with or without a decimal point.");
+        return;
+    }
+    if (newquota == 0) {
+        var warn_zero = 0;
+        for (var i=0; i<document.'.$state.'.tool.length; i++) {
+            if (document.'.$state.'.tool[i].value == "files") {
+                if (document.'.$state.'.tool[i].checked) {
+                    warn_zero = 1;
+                }
+            }
+        }
+        if (warn_zero == 1) {
+            alert("You have indicated that the file repository should be enabled, but you have set the respository quota to 0 Mb.\nThis will prevent any upload of files.\nPlease set a value or disable the repository feature.");
+            return;
+        }
+    } 
+';
+    }
     my $jscript = &Apache::loncommon::check_uncheck_jscript();
     $jscript .= qq|
 function nextPage(formname,nextstate) {
     formname.state.value= nextstate;
+    $validate_script
     formname.submit();
 }
 function backPage(formname,prevstate) {
@@ -1204,12 +1244,7 @@
         'doyo' => "Do you want to assign different functionality ".
                   "to different $gpterm members?",
     );
-    my $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
-    if ($crsquota eq '') {
-        $crsquota = 20;
-    }
-    my $freespace = $crsquota - &Apache::longroup::sum_quotas();
-    my $maxposs = $$stored{'quota'} + $freespace;
+    my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
     &topic_bar($r,$tabcol,$image,$lt{'gnde'});
     $r->print('
    <tr>
@@ -1310,6 +1345,22 @@
     return;
 }
 
+sub get_quota_constraints {
+    my ($action,$stored) = @_;
+    my ($crsquota,$freespace,$maxposs); 
+    $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
+    if ($crsquota eq '') {
+        $crsquota = 20;
+    }
+    $freespace = $crsquota - &Apache::longroup::sum_quotas();
+    if ($action eq 'create') {
+        $maxposs = $freespace;
+    } else {
+        $maxposs = $$stored{'quota'} + $freespace;
+    }
+    return ($crsquota,$freespace,$maxposs);
+}
+
 sub membership_options {
     my ($r,$action,$state,$tabcol,$sectioncount,$image,$gpterm,$ucgpterm) = @_;
     my $crstype = &Apache::loncommon::course_type();
@@ -2875,6 +2926,22 @@
                              'specificity','autoadd','autodrop','quota');
     my @mult_attributes = ('roles','types','sectionpick','defpriv');
 
+    my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
+                                                                $stored);
+    my $quota = $env{'form.quota'};
+    
+    $quota =~ s/^\s*([^\s]*)\s*$/$1/;
+    if ($quota eq '') {
+        $quota = 0;
+    }
+    if ($quota !~ /^\d*\.?\d*$/) {
+        $quota = 0;
+        $r->print(&mt('The value you entered for the quota for the file repository in this [_1] contained invalid characters, so it has been set to 0 Mb. You can change this by modifying the [_1] settings.<br />',$gpterm));
+    }
+    if ($quota > $maxposs) {
+        $quota = $maxposs;
+        $r->print(&mt('The value you entered for the quota for the file repository in this [_1] exceeded the maximum possible value, so it has been set to [_2] Mb (the maximum possible value).<br />',$gpterm,$maxposs));
+    }
     my %groupinfo = (
                      description => $esc_description,
                      startdate => $startdate,
@@ -2886,8 +2953,9 @@
                      specificity => $specificity,
                      autoadd => $env{'form.autoadd'},
                      autodrop => $env{'form.autodrop'},
-                     quota => $env{'form.quota'},                
+                     quota => $quota,
                    );
+
     foreach my $func (keys(%{$functions})) {
         my $status;
         if (grep(/^$func$/,@{$tools})) {
@@ -2938,7 +3006,7 @@
                                            $description,$tools,\%groupinfo,
                                            $gpterm,$ucgpterm,$crstype);
             if ($result ne 'ok') {
-                $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].',$gpterm,$result));    
+                $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].<br />',$gpterm,$result));
             }
             $r->print(&mt('[_1] [_2] was created.<br />',$ucgpterm,$groupname));
         } else {
@@ -2952,7 +3020,7 @@
         &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
                                  'in '.lc($crstype).': '.$cnum.
                                  ' in domain: '.$cdom);
-        $r->print(&mt('An error occurred when [_1] the new [_2]. '.
+        $r->print(&mt('An error occurred when [_1] the [_2]. '.
                       'Please try again.',$actiontype{$action},$gpterm));
     }
     return $result;
@@ -3555,12 +3623,12 @@
     my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
                                                         $newfile);
     if ($newmapurl !~ m|^/uploaded|) {
-        $outcome = "Error uploading new folder ($newfile): $newmapurl";
+        $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'<br />';
         return $outcome;
     } 
     my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap);
     if ($fatal) {
-        $outcome = "Error reading contents of parent folder ($parentmap): $errtext\n";
+        $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'<br />';
         return $outcome;
     } else {
         my $newidx=&Apache::lonratedt::getresidx($newmapurl);
@@ -3569,7 +3637,7 @@
         $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
         my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1);
         if ($errtext) {
-           $outcome = "Error storing updated parent folder ($parentmap):  $errtext\n";
+            $outcome = &mt('Error storing updated parent folder')." ($parentmap):  $errtext".'<br />';
             return $outcome;
         }
     }
@@ -3590,7 +3658,7 @@
 
 sub parm_setter {
     my ($navmap,$cdom,$url,$groupname) = @_;
-    my %parmresult;
+    my $allresults;
     my %hide_settings = (
                            'course' =>  {
                                           'num' => 13,
@@ -3605,15 +3673,18 @@
     my $res = $navmap->getResourceByUrl($url);
     my $symb = $res->symb();
     foreach my $level (keys(%hide_settings)) {
-        $parmresult{$level} =  &Apache::lonparmset::storeparm_by_symb($symb,
+        my $parmresult =  &Apache::lonparmset::storeparm_by_symb($symb,
                                                  '0_hiddenresource',
                                                  $hide_settings{$level}{'num'},
                                                  $hide_settings{$level}{'set'},
                                                  'string_yesno',undef,$cdom,
                                                  undef,undef,
                                                  $hide_settings{$level}{'extra'});
+        if ($parmresult) {
+            $allresults .= $level.': '.$parmresult;
+        }
     }
-    return %parmresult;
+    return $allresults;
 }
 
 sub create_homepage {

--raeburn1152046252--