# HG changeset patch # User Ethan Zonca # Date 2010-10-16 22:00:11 # Node ID 3a9f86b70342c55c28c6fe0e812ff66add5dd8c3 # Parent 1d417d9e6bb36b73fabdf90d132fc00be252d239 Javascript updates diff --git a/scripts/scheduleInput.js b/scripts/scheduleInput.js --- a/scripts/scheduleInput.js +++ b/scripts/scheduleInput.js @@ -1,9 +1,16 @@ + + //-------------------------------------------------- + // General Notes + //-------------------------------------------------- + + /* classNum is declared in the to enable loading of saved classes */ + /* sectionsOfClass is declared in the to enable loading of saved sections */ + //-------------------------------------------------- // Validation Functions //-------------------------------------------------- - //-------------------------------------------------- // Default Error Message //-------------------------------------------------- @@ -17,8 +24,7 @@ jQuery.validator.addMethod( "selectNone", function(value, element) { - if (element.value == "none") - { + if (element.value == "none") { return false; } else return true; @@ -36,8 +42,7 @@ jQuery(element).parent().parent().children().children('.daysRequired:checked').each( function() { checkedCount++; }); - if (checkedCount == 0) - { + if (checkedCount == 0) { return false; } else return true; @@ -56,31 +61,14 @@ }); - jQuery(document).ready(function() { - //-------------------------------------------------- - // Validates the form (pre-submission check) - //-------------------------------------------------- - jQuery('#scheduleForm').validate({ - debug: false, - }); - - /* classNum is declared in the to enable loading of saved classes */ - /* sectionsOfClass is declared in the to enable loading of saved sections */ - function numberedIds(name){ - return '\ - \ - '; - } - function letteredIds(name){ - return '\ - \ - '; - } + //-------------------------------------------------- + // General Input Functions + //-------------------------------------------------- + + //-------------------------------------------------- + // Custom ID generator - @FIXME: un-abstract + //-------------------------------------------------- function customIds(name){ return ''; } @@ -88,7 +76,11 @@ //-------------------------------------------------- // Returns the common inputs for each new section. //-------------------------------------------------- - function getCommonInputs(cnum) { + function getCommonInputs(cnum){ + getCommonInputs(cnum,'','','','','',''); + } + + function getCommonInputs(cnum,name,synonym,stime,etime,days,prof) { var snum = sectionsOfClass[cnum]; var result = ''; @@ -135,30 +127,47 @@ return result; } + //-------------------------------------------------- + // Add a section to a class + //-------------------------------------------------- + function add_section(cnum) { + jQuery('.pclass'+cnum).after('' + getCommonInputs(cnum) + '
'); + } + //-------------------------------------------------- // Adds a new class to the input. //-------------------------------------------------- - function addRow(){ - sectionsOfClass[classNum] = 0; // This is class 0, initialize at 0 - jQuery('#jsrows').append('
'); + function add_class(){ + sectionsOfClass[classNum] = 0; // Initialize at 0 + jQuery('#jsrows').append('
'); jQuery('.className' + classNum).autocomplete({ source: "auto.php" }); classNum++; }; - - addRow(); // Add initial row + + + //-------------------------------------------------- + // Items bound to pageload/events + //-------------------------------------------------- + jQuery(document).ready(function() { //-------------------------------------------------- - // Adds a new class when the add class button is - // clicked. + // Validates the form (pre-submission check) + //-------------------------------------------------- + jQuery('#scheduleForm').validate({ + debug: false, + }); + + //-------------------------------------------------- + // Bind the class-adding method //-------------------------------------------------- jQuery('#addclass').click(function() { - addRow(); + add_class(); }); //-------------------------------------------------- - // Deletes the selected class from input. + // Deletes the selected class from input //-------------------------------------------------- jQuery('.deleteClass').live('click', function() { if(confirm('Delete class and all sections of this class?')) { @@ -167,26 +176,19 @@ }); //-------------------------------------------------- - // Deletes the selected section from the input. + // Deletes the selected section from the input //-------------------------------------------------- jQuery('.deleteSection').live('click', function() { - sectionsOfClass[jQuery(this).parent().parent().attr("title")]--; // TODO: this only decreases the number of classes, so php should loop until this number of classes is found in the array + sectionsOfClass[jQuery(this).parent().parent().attr("title")]--; // Decreases the number of classes jQuery(this).parent().parent().remove(); }); //-------------------------------------------------- - // Adds a section to the selected class. + // Bind the section-adding method //-------------------------------------------------- jQuery('.addSection').live('click', function() { + add_section(jQuery(this).parent().parent().attr("title"), sectionsOfClass[jQuery(this).parent().parent().attr("title")]); sectionsOfClass[jQuery(this).parent().parent().attr("title")]++; // Increases sectionsOfClass[classNum] - jQuery(this).parent().parent().after('' + getCommonInputs(jQuery(this).parent().parent().attr("title")) + '
'); - }); - - //-------------------------------------------------- - // Resets the form - //-------------------------------------------------- - jQuery('#reset').click(function() { - jQuery('#scheduleForm').resetForm(); }); //-------------------------------------------------- @@ -215,8 +217,13 @@ //-------------------------------------------------- jQuery('.advanced').hide(); jQuery('#showadvanced').click( function() { - jQuery('#showadvanced').hide(); - jQuery('.advanced').slideToggle(); + jQuery('#showadvanced').hide(); + jQuery('.advanced').slideToggle(); }); + //-------------------------------------------------- + // Add initial class + //-------------------------------------------------- + add_class(); + });