[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX][UX] Calendar: fix date offset bug and enable multi-day range creation
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69a9956dd5ab_3b1887ec13674@gitlab-sidekiq-low-urgency-cpu-bound-v2-6bcf45fb85-lfdcg.mail> |
Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
2d801763 by MAGENE Sem Joel at 2026-03-05T14:29:18+00:00
[FIX][UX] Calendar: fix date offset bug and enable multi-day range creation
---
* [FIX][UX] Calendar: fix date offset bug and enable multi-day range creation
See merge request tikiwiki/tiki!9605
- - - - -
3 changed files:
- lib/core/Services/Calendar/Controller.php
- src/js/jquery-tiki/tiki-calendar.js
- templates/calendar/edit_item.tpl
Changes:
=====================================
lib/core/Services/Calendar/Controller.php
=====================================
@@ -385,10 +385,22 @@ class Services_Calendar_Controller extends Services_Calendar_BaseController
// set up default start and end
$dateNow->setTZbyID($displayTimezone);
- if ($input->prefill_start->int()) {
- $start = $input->prefill_start->int();
- if ($input->prefill_end->int()) {
- $end = $input->prefill_end->int();
+ if ($input->prefill_start->text()) {
+ $prefillStart = $input->prefill_start->text();
+ $prefillEnd = $input->prefill_end->text();
+
+ $tikidate = new TikiDate();
+ $tikidate->setTZbyID($displayTimezone);
+
+ $tikidate->setDate($prefillStart, $displayTimezone);
+ $start = $tikidate->getTime();
+ if ($prefillEnd && strtotime($prefillEnd) !== false) {
+ $tikidate->setDate($prefillEnd, $displayTimezone);
+ $end = $tikidate->getTime();
+ // subtract 1 sec to make it inclusive
+ if (strlen($prefillEnd) <= 10 || strpos($prefillEnd, '00:00:00') !== false) {
+ $end -= 1;
+ }
$duration = $end - $start;
} else {
$duration = 60 * 60;
@@ -408,8 +420,8 @@ class Services_Calendar_Controller extends Services_Calendar_BaseController
} else {
$hour = $dateNow->date->format('H');
if ($input->offsetExists('todate')) {
- // set the correct day clicked on
- $dateNow->setDate($input->todate->int());
+ $dateNow->setTZbyID($displayTimezone);
+ $dateNow->setDate($input->todate->text(), $displayTimezone);
$hour = $dateNow->date->format('H');
}
$tz = date_default_timezone_get();
@@ -580,7 +592,7 @@ class Services_Calendar_Controller extends Services_Calendar_BaseController
'modal' => $input->modal->int(),
'displayTimezone' => $displayTimezone,
'timezones' => $timezones,
- 'prefilled' => $input->prefill_start->int() ? true : false,
+ 'prefilled' => $input->prefill_start->text() ? true : false,
// related tracker items
'trackerItems' => ! empty($trackerItems) ? $trackerItems : [],
];
=====================================
src/js/jquery-tiki/tiki-calendar.js
=====================================
@@ -12,10 +12,41 @@ $.fn.setupEventCalendar = function (
returnUrl = "tiki-calendar.php",
associatedWikiPage = null
) {
+ let isOpeningModal = false;
this.each(function () {
const calendarEl = document.getElementById(targetId);
$(calendarEl).tikiModal(tr("Loading..."));
-
+ const openNewEventModal = (startStr, endStr = null) => {
+ if (isOpeningModal) return;
+ const countCals = $("#filtercal ul li").length;
+ if (countCals >= 1 || targetId != "calendar") {
+ isOpeningModal = true;
+ $(calendarEl).tikiModal(" "); // Use the container for the loading overlay
+ const params = {
+ prefill_start: startStr,
+ modal: 1,
+ return_url: returnUrl,
+ };
+ if (endStr) {
+ params.prefill_end = endStr;
+ }
+ $.openModal({
+ title: tr("New event"),
+ size: "modal-lg",
+ remote: $.service("calendar", "edit_item", params),
+ open: function () {
+ $(calendarEl).tikiModal();
+ $("form:not(.no-ajax)", this).addClass("no-ajax");
+ isOpeningModal = false;
+ },
+ error: function () {
+ isOpeningModal = false;
+ },
+ });
+ } else {
+ location.href = "tiki-calendar.php";
+ }
+ };
calendarContainer[0] = createCalendar(document.getElementById(targetId), [DayGrid, TimeGrid, Interaction, List], {
eventTimeFormat: {
hour: "numeric",
@@ -32,7 +63,12 @@ $.fn.setupEventCalendar = function (
},
editable: true,
selectable: true,
+ unselectAuto: true,
eventSources: [{ url: urlEventSource }],
+ select: function (info) {
+ // Handle Drag Selection
+ openNewEventModal(info.startStr, info.endStr);
+ },
slotMinTime: eventCalendarParams.minHourOfDay,
slotMaxTime: eventCalendarParams.maxHourOfDay,
nowIndicator: true,
@@ -224,27 +260,13 @@ $.fn.setupEventCalendar = function (
}
},
dateClick: function (info) {
- // Handle date clicks in EventCalendar.
- // If a date number is clicked, switch to Day View for the selected date.
- // If any other part of the date cell is clicked, open a form to create a new event.
if (info.jsEvent.target.classList.contains("ec-day-head")) {
calendarContainer[0].changeView("timeGridDay", info.dateStr);
+ // Prevent 'select' from firing if we are just switching views
+ calendarContainer[0].unselect();
} else {
- let $this = $(info.dayEl).tikiModal(" ");
- const countCals = $("#filtercal ul li").length;
- if (countCals >= 1 || targetId != "calendar") {
- $.openModal({
- title: tr("New event"),
- size: "modal-lg",
- remote: $.service("calendar", "edit_item", { todate: info.date.toUnix(), modal: 1, return_url: returnUrl }),
- open: function () {
- $this.tikiModal();
- $("form:not(.no-ajax)", this).addClass("no-ajax"); // Remove default ajax handling, we replace it
- },
- });
- } else {
- location.href = "tiki-calendar.php";
- }
+ // Handle Single Click
+ openNewEventModal(info.dateStr);
}
},
eventResize: function (info) {
=====================================
templates/calendar/edit_item.tpl
=====================================
@@ -102,24 +102,6 @@
</div>
</div>
- {if $prefilled}
- <input type="hidden" name="calitem[end_or_duration]" value="end" id="end_or_duration">
- <input type="hidden" name="calitem[start]" value="{$calitem.start}">
- <input type="hidden" name="calitem[end]" value="{$calitem.end}">
- <input type="hidden" name="exact_start_end" value="1">
- <div class="row mt-md-3 mb-3 date">
- <label class="col-form-label col-sm-3">{tr}Start{/tr}</label>
- <div class="col-sm-7 start">
- {$calitem.start|tiki_short_datetime} {$displayTimezone}
- </div>
- </div>
- <div class="row mt-md-3 mb-3 date">
- <label class="col-form-label col-sm-3">{tr}End{/tr}</label>
- <div class="col-sm-7 end">
- {$calitem.end|tiki_short_datetime} {$displayTimezone}
- </div>
- </div>
- {else}
<div class="mb-3 row">
<label class="col-form-label col-sm-3">{tr}Recurrence{/tr}</label>
<div class="col-sm-9">
@@ -211,7 +193,6 @@
</span>
{/if}
</div>
- {/if}
<div class="mb-3 row">
<label class="col-form-label col-sm-3">{tr}Description{/tr}</label>
<div class="col-sm-9">
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2d80176387f7938848954df01ebce325707db26e
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2d80176387f7938848954df01ebce325707db26e
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs