202 lines
No EOL
5 KiB
Text
202 lines
No EOL
5 KiB
Text
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
|
pageEncoding="UTF-8"%>
|
|
<%@ page import="java.util.Map"%>
|
|
<%@ page import="java.util.HashMap"%>
|
|
<%@ page import="java.util.List"%>
|
|
<%@ page import="java.util.ArrayList"%>
|
|
<%@ page import="java.util.Set"%>
|
|
<%@ page import="java.util.HashSet"%>
|
|
<%@ page import="java.util.Collections"%>
|
|
<%@ page import="java.util.Comparator"%>
|
|
<%@ page import="com.stephenschafer.email.Mapping"%>
|
|
<%@ page import="com.stephenschafer.email.Util"%>
|
|
<%@ page import="com.stephenschafer.email.User"%>
|
|
<%
|
|
final String address = request.getParameter("address");
|
|
final boolean mobile = "true".equalsIgnoreCase(request.getParameter("mobile"));
|
|
final User user = Util.identify(session);
|
|
if (user == null) {
|
|
session.setAttribute("return-servlet-path", request.getServletPath());
|
|
session.setAttribute("return-query-string", request.getQueryString());
|
|
response.sendRedirect("login.jsp");
|
|
return;
|
|
}
|
|
Util.updateSession(session);
|
|
@SuppressWarnings("unchecked")
|
|
final List<String> targetList = (List<String>) session.getAttribute("target-list");
|
|
final Mapping mapping = address == null ? null : Util.getMapping(address);
|
|
final String username = user.getName();
|
|
final String selectedTarget = "sandy".equals(username) ? "sandy" : "elephant".equals(username) ? "steve" : "";
|
|
final String header = mobile ? selectedTarget : "Mapping";
|
|
final String targetDisplay = mobile ? "display: none" : "";
|
|
final String disabledAttr = mapping == null ? "" : mapping.isDisabled() ? " checked" : "";
|
|
final String disableDisplay = mobile ? "display: none" : "";
|
|
final String descriptionValue = mapping == null ? "" : mapping.getDisplayDescription();
|
|
final String dateValue = mapping == null ? "" : mapping.getFormattedDate();
|
|
%>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>Edit Mapping</title>
|
|
<style>
|
|
body {
|
|
font-family: sans-serif;
|
|
font-size: 10pt;
|
|
color: #333;
|
|
}
|
|
table {
|
|
font-family: inherit;
|
|
font-size: inherit;
|
|
}
|
|
table.mapping {
|
|
}
|
|
table.mapping tr.mapping {
|
|
}
|
|
table.mapping tr.mapping td:first-of-type {
|
|
padding-right: 10px;
|
|
white-space: nowrap;
|
|
}
|
|
@media only screen and (min-resolution:2x) {
|
|
body {
|
|
font-size: 300%;
|
|
}
|
|
h1 {
|
|
display: none;
|
|
}
|
|
button {
|
|
margin-bottom: .5em;
|
|
font-size: inherit;
|
|
}
|
|
input {
|
|
display: block;
|
|
margin-bottom: .5em;
|
|
font-size: inherit;
|
|
}
|
|
input[type="checkbox"] {
|
|
width: 1em;
|
|
height: 1em;
|
|
}
|
|
select {
|
|
display: block;
|
|
margin-bottom: .5em;
|
|
font-size: inherit;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: .5em;
|
|
font-size: inherit;
|
|
}
|
|
}
|
|
</style>
|
|
<script>
|
|
|
|
function targetChanged() {
|
|
var targetSelect = document.mapping.target;
|
|
var emailInput = document.mapping["email-address"];
|
|
var request = new XMLHttpRequest();
|
|
request.open("POST", "new-alias", true);
|
|
request.onreadystatechange = function() {
|
|
if(request.readyState != 4) {
|
|
return;
|
|
}
|
|
if(request.status != 200) {
|
|
alert("Http error " + request.status + " on " + request.statusText);
|
|
debugger;
|
|
return;
|
|
}
|
|
try {
|
|
var response = JSON.parse(request.responseText);
|
|
if(response.error != null) {
|
|
}
|
|
else {
|
|
emailInput.value = response.value;
|
|
}
|
|
}
|
|
catch(e) {
|
|
debugger;
|
|
}
|
|
};
|
|
request.setRequestHeader("Content-Type", "application/json");
|
|
request.setRequestHeader("Accept", "application/json");
|
|
request.send(targetSelect.value);
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body onload="targetChanged()">
|
|
<h1><%=header %></h1>
|
|
<form action="post-mapping" method="post" name="mapping">
|
|
<input type="hidden" name="new" value="<%=mapping == null ? "true" : "false" %>"/>
|
|
<input type="hidden" name="mobile" value="<%=mobile ? "true" : "false" %>"/>
|
|
<table class="mapping">
|
|
|
|
<tr style="<%=targetDisplay%>" >
|
|
<td>Target</td>
|
|
<td>
|
|
<select name="target" onchange="targetChanged()">
|
|
<%
|
|
for(final String target : targetList) {
|
|
final boolean selected = mapping != null ? target.equals(mapping.getTarget()) : selectedTarget.equals(target);
|
|
final String selectedAttr = selected ? " selected" : "";
|
|
%> <option value="<%=target%>"<%=selectedAttr%>><%=target%></option>
|
|
<%
|
|
}
|
|
%> </select>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>Email Address</td>
|
|
<td>
|
|
<%
|
|
if(mapping == null) {
|
|
%> <input type="text" name="email-address" value="" size="24"/>
|
|
<%
|
|
}
|
|
else {
|
|
%> <input type="hidden" name="email-address" value="<%=mapping.getAddress()%>" size="24"/>
|
|
<%=mapping.getAddress()%>
|
|
<%
|
|
}
|
|
%></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>Description</td>
|
|
<td>
|
|
<input type="text" name="description" value="<%=descriptionValue %>" size="24"/>
|
|
</td>
|
|
</tr>
|
|
|
|
<%
|
|
if(mapping != null) {
|
|
%><tr>
|
|
<td>Date</td>
|
|
<td>
|
|
<input type="text" name="date" value="<%=dateValue %>" size="10"/>
|
|
</td>
|
|
</tr>
|
|
|
|
<%
|
|
}
|
|
%><tr style="<%=disableDisplay %>">
|
|
<td>Disabled</td>
|
|
<td>
|
|
<input type="checkbox" name="disabled" value="true"<%=disabledAttr %>/>
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
<div class="buttons">
|
|
<button type="submit">Submit</button>
|
|
<%
|
|
if(!mobile) {
|
|
%> <button type="button" onclick="window.location.href='index.jsp'">List</button>
|
|
<button type="button" onclick="window.history.back()">Back</button>
|
|
<%
|
|
}
|
|
%></div>
|
|
</form>
|
|
</body>
|
|
</html> |