summaryrefslogtreecommitdiff
path: root/media/js/pgeuconf.js
blob: 1b39df99ec31091dd2e2d0cc5e1b93a10c813a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Shared scripts for pgeu conference frontends */


/* Call for papers form */
async function addSpeakerClick(event) {
  event.preventDefault();

  let email = prompt('Enter the email address of the speaker to add.');
  if (email) {
    let ul = event.target.previousElementSibling;
    let select = ul.previousElementSibling;

    let res = await fetch('/events/' + select.dataset.urlname + '/callforpapers/lookups/speakers/?' + new URLSearchParams({'query': email}));
    if (res.status != 200) {
      alert('Speaker not found.\n\nNote that thee speaker must have an existing profile on this site with the given email address before they can be adde to a session.\n');
      return;
    }
    let speaker = await res.json();

    if (select.querySelector('option[value="' + speaker.id + '"]')) {
      alert('This speaker has already been added.');
      return;
    }

    let newli = document.createElement('li');
    newli.dataset.id = speaker.id;
    newli.innerHTML = speaker.name + ' (<a class="pgeu-speaker-remove" href=#"#>remove</a>)';
    ul.appendChild(newli);

    let newoption = document.createElement('option');
    newoption.value = speaker.id;
    newoption.selected = true;
    select.appendChild(newoption);
  }

  return false;
}

function removeSpeakerClick(event) {
  if (event.target.tagName == 'A' && event.target.classList.contains('pgeu-speaker-remove')) {
    event.preventDefault();

    let idtoremove = event.target.parentNode.dataset.id;

    if (!confirm('Are you sure you want to remove this speaker?')) {
      return;
    }

    /* <a>.<li>.<ul>.<select> */
    event.target.parentNode.parentNode.previousElementSibling.querySelector('option[value="' + idtoremove + '"]').remove();

    event.target.parentNode.remove();

    alert('Speaker removed. You have to also save the form to make it permanent.');
  }
}

/*
 * Global event listeners
 */
document.addEventListener('DOMContentLoaded', (event) => {
  /* Call for papers form */
  document.querySelectorAll("button.pgeu-speaker-add").forEach((button) => {
    button.addEventListener('click', addSpeakerClick);
  });
  document.querySelectorAll("ul.pgeu-speaker-list").forEach((ul) => {
    ul.addEventListener('click', removeSpeakerClick);
  });

  /* Invoice confirm */
  document.querySelectorAll("input.pgeu-confirm-invoice-button").forEach((input) => {
    input.addEventListener('click', (event) => {
      if (!confirm('Once you proceed to payment, an invoice will be generated for your ' + event.target.dataset.confirmwhat + ', and you will no longer be able to change it.\n\nThis invoice will be addressed to the person, company and address specified in the registration - please take a moment to review those fields if you need to.\n\nThe invoice will be delivered as a PDF in your browser, no paper invoice will be sent.\n\Are you sure you want to proceed to payment?')) {
        event.preventDefault();
      }
    });
  });

  /* Registration cancellation */
  document.querySelectorAll("input.pgeu-confirm-cancel-registration-button").forEach((input) => {
    input.addEventListener('click', (event) => {
      if (!confirm('Are you sure you want to cancel and remove your registration?')) {
        event.preventDefault();
      }
    });
  });

  /* Generic page-level alerts */
  document.querySelectorAll("div.pgeu-pagealert").forEach((div) => {
    alert(div.innerText);
  });
});