2.1 --- a/imipweb/calendar.py Tue Apr 07 23:16:35 2015 +0200
2.2 +++ b/imipweb/calendar.py Mon May 11 20:00:18 2015 +0200
2.3 @@ -241,11 +241,16 @@
2.4
2.5 "Show the calendar for the current user."
2.6
2.7 - handled = self.handle_newevent()
2.8 -
2.9 self.new_page(title="Calendar")
2.10 page = self.page
2.11
2.12 + handled = self.handle_newevent()
2.13 + freebusy = self.store.get_freebusy(self.user)
2.14 +
2.15 + if not freebusy:
2.16 + page.p("No events scheduled.")
2.17 + return
2.18 +
2.19 # Form controls are used in various places on the calendar page.
2.20
2.21 page.form(method="POST")
2.22 @@ -253,33 +258,6 @@
2.23 self.show_requests_on_page()
2.24 participants = self.show_participants_on_page()
2.25
2.26 - # Show a button for scheduling a new event.
2.27 -
2.28 - page.p(class_="controls")
2.29 - page.input(name="newevent", type="submit", value="New event", id="newevent", accesskey="N")
2.30 - page.p.close()
2.31 -
2.32 - # Show controls for hiding empty days and busy slots.
2.33 - # The positioning of the control, paragraph and table are important here.
2.34 -
2.35 - page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D")
2.36 - page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B")
2.37 -
2.38 - page.p(class_="controls")
2.39 - page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable")
2.40 - page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable")
2.41 - page.label("Show empty days", for_="showdays", class_="showdays disable")
2.42 - page.label("Hide empty days", for_="showdays", class_="showdays enable")
2.43 - page.input(name="reset", type="submit", value="Clear selections", id="reset")
2.44 - page.label("Clear selections", for_="reset", class_="reset")
2.45 - page.p.close()
2.46 -
2.47 - freebusy = self.store.get_freebusy(self.user)
2.48 -
2.49 - if not freebusy:
2.50 - page.p("No events scheduled.")
2.51 - return
2.52 -
2.53 # Obtain the user's timezone.
2.54
2.55 tzid = self.get_tzid()
2.56 @@ -403,9 +381,33 @@
2.57
2.58 add_empty_days(days, tzid)
2.59
2.60 - # Show the controls permitting day selection.
2.61 + # Show the controls permitting day selection as well as the controls
2.62 + # configuring the new event display.
2.63
2.64 self.show_calendar_day_controls(days)
2.65 + self.show_calendar_interval_controls(days)
2.66 +
2.67 + # Show a button for scheduling a new event.
2.68 +
2.69 + page.p(class_="controls")
2.70 + page.input(name="newevent", type="submit", value="New event", id="newevent", class_="newevent-with-periods", accesskey="N")
2.71 + page.span("Select days or periods for a new event.", class_="newevent-no-periods")
2.72 + page.p.close()
2.73 +
2.74 + # Show controls for hiding empty days and busy slots.
2.75 + # The positioning of the control, paragraph and table are important here.
2.76 +
2.77 + page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D")
2.78 + page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B")
2.79 +
2.80 + page.p(class_="controls")
2.81 + page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable")
2.82 + page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable")
2.83 + page.label("Show empty days", for_="showdays", class_="showdays disable")
2.84 + page.label("Hide empty days", for_="showdays", class_="showdays enable")
2.85 + page.input(name="reset", type="submit", value="Clear selections", id="reset")
2.86 + page.label("Clear selections", for_="reset", class_="reset newevent-with-periods")
2.87 + page.p.close()
2.88
2.89 # Show the calendar itself.
2.90
2.91 @@ -438,15 +440,74 @@
2.92
2.93 page.style(type="text/css")
2.94
2.95 + l = []
2.96 +
2.97 for day in days:
2.98 - daystr = format_datetime(day)
2.99 - page.add("""\
2.100 -input.newevent.selector#day-%s-:checked ~ table label.day.day-%s,
2.101 -input.newevent.selector#day-%s-:checked ~ table label.timepoint.day-%s {
2.102 + daystr, dayid = self._day_value_and_identifier(day)
2.103 + l.append("""\
2.104 +input.newevent.selector#%s:checked ~ table label.day.day-%s,
2.105 +input.newevent.selector#%s:checked ~ table label.timepoint.day-%s""" % (dayid, daystr, dayid, daystr))
2.106 +
2.107 + page.add(",\n".join(l))
2.108 + page.add(""" {
2.109 background-color: #5f4;
2.110 text-decoration: underline;
2.111 }
2.112 -""" % (daystr, daystr, daystr, daystr))
2.113 +""")
2.114 +
2.115 + page.style.close()
2.116 +
2.117 + def show_calendar_interval_controls(self, days):
2.118 +
2.119 + "Show controls for the intervals provided by 'days'."
2.120 +
2.121 + page = self.page
2.122 + slots = self.env.get_args().get("slot", [])
2.123 +
2.124 + for day, intervals in days.items():
2.125 + for point, endpoint in intervals:
2.126 + value, identifier = self._slot_value_and_identifier(point, endpoint)
2.127 + self._slot_selector(value, identifier, slots)
2.128 +
2.129 + # Generate a dynamic stylesheet to allow day selections to colour
2.130 + # specific days.
2.131 + # NOTE: The style details need to be coordinated with the static
2.132 + # NOTE: stylesheet.
2.133 +
2.134 + page.style(type="text/css")
2.135 +
2.136 + l = []; l2 = []; l3 = []
2.137 +
2.138 + for day, intervals in days.items():
2.139 + for point, endpoint in intervals:
2.140 + daystr, dayid = self._day_value_and_identifier(day)
2.141 + timestr, timeid = self._slot_value_and_identifier(point, endpoint)
2.142 + l.append("""\
2.143 +input.newevent.selector#%s:checked ~ p .newevent-no-periods,
2.144 +input.newevent.selector#%s:checked ~ p .newevent-no-periods""" % (dayid, timeid))
2.145 + l2.append("""\
2.146 +input.newevent.selector#%s:checked ~ p .newevent-with-periods,
2.147 +input.newevent.selector#%s:checked ~ p .newevent-with-periods""" % (dayid, timeid))
2.148 + l3.append("""\
2.149 +input.newevent.selector#%s:checked ~ table label.timepoint[for=%s]""" % (timeid, timeid))
2.150 +
2.151 + page.add(",\n".join(l))
2.152 + page.add(""" {
2.153 + display: none;
2.154 +}""")
2.155 +
2.156 + page.add(",\n".join(l2))
2.157 + page.add(""" {
2.158 + display: inline;
2.159 +}
2.160 +""")
2.161 +
2.162 + page.add(",\n".join(l3))
2.163 + page.add(""" {
2.164 + background-color: #5f4;
2.165 + text-decoration: underline;
2.166 +}
2.167 +""")
2.168
2.169 page.style.close()
2.170
2.171 @@ -691,8 +752,6 @@
2.172 tzid = self.get_tzid()
2.173 daystr = format_datetime(point.point.date())
2.174 value, identifier = self._slot_value_and_identifier(point, endpoint)
2.175 - slots = self.env.get_args().get("slot", [])
2.176 - self._slot_selector(value, identifier, slots)
2.177 page.label(self.format_time(point.point, "long"), class_="timepoint day-%s" % daystr, for_=identifier)
2.178 page.span(self.format_time(endpoint and endpoint.point or get_end_of_day(point.point, tzid), "long"), class_="endpoint")
2.179
2.180 @@ -730,7 +789,7 @@
2.181
2.182 "Return a day value and HTML identifier for the given 'day'."
2.183
2.184 - value = "%s-" % format_datetime(day)
2.185 + value = format_datetime(day)
2.186 identifier = "day-%s" % value
2.187 return value, identifier
2.188