Commit 0953b481 authored by Martins Berzins's avatar Martins Berzins
Browse files

Added delete event feature

parent a667c04d
......@@ -127,6 +127,20 @@ public class CalendarController {
return "redirect:/calendar";
}
@PostMapping(value="/calendar", params="action=delete")
public String eventDelete(Model model, Event event, String oldDate){
User currUser = findCurrentUser();
String[] dateTimeParts = oldDate.split("T");
LocalDate localDate = LocalDate.parse(dateTimeParts[0]);
LocalTime localTime = LocalTime.parse(dateTimeParts[1]);
Calendar c1 = calendarRepo.findByName(currUser.getActiveCalendar());
Event e1 = eventRepo.findByCalendarAndStartDateAndStartTime(c1, localDate, localTime);
eventRepo.delete(e1);
return "redirect:/calendar";
}
@GetMapping(value="/add-new-calendar")
public String addNewCalendarGet(Calendar calendar)
......
......@@ -136,8 +136,10 @@ a:hover {
<input name="startDate" id="newevDate" type="hidden" th:field="*{startDate}" />
<input name ="startTime" id="newevTime" type="hidden" th:field="*{startTime}" />
<br><hr>
<input onclick="editEvent()" id="editbtn" class="btn btn-lg btn-success btn-block" type="button" value="Edit"/>
<button name="action" class="btn btn-lg btn-primary btn-block" id="savebtn" style="visibility:hidden" type="submit" value="edit">Save</button>
<button name="action" class="btn btn-lg btn-success btn-block" id="savebtn" style="visibility:hidden" type="submit" value="edit">Save</button>
<button name="action" class="btn btn-lg btn-danger btn-block" id="deletebtn" type="submit" value="delete">Delete</button>
<input onclick="editEvent()" id="editbtn" class="btn btn-lg btn-primary btn-block" type="button" value="Edit"/>
</form>
</div>
</div>
......@@ -181,6 +183,9 @@ $(document).ready(function() {
document.getElementById("newevDescription").value = info.description
document.getElementById("evType").textContent = info.type
document.getElementById("evDate").textContent = info.start._i
var oldDate = document.getElementById("evDate")
document.getElementById("oldDateSbm").value = oldDate.textContent
}
......@@ -241,8 +246,7 @@ function editEvent(){
document.getElementById("editbtn").style.visibility = "hidden"
document.getElementById("savebtn").style.visibility = "visible"
document.getElementById("oldDateSbm").value = oldDate.textContent
}
</script>
</body>
......
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