Skip to content

Add rfc7986 color support for VEVENT objects #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions assets/js/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ var set_mindate = function set_mindate(mindate, datepickers) {
* @param Object data The event data
*/
var open_event_edit_dialog = function open_event_edit_dialog(event) {

var is_new = false;
var title = t('labels', 'editevent');

Expand All @@ -570,7 +571,6 @@ var open_event_edit_dialog = function open_event_edit_dialog(event) {
}

// Clone original object
// TODO use a better approach (lodash.clone?)
event = jQuery.extend(true, {}, event);

// Deal with events not from Fullcalendar (i.e. directly from backend)
Expand Down Expand Up @@ -703,8 +703,41 @@ var open_event_edit_dialog = function open_event_edit_dialog(event) {
AgenDAVRepeat.setRepeatRuleOnForm(event.rrule, $('#tabs-recurrence'));
}

// Initialize color picker
$('input.pick_color').colorPicker();
// Show the reset button from the color picker
$('#color_selector').find('#reset_color').show();

if (is_new) {
// Initialize color picker with the calendar color for new events
$('input.pick_color').next('.color_picker').css('background-color', $.fn.colorPicker.calendarColor);
}
else {
// Event is not new but has no color,
// Initialize color picker with the calendar color for new events
if (event.color === undefined || event.color === null || event.color === '') {
$('input.pick_color').next('.color_picker').css('background-color', $.fn.colorPicker.calendarColor);
}
// Event has a color, initialize color picker with that color
else {
$('input.pick_color').next('.color_picker').css('background-color', event.color);
}
}

// Reminders
reminders_manager();

// Add event listener to update event color based on selected calendar
$('#event_edit_form select[name="calendar"]').on('change', function() {
var selectedCalendarId = $(this).val();
var selectedCalendar = event.calendars.find(function(calendar) {
return calendar.calendar === selectedCalendarId;
});
if (selectedCalendar) {
$.fn.colorPicker.calendarColor = selectedCalendar.color; // for reset button
$('input.pick_color').next('.color_picker').css('background-color', $.fn.colorPicker.calendarColor);
}
});
}
});
};
Expand Down Expand Up @@ -952,6 +985,8 @@ var calendar_modify_dialog = function calendar_modify_dialog(calendar_obj) {
width: 500,
pre_func: function() {
$('input.pick_color').colorPicker();
// Hide the reset button from the color picker
$('#color_selector').find('#reset_color').hide();

if (AgenDAVConf.enable_calendar_sharing === true && data.is_shared !== true) {
shares_manager();
Expand Down Expand Up @@ -1092,8 +1127,6 @@ var update_calendar_list = function update_calendar_list(maskbody) {
// Some values need to be generated
if (calendar.color === undefined || calendar.color === null) {
calendar.color = AgenDAVConf.default_calendar_color;
} else {
calendar.color = calendar.color.substr(0,7);
}
calendar.fg = fg_for_bg(calendar.color);

Expand All @@ -1116,6 +1149,9 @@ var update_calendar_list = function update_calendar_list(maskbody) {
own_calendars.appendChild(li[0]);
}

// Update colorPicker calendar color
$.fn.colorPicker.calendarColor = calendar.color;

});

// No calendars?
Expand Down Expand Up @@ -1352,16 +1388,9 @@ var reload_event_source = function reload_event_source(cal) {
* Returns a foreground color for a given background
*/
var fg_for_bg = function fg_for_bg(color) {
var colr = parseInt(color.substr(1), 16);

var is_dark = (colr >>> 16) + // R
((colr >>> 8) & 0x00ff) + // G
(colr & 0x0000ff) < 500; // B

return (is_dark) ? '#ffffff' : '#000000';
return colorMapping[color] || '#000000'; // Default to black if color not found
};


/**
* This method is called when a session has expired
*/
Expand Down Expand Up @@ -1527,6 +1556,12 @@ var event_render_callback = function event_render_callback(event, element) {
// Icons
var icons = [];

// Set the background and text colors of the event
if (event.color) {
element.css('background-color', event.color);
element.css('color', fg_for_bg(event.color));
}

if (event.rrule !== undefined) {
icons.push('fa-repeat');
}
Expand Down
Loading