diff --git a/application/modules/courses/views/scripts/edit/index.phtml b/application/modules/courses/views/scripts/edit/index.phtml index 88739cfd4e6e833f94764aed66ebb6d8340b7c43..2fcfcadd3a63750ac3fb25e75dbb4b31412df994 100644 --- a/application/modules/courses/views/scripts/edit/index.phtml +++ b/application/modules/courses/views/scripts/edit/index.phtml @@ -82,7 +82,7 @@ document.formSessionId = '<?php echo $this->formSessionId; ?>'; <h2>Crosslistings</h2> <fieldset class="three_column"> - <table> + <table id="crosslistingsTable"> <?php $hasTieIn = false; foreach($this->course->getCrosslistings() as $key => $crosslist) { if($crosslist['type'] == 'grad tie-in') { $hasTieIn = true; } @@ -539,6 +539,7 @@ document.formSessionId = '<?php echo $this->formSessionId; ?>'; <div class="column"> <input type="checkbox" + class="deliveryMethodsInput" id="deliveryMethods_classroom" name="deliveryMethods[]" value="Classroom" @@ -551,6 +552,7 @@ document.formSessionId = '<?php echo $this->formSessionId; ?>'; <div class="column"> <input type="checkbox" + class="deliveryMethodsInput" id="deliveryMethods_web" name="deliveryMethods[]" value="Web" diff --git a/document_root/javascript/courses/edit.js b/document_root/javascript/courses/edit.js index 733feb5f22cdbfc15fee6a59ba1a9a060f06b12d..a47e4d35547831fece4df15c68466c3170589f0f 100644 --- a/document_root/javascript/courses/edit.js +++ b/document_root/javascript/courses/edit.js @@ -42,6 +42,7 @@ $(document).ready(function() { $('.activitySelect').change(handleChangeActivity); $('#credits input').change(handleChangeCredits); $('.dfRemovalRadio').change(handleChangeDfRemoval); + $('.deliveryMethodsInput').change(handleChangeDeliveryMethods); $('#dialog').dialog({ autoOpen: false, @@ -332,21 +333,21 @@ function handleChangeCourseLetter() var courseLetter = this.value; var message = ''; - switch (courseLetter) { + switch (courseLetter.toUpperCase()) { case 'L': message = '"L" represents a laboratory class.'; break; case 'H': - message = '"L" represents an honors class.'; + message = '"H" represents an honors class.'; break; case 'X': - message = '"L" represents an independent study class.'; + message = '"X" represents a course that has a web delivery method.'; break; case 'G': - message = '"L" represents professional courses for graduate credit.'; + message = '"G" represents professional courses for graduate credit.'; break; case 'C': @@ -535,6 +536,85 @@ function handleChangeDfRemoval() } } +function doesCrosslistExist(subject, courseNumber, courseLetter) +{ + var itDoes = false; + $('#crosslistingsTable tr').each(function(index) { + if ($(this).attr('class') == 'hidden_new_record') { + return; + } + var courseCodeInputs = $(this).find('input.courseCodeInput'); + if (courseCodeInputs.length != 3) { + return; + } + + if (courseCodeInputs[0].value == subject && + courseCodeInputs[1].value == courseNumber && + courseCodeInputs[2].value == courseLetter) { + itDoes = index; + } + }) + return itDoes; +} + +function handleChangeDeliveryMethods() +{ + var message = ''; + var addCrosslist = false; + var removeCrosslist = false; + + var subject = $('#subject').val(); + var courseNumber = $('#courseNumber').val(); + var courseLetter = $('#courseLetter').val(); + + switch (this.value) { + case 'Web': + var crosslistExists = doesCrosslistExist(subject, courseNumber, 'X'); + + if (this.checked && !crosslistExists) { + message = 'Web delivered courses must have a crosslisting ending in an X. It will be created now.'; + addCrosslist = true; + } else if (!this.checked && crosslistExists !== false) { + message = 'Non-Web delivered courses must not have a crosslisting ending in an X. It will be removed now.'; + removeCrosslist = crosslistExists; + } + break; + } + + if (message) { + var deliveryMethodNode = this; + queuePopup( + message, + { + 'Reset': function() { + deliveryMethodNode.checked = !deliveryMethodNode.checked; + $(this).dialog('close'); + }, + 'Ignore': function() { + $(this).dialog('close'); + }, + 'Ok': function() { + if (addCrosslist) { + $('[alt=Add Crosslisting]').parent().click(); + var crosslistingRows = $('#crosslistingsTable tr'); + var newCrosslistingRow = $(crosslistingRows[crosslistingRows.length - 3]); + var newCrosslistingInputs = newCrosslistingRow.find('input.courseCodeInput'); + document.foobar = newCrosslistingInputs; + $(newCrosslistingInputs[0]).val(subject); + $(newCrosslistingInputs[1]).val(courseNumber); + $(newCrosslistingInputs[2]).val('X'); + } + if (removeCrosslist !== false) { + $('#crosslistingsTable tr:eq(' + removeCrosslist + ') a').click() + } + $(this).dialog('close'); + } + }, + 'dfRemoval' + ); + } +} + function handleOutcomeClicked() { this.blur();