File:  [LON-CAPA] / rat / client / parameter.html
Revision 1.11: download - view: text, annotated - select for diffs
Wed Aug 8 13:31:43 2001 UTC (22 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Merging Scott's changes and range

    1: <html>
    2: <!--
    3: The LearningOnline Network with CAPA
    4: Parameter Input Window
    5: 06/16/00,06/17,11/17,11/18,11/23,11/27,11/28,12/15,12/16,
    6: 03/21/01,03/24,06/26 Gerd Kortemeyer
    7: 07/24/01 Scott Harrison
    8: -->
    9: <head>
   10: <title>LON-CAPA</title>
   11: </head>
   12: 
   13: <script>
   14: 
   15: var ptype='';
   16: var pvalue='';
   17: var preturn='';
   18: var pcode='';
   19: var pscat='';
   20: var pmarker='';
   21: var pname='';
   22: 
   23: var svalue;
   24: var stype;
   25: var smarker;
   26: 
   27: var vars=new Array();
   28: 
   29: var cdate=new Date();
   30: 
   31: var csec;
   32: var cmin;
   33: var chour;
   34: var cday;
   35: 
   36: var months=new Array();
   37: 
   38: 
   39: function selwrite(text) {
   40:   this.window.selector.document.write(text);
   41: }
   42: 
   43: function choicestart() {
   44:   this.window.choices.document.clear();
   45:   choicewrite('<html><body bgcolor="#FFFFFF">');
   46: }
   47: 
   48: function choiceend() {
   49:   choicewrite('</body></html>');
   50:   this.window.choices.document.close();
   51: }
   52: 
   53: function choicewrite(text) {
   54:   this.window.choices.document.write(text);
   55: }
   56: 
   57: function tablestart(headtext) {
   58:   choicewrite('<table><tr bgcolor="#AAFFAA"><th colspan=3>'+
   59:               headtext+'</th></tr>');
   60: }
   61: 
   62: function valline(text,id1,id2) {
   63:   choicewrite('<tr bgcolor="#AAFFAA"><td>'+text+
   64:               '</td><td><input type=text size=4 name=val'+
   65:               id1+'></td><td>incl:<input type=checkbox name=val'+
   66:               id2+'></td></tr>');
   67: }
   68: 
   69: function datecalc() {
   70:     var sform=choices.document.forms.sch;
   71: 
   72:     cdate.setHours(sform.hours.options[sform.hours.selectedIndex].value);
   73:     cdate.setMinutes(sform.minutes.options[sform.minutes.selectedIndex].value);
   74:     cdate.setSeconds(sform.minutes.options[sform.seconds.selectedIndex].value);
   75:     cdate.setDate(sform.date.options[sform.date.selectedIndex].value);
   76:     cdate.setMonth(sform.month.options[sform.month.selectedIndex].value);
   77:     cdate.setFullYear(sform.year.options[sform.year.selectedIndex].value);
   78: 
   79:     draw();
   80: }
   81: 
   82: function hour() {
   83:    var thishour=cdate.getHours();
   84:     var i; var j;
   85:     choicewrite('<select name=hours onChange="parent.datecalc();">');
   86:     for (i=0;i<=23;i++) {
   87:         choicewrite('<option value='+i);
   88:         if (i==thishour) {
   89:             choicewrite(' selected');
   90:         }
   91:         choicewrite('>');
   92:         if (i==12) { choicewrite('noon'); } else {
   93:            if (i==0) { choicewrite('midnight') } else {
   94:               
   95:                  if (i<12) { choicewrite(i+' am'); } else {
   96:                     j=i-12; choicewrite(j+' pm');
   97:                  }
   98:               
   99:            }
  100:         }
  101:         choicewrite('</option>');
  102:     }
  103:     choicewrite('</select>');
  104: }
  105: 
  106: function minute() {
  107:    var thisminutes=cdate.getMinutes();
  108:     var i;
  109:     choicewrite('<select name=minutes onChange="parent.datecalc();">');
  110:     for (i=0;i<=59;i++) {
  111:         choicewrite('<option value='+i);
  112:         if (i==thisminutes) {
  113:             choicewrite(' selected');
  114:         }
  115:         choicewrite('>'+i+'</option>');
  116:     }
  117:     choicewrite('</select>');
  118: } 
  119: 
  120: function second() {
  121:    var thisseconds=cdate.getSeconds();
  122:     var i;
  123:     choicewrite('<select name=seconds onChange="parent.datecalc();">');
  124:     for (i=0;i<=59;i++) {
  125:         choicewrite('<option value='+i);
  126:         if (i==thisseconds) {
  127:             choicewrite(' selected');
  128:         }
  129:         choicewrite('>'+i+'</option>');
  130:     }
  131:     choicewrite('</select>');
  132: } 
  133: 
  134: 
  135: function date() {
  136:    var thisdate=cdate.getDate();
  137:     var i;
  138:     choicewrite('<select name=date onChange="parent.datecalc();">');
  139:     for (i=1;i<=31;i++) {
  140:         choicewrite('<option value='+i);
  141:         if (i==thisdate) {
  142:             choicewrite(' selected');
  143:         }
  144:         choicewrite('>'+i+'</option>');
  145:     }
  146:     choicewrite('</select>');
  147: }
  148: 
  149: function year() {
  150:    var thisyear=cdate.getFullYear();
  151:     var i;
  152:     choicewrite('<select name=year onChange="parent.datecalc();">');
  153:     for (i=thisyear-25;i<=thisyear+50;i++) {
  154:         choicewrite('<option value='+i);
  155:         if (i==thisyear) {
  156:             choicewrite(' selected');
  157:         }
  158:         choicewrite('>'+i+'</option>');
  159:     }
  160:     choicewrite('</select>');
  161: }
  162: 
  163: function month() {
  164:     var thismonth=cdate.getMonth();
  165:     var i;
  166:     choicewrite('<select name=month onChange="parent.datecalc();">');
  167:     for (i=0;i<=11;i++) {
  168:         choicewrite('<option value='+i);
  169:         if (i==thismonth) {
  170:             choicewrite(' selected');
  171:         }
  172:         choicewrite('>'+months[i]+'</option>');
  173:     }
  174:     choicewrite('</select>');
  175: }
  176:     
  177:     
  178: function intminute() {
  179:    var thisminutes=cmins;
  180:     var i;
  181:     choicewrite('<select name=minutes onChange="parent.intcalc();">');
  182:     for (i=0;i<=59;i++) {
  183:         choicewrite('<option value='+i);
  184:         if (i==thisminutes) {
  185:             choicewrite(' selected');
  186:         }
  187:         choicewrite('>'+i+'</option>');
  188:     }
  189:     choicewrite('</select>');
  190: } 
  191: 
  192: function inthour() {
  193:    var thishours=chours;
  194:     var i;
  195:     choicewrite('<select name=hours onChange="parent.intcalc();">');
  196:     for (i=0;i<=23;i++) {
  197:         choicewrite('<option value='+i);
  198:         if (i==thishours) {
  199:             choicewrite(' selected');
  200:         }
  201:         choicewrite('>'+i+'</option>');
  202:     }
  203:     choicewrite('</select>');
  204: } 
  205: 
  206: function intsecond() {
  207:    var thisseconds=csecs;
  208:     var i;
  209:     choicewrite('<select name=seconds onChange="parent.intcalc();">');
  210:     for (i=0;i<=59;i++) {
  211:         choicewrite('<option value='+i);
  212:         if (i==thisseconds) {
  213:             choicewrite(' selected');
  214:         }
  215:         choicewrite('>'+i+'</option>');
  216:     }
  217:     choicewrite('</select>');
  218: } 
  219: 
  220: 
  221: function intday() {
  222:    var thisdate=cdays;
  223:     var i;
  224:     choicewrite('<select name=date onChange="parent.intcalc();">');
  225:     for (i=0;i<=31;i++) {
  226:         choicewrite('<option value='+i);
  227:         if (i==thisdate) {
  228:             choicewrite(' selected');
  229:         }
  230:         choicewrite('>'+i+'</option>');
  231:     }
  232:     choicewrite('</select>');
  233: }
  234: 
  235: function intcalc() {
  236:     var sform=choices.document.forms.sch;
  237:     svalue=((sform.date.options[sform.date.selectedIndex].value*24+
  238:              sform.hours.options[sform.hours.selectedIndex].value*1)*60+
  239:              sform.minutes.options[sform.minutes.selectedIndex].value*1)*60+
  240:              sform.seconds.options[sform.seconds.selectedIndex].value*1;
  241:     draw();
  242: }
  243: 
  244: function integereval() {
  245:    svalue=choices.document.forms.sch.intval.value;
  246:    svalue=Math.round(svalue);
  247:    if (pscat=='zeropos') { svalue=Math.abs(svalue); }
  248:    if ((pscat=='pos') && (svalue==0)) {
  249:       svalue='';
  250:    }
  251:    if (pscat.indexOf('range')!=-1) {
  252:       var rangeparts=new Array;
  253:       rangeparts=split('_',pscat);
  254:       rangeparts=split('...',rangeparts[1]);
  255:       if (svalue<rangeparts[0]) { svalue=rangeparts[0]; }
  256:       if (svalue>rangeparts[1]) { svalue=rangeparts[1]; }
  257:    }
  258:    draw();
  259: }
  260: 
  261: function floateval() {
  262:    svalue=choices.document.forms.sch.floatval.value;
  263:    svalue=1.0*svalue;
  264:    if (pscat=='pos') { svalue=Math.abs(svalue); }
  265:    if ((pscat=='zeroone') && ((svalue<0) || (svalue>1))) {
  266:       svalue='';
  267:    }
  268:    draw();
  269: }
  270: 
  271: function stringeval() {
  272:    svalue=choices.document.forms.sch.stringval.value;
  273:    draw();
  274: }
  275: 
  276: function intervaldis() {
  277:     csecs=svalue;
  278:     cdays=Math.floor(csecs/86400);
  279:     csecs-=cdays*86400;
  280:     chours=Math.floor(csecs/3600);
  281:     csecs-=chours*3600;
  282:     cmins=Math.floor(csecs/60);
  283:     csecs-=cmins*60;
  284:     choicewrite(cdays+' days '+chours+' hours '
  285:                +cmins+' mins '+csecs+' secs');
  286: }
  287:     
  288:     
  289:     
  290: function afterproc() {
  291:   choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>Error after rounding: '
  292:              +'<input type=checkbox name=val1></td></tr>');
  293: }
  294: 
  295: function draw() {
  296:    choicestart();
  297:    choicewrite('<form name=sch');
  298:    if (ptype=='int') {
  299:       choicewrite(' action="javascript:integereval();"');
  300:    }
  301:    if (ptype=='float') {
  302:       choicewrite(' action="javascript:floateval();"');
  303:    }
  304:    if (ptype=='string') {
  305:       choicewrite(' action="javascript:stringeval();"');
  306:    }
  307:    choicewrite('>');
  308:    if (ptype=='tolerance') {
  309: // 0: pscat
  310: // 1: after processing
  311:       if (pscat=='default') {
  312:          tablestart('Use default value or algorithm of resource');
  313:       }
  314:       if (pscat=='exact') {
  315:          tablestart('Accept only exact value, zero tolerance');
  316:          afterproc();
  317:       }
  318:       if (pscat=='relative_sym') {
  319: // 2: percentage
  320: // 3: open
  321:          tablestart('Percentage error, symmetric around value');
  322:          valline('Percentage',2,3);
  323:          afterproc();
  324:       }
  325:       if (pscat=='relative') {
  326: // 2: left
  327: // 3: open
  328: // 4: right
  329: // 5: open
  330:          tablestart('Percentage error, asymmetric around value');
  331:          valline('Upper percentage',2,3);
  332:          valline('Lower percentage',4,5);
  333:          afterproc();
  334:       }
  335:       if (pscat=='absolute_sym') {
  336:          tablestart('Absolute error, symmetric around value');
  337:          valline('Value',2,3);
  338:          afterproc();
  339:       }
  340:       if (pscat=='absolute') {
  341:          tablestart('Absolute error, asymmetric around value');
  342:          valline('Upper value',2,3);
  343:          valline('Lower value',4,5);
  344:          afterproc();
  345:       }
  346:       if (pscat=='sigdigits') {
  347:          tablestart('Agreement on significant digits');
  348:   choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>Number of digits: '
  349:              +'<input type=text size=4 name=val2></td></tr>');
  350: 
  351: choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>Accept if more digits given: '
  352:              +'<input type=checkbox name=val3></td></tr>');
  353:          
  354:       }
  355:    }
  356: 
  357:    if (ptype=='date') {
  358:      if (pscat=='default') {
  359:          tablestart('Default value or none');
  360:          choicewrite('</table>');
  361:      } else {
  362:       if (pscat=='start') {
  363:          tablestart('Starting or opening date and time');
  364:       }
  365:       if (pscat=='end') {
  366:          tablestart('Ending or closing date and time');
  367:       }
  368:       if (pscat=='interval') {
  369:          tablestart('Time interval');
  370:          choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>');
  371:          intervaldis();
  372:          choicewrite('</td></tr><tr bgcolor="#AAFFAA"><td>Time:'
  373:          +'</td><td colspan=2>');
  374:          intday();choicewrite('days ');
  375:          inthour();choicewrite('hours ');
  376:          intminute(); choicewrite('mins '); intsecond();
  377:          choicewrite('secs</td></tr></table>');         
  378:       } else { 
  379:          choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>'
  380:          +cdate.toString()+
  381:          '</td></tr><tr bgcolor="#AAFFAA"><td>Date:</td><td colspan=2>');
  382:          month();date();year();
  383:          choicewrite('</td></tr><tr bgcolor="#AAFFAA"><td>Time:'
  384:          +'</td><td colspan=2>');hour();choicewrite('h ');minute();
  385:          choicewrite('m ');second();
  386:          choicewrite('s</td></tr></table>');
  387:       }
  388:      }
  389:    }
  390: 
  391:    if (ptype=='int') {
  392:       if (pscat=='default') {
  393:          tablestart('Default value or none');
  394:          choicewrite('</table>');         
  395:       } else {
  396:         if (pscat=='pos') {
  397:            tablestart('Positive (non-zero) integer');
  398:         }
  399:         if (pscat=='zeropos') {
  400:            tablestart('Positive integer or zero');
  401:         }
  402:         if (pscat.indexOf('range')!=-1) {
  403:            var rangeparts=new Array;
  404:            rangeparts=split('_',pscat);
  405:            tablestart('Integer in the range ['+rangeparts[1]+']');
  406:         }
  407:         if (pscat=='any') {
  408:            tablestart('Integer');
  409:         }
  410:         choicewrite('<tr bgcolor="#AAFFAA"><td>Value:</td><td colspan=2>');
  411:         choicewrite('<input name=intval size=10 value="'+svalue+
  412:                     '" name=intval onChange="parent.integereval()">');
  413:         choicewrite('</td></table>');
  414:       }
  415:    }
  416: 
  417:    if (ptype=='float') {
  418:       if (pscat=='default') {
  419:          tablestart('Default value or none');
  420:          choicewrite('</table>');         
  421:       } else {
  422:         if (pscat=='pos') {
  423:            tablestart('Positive floating point number or zero');
  424:         }
  425:         if (pscat=='zeroone') {
  426:            tablestart('Floating point number between zero and one');
  427:         }
  428:         if (pscat=='any') {
  429:            tablestart('Floating point number');
  430:         }
  431:         choicewrite('<tr bgcolor="#AAFFAA"><td>Value:</td><td colspan=2>');
  432:         choicewrite('<input name=floatval size=10 value="'+svalue+
  433:                     '" name=floatval onChange="parent.floateval()">');
  434:         choicewrite('</td></table>');
  435:       }
  436:    }
  437: 
  438:    if (ptype=='string') {
  439:       if (pscat=='default') {
  440:          tablestart('Default value or none');
  441:          choicewrite('</table>');         
  442:       } else {
  443:         if (pscat=='any') {
  444:            tablestart('Text');
  445:         }
  446:         choicewrite('<tr bgcolor="#AAFFAA"><td>Value:</td><td colspan=2>');
  447:         choicewrite('<input name=intval size=20 value="'+svalue+
  448:                     '" name=stringval onChange="parent.stringeval()">');
  449:         choicewrite('</td></table>');
  450:       }
  451:    }
  452: 
  453:    choicewrite('</table></form>');
  454:    choiceend();
  455: }
  456: 
  457: function sopt(va,text) {
  458:    selwrite('<option value="'+va+'"');
  459:    if (va==pscat) {
  460:      selwrite(' selected');
  461:    }
  462:    selwrite('>'+text+'</option>');
  463: }
  464: 
  465: function catchange() {
  466:    var sform=selector.document.forms.fsel.fcat;
  467:    pscat=sform.options[sform.selectedIndex].value;
  468:    draw();
  469: }
  470: 
  471: function assemble() {
  472:     if ((ptype=='date') && (pscat!='interval')) {
  473:         svalue=Math.round(cdate.getTime()/1000);
  474:     }
  475:     if (pscat=='default') { svalue=''; }
  476:     stype=ptype+'_'+pscat;
  477: }
  478: 
  479: 
  480: function init() {
  481:   var i;
  482:   var subs=new Array();
  483:   var namevalue=this.window.location.search.split('&');
  484:   namevalue[0]=namevalue[0].substr(1,namevalue[0].length-1);
  485: 
  486:   for (i=0;i<namevalue.length;i++) {
  487:      var pair=namevalue[i].split('=');
  488:      pair[1]=unescape(pair[1]);
  489:      if (pair[0]=='value') { pvalue=pair[1]; }
  490:      if (pair[0]=='type') { subs=pair[1].split('_');
  491:                             ptype=subs[0];
  492:                             pscat=subs[1];
  493:                             if (typeof(subs[2])!="undefined") { 
  494:                                pscat+='_'+subs[2]; 
  495:                             }
  496:                             if ((pscat=='') || (typeof(pscat)=="undefined")) { 
  497:                                pscat='default';
  498:                             }
  499:                            }
  500:      if (pair[0]=='return') { preturn=pair[1]; }
  501:      if (pair[0]=='call') { pcode=pair[1]; }
  502:      if (pair[0]=='marker') { pmarker=pair[1]; }
  503:      if (pair[0]=='name') { pname=pair[1]; }
  504:   }
  505: 
  506:   svalue=pvalue;
  507:   if (((ptype=='float') || (ptype=='string') || (ptype=='int')) &&
  508:       (pscat=='default') && 
  509:       (typeof(svalue)!="undefined") && 
  510:       (svalue!=0) && (svalue!='')) { pscat='any'; }
  511: 
  512:   this.window.selector.document.clear();
  513:   selwrite('<html><body bgcolor="#FFFFFF">');
  514: 
  515:   selwrite('<form name="fsel"><b>'+pname+'</b><br>');
  516:   selwrite('<select name="fcat" onChange="parent.catchange();">');
  517:   if (ptype=='tolerance') {
  518:      sopt('default','Default');
  519:      sopt('exact','Exact Value (no tolerance)');
  520:      sopt('relative_sym','Relative Tolerance, Symmetric (percent)');
  521:      sopt('relative','Relative Tolerance (percentages)');
  522:      sopt('absolute_sym','Absolute Tolerance, Symmetric (value)');
  523:      sopt('absolute','Absolute Tolerance (values)');
  524:      sopt('sigdigits','Significant Digits (number)');
  525:   }
  526: 
  527:   if (ptype=='date') {
  528:      sopt('default','Default');
  529:      sopt('start','Starting Date');
  530:      sopt('end','Ending Date');
  531:      sopt('interval','Time Interval');
  532:      
  533:      if ((pvalue!='') && (typeof(pvalue)!="undefined")) {
  534:         cdate.setTime(pvalue*1000);
  535:      }
  536:  
  537:      months[0]='January';
  538:      months[1]='February';
  539:      months[2]='March';
  540:      months[3]='April';
  541:      months[4]='May';
  542:      months[5]='June';
  543:      months[6]='July';
  544:      months[7]='August';
  545:      months[8]='September';
  546:      months[9]='October';
  547:      months[10]='November';
  548:      months[11]='December';
  549:   }
  550:    
  551:   if (ptype=='int') {
  552:      sopt('default','Default');
  553:      sopt('pos','Positive Integer, Not Zero');
  554:      sopt('zeropos','Positive Integer or Zero');
  555:      sopt('range','Integer Range');
  556:      sopt('any','Integer');
  557:   }
  558: 
  559:   if (ptype=='float') {
  560:      sopt('default','Default');
  561:      sopt('zeroone','Floating Point between 0 and 1');
  562:      sopt('pos','Positive Floating Point');
  563:      sopt('any','Floating Point');
  564: 
  565:   }
  566: 
  567:   if (ptype=='string') {
  568:      sopt('default','Default');
  569:      sopt('string','String Value');
  570:   }
  571: 
  572:   selwrite('</select></form>');
  573: 
  574:   selwrite('<a href="javascript:parent.assemble();');
  575:   if (preturn!='') {
  576:      selwrite(
  577:       'parent.opener.document.'+preturn+'_value.value=parent.window.svalue;');
  578:      selwrite(
  579:       'parent.opener.document.'+preturn+'_type.value=parent.window.stype;');
  580:   }
  581:   if (pmarker!='') {
  582:      selwrite(
  583:      'parent.opener.document.'+preturn+'_marker.value=parent.window.pmarker;');
  584:   }
  585:   if (pcode!='') {
  586:      selwrite('parent.opener.'+pcode+'();');
  587:   }
  588:   selwrite('">Store</a>&nbsp;&nbsp;');
  589: 
  590:   selwrite('<a href="javascript:');
  591:      selwrite(
  592:       'parent.opener.document.'+preturn+'_value.value='+"'';");
  593:   if (pmarker!='') {
  594:      selwrite(
  595:      'parent.opener.document.'+preturn+'_marker.value=parent.window.pmarker;');
  596:   }
  597:   if (pcode!='') {
  598:      selwrite('parent.opener.'+pcode+'();');
  599:   }
  600:   selwrite('">Delete</a>&nbsp;&nbsp;');
  601:  
  602:   selwrite('<a href="javascript:');
  603:   if (preturn!='') {
  604:      selwrite('parent.opener.document.'+preturn+'_value.value='+"'';");
  605:      selwrite('parent.opener.document.'+preturn+'_type.value='+"'';");
  606:   }
  607:   if (pmarker!='') {
  608:      selwrite('parent.opener.document.'+preturn+'_marker.value='+"'';");
  609:   }
  610:   if (pcode!='') {
  611:      selwrite('parent.opener.'+pcode+'();');
  612:   }
  613:   selwrite('">Cancel</a>'); 
  614:  
  615:   selwrite('</body></html>');
  616:   this.window.selector.document.close();
  617:   draw();
  618:   
  619: }
  620: 
  621: </script>
  622: 
  623: <frameset rows="120,*" onLoad="init();">
  624: <frame name=selector src="empty.html">
  625: <frame name=choices src="empty.html">
  626: </frameset>
  627: 
  628: 
  629: 
  630: </html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>