@@ -10,6 +10,7 @@ jQuery(document).ready(function () {
1010
1111 let sessions = content . find ( ".session" ) . not ( ".readonly" ) ;
1212 let timeslots = content . find ( ".timeslot" ) ;
13+ let timeslotLabels = content . find ( ".time-label" ) ;
1314 let days = content . find ( ".day-flow .day" ) ;
1415
1516 // hack to work around lack of position sticky support in old browsers, see https://caniuse.com/#feat=css-sticky
@@ -68,41 +69,92 @@ jQuery(document).ready(function () {
6869 }
6970 }
7071
72+ /**
73+ * Mark or unmark a session that conflicts with the selected session
74+ *
75+ * @param constraintElt The element corresponding to the specific constraint
76+ * @param wouldViolate True to mark or false to unmark
77+ */
78+ function setSessionWouldViolate ( constraintElt , wouldViolate ) {
79+ constraintElt = jQuery ( constraintElt ) ;
80+ let constraintDiv = constraintElt . closest ( 'div.session' ) ; // find enclosing session div
81+ constraintDiv . toggleClass ( 'would-violate-hint' , wouldViolate ) ; // mark the session container
82+ constraintElt . toggleClass ( 'would-violate-hint' , wouldViolate ) ; // and the specific constraint
83+ }
84+
85+ /**
86+ * Mark or unmark a timeslot that conflicts with the selected session
87+ *
88+ * If wholeInterval is true, marks the entire column in addition to the timeslot.
89+ * This currently works by setting the class for the timeslot and the time-label
90+ * in its column. Because this is called for every timeslot in the interval, the
91+ * overall effect is to highlight the entire column.
92+ *
93+ * @param timeslotElt Timeslot element to be marked/unmarked
94+ * @param wouldViolate True to mark or false to unmark
95+ * @param wholeInterval Should the entire time interval be flagged or just the timeslot?
96+ */
97+ function setTimeslotWouldViolate ( timeslotElt , wouldViolate , wholeInterval ) {
98+ timeslotElt = jQuery ( timeslotElt ) ;
99+ timeslotElt . toggleClass ( 'would-violate-hint' , wouldViolate ) ;
100+ if ( wholeInterval ) {
101+ let index = timeslotElt . index ( ) ; // position of this timeslot relative to its container
102+ let label = timeslotElt
103+ . closest ( 'div.room-group' )
104+ . find ( 'div.time-header .time-label' )
105+ . get ( index ) ; // get time-label corresponding to this timeslot
106+ jQuery ( label ) . toggleClass ( 'would-violate-hint' , wouldViolate ) ;
107+ }
108+ }
109+
110+ /**
111+ * Remove all would-violate-hint classes on timeslots
112+ */
113+ function resetTimeslotsWouldViolate ( ) {
114+ timeslots . removeClass ( "would-violate-hint" ) ;
115+ timeslotLabels . removeClass ( "would-violate-hint" ) ;
116+ }
117+
71118 function showConstraintHints ( selectedSession ) {
72119 let sessionId = selectedSession ? selectedSession . id . slice ( "session" . length ) : null ;
73120 // hints on the sessions
74121 sessions . find ( ".constraints > span" ) . each ( function ( ) {
75- if ( ! sessionId ) {
76- jQuery ( this ) . removeClass ( "would-violate-hint" ) ;
77- return ;
122+ let wouldViolate = false ;
123+ let applyChange = true ;
124+ if ( sessionId ) {
125+ let sessionIds = this . dataset . sessions ;
126+ if ( ! sessionIds ) {
127+ applyChange = False ;
128+ } else {
129+ wouldViolate = sessionIds . split ( "," ) . indexOf ( sessionId ) !== - 1 ;
130+ }
78131 }
79132
80- let sessionIds = this . dataset . sessions ;
81- if ( ! sessionIds )
82- return ;
83-
84- let wouldViolate = sessionIds . split ( "," ) . indexOf ( sessionId ) != - 1 ;
85- jQuery ( this ) . toggleClass ( "would-violate-hint" , wouldViolate ) ;
133+ if ( applyChange ) {
134+ setSessionWouldViolate ( this , wouldViolate ) ;
135+ }
86136 } ) ;
87137
88138 // hints on timeslots
89- timeslots . removeClass ( "would-violate-hint" ) ;
139+ resetTimeslotsWouldViolate ( ) ;
90140 if ( selectedSession ) {
91141 let intervals = [ ] ;
92142 timeslots . filter ( ":has(.session .constraints > span.would-violate-hint)" ) . each ( function ( ) {
93143 intervals . push ( [ this . dataset . start , this . dataset . end ] ) ;
94144 } ) ;
95145
96146 let overlappingTimeslots = findTimeslotsOverlapping ( intervals ) ;
97- for ( let i = 0 ; i < overlappingTimeslots . length ; ++ i )
98- overlappingTimeslots [ i ] . addClass ( "would-violate-hint" ) ;
147+ for ( let i = 0 ; i < overlappingTimeslots . length ; ++ i ) {
148+ setTimeslotWouldViolate ( overlappingTimeslots [ i ] , true , true ) ;
149+ }
99150
100151 // check room sizes
101152 let attendees = + selectedSession . dataset . attendees ;
102153 if ( attendees ) {
103154 timeslots . not ( ".would-violate-hint" ) . each ( function ( ) {
104- if ( attendees > + jQuery ( this ) . closest ( ".timeslots" ) . data ( "roomcapacity" ) )
105- jQuery ( this ) . addClass ( "would-violate-hint" ) ;
155+ if ( attendees > + jQuery ( this ) . closest ( ".timeslots" ) . data ( "roomcapacity" ) ) {
156+ setTimeslotWouldViolate ( this , true , false ) ;
157+ }
106158 } ) ;
107159 }
108160 }
0 commit comments