1.1 --- a/imipweb/calendar.py Tue Apr 07 23:16:35 2015 +0200
1.2 +++ b/imipweb/calendar.py Mon May 11 20:00:18 2015 +0200
1.3 @@ -241,11 +241,16 @@
1.4
1.5 "Show the calendar for the current user."
1.6
1.7 - handled = self.handle_newevent()
1.8 -
1.9 self.new_page(title="Calendar")
1.10 page = self.page
1.11
1.12 + handled = self.handle_newevent()
1.13 + freebusy = self.store.get_freebusy(self.user)
1.14 +
1.15 + if not freebusy:
1.16 + page.p("No events scheduled.")
1.17 + return
1.18 +
1.19 # Form controls are used in various places on the calendar page.
1.20
1.21 page.form(method="POST")
1.22 @@ -253,33 +258,6 @@
1.23 self.show_requests_on_page()
1.24 participants = self.show_participants_on_page()
1.25
1.26 - # Show a button for scheduling a new event.
1.27 -
1.28 - page.p(class_="controls")
1.29 - page.input(name="newevent", type="submit", value="New event", id="newevent", accesskey="N")
1.30 - page.p.close()
1.31 -
1.32 - # Show controls for hiding empty days and busy slots.
1.33 - # The positioning of the control, paragraph and table are important here.
1.34 -
1.35 - page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D")
1.36 - page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B")
1.37 -
1.38 - page.p(class_="controls")
1.39 - page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable")
1.40 - page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable")
1.41 - page.label("Show empty days", for_="showdays", class_="showdays disable")
1.42 - page.label("Hide empty days", for_="showdays", class_="showdays enable")
1.43 - page.input(name="reset", type="submit", value="Clear selections", id="reset")
1.44 - page.label("Clear selections", for_="reset", class_="reset")
1.45 - page.p.close()
1.46 -
1.47 - freebusy = self.store.get_freebusy(self.user)
1.48 -
1.49 - if not freebusy:
1.50 - page.p("No events scheduled.")
1.51 - return
1.52 -
1.53 # Obtain the user's timezone.
1.54
1.55 tzid = self.get_tzid()
1.56 @@ -403,9 +381,33 @@
1.57
1.58 add_empty_days(days, tzid)
1.59
1.60 - # Show the controls permitting day selection.
1.61 + # Show the controls permitting day selection as well as the controls
1.62 + # configuring the new event display.
1.63
1.64 self.show_calendar_day_controls(days)
1.65 + self.show_calendar_interval_controls(days)
1.66 +
1.67 + # Show a button for scheduling a new event.
1.68 +
1.69 + page.p(class_="controls")
1.70 + page.input(name="newevent", type="submit", value="New event", id="newevent", class_="newevent-with-periods", accesskey="N")
1.71 + page.span("Select days or periods for a new event.", class_="newevent-no-periods")
1.72 + page.p.close()
1.73 +
1.74 + # Show controls for hiding empty days and busy slots.
1.75 + # The positioning of the control, paragraph and table are important here.
1.76 +
1.77 + page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D")
1.78 + page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B")
1.79 +
1.80 + page.p(class_="controls")
1.81 + page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable")
1.82 + page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable")
1.83 + page.label("Show empty days", for_="showdays", class_="showdays disable")
1.84 + page.label("Hide empty days", for_="showdays", class_="showdays enable")
1.85 + page.input(name="reset", type="submit", value="Clear selections", id="reset")
1.86 + page.label("Clear selections", for_="reset", class_="reset newevent-with-periods")
1.87 + page.p.close()
1.88
1.89 # Show the calendar itself.
1.90
1.91 @@ -438,15 +440,74 @@
1.92
1.93 page.style(type="text/css")
1.94
1.95 + l = []
1.96 +
1.97 for day in days:
1.98 - daystr = format_datetime(day)
1.99 - page.add("""\
1.100 -input.newevent.selector#day-%s-:checked ~ table label.day.day-%s,
1.101 -input.newevent.selector#day-%s-:checked ~ table label.timepoint.day-%s {
1.102 + daystr, dayid = self._day_value_and_identifier(day)
1.103 + l.append("""\
1.104 +input.newevent.selector#%s:checked ~ table label.day.day-%s,
1.105 +input.newevent.selector#%s:checked ~ table label.timepoint.day-%s""" % (dayid, daystr, dayid, daystr))
1.106 +
1.107 + page.add(",\n".join(l))
1.108 + page.add(""" {
1.109 background-color: #5f4;
1.110 text-decoration: underline;
1.111 }
1.112 -""" % (daystr, daystr, daystr, daystr))
1.113 +""")
1.114 +
1.115 + page.style.close()
1.116 +
1.117 + def show_calendar_interval_controls(self, days):
1.118 +
1.119 + "Show controls for the intervals provided by 'days'."
1.120 +
1.121 + page = self.page
1.122 + slots = self.env.get_args().get("slot", [])
1.123 +
1.124 + for day, intervals in days.items():
1.125 + for point, endpoint in intervals:
1.126 + value, identifier = self._slot_value_and_identifier(point, endpoint)
1.127 + self._slot_selector(value, identifier, slots)
1.128 +
1.129 + # Generate a dynamic stylesheet to allow day selections to colour
1.130 + # specific days.
1.131 + # NOTE: The style details need to be coordinated with the static
1.132 + # NOTE: stylesheet.
1.133 +
1.134 + page.style(type="text/css")
1.135 +
1.136 + l = []; l2 = []; l3 = []
1.137 +
1.138 + for day, intervals in days.items():
1.139 + for point, endpoint in intervals:
1.140 + daystr, dayid = self._day_value_and_identifier(day)
1.141 + timestr, timeid = self._slot_value_and_identifier(point, endpoint)
1.142 + l.append("""\
1.143 +input.newevent.selector#%s:checked ~ p .newevent-no-periods,
1.144 +input.newevent.selector#%s:checked ~ p .newevent-no-periods""" % (dayid, timeid))
1.145 + l2.append("""\
1.146 +input.newevent.selector#%s:checked ~ p .newevent-with-periods,
1.147 +input.newevent.selector#%s:checked ~ p .newevent-with-periods""" % (dayid, timeid))
1.148 + l3.append("""\
1.149 +input.newevent.selector#%s:checked ~ table label.timepoint[for=%s]""" % (timeid, timeid))
1.150 +
1.151 + page.add(",\n".join(l))
1.152 + page.add(""" {
1.153 + display: none;
1.154 +}""")
1.155 +
1.156 + page.add(",\n".join(l2))
1.157 + page.add(""" {
1.158 + display: inline;
1.159 +}
1.160 +""")
1.161 +
1.162 + page.add(",\n".join(l3))
1.163 + page.add(""" {
1.164 + background-color: #5f4;
1.165 + text-decoration: underline;
1.166 +}
1.167 +""")
1.168
1.169 page.style.close()
1.170
1.171 @@ -691,8 +752,6 @@
1.172 tzid = self.get_tzid()
1.173 daystr = format_datetime(point.point.date())
1.174 value, identifier = self._slot_value_and_identifier(point, endpoint)
1.175 - slots = self.env.get_args().get("slot", [])
1.176 - self._slot_selector(value, identifier, slots)
1.177 page.label(self.format_time(point.point, "long"), class_="timepoint day-%s" % daystr, for_=identifier)
1.178 page.span(self.format_time(endpoint and endpoint.point or get_end_of_day(point.point, tzid), "long"), class_="endpoint")
1.179
1.180 @@ -730,7 +789,7 @@
1.181
1.182 "Return a day value and HTML identifier for the given 'day'."
1.183
1.184 - value = "%s-" % format_datetime(day)
1.185 + value = format_datetime(day)
1.186 identifier = "day-%s" % value
1.187 return value, identifier
1.188