@@ -562,6 +562,7 @@ var set_mindate = function set_mindate(mindate, datepickers) {
562
562
* @param Object data The event data
563
563
*/
564
564
var open_event_edit_dialog = function open_event_edit_dialog ( event ) {
565
+
565
566
var is_new = false ;
566
567
var title = t ( 'labels' , 'editevent' ) ;
567
568
@@ -570,7 +571,6 @@ var open_event_edit_dialog = function open_event_edit_dialog(event) {
570
571
}
571
572
572
573
// Clone original object
573
- // TODO use a better approach (lodash.clone?)
574
574
event = jQuery . extend ( true , { } , event ) ;
575
575
576
576
// 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) {
703
703
AgenDAVRepeat . setRepeatRuleOnForm ( event . rrule , $ ( '#tabs-recurrence' ) ) ;
704
704
}
705
705
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
+
706
725
// Reminders
707
726
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
+ } ) ;
708
738
}
709
739
} ) ;
710
740
} ;
@@ -1114,6 +1144,9 @@ var update_calendar_list = function update_calendar_list(maskbody) {
1114
1144
own_calendars . appendChild ( li [ 0 ] ) ;
1115
1145
}
1116
1146
1147
+ // Update colorPicker calendar color
1148
+ $ . fn . colorPicker . calendarColor = calendar . color ;
1149
+
1117
1150
} ) ;
1118
1151
1119
1152
// No calendars?
@@ -1353,7 +1386,6 @@ var fg_for_bg = function fg_for_bg(color) {
1353
1386
return colorMapping [ color ] || '#000000' ; // Default to black if color not found
1354
1387
} ;
1355
1388
1356
-
1357
1389
/**
1358
1390
* This method is called when a session has expired
1359
1391
*/
0 commit comments