Skip to content

Commit

Permalink
Click on calendar prefills date in event wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Alf-Melmac committed May 16, 2021
1 parent 5169af8 commit 7eb644c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import static de.webalf.slotbot.util.permissions.ApplicationPermissionHelper.HAS_ROLE_CREATOR;
Expand Down Expand Up @@ -49,7 +50,7 @@ public ModelAndView getEventHtml() {
.toUri().toString()
//Remove parameters, because the calendar adds them by itself
.split("\\?")[0]);
mav.addObject("createEventUrl", linkTo(methodOn(EventWebController.class).getWizardHtml()).toUri().toString());
mav.addObject("createEventUrl", linkTo(methodOn(EventWebController.class).getWizardHtml(null)).toUri().toString());
mav.addObject(START_URL_STRING, START_URL);
mav.addObject("eventManageRoles", BotPermissionHelper.getEventManageApplicationRoles());

Expand All @@ -58,11 +59,12 @@ public ModelAndView getEventHtml() {

@GetMapping("/new")
@PreAuthorize(HAS_ROLE_CREATOR)
public ModelAndView getWizardHtml() {
public ModelAndView getWizardHtml(@RequestParam(required = false) String date) {
ModelAndView mav = new ModelAndView("eventWizard");

mav.addObject(START_URL_STRING, START_URL);
mav.addObject(EVENTS_URL_STRING, EVENTS_URL);
mav.addObject("date", date);
mav.addObject("eventTypes", eventTypeService.findAll());
mav.addObject("eventFieldDefaultsUrl", linkTo(methodOn(EventController.class).getEventFieldDefaults(null)).toUri().toString());
mav.addObject("postEventUrl", linkTo(methodOn(EventController.class).postEvent(null)).toUri().toString());
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/static/assets/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ $(function () {
const calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
locale: 'de',
/*headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},*/
eventSources: [
{
url: getEventsUrl,
Expand All @@ -31,7 +26,7 @@ $(function () {
// Allow event manage roles to click on the calendar to create event
if (eventManageRoles.includes(authentication.authorities.filter(authority => authority.authority.startsWith('ROLE_'))[0].authority)) {
calendar.on('dateClick', function (info) {
window.location.href = createEventUrl;
window.location.href = `${createEventUrl}?date=${info.dateStr}`;
});
}
calendar.render();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/eventWizard.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h3>Allgemeine Informationen</h3>
<label for="eventDate">Datum</label>
<div id="datepicker" class="input-group date" data-target-input="nearest">
<input id="eventDate" class="form-control datetimepicker-input" type="text"
data-dtokey="date" data-target="#datepicker" required>
data-dtokey="date" data-target="#datepicker" required th:value="${date}">
<div class="input-group-append" data-target="#datepicker"
data-toggle="datetimepicker">
<div class="input-group-text"><em class="far fa-calendar-alt"></em></div>
Expand Down

0 comments on commit 7eb644c

Please sign in to comment.