Skip to content
Snippets Groups Projects
Commit 458fd7d7 authored by cramakri's avatar cramakri
Browse files

BIS-111 SP-187 : Refactor login page to avoid code duplication

SVN: 26030
parent cf43ad62
No related branches found
No related tags found
No related merge requests found
/**
* A module for configuring the login page to openBIS. It hides and shows
* the login form and main content as necessary. It invokes a specified
* function on successful login.
*
* This module assumes that the page follows the structure of our standard
* login page. This means that the Following elements are defined :
*
* div#login-form-div
* form#login-form
* input#username
* input#password
* button#login-button
* div#main
* button#logout-button
*
* Assuming these elements are defined, this module configures their appeareance
* and behavior.The div#main element is initially hidden until the user logs in.
* Once logged in, the div#login-form-div element is hidden and the div#main
* element is made visible.
*
* @module openbis-login
* @requires jquery
*/
/**
* Configure the login page to hide and show the login form and main content
* as appropriate
*
* @param openbis The openbis facade object
* @param onLogin The function to be called when login succeeds.
* @function
*/
function configureLoginPage(openbis, onLogin)
{
$('#main').hide();
var username = $("#username").value;
if(username == null || username.length==0) {
$("#username").focus();
} else {
$("#login-button").focus();
}
$('#logout-button').click(function() {
openbis.logout(function(data) {
$("#login-form-div").show();
$("#main").hide();
$("#username").focus();
});
});
$('#login-form').submit(function() {
openbis.login( $.trim($('#username').val()), $.trim($('#password').val()), function(data) { onLogin(data) })
});
openbis.ifRestoredSessionActive(function(data) { onLogin(data) });
// Make the ENTER key the default button
$("login-form input").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$('button[type=submit].default').click();
return false;
} else {
return true;
}
});
}
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<script type="text/javascript" src="d3.time.js"></script> <script type="text/javascript" src="d3.time.js"></script>
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="openbis.js"></script> <script type="text/javascript" src="openbis.js"></script>
<script type="text/javascript" src="openbis-login.js"></script>
<!-- To speed development, cache the requests --> <!-- To speed development, cache the requests -->
<!-- <script type="text/javascript" src="openbis-request-cache.js"></script> --> <!-- <script type="text/javascript" src="openbis-request-cache.js"></script> -->
<script> <script>
...@@ -153,38 +154,7 @@ function enterApp(data) ...@@ -153,38 +154,7 @@ function enterApp(data)
$(document).ready(function() { $(document).ready(function() {
$('#main').hide(); configureLoginPage(openbisServer, enterApp);
var username = $("#username").value;
if(username == null || username.length==0) {
$("#username").focus();
} else {
$("#login-button").focus();
}
$('#logout-button').click(function() {
openbisServer.logout(function(data) {
$("#login-form-div").show();
$("#main").hide();
$("#username").focus();
});
});
$('#login-form').submit(function() {
openbisServer.login( $.trim($('#username').val()), $.trim($('#password').val()), function(data) { enterApp(data) })
});
openbisServer.ifRestoredSessionActive(function(data) { enterApp(data) });
// Make the ENTER key the default button
$("login-form input").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$('button[type=submit].default').click();
return false;
} else {
return true;
}
});
}); });
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment