Changeset - cdb656e2318a
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2011-02-16 13:20:55
ohnobinki@ohnopublishing.net
Fix up some javascript stuff for the input page with the help of jslint.
1 file changed with 47 insertions and 50 deletions:
0 comments (0 inline, 0 general)
scripts/scheduleInput.js
Show inline comments
 
@@ -38,44 +38,42 @@ var sectionsOfClass = new Array();
 

	
 
	//--------------------------------------------------
 
	// Time Selection Validation
 
	//--------------------------------------------------
 
	jQuery.validator.addMethod( 
 
		"selectNone", 
 
		function(value, element) { 
 
			if (element.value == "none") { 
 
				return false; 
 
			} 
 
			else return true; 
 
		}, 
 
		"<p class=\"error\">Please select a time</p>" 
 
	); 
 
		"<p class=\"error\">Please select a time</p>"); 
 
	
 
	//--------------------------------------------------
 
	// Days of Week validation
 
	//--------------------------------------------------
 
	jQuery.validator.addMethod( 
 
		"daysRequired", 
 
		function(value, element) { 
 
			var checkedCount = 0;
 
			jQuery(element).parent().parent().children().children('.daysRequired:checked').each( function() {
 
				checkedCount++;
 
			});
 
			if (checkedCount == 0) { 
 
			if (checkedCount === 0) { 
 
				return false; 
 
			} 
 
			else return true; 
 
		}, 
 
		"<p class=\"error\">Select a day!</p>" 
 
	); 
 
		"<p class=\"error\">Select a day!</p>"); 
 

	
 
/**
 
 * Class name validation: only require a class name if it has at least
 
 * one section. Backend throws out empty classes and it's more
 
 * convenient if we can let the user have one extra, empty class. This
 
 * is because we automatically add a new class each time we do an
 
 * autofill to make the life of the user easier and less confusing.
 
 */
 
jQuery.validator.addMethod('classRequired',
 
			   function(value, element)
 
			   {
 
			       if (value.length)
 
@@ -92,26 +90,25 @@ jQuery.validator.addMethod('classRequire
 
				* sections. This only works when the
 
				* class was added and the user _never_
 
				* clicked the Add Section button. Once
 
				* the user clicks that button, he has
 
				* to delete the class because of how
 
				* our numbering works.
 
				*/
 
			       if (!sectionsOfClass[cnum])
 
				   return true;
 

	
 
			       return false;
 
			   },
 
			   '<p class="error">Enter Class Name.</p>'
 
			   );
 
			   '<p class="error">Enter Class Name.</p>');
 

	
 
	//--------------------------------------------------
 
	// Add validation rules
 
	//--------------------------------------------------
 
	jQuery.validator.addClassRules("selectRequired", {
 
		selectNone: true
 
	});
 
	jQuery.validator.addClassRules("daysRequired", {
 
		daysRequired: true
 
	});
 
jQuery.validator.addClassRules('classRequired', { classRequired: true });
 

	
 
@@ -127,90 +124,90 @@ jQuery.validator.addClassRules('classReq
 
function genSectionHtml(cnum)
 
{
 
    genSectionHtml_n(cnum, '', '', '', '', '', '', '');
 
}
 

	
 
/* @TODO: This should select & set items based on args, if the args != '' */
 
function genSectionHtml_n(cnum, name, synonym, stime, etime, days, prof, location, type)
 
{
 
		var snum = sectionsOfClass[cnum];
 
		
 
		var cssclasses = 'section class' + cnum;
 
		if(type == 'lab') {
 
		  cssclasses += ' lab'
 
		    cssclasses += ' lab';
 
		}
 
		
 
		var result = '<tr class="' + cssclasses + '"><td class="none"></td>';
 
	        result = result + '<td class="sectionIdentifier center"><input type="text" size="1" class="required" name="postData[' + cnum + '][' + snum + '][letter]" value="' + name + '" /><input type="hidden" name="postData[' + cnum + '][' + snum + '][synonym]" value="' + synonym + '" /></td>';
 
		result = result + '<td class="professor center"><input type="text" size="10" class="profName" name="postData[' + cnum + ']['+ snum + '][professor]" value="' + prof + '" /></td>';
 
		result = result + '<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][start]"><option value="none"></option>'
 
				 + genOptionHtml("0700", "7:00 am", stime) + genOptionHtml("0730", "7:30 am", stime)
 
				 + genOptionHtml("0800", "8:00 am", stime) + genOptionHtml("0830", "8:30 am", stime)
 
				 + genOptionHtml("0900", "9:00 am", stime) + genOptionHtml("0930", "9:30 am", stime)
 
				 + genOptionHtml("1000", "10:00 am", stime) + genOptionHtml("1030", "10:30 am", stime)
 
				 + genOptionHtml("1100", "11:00 am", stime) + genOptionHtml("1130", "11:30 am", stime)
 
				 + genOptionHtml("1200", "12:00 pm", stime) + genOptionHtml("1230", "12:30 pm", stime)
 
				 + genOptionHtml("1300", "1:00 pm", stime) + genOptionHtml("1330", "1:30 pm", stime)
 
				 + genOptionHtml("1400", "2:00 pm", stime) + genOptionHtml("1430", "2:30 pm", stime)
 
				 + genOptionHtml("1500", "3:00 pm", stime) + genOptionHtml("1530", "3:30 pm", stime)
 
				 + genOptionHtml("1600", "4:00 pm", stime) + genOptionHtml("1630", "4:30 pm", stime)
 
				 + genOptionHtml("1700", "5:00 pm", stime) + genOptionHtml("1730", "5:30 pm", stime)
 
				 + genOptionHtml("1800", "6:00 pm", stime) + genOptionHtml("1830", "6:30 pm", stime)
 
				 + genOptionHtml("1900", "7:00 pm", stime) + genOptionHtml("1930", "7:30 pm", stime)
 
				 + genOptionHtml("2000", "8:00 pm", stime) + genOptionHtml("2030", "8:30 pm", stime)
 
		    + genOptionHtml("2100", "9:00 pm", stime);
 
		result = result + '<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][start]"><option value="none"></option>' +
 
		    genOptionHtml("0700", "7:00 am", stime) + genOptionHtml("0730", "7:30 am", stime) +
 
		    genOptionHtml("0800", "8:00 am", stime) + genOptionHtml("0830", "8:30 am", stime) +
 
		    genOptionHtml("0900", "9:00 am", stime) + genOptionHtml("0930", "9:30 am", stime) +
 
		    genOptionHtml("1000", "10:00 am", stime) + genOptionHtml("1030", "10:30 am", stime) +
 
		    genOptionHtml("1100", "11:00 am", stime) + genOptionHtml("1130", "11:30 am", stime) +
 
		    genOptionHtml("1200", "12:00 pm", stime) + genOptionHtml("1230", "12:30 pm", stime) +
 
		    genOptionHtml("1300", "1:00 pm", stime) + genOptionHtml("1330", "1:30 pm", stime) +
 
		    genOptionHtml("1400", "2:00 pm", stime) + genOptionHtml("1430", "2:30 pm", stime) +
 
		    genOptionHtml("1500", "3:00 pm", stime) + genOptionHtml("1530", "3:30 pm", stime) +
 
		    genOptionHtml("1600", "4:00 pm", stime) + genOptionHtml("1630", "4:30 pm", stime) +
 
		    genOptionHtml("1700", "5:00 pm", stime) + genOptionHtml("1730", "5:30 pm", stime) +
 
		    genOptionHtml("1800", "6:00 pm", stime) + genOptionHtml("1830", "6:30 pm", stime) +
 
		    genOptionHtml("1900", "7:00 pm", stime) + genOptionHtml("1930", "7:30 pm", stime) +
 
		    genOptionHtml("2000", "8:00 pm", stime) + genOptionHtml("2030", "8:30 pm", stime) +
 
		    genOptionHtml("2100", "9:00 pm", stime);
 

	
 
		if (stime.length > 0)
 
		    {
 
			var stime_end = stime.substr(2);
 
			if (stime_end != '00' && stime_end != '30')
 
			    result = result + genOptionHtml(stime, prettyTime(stime), stime);
 
		    }
 

	
 
		result = result + '</select></td>\
 
			<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][end]"><option value="none"></option>'
 
				 + genOptionHtml("0720", "7:20 am", etime) + genOptionHtml("0750", "7:50 am", etime)
 
				 + genOptionHtml("0820", "8:20 am", etime) + genOptionHtml("0850", "8:50 am", etime)
 
				 + genOptionHtml("0920", "9:20 am", etime) + genOptionHtml("0950", "9:50 am", etime)
 
				 + genOptionHtml("1020", "10:20 am", etime) + genOptionHtml("1050", "10:50 am", etime)
 
				 + genOptionHtml("1120", "11:20 am", etime) + genOptionHtml("1150", "11:50 am", etime)
 
				 + genOptionHtml("1220", "12:20 pm", etime) + genOptionHtml("1250", "12:50 pm", etime)
 
				 + genOptionHtml("1320", "1:20 pm", etime) + genOptionHtml("1350", "1:50 pm", etime)
 
				 + genOptionHtml("1420", "2:20 pm", etime) + genOptionHtml("1450", "2:50 pm", etime)
 
				 + genOptionHtml("1520", "3:20 pm", etime) + genOptionHtml("1550", "3:50 pm", etime)
 
				 + genOptionHtml("1620", "4:20 pm", etime) + genOptionHtml("1650", "4:50 pm", etime)
 
				 + genOptionHtml("1720", "5:20 pm", etime) + genOptionHtml("1750", "5:50 pm", etime)
 
				 + genOptionHtml("1820", "6:20 pm", etime) + genOptionHtml("1850", "6:50 pm", etime)
 
				 + genOptionHtml("1920", "7:20 pm", etime) + genOptionHtml("1950", "7:50 pm", etime)
 
				 + genOptionHtml("2020", "8:20 pm", etime) + genOptionHtml("2050", "8:50 pm", etime)
 
		    + genOptionHtml("2120", "9:20 pm", etime);
 
			<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][end]"><option value="none"></option>' +
 
		    genOptionHtml("0720", "7:20 am", etime) + genOptionHtml("0750", "7:50 am", etime) +
 
		    genOptionHtml("0820", "8:20 am", etime) + genOptionHtml("0850", "8:50 am", etime) +
 
		    genOptionHtml("0920", "9:20 am", etime) + genOptionHtml("0950", "9:50 am", etime) +
 
		    genOptionHtml("1020", "10:20 am", etime) + genOptionHtml("1050", "10:50 am", etime) +
 
		    genOptionHtml("1120", "11:20 am", etime) + genOptionHtml("1150", "11:50 am", etime) +
 
		    genOptionHtml("1220", "12:20 pm", etime) + genOptionHtml("1250", "12:50 pm", etime) +
 
		    genOptionHtml("1320", "1:20 pm", etime) + genOptionHtml("1350", "1:50 pm", etime) +
 
		    genOptionHtml("1420", "2:20 pm", etime) + genOptionHtml("1450", "2:50 pm", etime) +
 
		    genOptionHtml("1520", "3:20 pm", etime) + genOptionHtml("1550", "3:50 pm", etime) +
 
		    genOptionHtml("1620", "4:20 pm", etime) + genOptionHtml("1650", "4:50 pm", etime) +
 
		    genOptionHtml("1720", "5:20 pm", etime) + genOptionHtml("1750", "5:50 pm", etime) +
 
		    genOptionHtml("1820", "6:20 pm", etime) + genOptionHtml("1850", "6:50 pm", etime) +
 
		    genOptionHtml("1920", "7:20 pm", etime) + genOptionHtml("1950", "7:50 pm", etime) +
 
		    genOptionHtml("2020", "8:20 pm", etime) + genOptionHtml("2050", "8:50 pm", etime) +
 
		    genOptionHtml("2120", "9:20 pm", etime);
 

	
 
		if (etime.length > 0)
 
		    {
 
			var etime_end = etime.substr(2);
 
			if (etime_end != '50' && etime_end != '20')
 
			    result = result + genOptionHtml(etime, prettyTime(etime), etime);
 
		    }
 

	
 
		result = result + '</select></td>\
 
			<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][0]" value="1" ' + (days.m ? 'checked="checked"' : '') + ' /></td>\
 
			<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][1]" value="1" ' + (days.t ? 'checked="checked"' : '') + ' /></td>\
 
			<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][2]" value="1" ' + (days.w ? 'checked="checked"' : '') + ' /></td>\
 
			<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][3]" value="1" ' + (days.h ? 'checked="checked"' : '') + ' /></td>\
 
			<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][4]" value="1" ' + (days.f ? 'checked="checked"' : '') + ' /></td>\
 
			<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][5]" value="1" ' + (days.s ? 'checked="checked"' : '') + ' /></td>';
 
		result = result + '<td class="removeCell"><div class="deleteSection"><input type="button" value="x" class="gray" /></div></td><td class="emptyCell">' 
 
		    + '<input type="hidden" name="postData[' + cnum + '][' + snum + '][location]" value="' + location + '" />'
 
		    + '<input type="hidden" name="postData[' + cnum + '][' + snum + '][type]" value="' + type + '" />'
 
		    + '</td></tr>';
 
		result = result + '<td class="removeCell"><div class="deleteSection"><input type="button" value="x" class="gray" /></div></td><td class="emptyCell">' +
 
		    '<input type="hidden" name="postData[' + cnum + '][' + snum + '][location]" value="' + location + '" />' +
 
		    '<input type="hidden" name="postData[' + cnum + '][' + snum + '][type]" value="' + type + '" />' +
 
		    '</td></tr>';
 
		return result;
 
	}
 

	
 
