Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d348dee
refactor: move agenda_timezone.js code out of global scope
jennifer-richards Mar 23, 2022
f1dbcd6
refactor: separate function defs from adding to 'window'
jennifer-richards Mar 23, 2022
4f82d94
refactor: eliminate 'var' declarations and clean up lint
jennifer-richards Mar 23, 2022
a22a000
chore: remove unused CSS
jennifer-richards Mar 23, 2022
9dcee86
fix: add/maintain link to current session row on the agenda
jennifer-richards Mar 23, 2022
734e0a1
fix: move link to current session to the RH nav panel
jennifer-richards Mar 23, 2022
1d051ec
fix: nav to next session as "current" if no sessions ongoing
jennifer-richards Mar 23, 2022
6b5d0ff
fix: restore the horizontal line "current session" indicator
jennifer-richards Mar 23, 2022
2240827
refactor: clean up js and css for readability/accurate naming
jennifer-richards Mar 23, 2022
ad9634d
refactor: use $border-widths map; move inline style to ietf.scss
jennifer-richards Mar 24, 2022
1dc280d
fix: correct test for whether extra-nav elements are present
jennifer-richards Mar 24, 2022
b29ebfa
feat: clean up righthand panel nav formatting
jennifer-richards Mar 24, 2022
6d447b2
Merge branch 'feat/bs5' into jennifer/tix3697
jennifer-richards Mar 24, 2022
9c74c1a
Merge branch 'feat/bs5' into jennifer/tix3697
jennifer-richards Mar 24, 2022
e1b9392
feat: render second tz select widget on agenda RH panel
jennifer-richards Mar 25, 2022
7a601e1
refactor: convert "local" to local timezone on init
jennifer-richards Mar 25, 2022
e418a1d
fix: use renamed variable in tz-display template
jennifer-richards Mar 25, 2022
a501561
fix: allow omission of id_suffix param to tz-display.html
jennifer-richards Mar 25, 2022
18019b1
fix: clean up positioning of secondary timezone selector
jennifer-richards Mar 25, 2022
3a220a7
feat: hide "Current session" link when meeting is over
jennifer-richards Mar 25, 2022
0b94e32
fix: remove "Meeting" option for upcoming meeting timezone
jennifer-richards Mar 28, 2022
678d1c6
fix: accept 'local' as the initially selected time zone
jennifer-richards Mar 28, 2022
079a523
feat: keep select2 widget in sync with time zone set on page
jennifer-richards Mar 28, 2022
3e45260
refactor: clean up some javascript/jquery syntax
jennifer-richards Mar 28, 2022
8171f30
fix: eliminate race condition when selecting rows
jennifer-richards Apr 7, 2022
3244e0c
Merge remote-tracking branch 'origin/feat/bs5' into jennifer/tix3697
jennifer-richards Apr 7, 2022
9e18504
style: remove outdated comment; compare with '==='
jennifer-richards Apr 7, 2022
b618af2
Merge remote-tracking branch 'origin/jennifer/agenda-tz-widget' into …
jennifer-richards Apr 7, 2022
2c9717f
Merge remote-tracking branch 'origin/feat/bs5' into jennifer/agenda-t…
jennifer-richards Apr 7, 2022
b1a8c75
Merge branch 'feat/bs5' into jennifer/agenda-tz-widget
jennifer-richards Apr 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions ietf/static/js/timezone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright The IETF Trust 2021, All Rights Reserved

// Copyright The IETF Trust 2021, All Rights Reserved
/* global moment */
/*
Timezone selection handling. Relies on the moment.js library.

Expand All @@ -8,21 +8,16 @@
names. Time zone can be changed via the select input or by calling the use() method with
the name of a time zone (or 'local' to guess the user's local timezone).
*/
window.ietf_timezone; // public interface

(function () {
'use strict';
// Callback for timezone change - called after current_timezone is updated
var timezone_change_callback;
var current_timezone;
let timezone_change_callback;
let current_timezone;
let tz_radios;
let tz_selects;

// Select timezone to use. Arg is name of a timezone or 'local' to guess local tz.
function use_timezone(newtz) {
// Guess local timezone if necessary
if (newtz.toLowerCase() === 'local') {
newtz = moment.tz.guess();
}

if (current_timezone !== newtz) {
current_timezone = newtz;
// Update values of tz-select inputs but do not trigger change event
Expand All @@ -31,40 +26,52 @@ window.ietf_timezone; // public interface
if (timezone_change_callback) {
timezone_change_callback(newtz);
}
tz_radios.filter(`[value="${newtz}"]`).prop('checked', true);
tz_radios.filter(`[value!="${newtz}"]`).prop('checked', false);
tz_selects.val(newtz);
tz_selects.trigger('change.select2'); // notify only select2 of change to avoid change event storm
}
}

function handle_change_event(evt) {
const newtz = evt.target.value;
use_timezone(newtz); // use the requested timezone
}

/* Initialize timezone system
*
* This will set the timezone to the value of 'current'. Set up the tz_change callback
* before initializing.
*/
function timezone_init(current) {
var tz_names = moment.tz.names();
var select = $('select.tz-select');

select.empty();
if (current === 'local') {
current = moment.tz.guess();
}
tz_selects = $('select.tz-select');
tz_selects.empty();
$.each(tz_names, function (i, item) {
select.append($('<option/>', {
tz_selects.append($('<option/>', {
selected: current === item,
html: item,
value: item
}));
});
select.on("change", function () {
use_timezone(this.value);
});
tz_radios = $('input.tz-select[type="radio"]');
tz_radios.filter('[value="local"]').prop('value', moment.tz.guess());
tz_radios.on('change', handle_change_event);
tz_selects.on('change', handle_change_event);
/* When navigating back/forward, the browser may change the select input's
* value after the window load event. It does not fire the change event on
* the input when it does this. The pageshow event occurs after such an update,
* so trigger the change event ourselves to be sure the UI stays consistent
* with the timezone select input. */
window.addEventListener('pageshow', function () { select.trigger("change"); });
window.addEventListener('pageshow', function () { tz_selects.trigger("change"); });
use_timezone(current);
}

// Expose public interface
ietf_timezone = {
window.ietf_timezone = {
get_current_tz: function () { return current_timezone; },
initialize: timezone_init,
set_tz_change_callback: function (cb) { timezone_change_callback = cb; },
Expand Down
17 changes: 13 additions & 4 deletions ietf/templates/meeting/agenda.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@
{% endif %}
{# the contents of #extra-nav will be moved into the RH nav panel #}
<div id="extra-nav" class="d-none">
<a class="nav-link now-link" href="#">Current session</a>
<div class="d-flex flex-column">
{% if now.date <= schedule.meeting.end_date %}
<a class="nav-link now-link" href="#">Current session</a>
{% endif %}
<div class="px-3">
Showing <span class="current-tz">{{ timezone }}</span> time
</div>
<div class="px-3 w-100">
{% include 'meeting/tz-display.html' with id_suffix="-rh" meeting_timezone=timezone minimal=True only %}
</div>
</div>
</div>
{# cache this part -- it takes 3-6 seconds to generate #}
{% load cache %}
Expand All @@ -47,7 +57,7 @@ <h2>
{{ schedule.meeting.agenda_info_note|removetags:"h1"|safe }}
</p>
{% endif %}
{% include 'meeting/tz-display.html' with id_suffix="" timezone=timezone %}
{% include 'meeting/tz-display.html' with meeting_timezone=timezone only %}
{% include "meeting/agenda_filter.html" with filter_categories=filter_categories customize_button_text="Personalize the agenda view..." always_show=personalize %}
{% include "meeting/agenda_personalize_buttonlist.html" with meeting=schedule.meeting only %}
<div class="input-group mb-3">
Expand Down Expand Up @@ -321,8 +331,7 @@ <h2 class="mt-3">
{% endcache %}
{% endblock %}
{% block js %}
<script src="{% static 'ietf/js/agenda_filter.js' %}">
</script>
<script src="{% static 'ietf/js/agenda_filter.js' %}"></script>
<script>
// Update the agenda display with specified filters
function update_agenda_display(filter_params) {
Expand Down
76 changes: 44 additions & 32 deletions ietf/templates/meeting/tz-display.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
{% comment %}
Include this to display a timezone select widget. Must also include timezone.js as a script.
{% import "meeting/tz-display.html" with meeting_timezone="America/Halifax" id_suffix="" minimal=False only %}

Must provide the meeting_timezone option, which is the timezone to be used when the "Meeting" radio is
selected. If id_suffix is given, it is appended to the element IDs and radio input names to differentiate
multiple instances of the widget. If minimal is True, only the Meeting/Local/UTC radios are shown and no
arbitrary timezone select input is included in the widget.

As long as id_suffix is different, should allow for as many copies of the widget on a page as you'd like.
{% endcomment %}
{% load origin %}
{% origin %}
<div class="tz-display input-group my-3">
<label class="input-group-text border-primary bg-white fw-bold">Time zone:</label>
{% firstof id_suffix "" as suffix %}
<div class="tz-display {% if minimal %}btn-group{% else %}input-group{% endif %} my-3">
{% if not minimal %}<label class="input-group-text border-primary bg-white fw-bold">Time zone:</label>{% endif %}
{% if meeting_timezone is not None %}
<input type="radio"
name="tzradio{{ suffix }}"
class="btn-check tz-select"
id="meeting-timezone{{ suffix }}"
value="{{ meeting_timezone }}">
<label class="btn btn-outline-primary" for="meeting-timezone{{ suffix }}">Meeting</label>
{% endif %}
<input type="radio"
{% if timezone == "meeting" %}checked{% endif %}
name="tzradio"
class="btn-check"
id="meeting-timezone{{ id_suffix }}"
onclick="ietf_timezone.use('{{ timezone }}')">
<label class="btn btn-outline-primary" for="meeting-timezone{{ id_suffix }}">Meeting</label>
name="tzradio{{ suffix }}"
class="btn-check tz-select"
id="local-timezone{{ suffix }}"
value="local">
<label class="btn btn-outline-primary" for="local-timezone{{ suffix }}">Local</label>
<input type="radio"
{% if timezone == "local" %}checked{% endif %}
name="tzradio"
class="btn-check"
id="local-timezone{{ id_suffix }}"
onclick="ietf_timezone.use('local')">
<label class="btn btn-outline-primary" for="local-timezone{{ id_suffix }}">Local</label>
<input type="radio"
{% if timezone == "UTC" %}checked{% endif %}
name="tzradio"
class="btn-check"
id="utc-timezone{{ id_suffix }}"
onclick="ietf_timezone.use('UTC')">
<label class="btn btn-outline-primary" for="utc-timezone{{ id_suffix }}">UTC</label>
<label aria-label="Select timezone" class="visually-hidden" for="timezone-select{{ id_suffix }}"></label>
<select id="timezone-select{{ id_suffix }}"
class="tz-select select2-field form-select border-primary"
data-max-entries="1" data-minimum-input-length="0"
onchange="$('.tz-display input[name=tzradio]').prop('checked', false);">
{# Avoid blank while loading. JavaScript replaces the option list after init. #}
<option selected>
{{ timezone }}
</option>
</select>
</div>
name="tzradio{{ suffix }}"
class="btn-check tz-select"
id="utc-timezone{{ suffix }}"
value="UTC">
<label class="btn btn-outline-primary" for="utc-timezone{{ suffix }}">UTC</label>
{% if not minimal %}
<label aria-label="Select timezone" class="visually-hidden" for="timezone-select{{ id_suffix }}"></label>
<select id="timezone-select{{ suffix }}"
class="tz-select select2-field form-select border-primary"
data-max-entries="1" data-minimum-input-length="0">
{# Avoid blank while loading. JavaScript replaces the option list after init. #}
<option selected>
{{ meeting_timezone }}
</option>
</select>
{% endif %}
</div>
7 changes: 3 additions & 4 deletions ietf/templates/meeting/upcoming.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>Upcoming Meetings</h1>
{% endfor %}
</div>
{% endif %}
{% include 'meeting/tz-display.html' with id_suffix="" timezone="local" %}
{% include 'meeting/tz-display.html' with meeting_timezone=None only %}
{% include 'meeting/agenda_filter.html' with filter_categories=filter_categories customize_button_text="Customize the meeting list..." only %}
{% cache 600 upcoming-meetings entries.count %}
{% if entries %}
Expand Down Expand Up @@ -104,7 +104,7 @@ <h1>Upcoming Meetings</h1>
<h3 class="my-3">No upcoming meetings</h3>
{% endif %}
{% endcache %}
{% include 'meeting/tz-display.html' with id_suffix="-bottom" timezone="local" %}
{% include 'meeting/tz-display.html' with id_suffix="-bottom" meeting_timezone=None only %}
<div id="calendar">
</div>
{% endblock %}
Expand Down Expand Up @@ -142,8 +142,7 @@ <h3 class="my-3">No upcoming meetings</h3>
{% endif %}
{% endfor %}];

$(document)
.ready(function () {
$(function () {
// Init with best guess at local timezone.
ietf_timezone.set_tz_change_callback(timezone_changed);
ietf_timezone.initialize('local');
Expand Down