/*
* Copyright 2010 Nathan Gelderloos, Ethan Zonca, Nathan Phillip Brink
*
* This file is part of SlatePermutate.
*
* SlatePermutate is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SlatePermutate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SlatePermutate. If not, see
Please fill the field
"; }); //-------------------------------------------------- // Time Selection Validation //-------------------------------------------------- jQuery.validator.addMethod( "selectNone", function(value, element) { if (element.value == "none") { return false; } else return true; }, "Please select a time
" ); //-------------------------------------------------- // 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) { return false; } else return true; }, "Select a day!
" ); /** * 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) return true; var css_classes = jQuery(element).attr('class'); var cnum_pos = css_classes.indexOf('className'); var cnum = css_classes.substr(cnum_pos + 'className'.length, css_classes.indexOf(' ', cnum_pos) - cnum_pos - 'className'.length) * 1; if (cnum < 0 || cnum > classNum) alert('JS error: ' + cnum + ' is an invalid class number.'); /* * ignore the class with no * 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; }, 'Enter Class Name.
' ); //-------------------------------------------------- // Add validation rules //-------------------------------------------------- jQuery.validator.addClassRules("selectRequired", { selectNone: true }); jQuery.validator.addClassRules("daysRequired", { daysRequired: true }); jQuery.validator.addClassRules('classRequired', { classRequired: true }); //-------------------------------------------------- // General Input Functions //-------------------------------------------------- /** * \brief * Returns the common inputs for each new section. */ 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) { var snum = sectionsOfClass[cnum]; var result = '