1 <!-- This page defines the form to create or edit an instance of this module -->
2 <!-- It is used from /course/mod.php. The whole instance is available as $form. -->
5 TODO: display proper message when no sequences are received
10 include_once($CFG->dirroot
.'/mod/lams/constants.php');
12 if (!isset($form->name
)) {
15 if (!isset($form->introduction
)) {
16 $form->introduction
= '';
18 if (!isset($form->learning_session_id
)) {
19 $form->learning_session_id
= '';
22 if (!isset($form->create_sequence_url
)) {
23 $datetime = date("F d,Y g:i a");
24 $plaintext = trim($datetime).trim($USER->username
).trim($LAMSCONSTANTS->author_method
).trim($CFG->lams_serverid
).trim($CFG->lams_serverkey
);
25 $hash = sha1(strtolower($plaintext));
26 $form->create_sequence_url
= $CFG->lams_serverurl
.$LAMSCONSTANTS->login_request
.
27 '?'.$LAMSCONSTANTS->param_uid
.'='.$USER->username
.
28 '&'.$LAMSCONSTANTS->param_method
.'='.$LAMSCONSTANTS->author_method
.
29 '&'.$LAMSCONSTANTS->param_timestamp
.'='.urlencode($datetime).
30 '&'.$LAMSCONSTANTS->param_serverid
.'='.$CFG->lams_serverid
.
31 '&'.$LAMSCONSTANTS->param_hash
.'='.$hash.
32 '&'.$LAMSCONSTANTS->param_courseid
.'='.$form->course
;
36 <form id=
"form" method=
"post" action=
"mod.php" onSubmit=
"disableSumbit(this);">
38 <p id=
"message">Please wait .......
</p>
39 <table cellpadding=
"5">
41 <td align=
"right"><b><?php print_string("workspace", "lams") ?>:
</b></td>
43 <select id=
"workspace" name=
"workspace"></select>
47 <td align=
"right"><b><?php print_string("sequence","lams") ?>:
</b></td>
49 <select id=
"sequence" name=
"sequence"></select>
53 <td align=
"right"><b><?php print_string("name") ?>:
</b></td>
55 <input type=
"text" id=
"name" name=
"name" size=
"30" />
59 <td align=
"right"><p><b><?php print_string("introduction", "lams") ?>:
</b></p>
61 <!-- <font size="1"> DEPRECATED, USE CSS -->
64 helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
66 helpbutton("text", get_string("helptext"), "moodle", true, true);
68 emoticonhelpbutton("form", "introduction");
73 <!-- </font> DEPRECATED, USE CSS -->
77 print_textarea($usehtmleditor, 20, 50, 680, 400, "introduction", $form->introduction
);
82 <!-- The following line for Moodle 1.5 prints the visibility setting form element -->
83 <!-- <?php print_visible_setting($form); ?> -->
84 <!-- and if your module uses groups you would also have -->
85 <!-- ?php print_groupmode_setting($form); ? -->
88 <input type="hidden" name="learning_session_id"/>
89 <input type="hidden" name="create_sequence_url" id="create_sequence_url"/>
90 <input type="submit" id="save" name="save" value="<?php print_string("useSequence","lams") ?>" onClick="return validate();" />
91 <input type="button" id="edit" name="edit" value="<?php print_string("editSequence","lams") ?>" onClick="openAuthor(<?php
92 echo "'".$form->create_sequence_url."&".$LAMSCONSTANTS->param_ldid."=".@$form->sequence."'";?>);" />
93 <input type="button" id="create" name="create" value="<?php print_string("createSequence","lams") ?>" onClick="openAuthor(<?php
94 echo "'".$form->create_sequence_url."'";?>);" />
95 <input type="button" id="refresh" name="refresh" value="<?php print_string("refreshSequenceList","lams")?>" onclick="refreshLists();" />
96 <input type="submit" id="cancel" name=cancel value="<?php print_string("cancel") ?>" />
99 <!-- These hidden variables are always the same -->
100 <input type="hidden" name=course value="<?php p($form->course) ?>" />
101 <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
102 <input type="hidden" name=coursemodule value="<?php p($form->coursemodule) ?>" />
103 <input type="hidden" name=section value="<?php p($form->section) ?>" />
104 <input type="hidden" name=module value="<?php p($form->module) ?>" />
105 <input type="hidden" name=modulename value="<?php p($form->modulename) ?>" />
106 <input type="hidden" name=instance value="<?php p($form->instance) ?>" />
107 <input type="hidden" name=mode value="<?php p($form->mode) ?>" />
112 <script type="text/javascript">
116 workspaceObj = document.getElementById("workspace");
117 if (workspaceObj.options.length == 0){
118 alert("No workspace was returned from LAMS server! You may try refreshing sequence list.\nIf you still get the same problem, probably you have to cancel this activity.");
121 sequenceObj = document.getElementById("sequence");
122 if(sequenceObj.options.length == 0){
123 alert("No sequence was returned from LAMS server! You may try refreshing sequence list.\nIf you still get the same problem, probably you have to cancel this activity.");
126 if(trim(document.getElementById("name").value).length==0){
127 alert("You have to specify the activity name to proceed.");
133 function trim(trim_value){
134 if(trim_value.length < 1){
137 trim_value = rTrim(trim_value);
138 trim_value = lTrim(trim_value);
142 function rTrim(trim_value){
143 var w_space = String.fromCharCode(32);
144 var v_length = trim_value.length;
149 var iTemp = v_length -1;
152 if(trim_value.charAt(iTemp) != w_space){
153 strTemp = trim_value.substring(0,iTemp +1);
161 function lTrim(trim_value){
162 var w_space = String.fromCharCode(32);
166 var v_length = trim_value.length;
171 while(iTemp < v_length){
172 if(trim_value.charAt(iTemp) != w_space){
173 strTemp = trim_value.substring(iTemp,v_length);
181 function disableSubmit(dform) {
182 if (document.getElementById) {
183 for (var sch = 0; sch < dform.length; sch++) {
184 if (dform.elements[sch].type.toLowerCase() == "submit") dform.elements[sch].disabled = true;
190 function enableSubmit(dform) {
191 if (document.getElementById) {
192 for (var sch = 0; sch < dform.length; sch++) {
193 if (dform.elements[sch].type.toLowerCase() == "submit") dform.elements[sch].disabled = false;
199 var authorWin = null;
200 function openAuthor(url){
202 if(authorWin && authorWin.open && !authorWin.closed){
203 authorWin.document.location = url;
206 authorWin = window.open(url);
214 * This function is to initialize elements' status and refresh workspace and sequence lists
216 function refreshLists(){
217 document.getElementById("message").innerHTML = "<p>Please wait .......<" + "/p>";
218 disableSubmit(document.forms[0]);
219 document.getElementById("create").disabled = true;
220 document.getElementById("edit").disabled = true;
221 document.getElementById("refresh").disabled = true;
223 wsSelectObj = document.getElementById("workspace");
224 wsSelectObj.options.length = 0; //remove all options
225 wsSelectObj.options[0] = new Option("Loading...", "Loading...");
226 wsSelectObj.disabled = true;
228 seqSelectObj = document.getElementById("sequence");
229 seqSelectObj.options.length = 0; //remove all options
231 //clear the DynamicOptionList
232 dol = new DynamicOptionList("workspace","sequence");
233 dol.setFormName("form");
235 url = "../mod/lams/list.php?courseid="+document.getElementById('form').course.value;
236 if (window.XMLHttpRequest) { // Non-IE browsers
237 req = new XMLHttpRequest();
238 req.onreadystatechange = processStateChange;
240 req.open("GET", url, true);
245 } else if (window.ActiveXObject) { // IE
246 req = new ActiveXObject("Microsoft.XMLHTTP");
248 req.onreadystatechange = processStateChange;
249 req.open("GET", url, true);
255 function processStateChange() {
256 if (req.readyState == 4) { // Complete
257 var wsSelectObj = document.getElementById("workspace");
258 wsSelectObj.options.length = 0; //clear the workspace list
259 wsSelectObj.disabled = false;
260 enableSubmit(document.forms[0]);
261 document.getElementById("create").disabled = false;
262 document.getElementById("edit").disabled = false;
263 document.getElementById("refresh").disabled = false;
264 if (req.status == 200) { // OK response
265 var res = req.responseText.replace(/^\s*|\s*$/g,""); //get trimed result
266 var seqlistStr = res.split(':'); //seperate each set of {sid, workspace,sequence}
267 var seqlist = new Array();
269 var workspaceList = new Object();
271 //pass the response and construct the list again
272 for(var i=0; i<seqlistStr.length; i++){
273 var sws = seqlistStr[i].split(',');
276 var workspace = sws[1];
277 var sequence = sws[2];
279 if(workspaceList[workspace] == null){
280 //set workspace as keys in workspaceList (kind of like a map)
281 //therefore duplicated workspaces will be ignored
282 workspaceList[workspace] = 1; //insert workspace as a key
284 //insert workspace into workspace list
285 wsSelectObj.options[wsSelectObj.length] = new Option(workspace,workspace);
288 //insert sequence dependency into DynamicOptionList
289 dol.forValue(workspace).addOptionsTextValue(sequence,sid);
292 initDynamicOptionLists(); //construct the list
293 document.getElementById("message").innerHTML =
294 "<p>Select an existing sequence or create a new sequence.<" + "/p>";
295 }else if(req.status == 504){//gateway timeout. probabaly LAMS server is not available.
296 document.getElementById("message").innerHTML =
297 '<table align="center" width="57%" class="noticebox" border="0" cellpadding="15" cellspacing="0"><tr><td bgcolor="#FFAAAA" class="noticeboxcontent"><h4 class="main">It seems the LAMS server is not available!<br/> Please contact your administrator.<'+'/h4><'+'/td><'+'/tr><'+'/table>';
298 }else if(req.status == 401){//AuthenticationException thrown by LAMS server.
299 document.getElementById("message").innerHTML =
300 '<table align="center" width="57%" class="noticebox" border="0" cellpadding="15" cellspacing="0"><tr><td bgcolor="#FFAAAA" class="noticeboxcontent"><h4 class="main">This moodle server is not authenticated by LAMS!<br/> Please contact your administrator.<'+'/h4><'+'/td><'+'/tr><'+'/table>';
301 }else if(req.status == 502){//Unknow exception thrown by LAMS server
302 document.getElementById("message").innerHTML =
303 '<table align="center" width="57%" class="noticebox" border="0" cellpadding="15" cellspacing="0"><tr><td bgcolor="#FFAAAA" class="noticeboxcontent"><h4 class="main">An unexpected error returned from LAMS server:'+req.responseText+'! Please contact your administrator.<'+'/h4><'+'/td><'+'/tr><'+'/table>';
304 }else if(req.status == 417){//ServerNotFound exception thrown by LAMS server
305 document.getElementById("message").innerHTML =
306 '<table align="center" width="57%" class="noticebox" border="0" cellpadding="15" cellspacing="0"><tr><td bgcolor="#FFAAAA" class="noticeboxcontent"><h4 class="main">This moodle server has not registered in LAMS!<br/> Please contact your administrator.<'+'/h4><'+'/td><'+'/tr><'+'/table>';
307 }else if(req.status == 402){//All LAMS module settings have not not been set up
308 document.getElementById("message").innerHTML =
309 '<table align="center" width="57%" class="noticebox" border="0" cellpadding="15" cellspacing="0"><tr><td bgcolor="#FFAAAA" class="noticeboxcontent"><h4 class="main">All the LAMS module settings have not been set up!<br/> Please contact your administrator.<'+'/h4><'+'/td><'+'/tr><'+'/table>';
310 }else{//this error should come from moodle server itself
311 document.getElementById("message").innerHTML =
312 '<table align="center" width="57%" class="noticebox" border="0" cellpadding="15" cellspacing="0"><tr><td bgcolor="#FFAAAA" class="noticeboxcontent"><h4 class="main">It should be a moodle server error:'+req.status + ' ' + req.statusText+'! Please contact your administrator.<'+'/h4><'+'/td><'+'/tr><'+'/table>';
317 var dynamicOptionListCount=0;
318 var dynamicOptionListObjects = new Array();
320 // Init call to setup lists after page load. One call to this function sets up all lists.
321 function initDynamicOptionLists() {
322 // init each DynamicOptionList object
323 for (var i=0; i<dynamicOptionListObjects.length; i++) {
324 var dol = dynamicOptionListObjects[i];
326 // Find the form associated with this list
327 if (dol.formName!=null) {
328 dol.form = document.forms[dol.formName];
330 else if (dol.formIndex!=null) {
331 dol.form = document.forms[dol.formIndex];
334 // Form wasn't set manually, so go find it!
335 // Search for the first form element name in the lists
336 var name = dol.fieldNames[0][0];
337 for (var f=0; f<document.forms.length; f++) {
338 if (typeof(document.forms[f][name])!="undefined") {
339 dol.form = document.forms[f];
343 if (dol.form==null) {
344 alert("ERROR: Couldn't find form element "+name+" in any form on the page! Init aborted"); return;
348 // Form is found, now set the onchange attributes of each dependent select box
349 for (var j=0; j<dol.fieldNames.length; j++) {
350 // For each set of field names...
351 for (var k=0; k<dol.fieldNames[j].length-1; k++) {
352 // For each field in the set...
353 var selObj = dol.form[dol.fieldNames[j][k]];
354 if (typeof(selObj)=="undefined") { alert("Select box named "+dol.fieldNames[j][k]+" could not be found in the form. Init aborted"); return; }
355 // Map the HTML options in the first select into the options we created
357 if (selObj.options!=null) {
358 for (l=0; l<selObj.options.length; l++) {
359 var sopt = selObj.options[l];
360 var m = dol.findMatchingOptionInArray(dol.options,sopt.text,sopt.value,false);
362 var reselectForNN6 = sopt.selected;
363 var m2 = new Option(sopt.text, sopt.value, sopt.defaultSelected, sopt.selected);
364 m2.selected = sopt.selected; // For some reason I need to do this to make NN4 happy
365 m2.defaultSelected = sopt.defaultSelected;
367 selObj.options[l] = m2;
368 selObj.options[l].selected = reselectForNN6; // Reselect this option for NN6 to be happy. Yuck.
373 if (selObj.onchange==null) {
374 // We only modify the onChange attribute if it's empty! Otherwise do it yourself in your source!
375 selObj.onchange = new Function("dynamicOptionListObjects["+dol.index+"].change(this)");
380 // Set the preselectd options on page load
381 resetDynamicOptionLists();
384 // This function populates lists with the preselected values.
385 // It's pulled out into a separate function so it can be hooked into a 'reset' button on a form
386 // Optionally passed a form object which should be the only form reset
387 function resetDynamicOptionLists(theform) {
388 // reset each DynamicOptionList object
389 for (var i=0; i<dynamicOptionListObjects.length; i++) {
390 var dol = dynamicOptionListObjects[i];
391 if (typeof(theform)=="undefined" || theform==null || theform==dol.form) {
392 for (var j=0; j<dol.fieldNames.length; j++) {
393 dol.change(dol.form[dol.fieldNames[j][0]],true); // Second argument says to use preselected values rather than default values
399 // An object to represent an Option() but just for data-holding
400 function DOLOption(text,value,defaultSelected,selected) {
403 this.defaultSelected = defaultSelected;
404 this.selected = selected;
405 this.options = new Array(); // To hold sub-options
409 // DynamicOptionList CONSTRUCTOR
410 function DynamicOptionList() {
411 this.form = null;// The form this list belongs to
412 this.options = new Array();// Holds the options of dependent lists
413 this.longestString = new Array();// Longest string that is currently a potential option (for Netscape)
414 this.numberOfOptions = new Array();// The total number of options that might be displayed, to build dummy options (for Netscape)
415 this.currentNode = null;// The current node that has been selected with forValue() or forText()
416 this.currentField = null;// The current field that is selected to be used for setValue()
417 this.currentNodeDepth = 0;// How far down the tree the currentNode is
418 this.fieldNames = new Array();// Lists of dependent fields which use this object
419 this.formIndex = null;// The index of the form to associate with this list
420 this.formName = null;// The name of the form to associate with this list
421 this.fieldListIndexes = new Object();// Hold the field lists index where fields exist
422 this.fieldIndexes = new Object();// Hold the index within the list where fields exist
423 this.selectFirstOption = true;// Whether or not to select the first option by default if no options are default or preselected, otherwise set the selectedIndex = -1
424 this.numberOfOptions = new Array();// Store the max number of options for a given option list
425 this.longestString = new Array();// Store the longest possible string
426 this.values = new Object(); // Will hold the preselected values for fields, by field name
429 this.forValue = DOL_forValue;
430 this.forText = DOL_forText;
431 this.forField = DOL_forField;
432 this.forX = DOL_forX;
433 this.addOptions = DOL_addOptions;
434 this.addOptionsTextValue = DOL_addOptionsTextValue;
435 this.setDefaultOptions = DOL_setDefaultOptions;
436 this.setValues = DOL_setValues;
437 this.setValue = DOL_setValues;
438 this.setFormIndex = DOL_setFormIndex;
439 this.setFormName = DOL_setFormName;
440 this.printOptions = DOL_printOptions;
441 this.addDependentFields = DOL_addDependentFields;
442 this.change = DOL_change;
443 this.child = DOL_child;
444 this.selectChildOptions = DOL_selectChildOptions;
445 this.populateChild = DOL_populateChild;
446 this.change = DOL_change;
447 this.addNewOptionToList = DOL_addNewOptionToList;
448 this.findMatchingOptionInArray = DOL_findMatchingOptionInArray;
450 // Optionally pass in the dependent field names
451 if (arguments.length > 0) {
452 // Process arguments and add dependency groups
453 for (var i=0; i<arguments.length; i++) {
454 this.fieldListIndexes[arguments[i].toString()] = this.fieldNames.length;
455 this.fieldIndexes[arguments[i].toString()] = i;
457 this.fieldNames[this.fieldNames.length] = arguments;
460 // Add this object to the global array of dynamicoptionlist objects
461 this.index = window.dynamicOptionListCount++;
462 window["dynamicOptionListObjects"][this.index] = this;
465 // Given an array of Option objects, search for an existing option that matches value, text, or both
466 function DOL_findMatchingOptionInArray(a,text,value,exactMatchRequired) {
467 if (a==null || typeof(a)=="undefined") { return null; }
468 var value_match = null; // Whether or not a value has been matched
469 var text_match = null; // Whether or not a text has been matched
470 for (var i=0; i<a.length; i++) {
472 // If both value and text match, return it right away
473 if (opt.value==value && opt.text==text) { return opt; }
474 if (!exactMatchRequired) {
475 // If value matches, store it until we complete scanning the list
476 if (value_match==null && value!=null && opt.value==value) {
479 // If text matches, store it for later
480 if (text_match==null && text!=null && opt.text==text) {
485 return (value_match!=null)?value_match:text_match;
488 // Util function used by forValue and forText
489 function DOL_forX(s,type) {
490 if (this.currentNode==null) { this.currentNodeDepth=0; }
491 var useNode = (this.currentNode==null)?this:this.currentNode;
492 var o = this.findMatchingOptionInArray(useNode["options"],(type=="text")?s:null,(type=="value")?s:null,false);
494 o = new DOLOption(null,null,false,false);
496 useNode.options[useNode.options.length] = o;
498 this.currentNode = o;
499 this.currentNodeDepth++;
503 // Set the portion of the list structure that is to be used by a later operation like addOptions
504 function DOL_forValue(s) { return this.forX(s,"value"); }
506 // Set the portion of the list structure that is to be used by a later operation like addOptions
507 function DOL_forText(s) { return this.forX(s,"text"); }
509 // Set the field to be used for setValue() calls
510 function DOL_forField(f) { this.currentField = f; return this; }
512 // Create and add an option to a list, avoiding duplicates
513 function DOL_addNewOptionToList(a, text, value, defaultSelected) {
514 var o = new DOLOption(text,value,defaultSelected,false);
515 // Add the option to the array
516 if (a==null) { a = new Array(); }
517 for (var i=0; i<a.length; i++) {
518 if (a[i].text==o.text && a[i].value==o.value) {
522 if (o.defaultSelected) {
523 a[i].defaultSelected = true;
531 // Add sub-options to the currently-selected node, with the same text and value for each option
532 function DOL_addOptions() {
533 if (this.currentNode==null) { this.currentNode = this; }
534 if (this.currentNode["options"] == null) { this.currentNode["options"] = new Array(); }
535 for (var i=0; i<arguments.length; i++) {
536 var text = arguments[i];
537 this.addNewOptionToList(this.currentNode.options,text,text,false);
538 if (typeof(this.numberOfOptions[this.currentNodeDepth])=="undefined") {
539 this.numberOfOptions[this.currentNodeDepth]=0;
541 if (this.currentNode.options.length > this.numberOfOptions[this.currentNodeDepth]) {
542 this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length;
544 if (typeof(this.longestString[this.currentNodeDepth])=="undefined" || (text.length > this.longestString[this.currentNodeDepth].length)) {
545 this.longestString[this.currentNodeDepth] = text;
548 this.currentNode = null;
549 this.currentNodeDepth = 0;
552 // Add sub-options to the currently-selected node, specifying separate text and values for each option
553 function DOL_addOptionsTextValue() {
554 if (this.currentNode==null) { this.currentNode = this; }
555 if (this.currentNode["options"] == null) { this.currentNode["options"] = new Array(); }
556 for (var i=0; i<arguments.length; i++) {
557 var text = arguments[i++];
558 var value = arguments[i];
559 this.addNewOptionToList(this.currentNode.options,text,value,false);
560 if (typeof(this.numberOfOptions[this.currentNodeDepth])=="undefined") {
561 this.numberOfOptions[this.currentNodeDepth]=0;
563 if (this.currentNode.options.length > this.numberOfOptions[this.currentNodeDepth]) {
564 this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length;
566 if (typeof(this.longestString[this.currentNodeDepth])=="undefined" || (text.length > this.longestString[this.currentNodeDepth].length)) {
567 this.longestString[this.currentNodeDepth] = text;
570 this.currentNode = null;
571 this.currentNodeDepth = 0;
574 // Find the first dependent list of a select box
575 // If it's the last list in a chain, return null because there are no children
576 function DOL_child(obj) {
577 var listIndex = this.fieldListIndexes[obj.name];
578 var index = this.fieldIndexes[obj.name];
579 if (index < (this.fieldNames[listIndex].length-1)) {
580 return this.form[this.fieldNames[listIndex][index+1]];
585 // Set the options which should be selected by default for a certain value in the parent
586 function DOL_setDefaultOptions() {
587 if (this.currentNode==null) { this.currentNode = this; }
588 for (var i=0; i<arguments.length; i++) {
589 var o = this.findMatchingOptionInArray(this.currentNode.options,null,arguments[i],false);
591 o.defaultSelected = true;
594 this.currentNode = null;
597 // Set the options which should be selected when the page loads. This is different than the default value and ONLY applies when the page LOADS
598 function DOL_setValues() {
599 if (this.currentField==null) {
600 alert("Can't call setValues() without using forField() first!");
603 if (typeof(this.values[this.currentField])=="undefined") {
604 this.values[this.currentField] = new Object();
606 for (var i=0; i<arguments.length; i++) {
607 this.values[this.currentField][arguments[i]] = true;
609 this.currentField = null;
612 // Manually set the form for the object using an index
613 function DOL_setFormIndex(i) {
617 // Manually set the form for the object using a form name
618 function DOL_setFormName(n) {
622 // Print blank <option> objects for Netscape4, since it refuses to grow or shrink select boxes for new options
623 function DOL_printOptions(name) {
624 // Only need to write out "dummy" options for Netscape4
625 if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) <= 4)){
626 var index = this.fieldIndexes[name];
628 if (typeof(this.numberOfOptions[index])!="undefined") {
629 for (var i=0; i<this.numberOfOptions[index]; i++) {
634 if (typeof(this.longestString[index])!="undefined") {
635 for (var i=0; i<this.longestString[index].length; i++) {
639 document.writeln(ret);
643 // Add a list of field names which use this option-mapping object.
644 // A single mapping object may be used by multiple sets of fields
645 function DOL_addDependentFields() {
646 for (var i=0; i<arguments.length; i++) {
647 this.fieldListIndexes[arguments[i].toString()] = this.fieldNames.length;
648 this.fieldIndexes[arguments[i].toString()] = i;
650 this.fieldNames[this.fieldNames.length] = arguments;
653 // Called when a parent select box is changed. It populates its direct child, then calls change on the child object to continue the population.
654 function DOL_change(obj, usePreselected) {
655 if (usePreselected==null || typeof(usePreselected)=="undefined") { usePreselected = false; }
656 var changedListIndex = this.fieldListIndexes[obj.name];
657 var changedIndex = this.fieldIndexes[obj.name];
658 var child = this.child(obj);
659 if (child == null) { return; } // No child, no need to continue
660 if (obj.type == "select-one") {
661 // Treat single-select differently so we don't have to scan the entire select list, which could potentially speed things up
662 if (child.options!=null) {
663 child.options.length=0; // Erase all the options from the child so we can re-populate
665 if (obj.options!=null && obj.options.length>0 && obj.selectedIndex>=0) {
666 var o = obj.options[obj.selectedIndex];
667 this.populateChild(o.DOLOption,child,usePreselected);
668 this.selectChildOptions(child,usePreselected);
671 else if (obj.type == "select-multiple") {
672 // For each selected value in the parent, find the options to fill in for this list
673 // Loop through the child list and keep track of options that are currently selected
674 var currentlySelectedOptions = new Array();
675 if (!usePreselected) {
676 for (var i=0; i<child.options.length; i++) {
677 var co = child.options[i];
679 this.addNewOptionToList(currentlySelectedOptions, co.text, co.value, co.defaultSelected);
683 child.options.length=0;
684 if (obj.options!=null) {
685 var obj_o = obj.options;
686 // For each selected option in the parent...
687 for (var i=0; i<obj_o.length; i++) {
688 if (obj_o[i].selected) {
689 // if option is selected, add its children to the list
690 this.populateChild(obj_o[i].DOLOption,child,usePreselected);
693 // Now go through and re-select any options which were selected before
694 var atLeastOneSelected = false;
695 if (!usePreselected) {
696 for (var i=0; i<child.options.length; i++) {
697 var m = this.findMatchingOptionInArray(currentlySelectedOptions,child.options[i].text,child.options[i].value,true);
699 child.options[i].selected = true;
700 atLeastOneSelected = true;
704 if (!atLeastOneSelected) {
705 this.selectChildOptions(child,usePreselected);
709 // Change all the way down the chain
710 this.change(child,usePreselected);
712 function DOL_populateChild(dolOption,childSelectObj,usePreselected) {
713 // If this opton has sub-options, populate the child list with them
714 if (dolOption!=null && dolOption.options!=null) {
715 for (var j=0; j<dolOption.options.length; j++) {
716 var srcOpt = dolOption.options[j];
717 if (childSelectObj.options==null) { childSelectObj.options = new Array(); }
718 // Put option into select list
719 var duplicate = false;
720 var preSelectedExists = false;
721 for (var k=0; k<childSelectObj.options.length; k++) {
722 var csi = childSelectObj.options[k];
723 if (csi.text==srcOpt.text && csi.value==srcOpt.value) {
729 var newopt = new Option(srcOpt.text, srcOpt.value, false, false);
730 newopt.selected = false; // Again, we have to do these two statements for NN4 to work
731 newopt.defaultSelected = false;
732 newopt.DOLOption = srcOpt;
733 childSelectObj.options[childSelectObj.options.length] = newopt;
739 // Once a child select is populated, go back over it to select options which should be selected
740 function DOL_selectChildOptions(obj,usePreselected) {
741 // Look to see if any options are preselected=true. If so, then set then selected if usePreselected=true, otherwise set defaults
742 var values = this.values[obj.name];
743 var preselectedExists = false;
744 if (usePreselected && values!=null && typeof(values)!="undefined") {
745 for (var i=0; i<obj.options.length; i++) {
746 var v = obj.options[i].value;
747 if (v!=null && values[v]!=null && typeof(values[v])!="undefined") {
748 preselectedExists = true;
753 // Go back over all the options to do the selection
754 var atLeastOneSelected = false;
755 for (var i=0; i<obj.options.length; i++) {
756 var o = obj.options[i];
757 if (preselectedExists && o.value!=null && values[o.value]!=null && typeof(values[o.value])!="undefined") {
759 atLeastOneSelected = true;
761 else if (!preselectedExists && o.DOLOption!=null && o.DOLOption.defaultSelected) {
763 atLeastOneSelected = true;
769 // If nothing else was selected, select the first one by default
770 if (this.selectFirstOption && !atLeastOneSelected && obj.options.length>0) {
771 obj.options[0].selected = true;
773 else if (!atLeastOneSelected && obj.type=="select-one") {
774 obj.selectedIndex = -1;
778 refreshLists();//refresh the lists when form is displayed.