<html>
	<head>
		<title>Tempe Generator</title>
		<style>body{margin:0;padding:0px;
		font:16px/1.5 Helvetica,Arial,Verdana,sans-serif;}
		h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;padding:15px 0px 0px 20px;}
		strong{display:inline-block;width:65px;}
		input[type=text]{width:150px;}
		label {color:#666;}
		ul {margin-top:0px;}
		small {color:#888;font-size:11px;line-height:12px;padding-top:3px;display:inline-block;}
		#error {color:red;border:1px solid red;margin-bottom:15px;padding:10px;display:inline-block;}
		#info {color:green;border:1px solid green;margin-bottom:15px;padding:10px;display:inline-block;}
		.info {background:#ececeb;font-size:12px;padding:3px;border:1px solid #666;margin-top:10px;display:inline-block;}
		.del {color:red !important;text-decoration:none;font-size:16px;}
		hr {border:0px;border-top:1px solid #999;} 
		li {list-style-position:outside;margin-left:-20px;}
		#sidebar{width:160px;overflow:hidden;overflow-y:auto;background:#ececeb;padding:20px 0px 0px 20px;}
		.left {width:150px;background:#ececeb;border-right:1px solid #999;font-size:13px;}
		.dir {list-style-type:none;margin-left:-35px;list-style-position:outside;}
		.dir_content { display:none;margin-left:10px;list-style-position:outside; }
		.tdown {display:none;}
		.red {background:red;}
		.currentfile {background:#3066D0;padding-left:5px;margin-left:-40px;list-style-position:inside;color:white;}
		.currentfile a { color:white !important;}
		.unsaved { background: #D95653; }
		.warning { border:1px solid red; background: #D95653; color:white; text-align:center; }
		.warning hr { border-top:1px solid white; } 
		a { color:blue;text-decoration:none; }
		a:hover { text-decoration:underline; }
		.value_label,.date_option { font-size:11px; color: #999; padding:3px; border:1px dotted #ccc; margin:4px 4px 4px 0px; }
		.value_label input,.date_option input {
			border:1px solid #ccc; font-size:11px;
			padding:2px 3px;
		}
		</style>
	</head>
	<body>
		<h1>Tempe Generator</h1>
		<br/>
		<table cellpadding="0" cellspacing="0" border="0" style="border-top:1px solid #999;width:100%">
			<tr valign="top">
				<td class="left">
					<div id="sidebar">
						<a href="{% nav index %}">Generate Scaffold</a><br/>
						<a href="{% nav index %}auth">Generate Authentication</a>
						<br/><br/>
						<a href="{% nav index %}models">Generate Model</a><br/>
						<a href="{% nav index %}views">Generate View</a><br/>
						<a href="{% nav index %}controllers">Generate Controller</a><br/>
						<br/>
						Scaffolds
						<ul id="scaffold_list">
							{% if files.scaffolds.length > 0 %}
							{% for file in files.scaffolds %}
							<li {% if file.check == "changed" %}class="changed"{% endif %}>
								<a href="../../{{ file.name }}">{{ file.name }}</a> 
								<div style="display:inline-block">
								[{% if file.check == "unchanged" %}<a href="{% nav generator_del_scaffold %}?name={{ file.name }}">del</a> |
								{% endif %}<a href="{% nav generator_edit_scaffold %}?name={{ file.name }}">edit</a>]</div>
							</li>
							{% endfor %}
							{% endif %}
						</ul>
						Models
						<ul>
							{% if files.models.length > 0 %}
							{% for f in files.models %}
							<li {% if f == path.1 %}class="currentfile"{% endif %}>
								<a href="{% nav generator_edit %}?file=../../models/{{f}}">{{ f }}</a></li>
							{% endfor %}
							{% endif %}
						</ul>
						Views
						<ul>
							{% if files.views.length > 1 %}
							{% for file in files.views %}
							{% if file.length == 2 %}
								<li class="dir">
									<span class="triangle tleft" {% if file.name == path.1 %}style="display:none;"{% endif %}>&gt;&nbsp;</span>
									<span class="triangle tdown" {% if file.name == path.1 %}style="display:inline;"{% endif %}>v&nbsp;</span>
									<a id="{{file.name}}" class="dir_1" href="#{{ file.name }}">{{file.name}}</a> 
									<ul class="dir_content" {% if file.name == path.1 %}style="display:block;"{% endif %}>
										{% for f in file.files %}
											{% if f.length == 2 %}
												<li class="dir">
													<span class="triangle tleft" {% if file.name == path.1 %}{% if f.name == path.2 %}style="display:none;"{% endif %}{% endif %}>&gt;&nbsp;</span>
													<span class="triangle tdown" {% if file.name == path.1 %}{% if f.name == path.2 %}style="display:inline;"{% endif %}{% endif %}>v&nbsp;</span>
													<a id="{{f.name}}" class="dir_2" href="#{{ f.name }}">{{f.name}}</a>
													<ul class="dir_content" {% if file.name == path.1 %}{% if f.name == path.2 %}style="display:block;"{% endif %}{% endif %}>
														{% for sf in f.files %}
															<li {% if file.name == path.1 %}{% if f.name == path.2 %}{% if sf.name == path.3 %}class="currentfile"{% endif %}{% endif %}{% endif %}>
																<a href="{% nav generator_edit %}?file={{sf.path}}">{{ sf.name }}</a>
															</li>
														{% endfor %}
													</ul>
												</li>
											{% else %}
											<li {% if file.name == path.1 %}{% if f == path.2 %}class="currentfile"{% endif %}{% endif %}>
												<a href="{% nav generator_edit %}?file=../../views/{{file.name}}/{{f}}">{{ f }}</a></li>
											{% endif %}
										{% endfor %}
									</ul>
								</li>
							{% else %}
								<li {% if file == path.1 %}class="currentfile"{% endif %}>
									<a href="{% nav generator_edit %}?file=../../views/{{file}}">{{ file }}</a></li>
							{% endif %}
							{% endfor %}
							{% endif %}
						</ul> 
						Controllers 
						<ul>
							{% if files.controllers.length > 0 %}
							{% for f in files.controllers %}
							<li {% if f == path.1 %}class="currentfile"{% endif %}>
								<a href="{% nav generator_edit %}?file=../../controllers/{{f}}">{{ f }}</a></li>
							{% endfor %}
							{% endif %}
						</ul>
					</div>
				</td>
				<td style="padding:30px;" class="right">
				{% if flash.error != '' %}
				<div id="error">{{ flash.error }}</div><br/>
				{% endif %}
				{% if flash.info != '' %}
				<div id="info">{{ flash.info }}</div><br/>
				{% endif %}
				{% block content %}{% endblock %}
				</td>
			</tr>
		</table>
	</body>
	<script src="{% nav index %}jq.js"></script>
	<script>
	
		$(document).ready(function() {
			$("#sidebar").height($(window).height() - 108);
			
			$(window).resize(function() {
				$("#sidebar").height($(window).height() - 108);
			});
			$(".dir_1,.dir_2").click(function() {
				$(this).next().toggle();
				$(this).prev().toggle();
				$(this).prev().prev().toggle();
			});
		});
	</script>
	{% block script %}
	<script>
		var isCtrl = false;
		$(document).ready(function() {
			$("input[name=name]").focus();			
			$("#editor").show();
			
			$("#add").click(function() {
				var f = $(".field:last").clone();
				f.find('.value_label').remove();
				f.find('.del').css('visibility','visible');
				f.find('input[type=text]').val('')
				 .keydown(function(e) { 
				 	if (e.which == 38) { $(this).parent().parent().prev().find("input[type=text]").focus();	}
				 	if (e.which == 40) { $(this).parent().parent().next().find("input[type=text]").focus();	}
				 	if ($(this).val() == "" && e.which == 8) {
				 		$(this).parent().parent().prev().find("input[type=text]").focus();
						$(this).parent().parent().remove();  
						return false;
					} 
				  });
				
				f.find(".required").attr('checked',false);
				f.find(".required_hidden").val('false');
				f.find('.type').val('string');
				f.find('.required').attr('checked','');
				f.insertBefore(".addField");
				$(".field:last input[type=text]").focus();
			});
			
			$(".del").live("click",function() {
				$(this).parent().parent().remove();
			});
			
			$(".field input[type=text]").keydown(function(e) {
				 if (e.which == 40) { $(this).parent().parent().next().find("input[type=text]").focus(); }				
			});
			$(document).keyup(function (e) { if (e.ctrlKey) isCtrl=false; })
			.keydown(function (e) { if(e.ctrlKey) isCtrl=true; if(e.which == 77 && isCtrl == true) { $("#add").click(); return false;} });
			
		});
	</script>
	{% endblock %}
	{% block script2 %}
	{% endblock %}
</html>
