we recently wanted to use the events calendar for vacation planning, showing events etc.
What we disliked was the default view that didn't visualize vacation days or weekends. So, as OTRS is very neatly moddable, here's our solution.
To color in the weekends, simply add to your skin folder (you are using custom skins, right?), or append to the defaults skin folder:
~otrs/var/httpd/htdocs/skins/Agent/[NameOfYourSkin|default]/css/thirdparty/fullcalendar-2.4.0/fullcalendar.min.css
Code: Select all
.fc-sat { background-color:#D1D0CE;}
.fc-sun { background-color:#D1D0CE;}
Now, to show all the vacation days you have configured in the SysConfig, create a copy of these files in your custom folder (this only works from 5.x +):
~otrs/Kernel/Output/HTML/Dashboard/EventsTicketCalendar.pm
~otrs/Kernel/Output/HTML/Templates/Standard/DashboardEventsTicketCalendar.tt
in the perl file, add after these lines:
Code: Select all
my @EventsDisplayed;
my $Counter = 1;
my $Limit = scalar keys %Tickets;
# get needed objects
my $TimeObject = $Kernel::OM->Get('Kernel::System::Time');
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
Code: Select all
# Begin of Customization
my $TimeVacationDaysOneTime = $ConfigObject->Get('TimeVacationDaysOneTime');
for my $CurYear (keys $TimeVacationDaysOneTime) {
for my $CurMonth (keys $TimeVacationDaysOneTime->{$CurYear}) {
my $SMonth = ($CurMonth < 10) ? "0$CurMonth" : $CurMonth;
for my $CurDay (keys $TimeVacationDaysOneTime->{$CurYear}->{$CurMonth}) {
my $SDay = ($CurDay < 10) ? "0$CurDay" : $CurDay;
$LayoutObject->Block(
Name => 'CalendarEventVacationDay',
Data => {
Date => "$CurYear-$SMonth-$SDay",
Color => "red",
},
);
}
}
}
# Now do the same, but for recurring vacation days. As fullcalendar does not support
# yearly recurring events, let's just create these for 3 years in the future and 1 year in the past
my $TimeVacationDays = $ConfigObject->Get('TimeVacationDays');
for my $CurMonth (keys $TimeVacationDays) {
my $SMonth = ($CurMonth < 10) ? "0$CurMonth" : $CurMonth;
for my $CurDay (keys $TimeVacationDays->{$CurMonth}) {
my @Now = localtime();
my $SYear = $Now[5] + 1900;
my $SDay = ($CurDay < 10) ? "0$CurDay" : $CurDay;
foreach ( -1, 0, 1, 2, 3) {
my $CurYear = $SYear + $_;
$LayoutObject->Block(
Name => 'CalendarEventVacationDay',
Data => {
Date => "$CurYear-$SMonth-$SDay",
Color => "red",
},
);
}
}
}
# This Block also puts an comma after each event. It's however not allowed on the last one
# Thus we output a "normal"-dummy event
# I found this simpler than counting two nested hashes for their length
# and decreasing a counter and so on
$LayoutObject->Block(
Name => 'CalendarEventVacationDayEND',
Data => {
Date => "2000-01-01",
Color => "red",
},
);
Code: Select all
ButtonText: {
today: [% Translate("Today") | JSON %],
month: [% Translate("month") | JSON %],
week: [% Translate("week") | JSON %],
day: [% Translate("day") | JSON %]
},
FirstDay: [% Data.FirstDay | html %],
Events: [
Code: Select all
[% RenderBlockStart("CalendarEventVacationDay") %]
{
start: "[% Data.Date | html %]",
color: "[% Data.Color | html %]",
rendering: 'background',
allDay: true
},
[% RenderBlockEnd("CalendarEventVacationDay") %]
[% RenderBlockStart("CalendarEventVacationDayEND") %]
{
start: "[% Data.Date | html %]",
color: "[% Data.Color | html %]",
rendering: 'background',
allDay: true
}
[% RenderBlockEnd("CalendarEventVacationDayEND") %]
Next project is to implement some kind of ordering to events, such that certain types of events are always rendered on the top.
EDIT:
Just noticed that this breaks when normal events are added. In that case a comma after the "CalendarEventVacationDayEND"-Block is needed.