source: tmcsimulator/branches/LCSv2/views/default/submit.html @ 624

Revision 624, 6.6 KB checked in by jdalbey, 6 years ago (diff)

LCS dynamically fill fieldrep from selected supervisor

Line 
1{{extend 'layout.html'}}
2<style>
3/* Hide the cross street lookup table */
4.hideme {display: none}
5</style>
6<script>
7/* When a route is selected from the combobox, filter the
8   list of locations for just those on that route. */
9function routechanged() {
10  var e = document.getElementById("routecombo");
11  var currentRoute = e.options[e.selectedIndex].text;
12  // update the list of locations
13  removeOptions(document.getElementById("startlocation"));
14  removeOptions(document.getElementById("endlocation"));
15  fillOptions(currentRoute);
16}
17// Remove all the options from a combo box
18function removeOptions(selectbox)
19{
20    var idx;
21    for(idx = selectbox.options.length - 1 ; idx >= 0 ; idx--)
22    {
23       selectbox.remove(idx);
24    }
25}
26
27// Fill the selectbox with items from the lookup table that match route
28function fillOptions(route)
29{
30    var i;   
31    var tbl = document.getElementById("stlookup");
32    var startloc = document.getElementById("startlocation")
33    var endloc = document.getElementById("endlocation")
34    var opt1,opt2;
35
36    // Examine all items in cross street lookup table
37    for(i = tbl.options.length - 1 ; i >= 0 ; i--)
38    {
39        var item = tbl.options[i].text;
40        // Parse the lookup table item into route and steet fields
41        var pos = item.search(",");
42        var currentRoute = item.substring(0,pos);
43        var currentStreet = item.substring(pos+1);
44        // if the crossstreet is for the desired route
45        if (route == currentRoute)
46        {
47            opt1 = document.createElement('option');
48            opt1.text = opt1.value = currentStreet;
49            // Add an option to the location combo boxes
50            startloc.add(opt1,0);
51            opt2 = document.createElement('option');
52            opt2.text = opt2.value = currentStreet;
53            endloc.add(opt2,0);
54        }
55    }
56    // Add an empty option to the select box
57    opt1 = document.createElement('option');
58    opt1.text = opt1.value = '';
59    startloc.add(opt1,0);
60    opt2 = document.createElement('option');
61    opt2.text = opt2.value = '';
62    endloc.add(opt2,0);
63    // Show the first (empty) option
64    startloc.selectedIndex = "0";
65    endloc.selectedIndex = "0";
66}
67/* When a supervisor is selected from the combobox, filter the
68   list of fieldrep (crew) for just those of that supervisor.
69   Note: this function is a near duplicate of routechanged() */
70function supervisorchanged() {
71  var e = document.getElementById("supervisorcombo");
72  var currentSuper = e.options[e.selectedIndex].text;
73  // update the list of crew
74  removeOptions(document.getElementById("fieldrep"));
75  fillCrew(currentSuper);
76}
77/* Fill the FieldRep selectbox with items that match supervisor
78   I.e., have the same radio call number.
79   Note: this function is a near duplicate of fillOptions()  */
80function fillCrew(supervisor)
81{
82    var i;   
83    var tbl = document.getElementById("crewlookup");
84    var dropdown = document.getElementById("fieldrep")
85    var opt1;
86
87    // Examine all items in crew lookup table
88    for(i = tbl.options.length - 1 ; i >= 0 ; i--)
89    {
90        var item = tbl.options[i].text;
91        // Extract the call num from the lookup table item
92        var currentCallnum = item.substring(0,2);
93        // if the supervisor's call num matches crew call num
94        var superCallnum = supervisor.substring(0,2)
95        if (currentCallnum.startsWith(superCallnum))
96        {
97            // Add an option to the fieldrep combo box
98            opt1 = document.createElement('option');
99            opt1.text = opt1.value = item;
100            dropdown.add(opt1,0);
101        }
102    }
103    // Add an empty option to the select box
104    opt1 = document.createElement('option');
105    opt1.text = opt1.value = '';
106    dropdown.add(opt1,0);
107    // Show the first (empty) option
108    dropdown.selectedIndex = "0";
109}
110</script>
111<script>
112/*  Dynamically generate lane closed checkboxes.
113  When user choses "Lane" as the closure type AND "Mainline" as the Facility,
114  then display checkboxes for which lanes to close.
115*/
116function closuretypechanged() 
117{
118  // Define table of routes and number of lanes for current Scenario
119  const lanedict = {  "5": 5,  "73": 3,  "405": 4,  "55" : 4 };
120  // get references to UI elements
121  var rte = document.getElementById("routecombo");
122  var currentRoute = rte.options[rte.selectedIndex].text;
123  var boxes = document.getElementById("boxes")
124  boxes.textContent = '';
125  var e = document.getElementById("closuretype");
126  var currentType = e.options[e.selectedIndex].text;
127  var facility = document.getElementById("facilitycombo");
128  var currentFacility = facility.options[facility.selectedIndex].text;
129  var x = document.getElementById("lanechooser")
130  // See if the desired choices are selected
131  if (currentType == "Lane" && (currentFacility=="Mainline" || currentFacility=="On Ramp" || currentFacility=="Off Ramp"))
132  {
133     // Validate that a route has been chosen
134     if (currentRoute == "")
135     {
136        alert("Must select a route before choosing lanes to close.")
137        e.selectedIndex = 0
138        return;
139      }
140      x.style.display = "block"  // make boxes visible
141      var boxlimit = 4;  // default number of checkboxes for unused routes
142      // Get the total number of lanes from the lookup table
143      if (currentRoute in lanedict)
144      {
145          boxlimit =  lanedict[currentRoute]
146          // assign limit to hidden field
147          document.getElementById("lanecount").value = boxlimit.toString()
148      }
149      // Create a new checkbox for the desired number of total lanes
150      for (boxno = 1; boxno<=boxlimit; boxno++)
151      {
152      var check = document.createElement('input')
153      check.type = 'checkbox';
154      check.name = "lanes"
155      check.id = "lane"+boxno
156      check.value = boxno.toString()
157      boxes.appendChild(check);
158      var label = document.createElement('label')
159      label.htmlFor = "lane"+boxno;
160        label.appendChild(document.createTextNode(boxno.toString()));
161      boxes.appendChild(label)
162      }
163    }
164  else // hide the checkboxes
165    {
166        x.style.display = "none";
167    }
168 
169 }
170</script>
171<script>
172// Handle a user click on a radio button for "existing incident"
173function radioclicked()
174{
175    var btngroup = document.getElementsByName('existing');
176    // Is the YES button checked?
177    if(btngroup[1].checked)
178    {
179        // Turn on display of combo box to select a closure id
180        document.getElementById("closureselect").style.display = "block";
181    }
182    else
183    {
184        // Turn off the combo box display
185        document.getElementById("closureselect").style.display = "none";
186    }
187}
188</script>
189<div id="main" role="main" class="mainflex">
190    <div id="pageTitle" class="header"> Request Emergency Closure</div>
191
192    <div class="searchform">
193        {{=form}}
194    </div>
195</div>
Note: See TracBrowser for help on using the repository browser.