Changeset - aa34ac34003f
[Not reviewed]
default
0 3 1
ethanzonca - 15 years ago 2010-07-14 00:13:51

Added page class to input.php, fixed up some stuff. Needs a cleanup, maybe move class.*.php files to inc/
4 files changed with 259 insertions and 328 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
<?php
 

	
 
/* Class for general page generation */
 
class page {
 

	
 
// Private functions/variables
 

	
 
  private $base_title = 'SlatePermutate';
 
  private $doctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"';
 
  private $htmlargs = 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"';
 
  private $bodyargs = '';
 
  public $lastJobTable = '';
 

	
 
  private $isMobile = false; // Have a basic view when this is true
 
  private $pageGenTime = 0;
 
  private $indexpath = 'http://protofusion.org/SlatePermutate/'; // full url to index for php header redirection
 

	
 
  private $pageGenTime = 0;
 

	
 
  private $indexpath = 'http://protofusion.org/SlatePermutate/'; // full url to index for php header redirection
 
  // Scripts and styles
 
  private $headCode = array();
 

	
 
  private $trackingcode = '<script type="text/javascript">
 
				  var _gaq = _gaq || [];
 
				  _gaq.push([\'_setAccount\', \'UA-17441156-1\']);
 
				  _gaq.push([\'_trackPageview\']);
 
				  (function() {
 
				    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
 
				    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
 
				    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
 
				  })();
 
				</script>'; // Google analytics ga.js tracking code
 

	
 
  public $tablestripe = '<script type="text/javascript">
 
			  $(document).ready(function(){
 
			    $(".tablestripe tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
 
			    $(".tablestripe tr:even").addClass("alt");
 
			    $(".tablestripe tr:odd").addClass("alto");
 
			  });
 
			  </script>';
 

	
 
  private $title = ''; // Title of page
 
  private $scripts = ''; // Scripts to include on page
 

	
 
  public function __construct($ntitle, $nscripts = ''){
 
    $this->title = $ntitle;
 
    $this->scripts .= $nscripts;
 
    if($ntitle != "NOHEAD")
 
      $this->head();
 

	
 
    $headCode['jquery'] = '<script src="http://www.google.com/jsapi"></script><script type="text/javascript" charset="utf-8"> google.load("jquery", "1.3.2"); google.load("jqueryui", "1.7.2");</script>';
 
    $headCode['jValidate'] = '<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>';
 
    $headCode['schedInput'] = '<script type="text/javascript" src="scripts/scheduleInput.js"></script>';
 
  }
 

	
 
  private function top(){
 
    echo '<div id="header">
 
          <h1><em>SlatePermutate</em> -  Scheduler</h1>
 
          </div>
 
          <div id="content">';
 
  }
 

	
 
// Public functions/vars
 

	
 
  public function head(){
 
  private function head(){
 
    session_start();
 

	
 
    // @TODO: Add capability to load additional javascripts and stylesheets in array form
 

	
 
    $this->pageGenTime = round(microtime(), 3);
 

	
 
    echo '<!DOCTYPE ' . $this->doctype . '>
 
	  <html ' . $this->htmlargs . '>
 
	  <head>
 
	    <title>' . $this->title . ' :: ' . $this->base_title . '</title>
 

	
 
         <link rel="stylesheet" href="styles/general.css" type="text/css" media="screen" charset="utf-8">';
 
           <link rel="stylesheet" href="styles/general.css" type="text/css" media="screen" charset="utf-8">';
 

	
 
	echo $this->scripts;
 
	echo '</head>
 
    // Write out all passed scripts
 
    foreach ($this->scripts as $script)
 
    	echo $headCode[$script];
 

	
 
    echo '</head>
 
	  <body '.$this->bodyargs.' >';
 
    echo $this->top(); // Write out top
 
  }
 

	
 

	
 
  public function foot(){
 
    echo '</div>';
 
    $this->pageGenTime = round(microtime(), 3);
 
    echo '<div id="footer"><h5>&copy; '. date('Y').' <a href="http://protofusion.org/~nathang/">Nathan Gelderloos</a><br />
 
                           with special thanks to <a href="http://ethanzonca.com">Ethan Zonca</a></h5>
 
          </div>';
 
    echo '<div id="footer"><h5>&copy; '. date('Y').' <a href="http://protofusion.org/~nathang/">Nathan Gelderloos</a><br /> with special thanks to <a href="http://ethanzonca.com">Ethan Zonca</a></h5></div>';
 
    echo $this->trackingcode;
 
    echo '</body></html>';
 
  }
 

	
 

	
 
  public function secondsToCompound($seconds) {
 
      $ret = "";
 
      $hours = intval(intval($seconds) / 3600);
 
      $ret .= "$hours:";
 
      $minutes = bcmod((intval($seconds) / 60),60);
 
      $ret .= "$minutes:";
input.php
Show inline comments
 
@@ -3,285 +3,19 @@
 
session_start();
 

	
 
include_once 'errors.php';
 
include_once 'class.schedule.php';
 
include_once 'class.class.php';
 
include_once 'class.section.php';
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html>
 
<head>
 
	<title>Scheduler</title>
 
<style type="text/css">
 
	body {
 
		width: 80%;
 
		margin:auto;
 
		font-family: sans-serif;
 
	}
 
	.defaultText { 
 
		width: 300px; }
 
	.defaultTextActive { 
 
		color: #a1a1a1; 
 
		font-style: italic; 
 
	}
 
	#savedBox {
 
		width: 15em;
 
		padding: 1em;
 
		border: 1px solid #000;
 
		float:right;
 
		background: #DDD;
 
		font-size: .8em;
 
	}
 
	#header {
 
		text-align: left;
 
		background: rgb(220,220,220); /* IE fallback */
 
		background: rgba(200,200,200, .3);  
 
	}
 
	#footer {
 
		text-align: right;
 
		background: rgb(220,220,220); /* IE fallback */
 
		background: rgba(200,200,200, .3); 
 
	}
 
	.error {
 
		color: #F00; /* For validation errors */
 
	} 
 
	.error p {
 
		padding: 0;
 
		margin: 0;
 
		font-size: .7em;
 
	}
 
	td.center {
 
		text-align:center;
 
	}
 
	.section:nth-child(even) {
 
		background: #DDDDDD;
 
	}
 
	.none {
 
		background: #fff;
 
	}
 
	.class {
 
		background: #99FF99;
 
	}
 
	#classage {
 
		float:left;
 
	}
 
	.paddingtop {
 
		padding: .5em;
 
		padding-top: .8em;
 
	}
 
</style>
 

	
 
<script src="http://www.google.com/jsapi"></script>
 

	
 
<script type="text/javascript" charset="utf-8">
 
	google.load("jquery", "1.3.2");
 
	google.load("jqueryui", "1.7.2");
 
</script> 
 

	
 
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>
 

	
 
<script type="text/javascript">
 
	/* Set all default error messages to this */
 
	jQuery.each(jQuery.validator.messages, function(i) {
 
		jQuery.validator.messages[i] = "<p class=\"error\">Please fill the field</p>";
 
	});
 

	
 
	jQuery.validator.addMethod( 
 
		"selectNone", 
 
		function(value, element) { 
 
			if (element.value == "none") 
 
			{ 
 
				return false; 
 
			} 
 
			else return true; 
 
		}, 
 
		"<p class=\"error\">Please select a time</p>" 
 
	); 
 

	
 
/* Doesn't work right now:  */ /*
 
	jQuery.validator.addMethod( 
 
		"daysRequired", 
 
		function(value, element) { 
 
			var numChecked = 0;
 
			jQuery(document).find('.daysRequire').each(function () {
 
				jQuery('#scheduleForm').append('<p>Found something!</p>');
 
				if(this.value != "none")
 
					numChecked++;
 
			});
 
			jQuery('#scheduleForm').append('<p>Finished each loop, found ' + numChecked + ' checked boxes</p>');
 

	
 
			if (numChecked >= 1) 
 
			{ 
 
				return false; 
 
			} 
 
			else return true; 
 
		}, 
 
		"<p class=\"error\">Please select one or more days!.</p>" 
 
	); 
 
*/
 

	
 
	jQuery.validator.addClassRules("selectRequired", {
 
		selectNone: true
 
	});
 
	
 
	jQuery.validator.addClassRules("daysRequire", {
 
		daysRequired: true
 
	});
 

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

	
 

	
 
	var classNum = 0;
 
	var sectionsOfClass = new Array(); // holds number of sections for each class
 
include_once 'inc/class.page.php';
 

	
 
	//--------------------------------------------------
 
	// Returns the common inputs for each new section.
 
	//--------------------------------------------------
 
	function getCommonInputs(cnum) {
 
		var snum = sectionsOfClass[cnum];
 

	
 
		var result = '<td>\
 
				<select name="postData[' + cnum + '][' + snum + '][letter]"><option value="-">-</option><option value="A">A</option><option value="B">B</option>\
 
				<option value="C">C</option><option value="D">D</option><option value="E">E</option><option value="F">F</option><option value="G">G</option>\
 
				<option value="H">H</option><option value="I">I</option><option value="J">J</option><option value="K">K</option></select></td>\
 
				</select></td>\
 
			<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][start]"><option value="none"></option>\
 
				<option value="700">7:00 am</option><option value="730">7:30 am</option>\
 
				<option value="800">8:00 am</option><option value="830">8:30 am</option>\
 
				<option value="900">9:00 am</option><option value="930">9:30 am</option>\
 
				<option value="1000">10:00 am</option><option value="1030">10:30 am</option>\
 
				<option value="1100">11:00 am</option><option value="1130">11:30 am</option>\
 
				<option value="1200">12:00 pm</option><option value="1230">12:30 pm</option>\
 
				<option value="1300">1:00 pm</option><option value="1330">1:30 pm</option>\
 
				<option value="1400">2:00 pm</option><option value="1430">2:30 pm</option>\
 
				<option value="1500">3:00 pm</option><option value="1530">3:30 pm</option>\
 
				<option value="1600">4:00 pm</option><option value="1630">4:30 pm</option>\
 
				<option value="1700">5:00 pm</option><option value="1730">5:30 pm</option>\
 
				<option value="1800">6:00 pm</option><option value="1830">6:30 pm</option>\
 
				<option value="1900">7:00 pm</option><option value="1930">7:30 pm</option>\
 
				<option value="2000">8:00 pm</option><option value="2030">8:30 pm</option>\
 
				<option value="2100">9:00 pm</option></select></td>\
 
			<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][end]"><option value="none"></option>\
 
				<option value="720">7:20 am</option><option value="750">7:50 am</option>\
 
				<option value="820">8:20 am</option><option value="850">8:50 am</option>\
 
				<option value="920">9:20 am</option><option value="950">9:50 am</option>\
 
				<option value="1020">10:20 am</option><option value="1050">10:50 am</option>\
 
				<option value="1120">11:20 am</option><option value="1150">11:50 am</option>\
 
				<option value="1220">12:20 pm</option><option value="1250">12:50 pm</option>\
 
				<option value="1320">1:20 pm</option><option value="1350">1:50 pm</option>\
 
				<option value="1420">2:20 pm</option><option value="1450">2:50 pm</option>\
 
				<option value="1520">3:20 pm</option><option value="1550">3:50 pm</option>\
 
				<option value="1620">4:20 pm</option><option value="1650">4:50 pm</option>\
 
				<option value="1720">5:20 pm</option><option value="1750">5:50 pm</option>\
 
				<option value="1820">6:20 pm</option><option value="1850">6:50 pm</option>\
 
				<option value="1920">7:20 pm</option><option value="1950">7:50 pm</option>\
 
				<option value="2020">8:20 pm</option><option value="2050">8:50 pm</option>\
 
				<option value="2120">9:20 pm</option></select></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][0]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][1]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][2]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][3]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][4]" value="1" /></td>';
 
	
 
		return result;
 
	}
 

	
 
	//--------------------------------------------------
 
	// Adds a new class to the input.
 
	//--------------------------------------------------
 
	function addRow(){
 
		sectionsOfClass[classNum] = 0; // This is class 0, initialize at 0
 
		jQuery('#jsrows').append('<tr title="' + classNum + '" class="class class' + classNum + '"><td><input type="text" class="required defText" title="Class Name" name="postData[' + classNum + '][name]" /></td>' + getCommonInputs(classNum) + '<td><div class="addSection"><input type="button" value="Add section" /></div></td><td><div class="deleteClass"><input type="button" value="Delete" /></div></td></tr>');
 
		classNum++;
 
	};
 
	
 
	addRow(); // Add initial row
 
