Skip to content

Commit b013552

Browse files
sayravaiihalaij1
authored andcommitted
Implement Participants page using DataTables
1 parent 0581160 commit b013552

22 files changed

Lines changed: 1363 additions & 430 deletions

File tree

assets/css/main.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js-translations/teacher.fi.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"Filter":
2424
"Suodatus",
2525

26+
"Reset filters":
27+
"Nollaa suodattimet",
28+
2629
"Collapse":
2730
"Supista",
2831

@@ -38,6 +41,18 @@
3841
"Student name":
3942
"Opiskelijan nimi",
4043

44+
"First name":
45+
"Etunimi",
46+
47+
"Last name":
48+
"Sukunimi",
49+
50+
"Email":
51+
"S\u00E4hk\u00F6posti",
52+
53+
"Status":
54+
"Tila",
55+
4156
"Organization":
4257
"Organisaatio",
4358

assets/js/buttons_popover.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,54 @@ $.fn.extend({
1515
*/
1616
buttons_popover: function (buttons, options) {
1717
this.each(function (i, elem) {
18-
const this_buttons = typeof buttons === "function" ?
19-
buttons(elem) :
20-
buttons;
18+
const this_buttons = typeof buttons === "function" ? buttons(elem) : buttons;
2119
const default_options = {
2220
html: true,
2321
sanitize: false,
2422
placement: 'bottom',
2523
trigger: 'focus',
26-
}
24+
container: 'body',
25+
};
2726
const all_options = $.extend({}, default_options, options);
2827

2928
const buttons_html = this_buttons.map(function (btn) {
3029
return ('<button id="' + btn.id + '" class="btn ' + btn.classes +
3130
'" ' + (btn.extra_attrs || "") + ">" + btn.text + "</button>")
3231
}).join(' ');
33-
// We have to attach the event handlers to body because the buttons are
34-
// created only when the popover is open and are destroyed when it is closed
32+
3533
const $elem = $(elem);
34+
// Make focusable for trigger: 'focus'
35+
$elem.attr({ 'tabindex': 0 });
36+
37+
// Attach delegated handlers for dynamically created buttons
38+
// Namespace per-button id to avoid duplicate handlers on re-init
3639
this_buttons.forEach(function (btn) {
37-
$('body').on('click', 'button#' + btn.id, function () {
38-
// Close this popover by triggering a click
39-
$elem.trigger('click');
40-
return btn.onclick();
41-
});
40+
const ev = 'click.buttonsPopover.' + btn.id;
41+
$('body')
42+
.off(ev, 'button#' + btn.id)
43+
.on(ev, 'button#' + btn.id, function () {
44+
// Hide popover then execute action
45+
try {
46+
const inst = bootstrap.Popover.getInstance($elem[0]);
47+
if (inst) inst.hide();
48+
} catch (e) { /* ignore */ }
49+
return btn.onclick();
50+
});
4251
});
4352

44-
$elem.attr({
45-
'data-bs-toggle': 'popover',
46-
'data-content': buttons_html,
47-
'tabindex': 0
48-
});
49-
$elem.popover(all_options);
53+
// Initialize Bootstrap 5 popover (idempotent)
54+
try {
55+
const existing = bootstrap.Popover.getInstance($elem[0]);
56+
if (!existing) {
57+
new bootstrap.Popover($elem[0], $.extend({}, all_options, { content: buttons_html }));
58+
} else {
59+
// Update content attribute for existing instance
60+
$elem.attr('data-bs-content', buttons_html);
61+
}
62+
} catch (e) {
63+
// As a fallback, set data attributes for any legacy initializers
64+
$elem.attr({ 'data-bs-toggle': 'popover', 'data-bs-content': buttons_html });
65+
}
5066
});
5167
},
5268
});

0 commit comments

Comments
 (0)