Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | const parentSelect = document.getElementById('parent_to_invite'); |
| 6 | const createButton = document.getElementById('create_linked_account_invite'); |
| 7 | const acceptButtons = document.querySelectorAll('.incoming_invite'); |
| 8 | const unlinkButtons = document.querySelectorAll('.unlink_account'); |
| 9 | |
| 10 | function CreateLinkedAccountInvite(ev) { |
| 11 | const email = parentSelect.value; |
| 12 | const message = { |
| 13 | email: email, |
| 14 | }; |
| 15 | const inviteCall = window.prpcClient.call( |
| 16 | 'monorail.Users', 'InviteLinkedParent', message); |
| 17 | inviteCall.then((resp) => { |
| 18 | location.reload(); |
| 19 | }).catch((reason) => { |
| 20 | console.error('Inviting failed: ' + reason); |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | function AcceptIncomingInvite(ev) { |
| 25 | const email = ev.target.attributes['data-email'].value; |
| 26 | const message = { |
| 27 | email: email, |
| 28 | }; |
| 29 | const acceptCall = window.prpcClient.call( |
| 30 | 'monorail.Users', 'AcceptLinkedChild', message); |
| 31 | acceptCall.then((resp) => { |
| 32 | location.reload(); |
| 33 | }).catch((reason) => { |
| 34 | console.error('Accepting failed: ' + reason); |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | function UnlinkAccounts(ev) { |
| 40 | const parent = ev.target.dataset.parent; |
| 41 | const child = ev.target.dataset.child; |
| 42 | const message = { |
| 43 | parent: {display_name: parent}, |
| 44 | child: {display_name: child}, |
| 45 | }; |
| 46 | const unlinkCall = window.prpcClient.call( |
| 47 | 'monorail.Users', 'UnlinkAccounts', message); |
| 48 | unlinkCall.then((resp) => { |
| 49 | location.reload(); |
| 50 | }).catch((reason) => { |
| 51 | console.error('Unlinking failed: ' + reason); |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | if (parentSelect) { |
| 57 | parentSelect.onchange = function(e) { |
| 58 | const email = parentSelect.value; |
| 59 | createButton.disabled = email ? '' : 'disabled'; |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | if (createButton) { |
| 64 | createButton.onclick = CreateLinkedAccountInvite; |
| 65 | } |
| 66 | |
| 67 | if (acceptButtons) { |
| 68 | for (const acceptButton of acceptButtons) { |
| 69 | acceptButton.onclick = AcceptIncomingInvite; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (unlinkButtons) { |
| 74 | for (const unlinkButton of unlinkButtons) { |
| 75 | unlinkButton.onclick = UnlinkAccounts; |
| 76 | } |
| 77 | } |