/**
 
 * Outputs an <option/> element. It will inlcude selected="selected"
 
 * if the value param equals the test_value param.
 
 */
 
function genOptionHtml(value, content, test_value)
 
{
 
    var selected = ' selected="selected"';
 
    if (value != test_value)
 
	selected = '';
 
@@ -230,25 +227,25 @@ function addTips()
 
    style: {
 
      border: { 
 
        width: 3,
 
        radius: 4,
 
        color: '#333'
 
      },
 
      name: 'dark',
 
      tip: true
 
    },
 
    show: { effect: { type: 'fade', length: 2000 } },
 
    show: { ready: true }, 
 
/*    hide: { when: { event: 'inactive' } }, */
 
    corner: { target: 'topMiddle', tooltip: 'bottomMiddle' },
 
    corner: { target: 'topMiddle', tooltip: 'bottomMiddle' }
 
  });
 
}
 

	
 
/**
 
 * \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] ++;
 

	
 
@@ -321,37 +318,37 @@ function add_sections(cnum, data)
 
								    }
 
							    }
 
						    }
 
						    );
 
				    }
 
				else
 
				    {
 
					/*
 
					 * The user selected a department, such as CS or MATH.
 
					 * Thus, we should append a '-' to the value and do a search for that.
 
					 */
 
					var newval = ui.item.value + '-';
 
					event.data.class_elem
 
					    .val(newval)
 
					    .autocomplete("search", newval);
 
					event.data.class_elem.
 
					    val(newval).
 
					    autocomplete("search", newval);
 

	
 
					/* void out the default event since we are setting the value ourselves, with a '-' */
 
					event.preventDefault();
 
				    }
 
			    });
 

	
 
		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
 
@@ -449,25 +446,25 @@ jQuery(document).ready(function() {
 
	// 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() == "")
 
	    if (jQuery(this).val().length === 0)
 
	    {
 
		jQuery(this).addClass("defaultTextActive");
 
		jQuery(this).val($(this)[0].title);
 
	    }
 
	});
 
	jQuery(".defText").blur();
 

	
 
	//--------------------------------------------------
 
	// Show/Hide advanced items
 
	//--------------------------------------------------
 
	jQuery('.advanced').hide();    
 
	jQuery('#showadvanced').click( function() {
0 comments (0 inline, 0 general)