[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Fix module calendar_new and wikiplugin-calendar feature
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68f232bf372f_2c8839207739b@gitlab-sidekiq-low-urgency-cpu-bound-v2-66ccc79dd4-q57jt.mail> |
Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
bb03f5a8 by franck franck kalunga at 2025-10-17T12:04:44+00:00
[FIX] Fix module calendar_new and wikiplugin-calendar feature
---
* [FIX] Fix module calendar_new and wikiplugin-calendar feature
See merge request tikiwiki/tiki!8779
- - - - -
7 changed files:
- lib/calendar/calendarlib.php
- lib/wiki-plugins/wikiplugin_calendar.php
- modules/mod-func-calendar_new.php
- src/js/jquery-tiki/tiki-calendar.js
- templates/modules/mod-calendar_new.tpl
- templates/tiki-calendar.tpl
- templates/wiki-plugins/wikiplugin_calendar.tpl
Changes:
=====================================
lib/calendar/calendarlib.php
=====================================
@@ -144,6 +144,7 @@ class CalendarLib extends TikiLib
{
global $prefs;
$canEditAnything = false;
+ $calendars = [];
foreach ($rawcalsData as $calendar) {
$calendar['perms'] = Perms::get([ 'type' => 'calendar', 'object' => $calendar['calendarId']]);
$calendars[$calendar['calendarId']] = $calendar;
@@ -167,6 +168,7 @@ class CalendarLib extends TikiLib
'slotDuration' => '00:' . str_pad($prefs['calendar_timespan'], 2, '0', STR_PAD_LEFT),
'initialDate' => date("Y-m-d"),
'canEditAnything' => $canEditAnything,
+ 'calendars' => $calendars,
];
}
=====================================
lib/wiki-plugins/wikiplugin_calendar.php
=====================================
@@ -79,7 +79,7 @@ function wikiplugin_calendar_info()
function wikiplugin_calendar($data, $params)
{
- global $prefs, $tiki_p_admin, $tiki_p_view_calendar;
+ global $prefs, $tiki_p_admin, $tiki_p_view_calendar, $tikiroot;
global $dc, $user;
$smarty = TikiLib::lib('smarty');
@@ -101,7 +101,7 @@ function wikiplugin_calendar($data, $params)
$pluginCalendarIds = implode(',', $params['calIds']);
$rawcals = $calendarlib->list_calendars();
-
+ $focusdate = date("Y-m-d");
switch ($params['viewmode']) {
case 'week':
$initialView = 'timeGridWeek';
@@ -119,10 +119,10 @@ function wikiplugin_calendar($data, $params)
$viewend = $viewstart + 90 * 86400 - 1; // 1 month approx
$defaultCalendarId = $params['calIds'][0];
- $calendars = [];
$calendarInitialParams = $calendarlib->generalParamsOfCalendar($rawcals['data']);
$calendarInitialParams['initialView'] = $initialView;
+ $calendars = $calendarInitialParams['calendars'];
$smarty->assign(
'eventCalendarParams',
$calendarInitialParams
@@ -137,14 +137,15 @@ function wikiplugin_calendar($data, $params)
$smarty->assign('pluginCalendarIds', $pluginCalendarIds);
$smarty->assign('displayedcals', $params['calIds']);
$thiscal = [];
- $checkedCalIds = [];
+ $checkedCalIds = $params['calIds'];
if (isset($_REQUEST["calIds"]) and is_array($_REQUEST["calIds"]) and count($_REQUEST["calIds"])) {
$defaultCalendarId = $_REQUEST["calIds"][0];
}
- $smarty->assign_by_ref('checkedCalIds', $checkedCalIds);
+ $smarty->assign_by_ref('checkedCalIds', $params['calIds']);
$smarty->assign('calendars', $calendars);
+ $smarty->assign('focusdate', $focusdate);
$smarty->assign('viewlist', $params['viewlist']);
$out = '';
=====================================
modules/mod-func-calendar_new.php
=====================================
@@ -145,16 +145,17 @@ function module_calendar_new($mod_reference, $module_params)
if (empty($rawcals['data'])) {
Feedback::errorAndDie(tra("You do not have permission to view the calendar"), \Laminas\Http\Response::STATUS_CODE_401);
}
-
+ $moduleCalendarFocusdate = date("Y-m-d");
$rawcals['data'] = array_filter($rawcals['data'], fn($current) => in_array($current['calendarId'], $calIds));
- $calendars = [];
$calendarInitialParams = $calendarlib->generalParamsOfCalendar($rawcals['data']);
$calendarInitialParams['initialView'] = $initialView;
+ $calendars = $calendarInitialParams['calendars'];
$smarty->assign(
'eventCalendarParams',
$calendarInitialParams
);
+ $smarty->assign('moduleCalendarFocusdate', $moduleCalendarFocusdate);
$smarty->assign('moduleCalendarIds', $moduleCalendarIds);
if ($calendarInitialParams['canEditAnything']) {
TikiLib::lib('header')
@@ -182,6 +183,9 @@ function module_calendar_new($mod_reference, $module_params)
}
$smarty->assign('name', 'calendar_new');
+ $smarty->assign('calendars', $calendars);
+ $smarty->assign_by_ref('checkedCalIds', $calIds);
+
$smarty->assign('show_calendar_module', 'y');
if (isset($save_todate)) {
=====================================
src/js/jquery-tiki/tiki-calendar.js
=====================================
@@ -217,21 +217,14 @@ $.fn.setupEventCalendar = function (
} else {
let $this = $(info.dayEl).tikiModal(" ");
const countCals = $("#filtercal ul li").length;
- if (countCals >= 1) {
+ if (countCals >= 1 || targetId != "calendar") {
$.openModal({
title: tr("New event"),
size: "modal-lg",
remote: $.service("calendar", "edit_item", { todate: info.date.toUnix(), modal: 1 }),
open: function () {
$this.tikiModal();
- $("form:not(.no-ajax)", this)
- .addClass("no-ajax") // Remove default ajax handling, we replace it
- .on(
- "submit",
- ajaxSubmitEventHandler(function (data) {
- calendarEditSubmit(data, this);
- })
- );
+ $("form:not(.no-ajax)", this).addClass("no-ajax"); // Remove default ajax handling, we replace it
},
});
} else {
=====================================
templates/modules/mod-calendar_new.tpl
=====================================
@@ -21,8 +21,17 @@
{if $viewlist neq 'list'}
{jq}
+ let paramOfModuleCalendar = {{$eventCalendarParams|json_encode}};
+ const moduleCalendarFocusDate = document.getElementById('date-module-calendar');
+ paramOfModuleCalendar['initialDate'] = $('#date-module-calendar').val();
+
const calendarContainer = [window.moduleCalendar];
$("#module-calendar").setupEventCalendar({{$eventCalendarParams|json_encode}}, calendarContainer, 'module-calendar', 'tiki-ajax_services.php?controller=calendar&action=list_items&calIds={{$moduleCalendarIds}}');
+ moduleCalendarFocusDate.addEventListener('change', () => {
+ document.getElementById('module-calendar').innerHTML = "";
+ paramOfModuleCalendar['initialDate'] = $('#date-module-calendar').val();
+ $("#module-calendar").setupEventCalendar(paramOfModuleCalendar, calendarContainer, 'module-calendar', 'tiki-ajax_services.php?controller=calendar&action=list_items&calIds={{$moduleCalendarIds}}');
+ })
{{if $prefs.print_pdf_from_url neq 'none'}$("#module-calendar").addEventCalendarPrint('#module-calendar-pdf-btn', calendarContainer[0]);{/if}}
{/jq}
{/if}
@@ -30,6 +39,30 @@
<a id="module-calendar-pdf-btn" href="#" class="text-end d-none" role="button">{icon name='pdf'} {tr}Export as PDF{/tr}</a>
{/if}
<div id="test"></div>
+ <div id="configlinks" class="mb-3 text-end">
+ <div id="configlinks" class="mb-3 text-end">
+ {if count($checkedCalIds)}
+ {$maxCalsForButton = 20}
+ {if count($checkedCalIds) > $maxCalsForButton}<select size="5">{/if}
+ {foreach $checkedCalIds as $checkedCalId}
+ {if $calendars}
+ {$thiscustombgcolor = $calendars[$checkedCalId].custombgcolor}
+ {$thiscustomfgcolor = $calendars[$checkedCalId].customfgcolor}
+ {$thiscalendarsname = $calendars[$checkedCalId].displayName|escape}
+ {if count($checkedCalIds) > $maxCalsForButton}
+ <option style="background:#{$thiscustombgcolor};color:#{$thiscustomfgcolor};" onclick="toggle('filtercal')">
+ {$thiscalendarsname}
+ </option>
+ {else}
+ {button href="{$checkedCalId|sefurl:'calendar'}" _style="background:#$thiscustombgcolor;color:#$thiscustomfgcolor;border:1px solid #$thiscustomfgcolor; " _text="{$thiscalendarsname}" _class='btn btn-sm me-2 mt-2' _icon_name='calendar'}
+ {/if}
+ {/if}
+ {/foreach}
+ {if count($checkedCalIds) > $maxCalsForButton}</select>{/if}
+ {/if}
+ </div>
+ </div>
+ <input type="date" value="{$moduleCalendarFocusdate}" id="date-module-calendar">
<div id='module-calendar'></div>
{if $viewlist eq 'list'}
{$out}
=====================================
templates/tiki-calendar.tpl
=====================================
@@ -135,7 +135,7 @@
{include file="export_calendar_in_csv_or_ical.tpl" isInMainCalendar="y"}
<h5 class="text-center text-secondary border-top border-bottom">
{tr}Displayed calendar{/tr}
- <h5>
+ </h5>
<div id="configlinks" class="mb-3 text-end">
{if count($checkedCalIds)}
{$maxCalsForButton = 20}
=====================================
templates/wiki-plugins/wikiplugin_calendar.tpl
=====================================
@@ -1,5 +1,5 @@
-<div>
- {if $tiki_p_add_events eq 'y'}
+<div class="border border-secondary p-2">
+ {if $tiki_p_add_events eq 'y' and $viewlist neq 'list'}
<a href="{bootstrap_modal controller='calendar' action='edit_item' size='modal-lg' defaultCalendarId=$defaultCalendarId}" class="btn btn-primary">{icon name='create'} {tr}Add Event{/tr}</a>
{/if}
{if count($calendars) >= 1 && $viewnavbar eq 'y'}
@@ -8,8 +8,16 @@
{if $viewlist neq 'list'}
{jq}
+ let content = {{$eventCalendarParams|json_encode}};
+ const elt = document.getElementById('date-plugin-calendar');
+ content['initialDate'] = $('#date-plugin-calendar').val();
const wikipluginCalendar = [window.pluginCalendar]
- $("#plugin-calendar").setupEventCalendar({{$eventCalendarParams|json_encode}}, wikipluginCalendar, 'plugin-calendar', 'tiki-ajax_services.php?controller=calendar&action=list_items&calIds={{$pluginCalendarIds}}');
+ $("#plugin-calendar").setupEventCalendar(content, wikipluginCalendar, 'plugin-calendar', 'tiki-ajax_services.php?controller=calendar&action=list_items&calIds={{$pluginCalendarIds}}');
+ elt.addEventListener('change', () => {
+ document.getElementById('plugin-calendar').innerHTML = "";
+ content['initialDate'] = $('#date-plugin-calendar').val();
+ $("#plugin-calendar").setupEventCalendar(content, wikipluginCalendar, 'plugin-calendar', 'tiki-ajax_services.php?controller=calendar&action=list_items&calIds={{$pluginCalendarIds}}');
+ })
{{if $prefs.print_pdf_from_url neq 'none'}$("#plugin-calendar").addEventCalendarPrint('#calendar-pdf-btn', wikipluginCalendar[0]);{/if}}
{/jq}
{/if}
@@ -17,6 +25,33 @@
<a id="calendar-pdf-btn" href="#" class="text-end d-none" role="button">{icon name='pdf'} {tr}Export as PDF{/tr}</a>
{/if}
<div id="test"></div>
+ <div id="configlinks" class="mb-3 text-end">
+ <div id="configlinks" class="mb-3 text-end">
+ {if count($checkedCalIds)}
+ {$maxCalsForButton = 20}
+ {if count($checkedCalIds) > $maxCalsForButton}<select size="5">{/if}
+ {foreach $checkedCalIds as $checkedCalId}
+ {if $calendars}
+ {$thiscustombgcolor = $calendars[$checkedCalId].custombgcolor}
+ {$thiscustomfgcolor = $calendars[$checkedCalId].customfgcolor}
+ {$thiscalendarsname = $calendars[$checkedCalId].displayName|escape}
+ {if count($checkedCalIds) > $maxCalsForButton}
+ <option style="background:#{$thiscustombgcolor};color:#{$thiscustomfgcolor};" onclick="toggle('filtercal')">
+ {$thiscalendarsname}
+ </option>
+ {else}
+ {button href="{$checkedCalId|sefurl:'calendar'}" _style="background:#$thiscustombgcolor;color:#$thiscustomfgcolor;border:1px solid #$thiscustomfgcolor; " _text="{$thiscalendarsname}" _class='btn btn-sm me-2 mt-2' _icon_name='calendar'}
+ {/if}
+ {/if}
+ {/foreach}
+ {if count($checkedCalIds) > $maxCalsForButton}</select>{/if}
+ {/if}
+ </div>
+ </div>
+ {if $viewlist neq 'list'}
+ <input type="date" value="{$focusdate}" id="date-plugin-calendar">
+ {/if}
+
<div id='plugin-calendar'></div>
{if $viewlist eq 'list'}
{$out}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/bb03f5a86de634fb2a4bb5fdeddc699911d95bef
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/bb03f5a86de634fb2a4bb5fdeddc699911d95bef
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs