Changeset - 59ee50e4d13c
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2010-10-29 19:45:23
ohnobinki@ohnopublishing.net
Automatically add a new class each time an auto.php?getsections AJAX call returns a valid list of sections to reduce user confusion about how to use autocomplete.
1 file changed with 10 insertions and 1 deletions:
0 comments (0 inline, 0 general)
scripts/scheduleInput.js
Show inline comments
 
@@ -154,77 +154,86 @@ function genOptionHtml(value, content, t
 
}
 

	
 
/**
 
 * \brief
 
 *   Add a section to a class.
 
 */
 
function add_section_n(cnum, name, synonym, stime, etime, days, prof, location)
 
{
 
    jQuery('.pclass'+cnum).after(genSectionHtml_n(cnum, name, synonym, stime, etime, days, prof, location));
 
    sectionsOfClass[cnum] ++;
 
}
 
function add_section(cnum)
 
{
 
    return add_section_n(cnum, '', '', '', '', {'m':false, 't':false, 'w':false, 'h':false, 'f':false}, '', '');
 
}
 

	
 
/**
 
 * 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);
 
	}
 
}
 

	
 
	//--------------------------------------------------
 
	// 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><input type="text" class="className required defText className'+classNum+'" title="Class Name" name="postData[' + classNum + '][name]" value="' + name + '" /></td><td colspan="9"></td><td class="tdInput"><div class="addSection"><input type="button" value="Add Section" class="gray" /></div></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td></tr>');
 

	
 
		jQuery('.className' + classNum).autocomplete({ source: "auto.php" });
 
		jQuery('.className' + classNum).bind('autocompleteselect', {'class_num': classNum},
 
			function(event, ui)
 
			    {
 
				if (ui.item && ui.item.value.indexOf('-'))
 
				    {
 
					jQuery.ajax(
 
						      {
 
							  url: 'auto.php',
 
							  data: {'getsections': 1, 'term': ui.item.value},
 
							  context: {'class_num': event.data.class_num},
 
							  success: function(data, textStatus, reqobj)
 
							      {
 
								  add_sections(this.class_num, data);
 
								  if (data.sections)
 
								      {
 
									  add_sections(this.class_num, data);
 
									  add_class();
 
								      }
 
							      }
 
						      }
 
						      );
 
				    }
 
			    });
 

	
 

	
 
		classNum++;
 

	
 
		return (classNum - 1);
 
	};
 
function add_class()
 
{
 
    return add_class_n('');
 
}
 

	
 

	
 
/**
 
 * \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.
0 comments (0 inline, 0 general)