#*
 * 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/style.vm" )
		<link rel="stylesheet" type="text/css" href="${context}/css/jquery-ui-1.10.1.custom.css" />
		<link rel="stylesheet" type="text/css" href="${context}/css/jquery-ui.css" />
		
		<script type="text/javascript" src="${context}/js/jquery/jquery-1.9.1.js"></script>    
		<script type="text/javascript" src="${context}/js/jqueryui/jquery-ui-1.10.1.custom.js"></script>
		<script type="text/javascript" src="${context}/js/underscore-1.4.4-min.js"></script>
		<script type="text/javascript" src="${context}/js/namespace.js"></script>
		<script type="text/javascript" src="${context}/js/backbone-0.9.10-min.js"></script>
		<script type="text/javascript" src="${context}/js/jquery.simplemodal-1.4.4.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/nav.vm" )
		<div class="messaging"><p id="messageClose">X</p><p id="message"></p></div>  

		<div class="content">
		
#if($errorMsg)
		<div class="box-error-message">$errorMsg</div>
#else
#if($error_message != "null")
		<div class="box-error-message">$error_message</div>
#elseif($success_message != "null")
		<div class="box-success-message">$success_message</div>
#end
#end		
		
			<div id="all-scheduledFlows-content">
				<div class="section-hd">
					<h2>Scheduled Flows</h2>
				</div>
			</div>
			
			<div class="scheduledFlows">
				<table id="scheduledFlowsTbl">
					<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)
#foreach($sched in $schedules)
						<tr class="row" >

							<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 id="removeSchedBtn" onclick="removeSched(${sched.scheduleId})" >Remove Schedule</button></td>
							<td><button id="addSlaBtn" 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>

		<!-- modal content -->

		<div id="slaModalBackground" class="modalBackground2">
			<div id="sla-options" class="modal modalContainer2">
				<a href='#' title='Close' class='modal-close'>x</a>
					<h3>SLA Options</h3>
					<div>
						<ul class="optionsPicker">
							<li id="slaOptions">General SLA Options</li>
						</ul>
					</div>
					<div class="optionsPane">
						<div id="generalPanel" class="generalPanel panel">
							<div id="slaActions">
								<h4>SLA Alert Emails</h4>
								<dl>
									<dt >SLA Alert Emails</dt>
									<dd>
										<textarea id="slaEmails"></textarea>
									</dd>
								</dl>
							</div>
							<br></br>
							<div id="slaRules">
								<h4>Flow SLA Rules</h4>
								<div class="tableDiv">
									<table 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><a href="#">Add Row</a></td></tr>
										</tbody>
									</table>
								</div>
							
							</div>
						</div>
					</div>
					<div class="actions">
						<!--a class="yes btn1" id="remove-sla-btn" href="#">Remove SLA</a-->
						<a class="yes btn1" id="set-sla-btn" href="#">Set/Change SLA</a>
						<a class="no simplemodal-close btn3" id="sla-cancel-btn" href="#">Cancel</a>
					</div>
			</div>
		</div>
	</body>
</html>
