[LON-CAPA-cvs] cvs: rat /client parameter.html

raeburn raeburn at source.lon-capa.org
Wed Jul 2 12:08:37 EDT 2025


raeburn		Wed Jul  2 16:08:37 2025 EDT

  Modified files:              
    /rat/client	parameter.html 
  Log:
  - Client side validation of grace parameter settings in table mode.
  
  
Index: rat/client/parameter.html
diff -u rat/client/parameter.html:1.97 rat/client/parameter.html:1.98
--- rat/client/parameter.html:1.97	Mon Jun 30 20:29:06 2025
+++ rat/client/parameter.html	Wed Jul  2 16:08:37 2025
@@ -5,7 +5,7 @@
 The LearningOnline Network with CAPA
 Parameter Input Window
 //
-// $Id: parameter.html,v 1.97 2025/06/30 20:29:06 raeburn Exp $
+// $Id: parameter.html,v 1.98 2025/07/02 16:08:37 raeburn Exp $
 //
 // Copyright Michigan State University Board of Trustees
 //
@@ -485,6 +485,76 @@
     assemble();
 }
 
+function validateGrace() {
+    var items = choices.document.getElementsByName('setgrace');
+    var needpcr = 0;
+    var neednum = 0;
+    if (items) {
+        if (items.length) {
+            if (items.length > 0) {
+                for (var i=0; i<items.length; i++) {
+                    var numnotnull = 0;
+                    var fracnotnull = 0;
+                    var graceDiv = items[i].closest('div');
+                    var timeSels = graceDiv.getElementsByTagName("select");
+                    if (timeSels.length) {
+                        for (var j=0; j<timeSels.length; j++) {
+                            var selidx = timeSels[j].selectedIndex;
+                            if (selidx >= 0) {
+                                var val = timeSels[j].options[selidx].value;
+                                if ((val !== null) && (val !== '') && (val !== 'undefined')) {
+                                    numnotnull = 1;
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                    var inputElems = graceDiv.getElementsByTagName("input");
+                    if (inputElems.length) {
+                        for (var j=0; j<inputElems.length; j++) {
+                            var iname = inputElems[j].getAttribute('name');
+                            if (iname == 'frac') {
+                                var ival = inputElems[j].value;
+                                ival.trim();
+                                var poss = parseFloat(ival);
+                                if ((typeof poss === 'number') && (!isNaN(poss))) {
+                                    if ((poss => 0) && (poss <= 1)) {
+                                        fracnotnull = 1; 
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                    }
+                    if (numnotnull && !fracnotnull) {   
+                        needpcr ++;
+                    }
+                    if (fracnotnull && !numnotnull) {
+                        neednum ++;
+                    }
+                }
+                if (needpcr) {
+                    if (needpcr == 1) {
+                        alert("Grace period setting is incomplete: enter a number between 0 and 1.0 for 'Partial Credit', or use 'Remove'.");
+                    } else {
+                        alert(needpcr+" Grace period settings are incomplete: for each enter a number between 0 and 1.0 for 'Partial Credit', or use 'Remove'.");
+                    }
+                    return;
+                }
+                if (neednum) {
+                    if (neednum == 1) {
+                        alert("Grace period setting is incomplete: select a number in at least one of the 'Time past due' select boxes, or use 'Remove'."); 
+                    } else {
+                        alert(neednum +" Grace period settings are incomplete: for each select a number in at least one of the 'Time past due' select boxes, or use 'Remove'."); 
+                    }
+                    return;
+                }
+            }
+        }
+    }
+    assemble();
+}
+
 function validateDeepLink() {
     var sform=choices.document.forms.sch;
     svalue = sform.deeplinkstate.options[sform.deeplinkstate.selectedIndex].value+',';
@@ -2112,6 +2182,8 @@
       selwrite('<a href="javascript:parent.validateInterval();');
   } else if ((ptype=='string') && (pscat=='deeplink')) {
       selwrite('<a href="javascript:parent.validateDeepLink();');
+  } else if ((ptype=='string') && (pscat=='grace')) {
+      selwrite('<a href="javascript:parent.validateGrace();');
   } else {
       selwrite('<a href="javascript:parent.assemble();');
   }




More information about the LON-CAPA-cvs mailing list