#*
 * 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/style.vm")
#parse ("azkaban/webapp/servlet/velocity/javascript.vm")

		<link rel="stylesheet" type="text/css" href="${context}/css/bootstrap-datetimepicker.css" />
		
		<script type="text/javascript" src="${context}/js/moment.min.js"></script>
		<script type="text/javascript" src="${context}/js/bootstrap-datetimepicker.min.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban/view/table-sort.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban/view/scheduled.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")

#if ($errorMsg)
  #parse ("azkaban/webapp/servlet/velocity/errormsg.vm")
#else

	## Page header.

		<div class="az-page-header">
			<div class="container-full">
        <h1><a href="${context}/schedule">Scheduled Flows</a></h1>
			</div>
		</div>

	## Page content.

		<div class="container-full">

  #parse ("azkaban/webapp/servlet/velocity/alerts.vm")
      
      <div class="row">
				<div class="col-xs-12">
          <table id="scheduledFlowsTbl" class="table table-striped table-condensed table-bordered table-hover">
            <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 colspan="10">No scheduled flow found.</td>
              </tr>
	#end
            </tbody>
          </table>
				</div><!-- /col-xs-12 -->
			</div><!-- /row -->

  ## Set SLA modal.

			<div class="modal modal-wide" 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>
		</div>
#end
	</body>
</html>
