blob: 28d24d478cc8262fae2fedd634a5b8a8c3e15f8f [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// 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.
Copybara854996b2021-09-07 19:36:02 +00004
5const parentSelect = document.getElementById('parent_to_invite');
6const createButton = document.getElementById('create_linked_account_invite');
7const acceptButtons = document.querySelectorAll('.incoming_invite');
8const unlinkButtons = document.querySelectorAll('.unlink_account');
9
10function 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
24function 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
39function 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
56if (parentSelect) {
57 parentSelect.onchange = function(e) {
58 const email = parentSelect.value;
59 createButton.disabled = email ? '' : 'disabled';
60 };
61}
62
63if (createButton) {
64 createButton.onclick = CreateLinkedAccountInvite;
65}
66
67if (acceptButtons) {
68 for (const acceptButton of acceptButtons) {
69 acceptButton.onclick = AcceptIncomingInvite;
70 }
71}
72
73if (unlinkButtons) {
74 for (const unlinkButton of unlinkButtons) {
75 unlinkButton.onclick = UnlinkAccounts;
76 }
77}