~homeworkprod/byceps

2032a0fde3cc9322e8d4efd6eebe2ef5416c8abd — Jochen Kupperschmidt 6 months ago d4522f2
Use arrow functions (consistently) in JavaScript code
24 files changed, 68 insertions(+), 91 deletions(-)

M byceps/blueprints/admin/board/templates/admin/board/board_view.html
M byceps/blueprints/admin/maintenance/templates/admin/maintenance/index.html
M byceps/blueprints/admin/news/templates/admin/news/item_view_version.html
M byceps/blueprints/admin/orga/templates/admin/orga/persons_for_brand.html
M byceps/blueprints/admin/orga_team/templates/admin/orga_team/teams_for_party.html
M byceps/blueprints/admin/shop/article/templates/admin/shop/article/view.html
M byceps/blueprints/admin/shop/order/templates/admin/shop/order/view.html
M byceps/blueprints/admin/shop/shop/templates/admin/shop/shop/view_for_brand.html
M byceps/blueprints/admin/snippet/templates/admin/snippet/index_mountpoints.html
M byceps/blueprints/admin/snippet/templates/admin/snippet/view_version.html
M byceps/blueprints/admin/ticketing/checkin/templates/admin/ticketing/checkin/index.html
M byceps/blueprints/admin/ticketing/templates/admin/ticketing/view_ticket.html
M byceps/blueprints/admin/tourney/category/templates/admin/tourney/category/index.html
M byceps/blueprints/admin/user/templates/admin/user/manage_roles.html
M byceps/blueprints/admin/user/templates/admin/user/view.html
M byceps/blueprints/admin/webhook/templates/admin/webhook/index.html
M byceps/blueprints/site/board/templates/site/board/category_view.html
M byceps/blueprints/site/seating/templates/site/seating/view_area.html
M byceps/blueprints/site/ticketing/templates/site/ticketing/index_mine.html
M byceps/blueprints/site/user/settings/templates/site/user/settings/view.html
M byceps/static/behavior/board.js
M byceps/static/behavior/common.js
M byceps/static/behavior/login.js
M byceps/static/behavior/seating.js
M byceps/blueprints/admin/board/templates/admin/board/board_view.html => byceps/blueprints/admin/board/templates/admin/board/board_view.html +1 -1
@@ 84,7 84,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        post_on_click_then_reload('[data-action="category-move-up"]');
        post_on_click_then_reload('[data-action="category-move-down"]');
        post_on_click_then_reload('[data-action="category-hide"]');

M byceps/blueprints/admin/maintenance/templates/admin/maintenance/index.html => byceps/blueprints/admin/maintenance/templates/admin/maintenance/index.html +1 -1
@@ 34,7 34,7 @@

{% block scripts %}
<script>
  onDomReady(function() {
  onDomReady(() => {
    confirmed_post_on_click_then_reload('[data-action="delete-old-login-events"]', '{{ _('Delete old login events?') }}');
  });
</script>

M byceps/blueprints/admin/news/templates/admin/news/item_view_version.html => byceps/blueprints/admin/news/templates/admin/news/item_view_version.html +1 -1
@@ 161,7 161,7 @@

{% block scripts %}
<script>
  onDomReady(function() {
  onDomReady(() => {
    confirmed_post_on_click_then_reload('[data-action="item-publish-now"]', 'Newspost jetzt veröffentlichen?');
  });
</script>

M byceps/blueprints/admin/orga/templates/admin/orga/persons_for_brand.html => byceps/blueprints/admin/orga/templates/admin/orga/persons_for_brand.html +1 -1
@@ 116,7 116,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_delete_on_click_then_reload('[data-action="orgaflag-remove"]', 'Person den Orga-Status entziehen?');
      });
    </script>

M byceps/blueprints/admin/orga_team/templates/admin/orga_team/teams_for_party.html => byceps/blueprints/admin/orga_team/templates/admin/orga_team/teams_for_party.html +1 -1
@@ 122,7 122,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_delete_on_click_then_reload('[data-action="team-delete"]', 'Team entfernen?');
        confirmed_delete_on_click_then_reload('[data-action="membership-remove"]', 'Person aus dem Team entfernen?');
      });

