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
 
@@ -177,52 +177,57 @@ function addTips()
 
      position:{
 
        my: 'top left', 
 
        at: 'bottom right',
 
      }
 
    }
 
  );
 

	
 
}
 

	
 
/**
 
 * \brief
 
 *   Add a section to a class.
 
 */
 
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
 
     * them in the correct order, we must reverse the add_setion_n()
 
     * calls.
 
     */
 
    for (i = data.sections.length - 1; i >= 0; i --)
 
	{
 
	    section = data.sections[i];
 
	    add_section_n(cnum, section.section, section.synonym, section.time_start, section.time_end, section.days, section.prof, section.location, section.type);
 
	}
 

	
 
    /*
 
     * Handle course-level interdependencies.
 
     */
 
@@ -365,63 +370,62 @@ function course_remove(course_i)
 
}
 

	
 
/**
 
 * \brief
 
 *   Figure whether or not a given course entry has sections.
 
 *
 
 * \param course_i
 
 *   The internal javascript representation of a course entry.
 
 * \return
 
 *   true or false.
 
 */
 
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);
 
	    slate_permutate_course_free = course_i;
 
	}
 
}
 

	
 
/**
 
 * \brief
 
 *   Render a slate_permutate-encoded time-of-day.
 
 *
 
 * \param time_str
 
 *   A four-character representation of a time of day based on a
 
 *   time's 24-hour representation.
 
 * \return
 
@@ -453,66 +457,66 @@ function prettyTime(time_str)
 
    return hour_str + ':' + time_str.substr(2) + ' ' + m + 'm';
 
}
 

	
 
//--------------------------------------------------
 
// Items bound to pageload/events
 
//--------------------------------------------------
 
jQuery(document).ready(function() {
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected class from input
 
	//--------------------------------------------------
 
	jQuery('.deleteClass').live('click', 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);
 
	});
 

	
 
	//--------------------------------------------------
 
	// Default text
 
	//--------------------------------------------------
 
	jQuery(".defText").focus(function(srcc)
 
	{
 
	    if (jQuery(this).val() == jQuery(this)[0].title)
 
	    {
 
		jQuery(this).removeClass("defaultTextActive");
 
		jQuery(this).val("");
 
	    }
 
	});
 
	jQuery(".defText").blur(function()
0 comments (0 inline, 0 general)