js: keep last selected ou on login form (fixes #31329)

This commit is contained in:
Benjamin Dauvergne 2019-03-12 19:40:32 +01:00
parent eac4437e5c
commit d856fc07ca
2 changed files with 17 additions and 0 deletions

View File

@ -265,6 +265,8 @@ class AuthenticationForm(auth_forms.AuthenticationForm):
def media(self):
media = super(AuthenticationForm, self).media
media.add_js(['authentic2/js/js_seconds_until.js'])
if app_settings.A2_LOGIN_FORM_OU_SELECTOR:
media.add_js(['authentic2/js/ou_selector.js'])
return media

View File

@ -0,0 +1,15 @@
$(function () {
var $ou_selector = $('#id_ou');
var cache_key = 'a2_login_ou';
var $form = $ou_selector.parents('form');
var last_selection = localStorage.getItem(cache_key);
if (last_selection) {
$ou_selector.val(last_selection);
}
$form.on('submit', function () {
var value = $ou_selector.val();
if (value) {
localStorage.setItem(cache_key, value);
}
});
});