Changeset - a58b788f2a55
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2011-02-09 17:06:35
ohnobinki@ohnopublishing.net
Don't use title attribute to store course index, use jQuery().data() instead.
1 file changed with 8 insertions and 4 deletions:
0 comments (0 inline, 0 general)
scripts/scheduleInput.js
Show inline comments
 
@@ -266,49 +266,52 @@ function add_section(cnum)
 
 */
 
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);
 
	}
 
}
 

	
 
	//--------------------------------------------------
 
	// Adds a new class to the input.
 
	//--------------------------------------------------
 
	function add_class_n(name)
 
	{
 
		sectionsOfClass[classNum] = 0; // Initialize at 0
 
		jQuery('#jsrows').append('<tr title="' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" value="' + name + '" /></td><td colspan="10"></td><td class="tdInput"><div class="addSection"><input type="button" value="+" class="gray" /></div></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td></tr>');
 
		jQuery('#jsrows').append('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" value="' + name + '" /></td><td colspan="10"></td><td class="tdInput"><div class="addSection"><input type="button" value="+" class="gray" /></div></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td></tr>');
 

	
 
		/* store classNum as course_i into the <tr />: */
 
		jQuery('#tr-course-' + classNum).data({course_i: classNum});
 

	
 
		var class_elem = jQuery('.className' + classNum);
 
		class_elem.autocomplete({ source: "auto.php" });
 
		class_elem.bind('autocompleteselect', {class_num: classNum, class_elem: class_elem},
 
			function(event, ui)
 
			    {
 
				if (!ui.item)
 
				    return;
 

	
 
				if (ui.item.value.indexOf('-') != -1)
 
				    {
 
					jQuery.ajax(
 
						    {
 
							url: 'auto.php',
 
							    data: {'getsections': 1, 'term': ui.item.value},
 
							    context: {'class_num': event.data.class_num},
 
							    success: function(data, textStatus, reqobj)
 
							    {
 
								var new_course_num;
 

	
 
								if (data.sections)
 
								    {
 
									add_sections(this.class_num, data);
 
									new_course_num = add_class();
 
@@ -383,83 +386,84 @@ function prettyTime(time_str)
 
}
 

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

	
 
	//--------------------------------------------------
 
	// Validates the form (pre-submission check)
 
	//--------------------------------------------------
 
	jQuery('#scheduleForm').validate({ debug: false });
 

	
 
	//--------------------------------------------------
 
	// Bind the class-adding method
 
	//--------------------------------------------------
 
	jQuery('#addclass').click(function() {
 
		add_class();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected class from input
 
	//--------------------------------------------------
 
	jQuery('.deleteClass').live('click', function() {
 
		if(confirm('Delete class and all sections of this class?')) {
 
			jQuery('.class'+ jQuery(this).parent().parent().attr("title")).remove();
 
		    jQuery('.class' + jQuery(this).parent().parent().data('course_i')).remove();
 
		}
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected section from the input
 
	//--------------------------------------------------
 
	jQuery('.deleteSection').live('click', function() {
 
	  // Decreases the total number of classes
 
	  sectionsOfClass[jQuery(this).parent().parent().attr("title")]--;
 
		sectionsOfClass[jQuery(this).parent().parent().data('course_i')]--;
 
	  
 
	  // 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();
 
	    }
 
	  });
 

	
 
	});
 

	
 
	//--------------------------------------------------
 
	// 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")]);
 
		var course_i = jQuery(this).parent().parent().data('course_i');
 
		add_section(course_i, sectionsOfClass[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()
 
	{
 
	    if (jQuery(this).val() == "")
 
	    {
 
		jQuery(this).addClass("defaultTextActive");
 
		jQuery(this).val($(this)[0].title);
 
	    }
 
	});
 
	jQuery(".defText").blur();
 

	
 
	//--------------------------------------------------
0 comments (0 inline, 0 general)