--- loncom/interface/lonhtmlcommon.pm 2004/02/12 22:23:30 1.46 +++ loncom/interface/lonhtmlcommon.pm 2004/02/16 23:27:03 1.51 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.46 2004/02/12 22:23:30 matthew Exp $ +# $Id: lonhtmlcommon.pm,v 1.51 2004/02/16 23:27:03 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -56,6 +56,7 @@ html. package Apache::lonhtmlcommon; use Time::Local; +use Time::HiRes; use Apache::lonlocal; use strict; @@ -556,6 +557,15 @@ Inputs =item $number_to_do The total number of items being processed. +=item $type Either 'popup' or 'inline' (popup is assumed if nothing is + specified) + +=item $width Specify the width in charaters of the input field. + +=item $formname Only useful in the inline case, if a form already exists, this needs to be used and specfiy the name of the form, otherwise the Progress line will be created in a new form of it's own + +=item $inputname Only useful in the inline case, if a form and an input of type text exists, use this to specify the name of the input field + =back Returns a hash containing the progress state data structure. @@ -624,42 +634,75 @@ Returns: none ######################################################## ######################################################## +my $uniq=0; +sub get_uniq_name { + $uniq++; + return 'uniquename'.$uniq; +} + # Create progress sub Create_PrgWin { - my ($r, $title, $heading, $number_to_do)=@_; - #the whole function called through timeout is due to issues - #in mozilla Read BUG #2665 if you want to know the whole story - $r->print('"); + "popwin.document.close();}". + "\nwindow.setTimeout(openpopwin,0)"); + $prog_state{'formname'}='popremain'; + $prog_state{'inputname'}="remaining"; + } elsif ($type eq 'inline') { + $prog_state{'window'}='window'; + if (!$formname) { + $prog_state{'formname'}=&get_uniq_name(); + &r_print($r,'
'); + } else { + $prog_state{'formname'}=$formname; + } + if (!$inputname) { + $prog_state{'inputname'}=&get_uniq_name(); + &r_print($r,''); + } else { + $prog_state{'inputname'}=$inputname; + + } + if (!$formname) { &r_print($r,'
'); } + &Update_PrgWin($r,\%prog_state,&mt('Starting')); + } - my %prog_state; $prog_state{'done'}=0; $prog_state{'firststart'}=&Time::HiRes::time(); $prog_state{'laststart'}=&Time::HiRes::time(); $prog_state{'max'}=$number_to_do; - - $r->rflush(); + return %prog_state; } # update progress sub Update_PrgWin { my ($r,$prog_state,$displayString)=@_; - $r->print(''); + &r_print($r,''); $$prog_state{'laststart'}=&Time::HiRes::time(); - $r->rflush(); } # increment progress state @@ -707,21 +750,34 @@ sub Increment_PrgWin { if ($user_browser eq 'explorer' && $user_os =~ 'mac') { $lasttime = ''; } - $r->print(''); + &r_print($r,''); $$prog_state{'laststart'}=&Time::HiRes::time(); - $r->rflush(); } # close Progress Line sub Close_PrgWin { my ($r,$prog_state)=@_; - $r->print(''."\n"); + if ($$prog_state{'type'} eq 'popup') { + &r_print($r,''."\n"); + } elsif ($$prog_state{'type'} eq 'inline') { + &Update_PrgWin($r,$prog_state,&mt('Done')); + } undef(%$prog_state); - $r->rflush(); } +sub r_print { + my ($r,$to_print)=@_; + if ($r) { + $r->print($to_print); + $r->rflush(); + } else { + print($to_print); + } +} # ------------------------------------------------------- Puts directory header