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