M byceps/blueprints/admin/shop/article/templates/admin/shop/article/view.html => byceps/blueprints/admin/shop/article/templates/admin/shop/article/view.html +1 -1
@@ 167,7 167,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_delete_on_click_then_reload('a.attachment-remove', 'Artikelanhang entfernen?');
      });
    </script>

M byceps/blueprints/admin/shop/order/templates/admin/shop/order/view.html => byceps/blueprints/admin/shop/order/templates/admin/shop/order/view.html +1 -1
@@ 93,7 93,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_post_on_click_then_reload('[data-action="order-flag-invoiced"]', 'Rechnung als versendet vermerken?');
        confirmed_delete_on_click_then_reload('[data-action="order-unflag-invoiced"]', 'Rechnung als nicht versendet vermerken?');


M byceps/blueprints/admin/shop/shop/templates/admin/shop/shop/view_for_brand.html => byceps/blueprints/admin/shop/shop/templates/admin/shop/shop/view_for_brand.html +1 -1
@@ 22,7 22,7 @@

{% block scripts %}
<script>
  onDomReady(function() {
  onDomReady(() => {
    confirmed_post_on_click('[data-action="create-shop"]', 'Shop erstellen?');
  });
</script>

M byceps/blueprints/admin/snippet/templates/admin/snippet/index_mountpoints.html => byceps/blueprints/admin/snippet/templates/admin/snippet/index_mountpoints.html +1 -1
@@ 76,7 76,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_delete_on_click_then_reload('[data-action="mountpoint-delete"]', 'Mountpoint entfernen?');
      });
    </script>

M byceps/blueprints/admin/snippet/templates/admin/snippet/view_version.html => byceps/blueprints/admin/snippet/templates/admin/snippet/view_version.html +1 -1
@@ 117,7 117,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_delete_on_click('[data-action="snippet-delete"]', 'Snippet löschen?');
      });
    </script>

M byceps/blueprints/admin/ticketing/checkin/templates/admin/ticketing/checkin/index.html => byceps/blueprints/admin/ticketing/checkin/templates/admin/ticketing/checkin/index.html +2 -2
@@ 84,12 84,12 @@

