Commit b00e4d86 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Merge branch 'master' into 'validation-error'

# Conflicts:
#   src/main/java/com/example/calendar/controller/CalendarController.java
parents d01524d5 06455d73
......@@ -117,8 +117,6 @@ public class CalendarController {
@GetMapping(value="/add-new-calendar")
public String addNewCalendarGet(Calendar calendar)
{
User currUser = findCurrentUser();
return "addNewCalendar";
}
......@@ -160,7 +158,6 @@ public class CalendarController {
ArrayList<Calendar> allUserCalendars = calendarRepo.findAllByUser(currUser);
JsonArray calendarArray = new JsonArray();
......@@ -169,31 +166,39 @@ public class CalendarController {
calendarJson.addProperty("title", allUserCalendars.get(i).getName());
calendarArray.add(calendarJson);
}
models.addAttribute("calendarList", calendarArray);
return "viewCalendars";
}
@PostMapping(value="/view-calendars", params="action=edit")
public String editCalendar(Model model, String calName){
Calendar c1 = calendarRepo.findByName(calName);
//TODO open page to edit name
return "ok";
public String editCalendar(Model model, String currName, String newName){
Calendar c1 = calendarRepo.findByName(currName);
c1.setName(newName);
calendarRepo.save(c1);
return "redirect:/view-calendars";
}
@PostMapping(value="/view-calendars", params="action=delete")
public String deleteCalendar(Model model, String calName){
Calendar c1 = calendarRepo.findByName(calName);
calendarRepo.delete(c1);
return "viewCalendars";
return "redirect:/view-calendars";
}
@PostMapping(value="/view-calendars", params="action=view")
public String viewCalendar(Model model, String calName){
Calendar c1 = calendarRepo.findByName(calName);
User currUser = findCurrentUser();
//currUser.setActiveCalendar(); TODO idk int of calendar, so change method?
ArrayList<Calendar> allUserCalendars = calendarRepo.findAllByUser(currUser);
int index = 0;
for (int i = 0; i < allUserCalendars.size(); i++){
if(allUserCalendars.get(i).getName() == calName) {
index = i;
}
}
currUser.setActiveCalendar(index);
userRepo.save(currUser);
return "ok";
return "redirect:/calendar";
}
}
......@@ -24,6 +24,9 @@
<li class="nav-item">
<a class="nav-link" href="/add-new-event">Add new event</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/view-calendars">View calendars</a>
</li>
</ul>
<form id="logoutForm" action="#" method="POST" th:action="@{/logout}" class="form-inline my-2 my-lg-0">
......
......@@ -10,6 +10,47 @@
<body>
<style>
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="#">SimpleCal</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
......@@ -21,8 +62,11 @@
<li class="nav-item">
<a class="nav-link" href="/calendar">Calendar</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Add new event <span class="sr-only">(current)</span></a>
<li class="nav-item">
<a class="nav-link" href="/add-new-event">Add new event</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">View calendars <span class="sr-only">(current)</span></a>
</li>
</ul>
......@@ -44,28 +88,56 @@
<div class="form-group">
<label for="chooseCalendarForm">Choose a calendar</label>
<select multiple class="form-control" id="calendarSelection" th:value="${calName}" name="calName">
<select onchange="change(event)" multiple class="form-control" id="calendarSelection" th:value="${calName}" name="calName">
</select>
</div>
<br>
<br> <button class="btn btn-lg btn-primary btn-block" type="submit" name="action" value="view">View</button>
<button class="btn btn-lg btn-success btn-block" type="submit" name="action" value="edit">Edit</button>
<br> <button id="viewbtn" class="btn btn-lg btn-primary btn-block" type="submit" name="action" value="view" disabled>View</button>
<input id="editbtn" class="btn btn-lg btn-success btn-block" type="button" value="Edit" disabled/>
<button id="delbtn" class="btn btn-lg btn-danger btn-block" type="submit" name="action" value="delete">Delete</button>
</form>
</div>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">&times;</span>
<form action="#" th:action="@{/view-calendars}" th:object="${model}" method="post">
Current name:
<input name="currName" type="text" id="currName" th:value="${currName}" readonly/>
New name:
<input name="newName" type="text" th:value="${newName}"/>
<br>
<hr> <button class="btn btn-sm btn-success btn-block" type="submit" name="action" value="edit">Save</button>
</form> </div>
</div>
<input type="hidden" id="calendars" th:value="${calendarList}"/>
<script>
function change(e) {
document.getElementById("viewbtn").disabled = false;
document.getElementById("editbtn").disabled = false;
document.getElementById("currName").value = e.target.value
}
var x = document.getElementById("calendarSelection");
var allCalendars = JSON.parse(document.getElementById("calendars").value)
if(allCalendars.length = 1) document.getElementById("delbtn").disabled = true;
var allCalendars = JSON.parse(document.getElementById("calendars").value)
if(allCalendars.length == 1) document.getElementById("delbtn").disabled = true;
for(let i = 0; i < allCalendars.length; i++){
option = document.createElement("option");
option.text = allCalendars[i].title;
......@@ -73,6 +145,35 @@ for(let i = 0; i < allCalendars.length; i++){
}
</script>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("editbtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment