#*
 * 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.ajax.utils.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban.nav.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban.project.view.js"></script>
		<script type="text/javascript">
			var contextURL = "${context}";
			var currentTime = ${currentTime};
			var timezone = "${timezone}";
			var errorMessage = null;
			var successMessage = null;

			var projectId = ${project.id};
			var execAccess = ${exec};
			var projectName = "$project.name";
		</script>
	</head>
	<body>

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

		<div class="container">

## Page error or success message.

#if ($errorMsg)
			<div class="panel panel-danger">
				<div class="panel-heading">Error</div>
				<div class="panel-body">
					$errorMsg
				</div>
			</div>
#else
	#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

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

			<div class="page-header">
				<h1><a href="${context}/manager?project=${project.name}">Project <small>$project.name</small></a></h1>
				<p>$project.description</p>
			</div>

			<div class="row">
				<div class="col-lg-8">
					<div class="panel panel-default">
						<div class="panel-heading">Flows</div>
						<div class="panel-body">

	#if ($flows)
		#foreach ($flow in $flows)
							<div class="panel panel-info" flow="${flow.id}" project="${project.name}">
								<div class="panel-heading" id="${flow.id}">
									<span>+</span>
									<a href="${context}/manager?project=${project.name}&flow=${flow.id}">${flow.id}</a>
								</div>
								<div class="panel-body">
									<div class="panel panel-default">
										<div class="panel-heading">Jobs</div>
										<div class="panel-body" id="${flow.id}-body">
										</div>
									</div>
								</div>
								<div class="panel-footer">
			#if (${exec})
									<button type="button" class="btn btn-primary" flowId="${flow.id}">Execute Flow</button>
			#end
								</div>
							</div>
		#end
	#else
							<p>No flows uploaded to this project</p>
	#end
						</div>
					</div>
				</div><!-- /col-lg-8 -->

				<div class="col-lg-4">
					<div class="well">
						<table>
							<tbody>
								<tr><th>Name:</td><td>$project.name</td></tr>
								<tr><th>Created Date:</td><td>$utils.formatDate($project.createTimestamp)</td></tr>
								<tr><th>Modified Date:</td><td>$utils.formatDate($project.lastModifiedTimestamp)</td></tr>
								<tr><th>Modified by:</td><td>$project.lastModifiedUser</td></tr>
							</tbody>
						</table>

						<hr>

						<table>
							<tbody>
								<tr><th>Project Admins:</td><td>$admins</td></tr>
								<tr><th>Your Permissions:</td><td>$userpermission.toString()</td></tr>
							</tbody>
						</table>
					</div>

					<div class="well">
						<button id="project-upload-btn" class="btn btn-primary">Upload</button>
						<button id="project-delete-btn" class="btn btn-danger">Delete Project</button>
					</div>

					<div class="well well-sm">
						<ul class="nav nav-pills nav-stacked">
							<li class="active"><a href="${context}/manager?project=${project.name}">Project</a></li>
						<li><a id="project-permission-btn" href="${context}/manager?project=${project.name}&permissions">Permissions</a></li>
	#if ($admin)
							<li><a id="project-logs-btn" href="${context}/manager?project=${project.name}&logs">Project Logs</a></li>
	#end
						</ul>
					</div>
				</div><!-- /col-lg-4 -->
			</div><!-- /row -->

## Upload project modal

			<div class="modal fade" id="upload-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">Upload Project Files</h4>
						</div>
						<div class="modal-body">
							<div class="alert alert-danger" id="modal-error-msg">$error_msg</div>
							<form id="upload-form" enctype="multipart/form-data" method="post" action="$!context/manager">
								<fieldset class="form-horizontal">
									<div class="form-group">
										<label for="path" class="col-sm-2 control-label">Job Archive</label>
										<div class="col-sm-10">
											<div class="fileinput fileinput-new" data-provides="datainput">
												<div class="form-control uneditable-input span3" data-trigger="fileinput">
													<i class="glyphicon glyphicon-file fileinput-exists"></i>
													<span class="fileinput-filename"></span>
												</div>
												<span class="input-group-addon btn btn-default btn-file">
													<span class="fileinput-new">Select file</span>
													<span class="fileinput-exists">Change</span>
													<input type="file" name="...">
												</span>
												<a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
											</div>
										</div>
									</div>
								</fieldset>
							</form>
						</div>
						<div class="modal-footer">
							<input type="hidden" name="project" value="$project.name">
							<input type="hidden" name="action" value="upload">
							<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
							<button type="button" class="btn btn-primary" id="upload-btn">Upload</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>

## Delete project modal.
			
			<div class="modal fade" id="delete-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">Delete Project</h4>
						</div>
						<div class="modal-body">
							<p>Warning: This project will be deleted and may not be recoverable.</p>
						</div>
						<div class="modal-footer">
							<input type="hidden" name="project" value="$project.name">
							<input type="hidden" name="delete" value="true">
							<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
							<button type="button" class="btn btn-primary" id="delete-btn">Yes</button>
						</div>
					</div>
				</div>
			</div>

	#parse ("azkaban/webapp/servlet/velocity/flowexecutionpanel2.vm")
	#parse ("azkaban/webapp/servlet/velocity/messagedialog2.vm")
#end

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

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

