Skip to content

Commit 86569d9

Browse files
committed
add write support for COLOR prop
1 parent f99fd6e commit 86569d9

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

assets/js/app/app.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ var set_mindate = function set_mindate(mindate, datepickers) {
562562
* @param Object data The event data
563563
*/
564564
var open_event_edit_dialog = function open_event_edit_dialog(event) {
565+
565566
var is_new = false;
566567
var title = t('labels', 'editevent');
567568

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

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

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

706+
// Initialize color picker
707+
$('input.pick_color').colorPicker();
708+
709+
if (is_new) {
710+
// Initialize color picker with the calendar color for new events
711+
$('input.pick_color').next('.color_picker').css('background-color', $.fn.colorPicker.calendarColor);
712+
}
713+
else {
714+
// Event is not new but has no color,
715+
// Initialize color picker with the calendar color for new events
716+
if (event.color === undefined || event.color === null || event.color === '') {
717+
$('input.pick_color').next('.color_picker').css('background-color', $.fn.colorPicker.calendarColor);
718+
}
719+
// Event has a color, initialize color picker with that color
720+
else {
721+
$('input.pick_color').next('.color_picker').css('background-color', event.color);
722+
}
723+
}
724+
706725
// Reminders
707726
reminders_manager();
727+
728+
// Add event listener to update event color based on selected calendar
729+
$('#event_edit_form select[name="calendar"]').on('change', function() {
730+
var selectedCalendarId = $(this).val();
731+
var selectedCalendar = event.calendars.find(function(calendar) {
732+
return calendar.calendar === selectedCalendarId;
733+
});
734+
if (selectedCalendar) {
735+
$('input.pick_color').next('.color_picker').css('background-color', $.fn.colorPicker.calendarColor);
736+
}
737+
});
708738
}
709739
});
710740
};
@@ -1114,6 +1144,9 @@ var update_calendar_list = function update_calendar_list(maskbody) {
11141144
own_calendars.appendChild(li[0]);
11151145
}
11161146

1147+
// Update colorPicker calendar color
1148+
$.fn.colorPicker.calendarColor = calendar.color;
1149+
11171150
});
11181151

11191152
// No calendars?
@@ -1353,7 +1386,6 @@ var fg_for_bg = function fg_for_bg(color) {
13531386
return colorMapping[color] || '#000000'; // Default to black if color not found
13541387
};
13551388

1356-
13571389
/**
13581390
* This method is called when a session has expired
13591391
*/

assets/templates/event_basic_form_part.dust

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@
6969
{>form_element_start for="description" label="description" /}
7070
<textarea name="description" class="form-control" rows="4">{description}</textarea>
7171
{>form_element_end/}
72+
73+
{>form_element_start for="color" label="color" /}
74+
<input name="color" type="text" value="{color}" class="color form-control pick_color" />
75+
{>form_element_end/}

0 commit comments

Comments
 (0)