$scripts = array('jquery','jValidate','schedInput');
 
$inputPage = new page('Scheduler', $scripts);
 
?>
 

	
 
	//--------------------------------------------------
 
	// Adds a new class when the add class button is 
 
	// clicked.
 
	//--------------------------------------------------
 
	jQuery('#classage').click(function() {
 
		addRow();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected class from input.
 
	//--------------------------------------------------
 
	jQuery('.deleteClass').live('click', function() {
 
		jQuery('.class'+ jQuery(this).parent().parent().attr("title")).remove();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected section from the input.
 
	//--------------------------------------------------
 
	jQuery('.deleteSection').live('click', function() {
 
		sectionsOfClass[jQuery(this).parent().parent().attr("title")]--; // TODO: this only decreases the number of classes, so php should loop until this number of classes is found in the array
 
		jQuery(this).parent().parent().remove();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Adds a section to the selected class.
 
	//--------------------------------------------------
 
	jQuery('.addSection').live('click', function() {
 
		sectionsOfClass[jQuery(this).parent().parent().attr("title")]++; // Increases sectionsOfClass[classNum]
 
		jQuery(this).parent().parent().after('<tr class="section class' + jQuery(this).parent().parent().attr("title") + '"><td class="none"></td>' + getCommonInputs(jQuery(this).parent().parent().attr("title")) + '<td></td><td><div class="deleteSection"><input type="button" value="Delete" /></div></td></tr>');
 
	});
 

	
 
	//--------------------------------------------------
 
	// Resets the form
 
	//--------------------------------------------------
 
	jQuery('#reset').click(function() {
 
		jQuery('#scheduleForm').resetForm();
 
    });
 

	
 
	//--------------------------------------------------
 
	// Default text stuff
 
	//--------------------------------------------------
 
    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();    
 

	
 
});
 

	
 
</script>
 

	
 
</head>
 
<body>
 

	
 
<div id="header">
 
	<h1>
 
		<em>
 
			SlatePermutate
 
		</em>
 
		-  Scheduler
 
	</h1>
 
</div>
 

	
 
<div id="content">
 
	<p>
 
<p>
 

	
 
<?
 
if(isset($_SESSION['saved']) && count($_SESSION['saved']) > 0){
 
	echo '<div id="savedBox" ><h3>Saved Schedules:</h3>';
 
	foreach($_SESSION['saved'] as $key => $schedule){
 
		$sch = unserialize($schedule);
 
@@ -346,26 +80,9 @@ if(isset($_SESSION['saved']) && count($_
 
		This would probably be very useful, in the case that the individual would like to edit a saved
 
		schedule. Right now, it is only possible to edit the most previous schedule using the back button
 
		in the browser and this still requires the user to add the classes and schedules (although they
 
		already populated as soon as they are added).</li>
 
</ul>
 

	
 
</div>
 

	
 
<div id="footer">
 
	<h5>
 
		&copy; 
 
		<?php echo Date("Y"); ?> 
 
		<a href="http://protofusion.org/~nathang/">
 
			Nathan Gelderloos
 
		</a>
 
		<br />
 
		with special thanks to 
 
		<a href="http://ethanzonca.com">
 
			Ethan Zonca
 
		</a>
 
	</h5>
 
</div>
 

	
 
</body>
 

	
 
</html>
 
<?
 
$inputPage->foot();
 
?>
 
\ No newline at end of file
scripts/scheduleInput.js
Show inline comments
 
new file 100644
 
	/* Set all default error messages to this */
 
	jQuery.each(jQuery.validator.messages, function(i) {
 
		jQuery.validator.messages[i] = "<p class=\"error\">Please fill the field</p>";
 
	});
 

	
 
	jQuery.validator.addMethod( 
 
		"selectNone", 
 
		function(value, element) { 
 
			if (element.value == "none") 
 
			{ 
 
				return false; 
 
			} 
 
			else return true; 
 
		}, 
 
		"<p class=\"error\">Please select a time</p>" 
 
	); 
 

	
 
/* Doesn't work right now:  */ /*
 
	jQuery.validator.addMethod( 
 
		"daysRequired", 
 
		function(value, element) { 
 
			var numChecked = 0;
 
			jQuery(document).find('.daysRequire').each(function () {
 
				jQuery('#scheduleForm').append('<p>Found something!</p>');
 
				if(this.value != "none")
 
					numChecked++;
 
			});
 
			jQuery('#scheduleForm').append('<p>Finished each loop, found ' + numChecked + ' checked boxes</p>');
 

	
 
			if (numChecked >= 1) 
 
			{ 
 
				return false; 
 
			} 
 
			else return true; 
 
		}, 
 
		"<p class=\"error\">Please select one or more days!.</p>" 
 
	); 
 
*/
 

	
 
	jQuery.validator.addClassRules("selectRequired", {
 
		selectNone: true
 
	});
 
	
 
	jQuery.validator.addClassRules("daysRequire", {
 
		daysRequired: true
 
	});
 

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

	
 

	
 
	var classNum = 0;
 
	var sectionsOfClass = new Array(); // holds number of sections for each class
 

	
 
	//--------------------------------------------------
 
	// Returns the common inputs for each new section.
 
	//--------------------------------------------------
 
	function getCommonInputs(cnum) {
 
		var snum = sectionsOfClass[cnum];
 

	
 
		var result = '<td>\
 
				<select name="postData[' + cnum + '][' + snum + '][letter]"><option value="-">-</option><option value="A">A</option><option value="B">B</option>\
 
				<option value="C">C</option><option value="D">D</option><option value="E">E</option><option value="F">F</option><option value="G">G</option>\
 
				<option value="H">H</option><option value="I">I</option><option value="J">J</option><option value="K">K</option></select></td>\
 
				</select></td>\
 
			<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][start]"><option value="none"></option>\
 
				<option value="700">7:00 am</option><option value="730">7:30 am</option>\
 
				<option value="800">8:00 am</option><option value="830">8:30 am</option>\
 
				<option value="900">9:00 am</option><option value="930">9:30 am</option>\
 
				<option value="1000">10:00 am</option><option value="1030">10:30 am</option>\
 
				<option value="1100">11:00 am</option><option value="1130">11:30 am</option>\
 
				<option value="1200">12:00 pm</option><option value="1230">12:30 pm</option>\
 
				<option value="1300">1:00 pm</option><option value="1330">1:30 pm</option>\
 
				<option value="1400">2:00 pm</option><option value="1430">2:30 pm</option>\
 
				<option value="1500">3:00 pm</option><option value="1530">3:30 pm</option>\
 
				<option value="1600">4:00 pm</option><option value="1630">4:30 pm</option>\
 
				<option value="1700">5:00 pm</option><option value="1730">5:30 pm</option>\
 
				<option value="1800">6:00 pm</option><option value="1830">6:30 pm</option>\
 
				<option value="1900">7:00 pm</option><option value="1930">7:30 pm</option>\
 
				<option value="2000">8:00 pm</option><option value="2030">8:30 pm</option>\
 
				<option value="2100">9:00 pm</option></select></td>\
 
			<td><select class="selectRequired" name="postData[' + cnum + '][' + snum + '][end]"><option value="none"></option>\
 
				<option value="720">7:20 am</option><option value="750">7:50 am</option>\
 
				<option value="820">8:20 am</option><option value="850">8:50 am</option>\
 
				<option value="920">9:20 am</option><option value="950">9:50 am</option>\
 
				<option value="1020">10:20 am</option><option value="1050">10:50 am</option>\
 
				<option value="1120">11:20 am</option><option value="1150">11:50 am</option>\
 
				<option value="1220">12:20 pm</option><option value="1250">12:50 pm</option>\
 
				<option value="1320">1:20 pm</option><option value="1350">1:50 pm</option>\
 
				<option value="1420">2:20 pm</option><option value="1450">2:50 pm</option>\
 
				<option value="1520">3:20 pm</option><option value="1550">3:50 pm</option>\
 
				<option value="1620">4:20 pm</option><option value="1650">4:50 pm</option>\
 
				<option value="1720">5:20 pm</option><option value="1750">5:50 pm</option>\
 
				<option value="1820">6:20 pm</option><option value="1850">6:50 pm</option>\
 
				<option value="1920">7:20 pm</option><option value="1950">7:50 pm</option>\
 
				<option value="2020">8:20 pm</option><option value="2050">8:50 pm</option>\
 
				<option value="2120">9:20 pm</option></select></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][0]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][1]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][2]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][3]" value="1" /></td>\
 
			<td><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][4]" value="1" /></td>';
 
	
 
		return result;
 
	}
 

	
 
	//--------------------------------------------------
 
	// Adds a new class to the input.
 
	//--------------------------------------------------
 
	function addRow(){
 
		sectionsOfClass[classNum] = 0; // This is class 0, initialize at 0
 
		jQuery('#jsrows').append('<tr title="' + classNum + '" class="class class' + classNum + '"><td><input type="text" class="required defText" title="Class Name" name="postData[' + classNum + '][name]" /></td>' + getCommonInputs(classNum) + '<td><div class="addSection"><input type="button" value="Add section" /></div></td><td><div class="deleteClass"><input type="button" value="Delete" /></div></td></tr>');
 
		classNum++;
 
	};
 
	
 
	addRow(); // Add initial row
 

	
 
	//--------------------------------------------------
 
	// Adds a new class when the add class button is 
 
	// clicked.
 
	//--------------------------------------------------
 
	jQuery('#classage').click(function() {
 
		addRow();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected class from input.
 
	//--------------------------------------------------
 
	jQuery('.deleteClass').live('click', function() {
 
		jQuery('.class'+ jQuery(this).parent().parent().attr("title")).remove();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Deletes the selected section from the input.
 
	//--------------------------------------------------
 
	jQuery('.deleteSection').live('click', function() {
 
		sectionsOfClass[jQuery(this).parent().parent().attr("title")]--; // TODO: this only decreases the number of classes, so php should loop until this number of classes is found in the array
 
		jQuery(this).parent().parent().remove();
 
	});
 

	
 
	//--------------------------------------------------
 
	// Adds a section to the selected class.
 
	//--------------------------------------------------
 
	jQuery('.addSection').live('click', function() {
 
		sectionsOfClass[jQuery(this).parent().parent().attr("title")]++; // Increases sectionsOfClass[classNum]
 
		jQuery(this).parent().parent().after('<tr class="section class' + jQuery(this).parent().parent().attr("title") + '"><td class="none"></td>' + getCommonInputs(jQuery(this).parent().parent().attr("title")) + '<td></td><td><div class="deleteSection"><input type="button" value="Delete" /></div></td></tr>');
 
	});
 

	
 
	//--------------------------------------------------
 
	// Resets the form
 
	//--------------------------------------------------
 
	jQuery('#reset').click(function() {
 
		jQuery('#scheduleForm').resetForm();
 
    });
 

	
 
	//--------------------------------------------------
 
	// Default text stuff
 
	//--------------------------------------------------
 
    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();    
 

	
 
});
 

	
styles/general.css
Show inline comments
 
  body {
 
    width: 80%;
 
    margin:auto;
 
    font-family: sans-serif;
 
  }
 
  #header {
 
    text-align: left;
 
    background: rgb(220,220,220); /* IE fallback */
 
    background: rgba(200,200,200, .3);  
 
  }
 
  #footer {
 
    text-align: right;
 
    background: rgb(220,220,220); /* IE fallback */
 
    background: rgba(200,200,200, .3); 
 
	#savedBox {
 
		width: 15em;
 
		padding: 1em;
 
		border: 1px solid #000;
 
		float:right;
 
		background: #DDD;
 
		font-size: .8em;
 
	}
 
	#header {
 
		text-align: left;
 
		background: rgb(220,220,220); /* IE fallback */
 
		background: rgba(200,200,200, .3);  
 
	}
 
	#footer {
 
		text-align: right;
 
		background: rgb(220,220,220); /* IE fallback */
 
		background: rgba(200,200,200, .3); 
 
	}
 
	.defaultText { 
 
		width: 300px; }
 
	.defaultTextActive { 
 
		color: #a1a1a1; 
 
		font-style: italic; 
 
	}
 
	.error {
 
		color: #F00; /* For validation errors */
 
	} 
 
	.error p {
 
		padding: 0;
 
		margin: 0;
 
		font-size: .7em;
 
	}
 
	td.center {
 
		text-align:center;
 
	}
 
	.section:nth-child(even) {
 
		background: #DDDDDD;
 
	}
 
	.none {
 
		background: #fff;
 
	}
 
	.class {
 
		background: #99FF99;
 
	}
 
	#classage {
 
		float:left;
 
	}
 
	.paddingtop {
 
		padding: .5em;
 
		padding-top: .8em;
 
	}
0 comments (0 inline, 0 general)