From 7ea2f37b89598b87cd462c98211b3d624cb19a38 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 29 Oct 2019 20:19:53 +0100 Subject: [PATCH] Moooaaar button (user delete) --- src/js/yunohost/controllers/users.js | 76 ++++++++++++++-------------- src/locales/en.json | 2 +- src/views/user/user_info.ms | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/js/yunohost/controllers/users.js b/src/js/yunohost/controllers/users.js index e66aa2c0..abcd04ae 100644 --- a/src/js/yunohost/controllers/users.js +++ b/src/js/yunohost/controllers/users.js @@ -63,7 +63,44 @@ // Show user information app.get('#/users/:user', function (c) { c.api('GET', '/users/'+ c.params['user'], {}, function(data) { - c.view('user/user_info', data); + c.view('user/user_info', data, function() { + + // Configure delete button behavior + $('button[data-action="delete"]').on("click", function() { + var user = $(this).data("user"); + + var params = {}; + + // make confirm content + var purgeCheckbox = '
'; + var purgeAlertMessage = ''; + var confirmModalContent = $('
'+ y18n.t('confirm_delete', [user]) +'

'+ purgeCheckbox +'
'+ purgeAlertMessage +'
'); + + // display confirm modal + c.confirm( + y18n.t('users'), + confirmModalContent, + function(){ + c.api('DELETE', '/users/'+ user, params, function(data) { + c.redirect_to('#/users'); + }); + } + ); + + // toggle purge warning and parameter + confirmModalContent.find("input").click(function(){ + + if (confirmModalContent.find("input").is(':checked')) { + params.purge = ""; + confirmModalContent.find(".danger").show(); + } + else { + delete params.purge; + confirmModalContent.find(".danger").hide(); + }; + }); + }); + }); }); }); @@ -188,41 +225,4 @@ }, 'GET'); }); - // Remove existing user - app.get('#/users/:user/delete', function (c) { - - var params = {}; - - // make confirm content - var purgeCheckbox = '
'; - var purgeAlertMessage = ''; - var confirmModalContent = $('
'+ y18n.t('confirm_delete', [c.params['user']]) +'

'+ purgeCheckbox +'
'+ purgeAlertMessage +'
'); - - // display confirm modal - c.confirm( - y18n.t('users'), - confirmModalContent, - function(){ - c.api('DELETE', '/users/'+ c.params['user'], params, function(data) { - c.redirect_to('#/users'); - }); - } - ); - - // toggle purge warning and parameter - confirmModalContent.find("input").click(function(){ - - if (confirmModalContent.find("input").is(':checked')) { - params.purge = ""; - confirmModalContent.find(".warning").show(); - } - else { - delete params.purge; - confirmModalContent.find(".warning").hide(); - }; - - }); - - }); - })(); diff --git a/src/locales/en.json b/src/locales/en.json index a4a70211..13cc943a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -428,6 +428,6 @@ "appslists_last_update": "Last update", "appslists_unknown_list": "Unknown apps list: %s", "name": "Name", - "purge_user_data_checkbox": "Purge %s's data? (This will remove the content of it's home and mail directories.)", + "purge_user_data_checkbox": "Purge %s's data? (This will remove the content of its home and mail directories.)", "purge_user_data_warning": "Purging user's data is not reversible. Be sure you know what you're doing!" } diff --git a/src/views/user/user_info.ms b/src/views/user/user_info.ms index ccca3788..7262aa89 100644 --- a/src/views/user/user_info.ms +++ b/src/views/user/user_info.ms @@ -62,7 +62,7 @@ {{t 'user_username_edit' username}} - {{t 'delete'}} +