|
1 | | -/* global OC, $ */ |
2 | | -(function(OC, $){ |
3 | | - |
4 | | - $(document).ready(function() { |
5 | | - function impersonate(userId) { |
6 | | - $.post( |
7 | | - OC.generateUrl('apps/impersonate/user'), |
8 | | - { userId: userId } |
9 | | - ).done(function() { |
10 | | - window.location = OC.generateUrl('apps/files'); |
11 | | - }).fail(function( result ) { |
12 | | - OC.dialogs.alert(result.responseJSON.message, t('impersonate', 'Could not impersonate user')); |
13 | | - }); |
14 | | - } |
15 | | - |
16 | | - function impersonateDialog(event) { |
17 | | - let userId = event.target.closest('.row').dataset.id; |
18 | | - OC.dialogs.confirm( |
19 | | - t('impersonate', 'Are you sure you want to impersonate "{userId}"?', {userId: userId}), |
20 | | - t('impersonate', 'Impersonate user' ), |
21 | | - function(result) { |
22 | | - if (result) { |
23 | | - impersonate(userId); |
24 | | - } |
25 | | - }, |
26 | | - true |
27 | | - ); |
| 1 | +/* global OC */ |
| 2 | +(function(OC) { |
| 3 | + function impersonate(userId) { |
| 4 | + var xhr = new XMLHttpRequest() |
| 5 | + xhr.onreadystatechange = function(data) { |
| 6 | + if (xhr.readyState === XMLHttpRequest.DONE) { |
| 7 | + if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) { |
| 8 | + window.location = OC.generateUrl('/') |
| 9 | + } else { |
| 10 | + OC.dialogs.alert(JSON.parse(xhr.response).message, t('impersonate', 'Could not impersonate user'), undefined, undefined) |
| 11 | + } |
| 12 | + } |
28 | 13 | } |
| 14 | + xhr.open('POST', OC.generateUrl('apps/impersonate/user')) |
| 15 | + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') |
| 16 | + xhr.send('userId=' + encodeURIComponent(userId) + '&requesttoken=' + encodeURIComponent(OC.requestToken)) |
| 17 | + } |
29 | 18 |
|
30 | | - let registerFunction = function (delay) { |
31 | | - if(OCA.Settings === undefined) { |
32 | | - delay = delay * 2; |
33 | | - if(delay === 0) { |
34 | | - delay = 15; |
| 19 | + function impersonateDialog(event) { |
| 20 | + var userId = event.target.closest('.row').dataset.id |
| 21 | + OC.dialogs.confirm( |
| 22 | + t('impersonate', 'Are you sure you want to impersonate "{userId}"?', { userId: userId }), |
| 23 | + t('impersonate', 'Impersonate user'), |
| 24 | + function(result) { |
| 25 | + if (result) { |
| 26 | + impersonate(userId) |
35 | 27 | } |
36 | | - if(delay > 500) { |
37 | | - console.warn("Could not register impersonate script"); |
38 | | - return; |
39 | | - } |
40 | | - setTimeout(function() {registerFunction(delay)}, delay); |
41 | | - } else { |
42 | | - OCA.Settings.UserList.registerAction('icon-user', t('impersonate', 'Impersonate'), impersonateDialog) |
| 28 | + }, |
| 29 | + true |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + var registerFunction = function(delay) { |
| 34 | + delay = delay || 0 |
| 35 | + if (OCA.Settings === undefined) { |
| 36 | + delay = delay * 2 |
| 37 | + if (delay === 0) { |
| 38 | + delay = 15 |
| 39 | + } |
| 40 | + if (delay > 500) { |
| 41 | + console.error('Could not register impersonate script') |
| 42 | + return |
43 | 43 | } |
44 | | - }; |
45 | | - registerFunction(0); |
46 | | - }); |
| 44 | + setTimeout(function() { registerFunction(delay) }, delay) |
| 45 | + } else { |
| 46 | + OCA.Settings.UserList.registerAction('icon-user', t('impersonate', 'Impersonate'), impersonateDialog) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + document.addEventListener('DOMContentLoaded', registerFunction) |
47 | 51 |
|
48 | | -})(OC, $); |
| 52 | +})(OC) |
0 commit comments