From c2eb9c81d5d4aaa423de8f1e68450d7c087ec78a Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 6 Jan 2024 20:02:19 +0100 Subject: [PATCH] refactoring --- lam/lib/baseType.inc | 11 ++--------- lam/lib/lists.inc | 2 +- lam/templates/lib/500_lam.js | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lam/lib/baseType.inc b/lam/lib/baseType.inc index 26adbf7ba..1d6e7ed48 100644 --- a/lam/lib/baseType.inc +++ b/lam/lib/baseType.inc @@ -4,7 +4,7 @@ use LAM\TYPES\ConfiguredType; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2005 - 2023 Roland Gruber + Copyright (C) 2005 - 2024 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -244,14 +244,7 @@ class baseType { $onchange = ''; if ($hasLockOptions && $hasUnlockOptions) { $radioDisabled = false; - $onchange = 'if (jQuery(\'#lam_accountStatusAction0:checked\').val()) {' . - 'jQuery(\'#lam_accountStatusDialogLockDiv\').removeClass(\'hidden\');' . - 'jQuery(\'#lam_accountStatusDialogUnlockDiv\').addClass(\'hidden\');' . - '}' . - 'else {' . - 'jQuery(\'#lam_accountStatusDialogLockDiv\').addClass(\'hidden\');' . - 'jQuery(\'#lam_accountStatusDialogUnlockDiv\').removeClass(\'hidden\');' . - '};'; + $onchange = 'window.lam.accountLists.lockUnlockRadioChange();'; } if (!$hasUnlockOptions) { $selectedRadio = 'lock'; diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index e0eef7304..dbb87999a 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -1030,7 +1030,7 @@ class lamList { $refreshButton->setTitle(_("Refresh")); $rightButtonGroup->addElement($refreshButton); $settingsLink = new htmlLink('', '#', '../../graphics/configure.svg'); - $settingsLink->setOnClick('listShowSettingsDialog(\'' . _('Change list settings') . '\', \'' . _('Ok') . '\', \'' . _('Cancel') . '\');'); + $settingsLink->setOnClick('window.lam.accountLists.listShowSettingsDialog(\'' . _('Change list settings') . '\', \'' . _('Ok') . '\', \'' . _('Cancel') . '\');'); $settingsLink->setTitle(_('Change settings')); $settingsLink->setCSSClasses(array('icon')); $rightButtonGroup->addElement($settingsLink); diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index de8261357..99614bb0b 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -64,6 +64,8 @@ function listPageNumberKeyPress(url, e) { return true; } +window.lam.accountLists = window.lam.accountLists || {}; + /** * Shows the dialog to change the list settings. * @@ -71,7 +73,7 @@ function listPageNumberKeyPress(url, e) { * @param okText text for Ok button * @param cancelText text for Cancel button */ -function listShowSettingsDialog(title, okText, cancelText) { +window.lam.accountLists.listShowSettingsDialog = function (title, okText, cancelText) { const dialogContent = document.getElementById('settingsDialog').cloneNode(true); dialogContent.classList.remove('hidden'); dialogContent.firstElementChild.id = 'settingsDialogForm_dlg'; @@ -89,6 +91,20 @@ function listShowSettingsDialog(title, okText, cancelText) { }); } +/** + * Executed when radio buttons change for (un)locking accounts. + */ +window.lam.accountLists.lockUnlockRadioChange = function () { + if (document.querySelector('#lam_accountStatusAction0:checked')) { + document.getElementById('lam_accountStatusDialogLockDiv').classList.remove('hidden'); + document.getElementById('lam_accountStatusDialogUnlockDiv').classList.add('hidden'); + } + else { + document.getElementById('lam_accountStatusDialogLockDiv').classList.add('hidden'); + document.getElementById('lam_accountStatusDialogUnlockDiv').classList.remove('hidden'); + } +} + /** * Submits the form by clicking on the given button if enter was pressed. * Example: SubmitForm('apply_filter', event);