#*
 * Copyright 2012 LinkedIn Corp.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
*#

<!DOCTYPE html> 
<html lang="en">
	<head>

#parse("azkaban/webapp/servlet/velocity/style2.vm")
#parse("azkaban/webapp/servlet/velocity/javascript.vm")

		<script type="text/javascript" src="${context}/js/azkaban.table.sort.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban.nav.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban.main.view.js"></script>
		<script type="text/javascript">
			var contextURL = "${context}";
			var currentTime = ${currentTime};
			var timezone = "${timezone}";
			var errorMessage = null;
			var successMessage = null;
		</script>
	</head>
	<body>

#set($current_page="all")
#parse("azkaban/webapp/servlet/velocity/nav2.vm")

		<div class="container">

## Page error or success message.

#if($error_message != "null")
			<div class="alert alert-danger">$error_message</div>
#elseif($success_message != "null")
			<div class="alert alert-success">$success_message</div>
#end

## Alert message
## TODO: See if this can be removed.

			<div class="alert alert-dismissable alert-messaging" id="messaging">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<p id="messaging-message"></p>
			</div>

## Page Header and project search form.

			<div class="row">
				<div class="col-lg-6">
#if ($allProjects)
					<h1>All Projects</h1>
					<p>My Projects</p>
#else
					<h1>My Projects</h1>
					<p>All Projects</p>
#end
				</div>
				<div class="col-lg-4">	
					<form id="search-form" method="get" class="form-inline" role="form">
						<input type="hidden" value="doaction" value="search">
#if ($allProjects)
						<input type="hidden" name="all" value="true">				
#end
						<div class="input-group">
							<input id="search-textbox" type="text" placeholder="Project name containing..." value=#if($search_term) ${search_term} #else "" #end class="form-control" name="searchterm">
							<span class="input-group-btn">
								<button class="btn btn-primary">Quick Search</button>
							</span>
						</div>
					</form>
				</div>
				<div class="col-lg-2" id="create-project">
#if (!$hideCreateProject)
					<button type="button" id="create-project-btn" class="btn btn-success">Create Project</button>
#end
				</div>
			</div>
			<hr>

## Table of projects.

			<div class="row">
				<div class="col-lg-12">
					<table class="table table-striped" id="all-jobs">
						<thead>
							<tr>
								<th class="tb-name">Name</th>
								<th class="tb-up-date">Modified Date</th>
								<th class="tb-owner">Modified By</th>
							</tr>
						</thead>
						<tbody>
#if(!$projects.isEmpty())
	#foreach($project in $projects)
							<tr>
								<td id="${project.name}" class="tb-name project-expand expanded">
									<span>+</span>
									<a href="${context}/manager?project=${project.name}">$project.name</a>
								</td>
								<td class="tb-up-date">$utils.formatDate($project.lastModifiedTimestamp)</td>
								<td class="tb-owner">$project.lastModifiedUser</td>
							</tr>
							<tr id="${project.name}-child" style="display: none;">
								<td colspan="3">
									<table class="table table-bordered">
										<thead>
											<tr>
												<th class="tb-name">Flows</th>
											</tr>
										</thead>
										<tbody id="${project.name}-tbody">
										</tbody>
									</table>
								</td>
							</tr>
	#end
#else
							<tr>
								<td colspan="3">No viewable projects found.</td>
							</tr>
#end
						</tbody>
					</table>
				</div>
			</div>

## Modal dialog to be displayed to create a new project.

			<div class="modal fade" id="create-project-modal">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title">Create Project</h4>
						</div>
						<div class="modal-body">
							<div class="alert alert-danger" id="modal-error-msg">$error_msg</div>
							<fieldset class="form-horizontal">
								<div class="form-group">
									<label for="path" class="col-sm-2 control-label">Name</label>
									<div class="col-sm-10">
										<input id="path" name="project" type="text" class="form-control" placeholder="Project name">
									</div>
								</div>
								<div class="form-group">
									<label for="description" class="col-sm-2 control-label">Description</label>
									<div class="col-sm-10">
										<textarea id="description" name="description" rows="2" cols="40" class="form-control" placeholder="Project description"></textarea>
									</div>
								</div>
							</fieldset>
						</div>
						<div class="modal-footer">
							<input name="action" type="hidden" value="create">
							<input name="redirect" type="hidden" value="$!context/">
							<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
							<button type="button" class="btn btn-primary" id="create-btn">Create Project</button>
						</div>
					</div>
				</div>
			</div>

## Modal dialog to be displayed when the user sesion is invalid. -->
			
			<div class="modal fade" id="invalid-session-modal">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title">Invalid Session</h4>
						</div>
						<div class="modal-body">
							<p>Session has expired. Please re-login.</p>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-primary" id="login-btn">Re-login</button>
						</div>
					</div>
				</div>
			</div>

#parse("azkaban/webapp/servlet/velocity/footer.vm")

		</div><!-- /container -->
	</body>
</html>


