Changeset - 150d5bddeadc
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2011-03-22 00:18:33
ohnobinki@ohnopublishing.net
Fix automatic maintenance of no more than one empty course row when adding and removing sections from an otherwise empty course.
1 file changed with 14 insertions and 10 deletions:
0 comments (0 inline, 0 general)
scripts/scheduleInput.js
Show inline comments
 
@@ -189,28 +189,33 @@ function addTips()
 
 */
 
function add_section_n(cnum, name, synonym, stime, etime, days, prof, location, type)
 
{
 
    jQuery('.pclass'+cnum).after(genSectionHtml_n(cnum, name, synonym, stime, etime, days, prof, location, type));
 
    sectionsOfClass[cnum] ++;
 

	
 
    /* store course_i in a place the newly added section will look for it */
 
    jQuery('.pclass' + cnum).next().data({course_i: cnum});
 

	
 
    /* unhide the saturday columns if it's used by autocomplete data */
 
    if (days.s)
 
	jQuery('#jsrows col.saturday').removeClass('collapsed');
 

	
 
    return last_section_i - 1;
 
}
 
function add_section(cnum)
 
{
 
    return add_section_n(cnum, '', '', '', '', {m: false, t: false, w: false, h: false, f: false, s: false}, '', '', '');
 
    var section_i = add_section_n(cnum, '', '', '', '', {m: false, t: false, w: false, h: false, f: false, s: false}, '', '', '');
 
    if (cnum == slate_permutate_course_free)
 
	course_free_check(cnum);
 
    return section_i;
 
}
 

	
 
/**
 
 * Add a list of sections gotten via an AJAX call.
 
 */
 
function add_sections(cnum, data)
 
{
 
    var i;
 
    if (!data.sections)
 
	return;
 
    /*
 
     * we get the sections in the correct order. For the user to see
 
@@ -377,39 +382,38 @@ function course_has_sections(course_i)
 
{
 
    return sectionsOfClass[course_i] > 0;
 
}
 

	
 
/**
 
 * \brief
 
 *   Figure out whether or not an empty course entry has become filled
 
 *   or whether a full course has become emptied and react.
 
 *
 
 * This mainly ensures that there is always exactly one course entry
 
 * spot, eliminating the need of an ``Add class'' button.
 
 *
 
 * \param that
 
 * \param course_i
 
 *   If this is not being called as a 'change' or 'keyup' event
 
 *   handler for a <input class="className"/>, then that may refer to
 
 *   a jQuery object representing the <input class="className"/> to
 
 *   inspect.
 
 *   handler for a <input class="className"/>, then course_i may refer to
 
 *   a the course_i to check.
 
 */
 
function course_free_check(that)
 
function course_free_check(course_i)
 
{
 
    var me;
 
    if (jQuery.type(that) == 'undefined')
 
	me = that;
 
    if (jQuery.type(course_i) == 'number')
 
	me = jQuery('.pclass' + course_i + ' .className');
 
    else
 
	me = jQuery(this);
 

	
 
    var course_i = me.parent().parent().data('course_i');
 
    course_i = me.parent().parent().data('course_i');
 
    if (course_i == slate_permutate_course_free && (me.val().length || course_has_sections(course_i)))
 
	{
 
	    /* I am no longer the empty course entry */
 
	    slate_permutate_course_free = -1;
 
	    add_class();
 
	}
 
    if (course_i != slate_permutate_course_free && !(me.val().length || course_has_sections(course_i)))
 
	{
 
	    /* I am now an empty course entry */
 
	    /* kill an other empty course entry if it exists... */
 
	    if (slate_permutate_course_free != -1)
 
		course_remove(slate_permutate_course_free);
 
@@ -465,42 +469,42 @@ jQuery(document).ready(function() {
 
		if(confirm('Delete class and all sections of this class?')) {
 
		    course_remove(jQuery(this).parent().parent().data('course_i'));
 
		}
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected section from the input
 
	//--------------------------------------------------
 
	jQuery('.deleteSection').live('click', function() {
 
	  // Decreases the total number of classes
 
		var course_i = jQuery(this).parent().parent().data('course_i');
 
		sectionsOfClass[course_i]--;
 
		course_free_check(jQuery('.pclass' + course_i + ' .className'));
 

	
 
	  // Find the ID cell of the row we're in
 
	  var row = jQuery(this).parent().parent().find(".sectionIdentifier");
 

	
 
	  // The first input is the one containing the section ID
 
	  var toMatch = jQuery(row).find("input").val();
 
	    
 
	  // This gets the second class of the row, "class#"
 
	  var classClass = "." + jQuery(row).parent().attr("class").split(" ")[1];
 

	
 
	  // Iterate over each section of this class
 
	  jQuery(classClass).each( function() {
 
	    // If this section has the same course ID as the item clicked, remove it.
 
	    if(jQuery(this).find("input").val() == toMatch){
 
		jQuery(this).remove();
 
	    }
 
	  });
 
	  course_free_check(course_i);
 
	});
 

	
 
	jQuery('.className').live('change', course_free_check).live('keyup', course_free_check);
 

	
 
	//--------------------------------------------------
 
	// Bind the section-adding method
 
	//--------------------------------------------------
 
	jQuery('.addSection').live('click', function() {
 
		var course_i = jQuery(this).parent().parent().data('course_i');
 
		add_section(course_i);
 
	});
 

	
0 comments (0 inline, 0 general)