File:  [LON-CAPA] / rat / client / parameter.html
Revision 1.6: download - view: text, annotated - select for diffs
Sat Dec 16 19:51:30 2000 UTC (23 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
Accepts other parameter types now

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

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