From 1901f33851f1e37682a3e8d26028f09b7ca5fc7f Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Thu, 25 Nov 2021 12:17:53 -0700 Subject: [PATCH] Create client layout for managing users --- public/scripts/manage/account.js | 33 ++++++++++++++++++++++++++++++++ public/stylesheets/form.css | 2 +- routes/manage.js | 4 +++- views/accounts/createuser.pug | 19 +++++++++++------- 4 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 public/scripts/manage/account.js diff --git a/public/scripts/manage/account.js b/public/scripts/manage/account.js new file mode 100644 index 0000000..6b51c2f --- /dev/null +++ b/public/scripts/manage/account.js @@ -0,0 +1,33 @@ +import * as Data from "../data.js"; +import * as Form from "../form.js"; + +const submissionForm = document.getElementById('submission-form'); +const emailTextbox = document.getElementById('email-textbox'); +const passwordTextbox = document.getElementById('password-textbox'); +const adminCheckbox = document.getElementById('admin-checkbox'); +const submitButton = document.getElementById('submit-button'); +const deleteButton = document.getElementById('delete-button'); + +async function Initialize() { + let params = new URLSearchParams(location.search); + let accountID = params.get('account'); + if(accountID) { + const account = await Data.getAccount(accountID); + console.log(account); + + emailTextbox.value = account.email; + + passwordTextbox.placeholder = "leave unchanged"; + + adminCheckbox.checked = account.isAdmin; + + Form.addHiddenValue('account', accountID, submissionForm); + + deleteButton.style.visibility = "visible"; + deleteButton.disabled = false; + } + emailTextbox.disabled = false; + passwordTextbox.disabled = false; + adminCheckbox.disabled = false; +} +Initialize(); \ No newline at end of file diff --git a/public/stylesheets/form.css b/public/stylesheets/form.css index 32123e7..389028c 100644 --- a/public/stylesheets/form.css +++ b/public/stylesheets/form.css @@ -42,6 +42,6 @@ form { align-items: center; } - #admin { + #admin-checkbox { width: auto; } \ No newline at end of file diff --git a/routes/manage.js b/routes/manage.js index 756c58d..e9d4377 100644 --- a/routes/manage.js +++ b/routes/manage.js @@ -138,7 +138,9 @@ router.post('/team', adminLoggedIn, function(req, res, next) { }); router.get('/account', adminLoggedIn, (req, res, next) => { - res.render('accounts/createuser', { title: 'Create user' }); + let title = req.query.account ? 'Manage User' : 'Create User' + + res.render('accounts/createuser', { title }); }); module.exports = router; diff --git a/views/accounts/createuser.pug b/views/accounts/createuser.pug index 02560ec..cc5324d 100644 --- a/views/accounts/createuser.pug +++ b/views/accounts/createuser.pug @@ -7,18 +7,23 @@ block stylesheets block content div#mobile-view h1 #{title} - form(action='/auth/register', method='POST') + form#submission-form(action='/auth/register', method='POST') span(class='form-section') label Email span(class='form-section-input') - input(type="email", name="email") + input#email-textbox(type="email", name="email" disabled) span(class='form-section') label Password - span(class='form-section-input') - input(type="password", name="password") + span(class='form-section-input' ) + input#password-textbox(type="password" name="password" disabled) span(class='form-section') span(class='form-section-checkbox') - input#admin(type="checkbox", name="admin") - label(for="admin") Grant admin privileges + input#admin-checkbox(type="checkbox" name="admin" disabled) + label(for="admin-checkbox") Grant admin privileges span(class='form-section') - button#submit-button(type="submit") Submit \ No newline at end of file + button#submit-button(type="submit" disabled) Submit + span(class='form-section') + button#delete-button(type="delete" disabled) Delete + +block scripts + script(src='/scripts/manage/account.js' type="module") \ No newline at end of file