Skip to content

Commit

Permalink
Introduced notification settings display bug
Browse files Browse the repository at this point in the history
Also tied notification settings gui to db notification settings
  • Loading branch information
arc12012 committed Apr 20, 2017
1 parent ef21eba commit ba78b24
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
37 changes: 31 additions & 6 deletions WebContent/html/webpages/profileSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="components/navbar.jsp"%>
</nav>
<%
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
%>
<!-- Sidebar -->
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
Expand Down Expand Up @@ -125,10 +128,12 @@
<!-- Notification Settings -->
<div class = "notificationContainer" style = "visibility: hidden;">
<!-- Where main user information is edited -->
<form action = "redirect/notificationSettingsRedirect.jsp" class = "infobar">
<form action = "redirect/notificationSettingsRedirect.jsp" class = "notificationForm" onsubmit="applyNotifications">
<h2>Email Notification Settings</h2>
<br>
<h4>Send me a messege when...</h4>
<input name="prefferedNotificationInteger" style="display: none;">
<input name="user" style="display: none;" value='"<%=self.getID()%>'>
<div style="float: left; margin-right: 10px;"><h5>Tickets are generated</h5></div>
<div style="float: right;">
<label class="switch">
Expand All @@ -154,9 +159,7 @@
</form>
</div>

<%
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
%>

<script>
var iconSelect;
Expand Down Expand Up @@ -195,7 +198,6 @@
document.getElementById('inputSSO').addEventListener('keyup',checkEmpty);
document.getElementById('closeBttn').addEventListener('click',function(){document.getElementById('missingcontent').style.display = "none";});
// Listeners for notification settings
document.getElementById('applyNotifications').addEventListener('click',applyNotifiationChanges);
document.getElementsByName('leaveMeAlone')[0].addEventListener('click',disableAllNotifications);
var typeTimer;
var doneTypingInterval = 2000 //ms
Expand Down Expand Up @@ -237,16 +239,39 @@
$('#missingcontent').css('display','block');
}
function applyNotifiationChanges(){
// Here is how the notification preferences integer works:
// Begin by converting to binary.
// First (least significant) bit: Ticket generation/order received email
// Second bit: Ticket approved email
// Third bit: Ticket rejected email
// If more email situations come up they can correspond to the fourth bit, fifth bit, etc.
// 1 means send email; 0 means do not send email
// This means determining what to set the new preference integer to is simply a matter of binary addition.
var bit1 = document.getElementById('notificationSlider1').checked ? 1 : 0;
var bit2 = document.getElementById('notificationSlider2').checked ? 1 : 0;
var bit3 = document.getElementById('notificationSlider3').checked ? 1 : 0;
var newNotificationPreferenceInteger = 1*bit1 + 2*bit2 + 4*bit3;
document.notificationForm.prefferedNotificationInteger.value=NotificationPreferenceInteger;
}
//populates form fields if info exists in db already
function populate(){
//get values from database
// Populationg profile settings
$('#inputName').val('<%=navname%>');
$('#inputSSO').val('<%=self.getID()%>');
$('#inputTelephone').val('<%=self.getPhone()%>');
$('#inputEmail').val('<%=self.getEmail()%>');
// -----------------Populating notification settings------------
// The notificationPreferences integer is explained in the applyNotifiationChanges() function above ^
var NotificationPreferenceInteger='<%=self.getNotificationPreferences()%>';
var bit1 = (NotificationPreferenceInteger/1)%2!=0;
var bit2 = (NotificationPreferenceInteger/2)%2!=0;
var bit3 = (NotificationPreferenceInteger/4)%2!=0;
document.getElementById("notificationSlider1").checked = (bit1==1);
document.getElementById("notificationSlider2").checked = (bit2==1);
document.getElementById("notificationSlider3").checked = (bit3==1);
}
function checkEmpty(){
Expand Down
33 changes: 33 additions & 0 deletions WebContent/html/webpages/redirect/notificationSettingsRedirect.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%@ page import = "database.*,entities.Device" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>Synchrony Financial</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel = "stylesheet" type = "text/css" href = "../../css/stylesheet.css">
<link rel = "shortcut icon" href = "../../imgs/synchrony-financial-logo-dlpx_1.ico">
</head>
<%
int user = Integer.parseInt(request.getParameter("prefferedNotificationInteger"));
int prefs = Integer.parseInt(request.getParameter("user"));
EmployeeQueries.updateNotificationPreferences(user,prefs);
%>
<script>
window.location.replace("../profileSettings.jsp");
</script>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="../components/navbar.jsp"%>
</nav>
</body>
</html>
10 changes: 10 additions & 0 deletions src/database/EmployeeQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,14 @@ public static User[] getAllUsers() throws SQLException, ClassNotFoundException{
connection.close();
return users;
}

public static void updateNotificationPreferences(int client, int preferences) throws SQLException, ClassNotFoundException{
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database, user, password);
Statement statement = connect.createStatement();
statement.executeQuery("UPDATE employee SET Notification_Preference = "+preferences+" WHERE Employee_ID = "+client+";");
statement.close();
connect.close();
}
}

0 comments on commit ba78b24

Please sign in to comment.