[LON-CAPA-cvs] cvs: loncom /interface lonsupportreq.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 13 Oct 2005 17:18:14 -0000


This is a MIME encoded message

--raeburn1129223894
Content-Type: text/plain

raeburn		Thu Oct 13 13:18:14 2005 EDT

  Modified files:              
    /loncom/interface	lonsupportreq.pm 
  Log:
  Make code used to construct connected Year-Semester-Department-Course select boxes usable by other forms (e.g., by lonnotify.pm), by passing in $formname as parameter.   
  
  
--raeburn1129223894
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20051013131814.txt"

Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.28 loncom/interface/lonsupportreq.pm:1.29
--- loncom/interface/lonsupportreq.pm:1.28	Mon Apr 11 20:20:00 2005
+++ loncom/interface/lonsupportreq.pm	Thu Oct 13 13:18:14 2005
@@ -1,5 +1,5 @@
 #
-# $Id: lonsupportreq.pm,v 1.28 2005/04/12 00:20:00 raeburn Exp $
+# $Id: lonsupportreq.pm,v 1.29 2005/10/13 17:18:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,7 +62,7 @@
     
 sub print_request_form {
     my ($r,$origurl,$function) = @_;
-    my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
+    my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,$formname);
     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0" onLoad="initialize_codes()"',1);
     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
     if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {
@@ -79,6 +79,7 @@
     $urole = $env{'request.role'};
     $usec = $env{'request.course.sec'};
     $cid = $env{'request.course.id'};
+    $formname = 'logproblem';
     if ($origurl =~ m-^http://-) {
         $server = $origurl;
     } else {
@@ -189,7 +190,7 @@
             if ($format_reply eq 'ok') {
                 my $numtypes = @codetitles;
                 &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
-                &javascript_code_selections($numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
+                &javascript_code_selections($formname,$numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
                 $loaditems = '';
             }
         }
@@ -1186,7 +1187,7 @@
 }
 
 sub javascript_code_selections {
-    my ($numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
+    my ($formname,$numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
     my $numtitles = @{$codetitles};
     my @seltitles = ();
     for (my $j=0; $j<$numtitles; $j++) {
@@ -1207,10 +1208,10 @@
     var ids = new Array ("$seltitle_str");
     var formitems = new Array ($numtitles);
     var longtitles = new Array ("$longtitles_str");
-    var idyr = document.logproblem.Year.selectedIndex
-    var idsem  = document.logproblem.Semester.selectedIndex
-    var iddept = document.logproblem.Department.selectedIndex
-    var idclass = document.logproblem.Number.selectedIndex
+    var idyr = document.$formname.Year.selectedIndex
+    var idsem  = document.$formname.Semester.selectedIndex
+    var iddept = document.$formname.Department.selectedIndex
+    var idclass = document.$formname.Number.selectedIndex
     var idyears = new Array("$$idlist{$$codetitles[0]}");
 END
     if ($longtitles[0]) {
@@ -1274,55 +1275,59 @@
     }
     $$script_tag .= (<<END_OF_BLOCK);
  var display = new Array($numtitles)
- if (caller == "") {
-    document.logproblem.Year.length = 0
-    document.logproblem.Year.options[0] = new Option("Select","-1",true,true)
-    display[0] = new Array(idyears.length)
-    for (var i=0; i<idyears.length; i++) {
-      display[0][i] = idyears[i]
-      if (longtitles[0] == 1) {
-          if (idyearslongs[i] != "") {
-              display[0][i] = idyearslongs[i]
-          }
-      }
-      document.logproblem.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
-    }
-    document.logproblem.Year.selectedIndex = 0;
- }
- if (caller == "$$codetitles[0]") {
-   document.logproblem.Department.length = 0
-   document.logproblem.Number.length = 0
-   document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
-   document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
-   if (idyr == 0) {
-    document.logproblem.Semester.length = 0
-    document.logproblem.Semester.options[0] = new Option("<-Pick $$codetitles[0]","-1",true,true)
-   }
-   else {
-    document.logproblem.Semester.length = 0
-    document.logproblem.Semester.options[0] = new Option("Select","-1",true,true)
-    display[1] = new Array(idsems[idyr-1].length)
-    for (var i=0; i<idsems[idyr-1].length; i++) {
-      display[1][i] = idsems[idyr-1][i]
-      if (longtitles[1] == 1) {
-          if (idsemslongs[idyr-1][i] != "") {
-              display[1][i] = idsemslongs[idyr-1][i]
-          }
-      }
-      document.logproblem.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
-    }
-   }
-   document.logproblem.Semester.selectedIndex = 0;
+ if (caller == "" || caller == "$$codetitles[0]") {
+     if (caller == "") {
+         document.$formname.Year.length = 0
+         document.$formname.Year.options[0] = new Option("Select","-1",true,true)
+         display[0] = new Array(idyears.length)
+         for (var i=0; i<idyears.length; i++) {
+             display[0][i] = idyears[i]
+             if (longtitles[0] == 1) {
+                 if (idyearslongs[i] != "") {
+                     display[0][i] = idyearslongs[i]
+                 }
+             }
+             else {
+                 if (idyearslongs[i] != "") {
+                     display[0][i] = idyears[i]
+                 }
+             }
+             document.$formname.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
+         }
+         document.$formname.Year.selectedIndex = 0;
+     }
+     document.$formname.Semester.length = 0
+     document.$formname.Department.length = 0;
+     document.$formname.Number.length = 0
+     document.$formname.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
+     document.$formname.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
+     if (idyr == 0 || caller == "") {
+         document.$formname.Semester.options[0] = new Option("<-Pick $$codetitles[0]","-1",true,true)
+     }
+     else {
+         document.$formname.Semester.options[0] = new Option("Select","-1",true,true)
+         display[1] = new Array(idsems[idyr-1].length)
+         for (var i=0; i<idsems[idyr-1].length; i++) {
+             display[1][i] = idsems[idyr-1][i]
+             if (longtitles[1] == 1) {
+                 if (idsemslongs[idyr-1][i] != "") {
+                     display[1][i] = idsemslongs[idyr-1][i]
+                 }
+             }
+             document.$formname.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
+         }
+     }
+     document.$formname.Semester.selectedIndex = 0;
  }
  if (caller == "$$codetitles[1]") {
-   document.logproblem.Department.length = 0
-   document.logproblem.Number.length = 0
-   document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
+   document.$formname.Department.length = 0
+   document.$formname.Number.length = 0
+   document.$formname.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
    if (idsem == 0) {
-     document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
+     document.$formname.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
    }
    else {
-    document.logproblem.Department.options[0] = new Option("Select","-1",true,true)    
+    document.$formname.Department.options[0] = new Option("Select","-1",true,true)    
     display[2] = new Array(idcodes[idyr-1][idsem-1].length)
     for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
       display[2][i] = idcodes[idyr-1][idsem-1][i]
@@ -1331,18 +1336,18 @@
               display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
           }
       }
-      document.logproblem.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
+      document.$formname.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
     }
    }
-   document.logproblem.Department.selectedIndex = 0
+   document.$formname.Department.selectedIndex = 0
  }
  if (caller == "$$codetitles[2]") {
-   document.logproblem.Number.length = 0
+   document.$formname.Number.length = 0
    if (iddept == 0) {
-     document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
+     document.$formname.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
    }
    else {
-    document.logproblem.Number.options[0] = new Option("Select","-1",true,true)
+    document.$formname.Number.options[0] = new Option("Select","-1",true,true)
     display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
     for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
       display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
@@ -1351,10 +1356,10 @@
             display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
         }
       }
-      document.logproblem.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
+      document.$formname.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
     }
    }
-   document.logproblem.Number.selectedIndex = 0
+   document.$formname.Number.selectedIndex = 0
  }
 }
 

--raeburn1129223894--