File:  [LON-CAPA] / rat / client / parameter.html
Revision 1.12: download - view: text, annotated - select for diffs
Wed Aug 8 15:40:52 2001 UTC (22 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Accepts tolerances, but does not read them yet.

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

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