From 30902bc9cdf019e09e72fbb269d6d177ec6457ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 24 Aug 2017 10:31:18 +0200 Subject: [PATCH] Orgs: made the admin picker a bit nicer to work with Also it now asks for a confirmation before transferring admin-ship to the new admin user. --- src/templates/organizations/view_embed.jade | 41 ++++++++++++++++----- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/templates/organizations/view_embed.jade b/src/templates/organizations/view_embed.jade index 61d9d449..67db116a 100644 --- a/src/templates/organizations/view_embed.jade +++ b/src/templates/organizations/view_embed.jade @@ -47,11 +47,16 @@ | {% endif %} .input-group label.item-admin-user Org admin - input#admin-select.form-control( - name='admin_user', - type='text', - placeholder='Administrator', - value='{{ admin_user.full_name }}') + p#admin-name + a(href='javascript:showAdminPicker()', title='Click to choose another administrator') {{ admin_user.full_name }} + p#admin-picker + input#admin-select.form-control( + name='admin_user', + type='text', + placeholder='Administrator') + a(href='javascript:hideAdminPicker()') + i.pi-cancel.text-danger + script $('#admin-picker').hide(); .input-group button#item-save.btn.btn-default.btn-block(type='submit') i.pi-check @@ -220,7 +225,7 @@ script. '{{config.ALGOLIA_PUBLIC_KEY}}', '{{config.ALGOLIA_INDEX_USERS}}', function (event, hit, dataset) { - setAdmin(hit.objectID); + setAdmin(hit.objectID, hit.full_name); } ); @@ -247,14 +252,21 @@ script. }); }; - function setAdmin(userId) { - if (!userId || userId.length == 0) { + function setAdmin(user_id, full_name) { + if (!user_id || user_id.length == 0) { toastr.error('Please select a user from the list'); return; } + + if (!confirm("Are you sure you want to transfer administrator privileges to " + full_name + "?")) { + hideAdminPicker(); + toastr.warning('Cancelled administrative transfer.'); + return; + } + patchOrganization({ op: 'assign-admin', - user_id: userId + user_id: user_id }) .done(function (data) { window.location.reload(); @@ -359,4 +371,15 @@ script. return false; } + function showAdminPicker() { + $('#admin-name').hide(); + $('#admin-picker').show(function() { + $(this).find('input').focus(); + }); + } + function hideAdminPicker() { + $('#admin-picker').hide(); + $('#admin-name').show(); + } + | {% endblock %}