{% block scripts %}
<script>
  onDomReady(function() {
  onDomReady(() => {
  {%- if tickets %}
    // Skip non-check-in links in ticket list for keyboard tab navigation.
    document
      .querySelectorAll('.tickets a:not(.button-check-in)')
      .forEach(function(node) { node.tabIndex = -1; });
      .forEach(node => { node.tabIndex = -1; });
  {%- endif %}

    post_on_click_then_reload('[data-action="check-in-user"]');

M byceps/blueprints/admin/ticketing/templates/admin/ticketing/view_ticket.html => byceps/blueprints/admin/ticketing/templates/admin/ticketing/view_ticket.html +1 -1
@@ 109,7 109,7 @@
<script>
  enableCopyToClipboard('ticket-id-copy-trigger');

  onDomReady(function() {
  onDomReady(() => {
    confirmed_post_on_click_then_reload('[data-action="revert-user-check-in"]', 'Check-In rückgängig machen?');
  });
</script>

M byceps/blueprints/admin/tourney/category/templates/admin/tourney/category/index.html => byceps/blueprints/admin/tourney/category/templates/admin/tourney/category/index.html +1 -1
@@ 59,7 59,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        post_on_click_then_reload('[data-action="category-move-up"]');
        post_on_click_then_reload('[data-action="category-move-down"]');
      });

M byceps/blueprints/admin/user/templates/admin/user/manage_roles.html => byceps/blueprints/admin/user/templates/admin/user/manage_roles.html +1 -1
@@ 71,7 71,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_post_on_click_then_reload('[data-action="role-assign"]', 'Rolle zuweisen?');
        confirmed_delete_on_click_then_reload('[data-action="role-deassign"]', 'Rolle entfernen?');
      });

M byceps/blueprints/admin/user/templates/admin/user/view.html => byceps/blueprints/admin/user/templates/admin/user/view.html +1 -1
@@ 137,7 137,7 @@
<script>
  enableCopyToClipboard('user-id-copy-trigger');

  onDomReady(function() {
  onDomReady(() => {
    confirmed_post_on_click_then_reload('[data-action="user-initialize"]', 'Benutzerkonto initialisieren?');
  });
</script>

M byceps/blueprints/admin/webhook/templates/admin/webhook/index.html => byceps/blueprints/admin/webhook/templates/admin/webhook/index.html +1 -1
@@ 107,7 107,7 @@

{% block scripts %}
<script>
  onDomReady(function() {
  onDomReady(() => {
    post_on_click_then_reload('[data-action="test-webhook"]');
  });
</script>

M byceps/blueprints/site/board/templates/site/board/category_view.html => byceps/blueprints/site/board/templates/site/board/category_view.html +1 -1
@@ 82,7 82,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_post_on_click('[data-action="mark-all-topics-in-category-as-viewed"]', 'Alle Themen in dieser Kategorie als gelesen markieren?');
      });
    </script>

M byceps/blueprints/site/seating/templates/site/seating/view_area.html => byceps/blueprints/site/seating/templates/site/seating/view_area.html +1 -1
@@ 49,7 49,7 @@
{% block scripts %}
    <script src="{{ url_for('static', filename='behavior/seating.js') }}"></script>
    <script>
      onDomReady(function() {
      onDomReady(() => {
        {%- if seat_management_enabled %}
        const selected_ticket_id = {% if selected_ticket_id|default %}'{{ selected_ticket_id }}'{% else %}null{% endif %};
        init_seat_management(selected_ticket_id);

M byceps/blueprints/site/ticketing/templates/site/ticketing/index_mine.html => byceps/blueprints/site/ticketing/templates/site/ticketing/index_mine.html +1 -1
@@ 26,7 26,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        confirmed_delete_on_click_then_reload('[data-action="withdraw-user"]', 'Dieses Ticket selbst nutzen?');
        confirmed_delete_on_click_then_reload('[data-action="withdraw-user-manager"]', 'Nutzer-Verwaltung zurückholen?');
        confirmed_delete_on_click_then_reload('[data-action="withdraw-seat-manager"]', 'Sitzplatz-Verwaltung zurückholen?');

M byceps/blueprints/site/user/settings/templates/site/user/settings/view.html => byceps/blueprints/site/user/settings/templates/site/user/settings/view.html +1 -1
@@ 30,7 30,7 @@

{% block scripts %}
    <script>
      onDomReady(function() {
      onDomReady(() => {
        // avatar
        confirmed_delete_on_click_then_reload('[data-action="avatar-delete"]', 'Avatarbild entfernen?');


M byceps/static/behavior/board.js => byceps/static/behavior/board.js +6 -8
@@ 1,4 1,4 @@
onDomReady(function() {
onDomReady(() => {

  confirmed_post_on_click('[data-action="topic-hide"]', 'Thema verstecken?');
  confirmed_delete_on_click('[data-action="topic-unhide"]', 'Thema wieder anzeigen?');


@@ 13,16 13,14 @@ onDomReady(function() {
  confirmed_delete_on_click('[data-action="posting-unhide"]', 'Beitrag wieder anzeigen?');

  const collpasedTextareas = document.querySelectorAll('textarea.collapsed');
  collpasedTextareas.forEach(function(textarea) {
  collpasedTextareas.forEach(textarea => {
    // Expand collapsible text area after receiving focus.
    textarea.addEventListener('focus', function() {
      textarea.classList.remove('collapsed');
    });
    textarea
      .addEventListener('focus', () => textarea.classList.remove('collapsed'));

    // Collapse text area on click on cancel button.
    textarea.form.querySelector('button.cancel').addEventListener('click', function() {
      textarea.classList.add('collapsed');
    });
    textarea.form.querySelector('button.cancel')
      .addEventListener('click', () => textarea.classList.add('collapsed'));
  });

});

M byceps/static/behavior/common.js => byceps/static/behavior/common.js +21 -25
@@ 51,19 51,19 @@ function confirmed_delete_on_click_then_reload(selector, confirmation_label) {
}

function _request_on_click(selector, method) {
  _onClickCallbackWithHref(selector, function(href) {
  _onClickCallbackWithHref(selector, href => {
    _ajax_then_redirect_to_location_response_header(method, href);
  });
}

function _request_on_click_then_reload(selector, method) {
  _onClickCallbackWithHref(selector, function(href) {
  _onClickCallbackWithHref(selector, href => {
    _ajax_then_reload(method, href);
  });
}

function _confirmed_request_on_click(selector, confirmation_label, method) {
  _onClickCallbackWithHref(selector, function(href) {
  _onClickCallbackWithHref(selector, href => {
    if (confirm(confirmation_label)) {
      _ajax_then_redirect_to_location_response_header(method, href);
    };


@@ 71,7 71,7 @@ function _confirmed_request_on_click(selector, confirmation_label, method) {
}

function _confirmed_request_on_click_then_reload(selector, confirmation_label, method) {
  _onClickCallbackWithHref(selector, function(href) {
  _onClickCallbackWithHref(selector, href => {
    if (confirm(confirmation_label)) {
      _ajax_then_reload(method, href);
    };


@@ 81,8 81,8 @@ function _confirmed_request_on_click_then_reload(selector, confirmation_label, m

function _onClickCallbackWithHref(selector, callback) {
  const elements = document.querySelectorAll(selector);
  elements.forEach(function(element) {
    element.addEventListener('click', function(event) {
  elements.forEach(element => {
    element.addEventListener('click', event => {
      const href = element.getAttribute('href');
      callback(href);



@@ 92,7 92,7 @@ function _onClickCallbackWithHref(selector, callback) {
}

function _ajax_then_redirect_to_location_response_header(method, request_url) {
  _ajax(method, request_url, function(response) {
  _ajax(method, request_url, response => {
    if (response.status == 204) {
      const redirectUrl = response.headers.get('Location');
      if (redirectUrl !== null) {


@@ 103,7 103,7 @@ function _ajax_then_redirect_to_location_response_header(method, request_url) {
}

function _ajax_then_reload(method, request_url) {
  _ajax(method, request_url, function(response) {
  _ajax(method, request_url, response => {
    if (response.status == 204) {
      location.href = location.href;
    }


@@ 125,8 125,8 @@ function _ajax(method, url, on_complete) {
 */
function enableDropdownMenuToggles() {
  const dropdownToggles = document.querySelectorAll('.dropdown .dropdown-toggle');
  dropdownToggles.forEach(function(triggerElement) {
    triggerElement.addEventListener('click', function(event) {
  dropdownToggles.forEach(triggerElement => {
    triggerElement.addEventListener('click', event => {
      const dropdown = triggerElement.parentNode;
      dropdown.classList.toggle('open');



@@ 142,7 142,7 @@ function enableDropdownMenuToggles() {
 */
function closeOpenDropdownMenus(clickTarget) {
  const openDropdowns = document.querySelectorAll('.dropdown.open');
  openDropdowns.forEach(function(openDropdown) {
  openDropdowns.forEach(openDropdown => {
    if (!openDropdown.contains(clickTarget)) {
      // Click was outside of this dropdown menu, so close it.
      openDropdown.classList.remove('open');


@@ 152,13 152,11 @@ function closeOpenDropdownMenus(clickTarget) {


// Add behavior to dropdown menus.
onDomReady(function() {
onDomReady(() => {
  enableDropdownMenuToggles();

  // Close open dropdowns if user clicks outside of an open dropdown.
  document.addEventListener('click', function(event) {
    closeOpenDropdownMenus(event.target);
  });
  document.addEventListener('click', event => closeOpenDropdownMenus(event.target));
});




@@ 173,7 171,7 @@ onDomReady(function() {
function enableCopyToClipboard(triggerElementId) {
  const triggerElement = document.getElementById(triggerElementId);

  triggerElement.addEventListener('click', function() {
  triggerElement.addEventListener('click', () => {
    const fieldId = this.dataset.fieldId;
    const field = document.getElementById(fieldId);



@@ 193,12 191,12 @@ function enableCopyToClipboard(triggerElementId) {

// Disable the submit button of forms with class
// `disable-submit-button-on-submit` on submit.
onDomReady(function() {
onDomReady(() => {
  const formsWhoseSubmitButtonShouldBeDisabledOnSubmit = document
      .querySelectorAll('form.disable-submit-button-on-submit');

  formsWhoseSubmitButtonShouldBeDisabledOnSubmit.forEach(function(form) {
    form.addEventListener('submit', function() {
  formsWhoseSubmitButtonShouldBeDisabledOnSubmit.forEach(form => {
    form.addEventListener('submit', () => {
      const submitButton = form.querySelector('button[type="submit"]');
      submitButton.disabled = true;
      submitButton.innerHTML += ' <svg class="icon spinning"><use xlink:href="/static/style/icons.svg#spinner"></use></svg>';


@@ 212,16 210,14 @@ onDomReady(function() {


// Enable log-out.
onDomReady(function() {
onDomReady(() => {
  document.querySelectorAll('a[data-action="logout"]')
    .forEach(function(anchor) {
      anchor.addEventListener('click', function(event) {
    .forEach(anchor => {
      anchor.addEventListener('click', event => {
        if (confirm('Wirklich abmelden?')) {
          const href = anchor.getAttribute('href');
          fetch(href, {method: 'POST'})
            .then(response => {
              location.href = '/authentication/login';
            });
            .then(response => location.href = '/authentication/login');
        };

        event.preventDefault();

M byceps/static/behavior/login.js => byceps/static/behavior/login.js +2 -2
@@ 1,7 1,7 @@
onDomReady(function() {
onDomReady(() => {
  const loginForm = document.getElementById('login-form');
  if (loginForm !== null) {
    loginForm.addEventListener('submit', function(event) {
    loginForm.addEventListener('submit', event => {
      event.preventDefault();

      const loginFailedNotice = document.getElementById('login-failed-notice');

M byceps/static/behavior/seating.js => byceps/static/behavior/seating.js +18 -35
@@ 3,8 3,8 @@
 */
function init_seat_tooltips() {
  document.querySelectorAll('.seat-with-tooltip')
    .forEach(function(seatContainer) {
      seatContainer.addEventListener('mouseover', function() {
    .forEach(seatContainer => {
      seatContainer.addEventListener('mouseover', () => {
        const dataset = seatContainer.dataset;

        let tooltipHTML = '<div class="seat-label">' + dataset.label + '</div>';


@@ 35,7 35,7 @@ function init_seat_tooltips() {
        seatContainer.appendChild(tooltipNode);
      });

      seatContainer.addEventListener('mouseout', function() {
      seatContainer.addEventListener('mouseout', () => {
        const tooltip = seatContainer.querySelector('.seat-tooltip');
        // Tooltip element won't exist at this point if the mouse
        // cursor is above a seat when the page is reloaded, so the


@@ 92,9 92,8 @@ function init_ticket_selector() {
function _make_ticket_selector_open_on_click() {
  const ticket_selector = document.querySelector('.ticket-selector');
  if (ticket_selector !== null) {
    ticket_selector.addEventListener('click', function() {
      this.classList.toggle('ticket-selector--open');
    });
    ticket_selector
      .addEventListener('click', () => this.classList.toggle('ticket-selector--open'));
  }
}



@@ 104,11 103,7 @@ function _make_ticket_selector_open_on_click() {
 */
function _select_ticket_on_click() {
  document.querySelectorAll('.ticket')
    .forEach(function(ticket) {
      ticket.addEventListener('click', function() {
        select_ticket(ticket);
      });
    });
    .forEach(ticket => ticket.addEventListener('click', () => select_ticket(ticket)));
}




@@ 141,9 136,7 @@ function select_ticket(ticket) {
  ticket_selection.dataset.selectedId = ticket_id;
  ticket_selection.dataset.selectedCode = ticket_code;
  ticket_selection.querySelectorAll('.ticket--current')
    .forEach(function(ticket) {
      ticket.classList.remove('ticket--current');
    });
    .forEach(ticket => ticket.classList.remove('ticket--current'));

  ticket.classList.add('ticket--current');



@@ 155,21 148,17 @@ function select_ticket(ticket) {

function set_current_managed_seat(ticket_id) {
  document.querySelectorAll('.area .seat--managed-current')
    .forEach(function(seat) {
      seat.classList.remove('seat--managed-current');
    });
    .forEach(seat => seat.classList.remove('seat--managed-current'));

  document.querySelectorAll('.seat-with-tooltip[data-ticket-id="' + ticket_id + '"] .seat--managed')
    .forEach(function(seat) {
      seat.classList.add('seat--managed-current');
    });
    .forEach(seat => seat.classList.add('seat--managed-current'));
}


function wire_seat_release_button() {
  const release_seat_trigger = document.getElementById('release-seat-trigger');
  if (release_seat_trigger !== null) {
    release_seat_trigger.addEventListener('click', function() {
    release_seat_trigger.addEventListener('click', () => {
      const seat_label = get_selected_seat_label();
      const confirmation_label = seat_label + ' (belegt durch Ticket ' + get_selected_ticket_code() + ') freigeben?';
      if (confirm(confirmation_label)) {


@@ 177,7 166,7 @@ function wire_seat_release_button() {

        const request_url = '/seating/ticket/' + ticket_id + '/seat';

        send_request('DELETE', request_url, function() {
        send_request('DELETE', request_url, () => {
          if (this.readyState === XMLHttpRequest.DONE) {
            if (this.status === 204) {
              reload_with_selected_ticket(ticket_id);


@@ 221,9 210,7 @@ function get_managed_ticket_ids() {

  document.getElementById('ticket-selection')
    .querySelectorAll('.ticket')
    .forEach(function(ticket) {
      managed_ticket_ids.add(ticket.dataset.id);
    });
    .forEach(ticket => managed_ticket_ids.add(ticket.dataset.id));

  return managed_ticket_ids;
}


@@ 239,9 226,7 @@ function mark_managed_seats() {

  for (const ticket_id of managed_ticket_ids.values()) {
    get_seats_with_ticket_code(ticket_id)
      .forEach(function(seat) {
        seat.classList.add('seat--managed');
      });
      .forEach(seat => seat.classList.add('seat--managed'));
  }
}



@@ 249,15 234,13 @@ function mark_managed_seats() {
function mark_seat_for_selected_managed_ticket() {
  const ticket_id = get_selected_ticket_id();
  get_seats_with_ticket_code(ticket_id)
    .forEach(function(seat) {
      seat.classList.add('seat--managed-current');
    });
    .forEach(seat => seat.classList.add('seat--managed-current'));
}


function mark_seats_as_occupiable() {
  document.querySelectorAll('.seat')
    .forEach(function(seat) {
    .forEach(seat => {
      const ticket_id = seat.parentNode.dataset.ticketId;
      if (ticket_id === undefined) {
        seat.classList.add('seat--occupiable');


@@ 269,8 252,8 @@ function mark_seats_as_occupiable() {

function init_occupiable_seats() {
  document.querySelectorAll('.seat--occupiable')
    .forEach(function(seat) {
      seat.addEventListener('click', function() {
    .forEach(seat => {
      seat.addEventListener('click', () => {
        const seat_label = seat.parentNode.dataset.label;
        const confirmation_label = seat_label + ' mit Ticket ' + get_selected_ticket_code() + ' reservieren?';
        if (confirm(confirmation_label)) {


@@ 279,7 262,7 @@ function init_occupiable_seats() {

          const request_url = '/seating/ticket/' + ticket_id + '/seat/' + seat_id;

          send_request('POST', request_url, function() {
          send_request('POST', request_url, () => {
            if (this.readyState === XMLHttpRequest.DONE) {
              if (this.status === 204) {
                reload_with_selected_ticket(ticket_id);