diff options
author | M Somerville <matthew-github@dracos.co.uk> | 2020-10-23 10:31:52 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-11-02 04:05:34 +0000 |
commit | e37e3af3656b4545e638494c3ada61e37df7ee0a (patch) | |
tree | 04cb8d92236cb3ab868b78e88d9386ca65cd8528 | |
parent | 4b5252e0671cb9636b141009ea27daebf9f70c42 (diff) |
[Borsetshire] Move sign-in button code inline.
This should fix a race condition on Travis where the button is clicked
before the JavaScript on the button has registered.
-rw-r--r-- | templates/web/borsetshire/auth/_general_top.html | 34 | ||||
-rw-r--r-- | web/cobrands/borsetshire/js.js | 21 |
2 files changed, 35 insertions, 20 deletions
diff --git a/templates/web/borsetshire/auth/_general_top.html b/templates/web/borsetshire/auth/_general_top.html index 3ab3c39bc..5067772fe 100644 --- a/templates/web/borsetshire/auth/_general_top.html +++ b/templates/web/borsetshire/auth/_general_top.html @@ -1,3 +1,5 @@ +<div class="hidden-nojs"> + <p> Click on one of the buttons below to log in as one of the four different types of user we’ve set up on this demo site: @@ -21,3 +23,35 @@ different types of user we’ve set up on this demo site: <p> Or sign in as normal, with an email address and password: </p> + +</div> + +<script nonce="[% csp_nonce %]"> +(function(){ + + fixmystreet.borsetshire = fixmystreet.borsetshire || {}; + fixmystreet.borsetshire.set_redirect = function(form) { + var e = form.username.value; + if (e == 'inspector@example.org') { + form.r.value = 'my/planned'; + } else if (e == 'cs@example.org') { + form.r.value = 'reports'; + } else if (e == 'super@example.org') { + form.r.value = 'admin'; + } + }; + + function set_up_button() { + var form = document.forms.general_auth; + form.username.value = this.getAttribute('data-email'); + form.password_sign_in.value = 'password'; + fixmystreet.borsetshire.set_redirect(form); + form.submit(); + } + + [].forEach.call(document.querySelectorAll('#demo-user-list button'), function(b) { + b.addEventListener('click', set_up_button); + }); + +})(); +</script> diff --git a/web/cobrands/borsetshire/js.js b/web/cobrands/borsetshire/js.js index 2888a9548..6c0da398e 100644 --- a/web/cobrands/borsetshire/js.js +++ b/web/cobrands/borsetshire/js.js @@ -4,27 +4,8 @@ return; } - function set_redirect(form) { - var e = form.username.value; - if (e == 'inspector@example.org') { - form.r.value = 'my/planned'; - } else if (e == 'cs@example.org') { - form.r.value = 'reports'; - } else if (e == 'super@example.org') { - form.r.value = 'admin'; - } - } - - $('#demo-user-list button').click(function(){ - var form = document.forms.general_auth; - form.username.value = $(this).data('email'); - form.password_sign_in.value = 'password'; - set_redirect(form); - form.submit(); - }); - $('form[name=general_auth]').on('submit', function() { - set_redirect(this); + fixmystreet.borsetshire.set_redirect(this); }); })(); |