#*
 * 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>
	<head>

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

		<link rel="stylesheet" type="text/css" href="${context}/css/jquery-ui-1.10.1.custom.css" />
		
		<script type="text/javascript" src="${context}/js/jqueryui/jquery-ui-1.10.1.custom.js"></script>
		<script type="text/javascript" src="${context}/js/jqueryui/jquery-ui-timepicker-addon.js"></script> 
		<script type="text/javascript" src="${context}/js/jqueryui/jquery-ui-sliderAccess.js"></script>
		<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.scheduled.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="schedule")
#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>

	## Page header.

			<div class="page-header">
				<h1>Scheduled Flows</h1>
			</div>

	## Page content.

			<div class="row">
				<div class="col-lg-12">
					<table id="scheduledFlowsTbl" class="table table-striped">
						<thead>
							<tr>
								<!--th class="execid">Execution Id</th-->
								<th>ID</th>
								<th>Flow</th>
								<th>Project</th>
								<th>Submitted By</th>
								<th class="date">First Scheduled to Run</th>
								<th class="date">Next Execution Time</th>
								<th class="date">Repeats Every</th>
								<th>Has SLA</th>
								<th colspan="2" class="action ignoresort">Action</th>
							</tr>
						</thead>
						<tbody>
	#if(!$schedules.isEmpty())
		#foreach($sched in $schedules)
							<tr>
								<td>${sched.scheduleId}</td>
								<td class="tb-name">
									<a href="${context}/manager?project=${sched.projectName}&flow=${sched.flowName}">${sched.flowName}</a>
								</td>
								<td>
									<a href="${context}/manager?project=${sched.projectName}">${sched.projectName}</a>
								</td>
								<td>${sched.submitUser}</td>
								<td>$utils.formatDateTime(${sched.firstSchedTime})</td>
								<td>$utils.formatDateTime(${sched.nextExecTime})</td>
								<td>$utils.formatPeriod(${sched.period})</td>
								<td>#if(${sched.slaOptions}) true #else false #end</td>
								<td><button type="button" id="removeSchedBtn" class="btn btn-sm btn-danger" onclick="removeSched(${sched.scheduleId})" >Remove Schedule</button></td>
								<td><button type="button" id="addSlaBtn" class="btn btn-sm btn-primary" onclick="slaView.initFromSched(${sched.scheduleId}, '${sched.flowName}')" >Set SLA</button></td>
							</tr>

		#end
	#else
							<tr>
								<td class="last">No scheduled flow found.</td>
							</tr>
	#end
						</tbody>
					</table>
				</div>
			</div><!-- /row -->

## Set SLA modal.

			<div class="modal modal-wide fade" id="sla-options">
				<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">SLA Options</h4>
						</div>
						<div class="modal-body">
							<h4>SLA Alert Emails</h4>
							<fieldset>
								<div class="form-group">
									<label>SLA Alert Emails</label>
									<textarea id="slaEmails" class="form-control"></textarea>
								</div>
							</fieldset>
							<h4>Flow SLA Rules</h4>
							<table class="table table-striped" id="flowRulesTbl">
								<thead>
									<tr>
										<th>Flow/Job</th>
										<th>Sla Rule</th>
										<th>Duration</th>
										<th>Email Action</th>
										<th>Kill Action</th>
									</tr>
								</thead>
								<tbody>
									<tr id="addRow">
										<td id="addRow-col" colspan="5">
											<span class="addIcon"></span>
											<button type="button" class="btn btn-xs btn-success">Add Row</button>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
							<!--<button type="button" class="btn btn-danger" id="remove-sla-btn">Remove SLA</button>-->
							<button type="button" class="btn btn-primary" id="set-sla-btn">Set/Change SLA</button>
						</div>
					</div>
				</div>
			</div>
#end

		</div>
	</body>
</html>
