# HG changeset patch # User Paul Boddie # Date 1431367218 -7200 # Node ID 779f4e9c5c343e15db9c59af481f69cd94a85c04 # Parent 904fc8d3a5e9d70947af3d65059fff4fcb3a46ea Moved day and time slot controls before the new event controls so that the new event controls can be changed according to any selections, also adding more dynamic stylesheet rules and making such rules slightly more concise. Changed the day value representation to omit the trailing "-" character. diff -r 904fc8d3a5e9 -r 779f4e9c5c34 htdocs/styles.css --- a/htdocs/styles.css Tue Apr 07 23:16:35 2015 +0200 +++ b/htdocs/styles.css Mon May 11 20:00:18 2015 +0200 @@ -115,6 +115,12 @@ vertical-align: top; } +/* New event controls. */ + +.newevent-with-periods { + display: none; +} + /* Selection of slots/periods for new events. */ input.newevent.selector { @@ -151,11 +157,6 @@ visibility: visible; } -input.newevent:checked ~ .timepoint { - background-color: #5f4; - text-decoration: underline; -} - /* Hiding/showing busy slots/periods or unused days. */ /* Hide the controls. */ diff -r 904fc8d3a5e9 -r 779f4e9c5c34 imipweb/calendar.py --- a/imipweb/calendar.py Tue Apr 07 23:16:35 2015 +0200 +++ b/imipweb/calendar.py Mon May 11 20:00:18 2015 +0200 @@ -241,11 +241,16 @@ "Show the calendar for the current user." - handled = self.handle_newevent() - self.new_page(title="Calendar") page = self.page + handled = self.handle_newevent() + freebusy = self.store.get_freebusy(self.user) + + if not freebusy: + page.p("No events scheduled.") + return + # Form controls are used in various places on the calendar page. page.form(method="POST") @@ -253,33 +258,6 @@ self.show_requests_on_page() participants = self.show_participants_on_page() - # Show a button for scheduling a new event. - - page.p(class_="controls") - page.input(name="newevent", type="submit", value="New event", id="newevent", accesskey="N") - page.p.close() - - # Show controls for hiding empty days and busy slots. - # The positioning of the control, paragraph and table are important here. - - page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D") - page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B") - - page.p(class_="controls") - page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable") - page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable") - page.label("Show empty days", for_="showdays", class_="showdays disable") - page.label("Hide empty days", for_="showdays", class_="showdays enable") - page.input(name="reset", type="submit", value="Clear selections", id="reset") - page.label("Clear selections", for_="reset", class_="reset") - page.p.close() - - freebusy = self.store.get_freebusy(self.user) - - if not freebusy: - page.p("No events scheduled.") - return - # Obtain the user's timezone. tzid = self.get_tzid() @@ -403,9 +381,33 @@ add_empty_days(days, tzid) - # Show the controls permitting day selection. + # Show the controls permitting day selection as well as the controls + # configuring the new event display. self.show_calendar_day_controls(days) + self.show_calendar_interval_controls(days) + + # Show a button for scheduling a new event. + + page.p(class_="controls") + page.input(name="newevent", type="submit", value="New event", id="newevent", class_="newevent-with-periods", accesskey="N") + page.span("Select days or periods for a new event.", class_="newevent-no-periods") + page.p.close() + + # Show controls for hiding empty days and busy slots. + # The positioning of the control, paragraph and table are important here. + + page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D") + page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B") + + page.p(class_="controls") + page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable") + page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable") + page.label("Show empty days", for_="showdays", class_="showdays disable") + page.label("Hide empty days", for_="showdays", class_="showdays enable") + page.input(name="reset", type="submit", value="Clear selections", id="reset") + page.label("Clear selections", for_="reset", class_="reset newevent-with-periods") + page.p.close() # Show the calendar itself. @@ -438,15 +440,74 @@ page.style(type="text/css") + l = [] + for day in days: - daystr = format_datetime(day) - page.add("""\ -input.newevent.selector#day-%s-:checked ~ table label.day.day-%s, -input.newevent.selector#day-%s-:checked ~ table label.timepoint.day-%s { + daystr, dayid = self._day_value_and_identifier(day) + l.append("""\ +input.newevent.selector#%s:checked ~ table label.day.day-%s, +input.newevent.selector#%s:checked ~ table label.timepoint.day-%s""" % (dayid, daystr, dayid, daystr)) + + page.add(",\n".join(l)) + page.add(""" { background-color: #5f4; text-decoration: underline; } -""" % (daystr, daystr, daystr, daystr)) +""") + + page.style.close() + + def show_calendar_interval_controls(self, days): + + "Show controls for the intervals provided by 'days'." + + page = self.page + slots = self.env.get_args().get("slot", []) + + for day, intervals in days.items(): + for point, endpoint in intervals: + value, identifier = self._slot_value_and_identifier(point, endpoint) + self._slot_selector(value, identifier, slots) + + # Generate a dynamic stylesheet to allow day selections to colour + # specific days. + # NOTE: The style details need to be coordinated with the static + # NOTE: stylesheet. + + page.style(type="text/css") + + l = []; l2 = []; l3 = [] + + for day, intervals in days.items(): + for point, endpoint in intervals: + daystr, dayid = self._day_value_and_identifier(day) + timestr, timeid = self._slot_value_and_identifier(point, endpoint) + l.append("""\ +input.newevent.selector#%s:checked ~ p .newevent-no-periods, +input.newevent.selector#%s:checked ~ p .newevent-no-periods""" % (dayid, timeid)) + l2.append("""\ +input.newevent.selector#%s:checked ~ p .newevent-with-periods, +input.newevent.selector#%s:checked ~ p .newevent-with-periods""" % (dayid, timeid)) + l3.append("""\ +input.newevent.selector#%s:checked ~ table label.timepoint[for=%s]""" % (timeid, timeid)) + + page.add(",\n".join(l)) + page.add(""" { + display: none; +}""") + + page.add(",\n".join(l2)) + page.add(""" { + display: inline; +} +""") + + page.add(",\n".join(l3)) + page.add(""" { + background-color: #5f4; + text-decoration: underline; +} +""") page.style.close() @@ -691,8 +752,6 @@ tzid = self.get_tzid() daystr = format_datetime(point.point.date()) value, identifier = self._slot_value_and_identifier(point, endpoint) - slots = self.env.get_args().get("slot", []) - self._slot_selector(value, identifier, slots) page.label(self.format_time(point.point, "long"), class_="timepoint day-%s" % daystr, for_=identifier) page.span(self.format_time(endpoint and endpoint.point or get_end_of_day(point.point, tzid), "long"), class_="endpoint") @@ -730,7 +789,7 @@ "Return a day value and HTML identifier for the given 'day'." - value = "%s-" % format_datetime(day) + value = format_datetime(day) identifier = "day-%s" % value return value, identifier