diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2008-11-14 16:58:59 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2008-11-14 16:58:59 +0000 |
commit | 61d957e372b623856338b8223fc80ad440bd1d93 (patch) | |
tree | 69729400501e84b6943ebdf42f739ad36e6242c2 /themes/default/js/user.js | |
parent | ed90edfa960d94705768cae7061804e3c44f650a (diff) |
Rename login.js to user.js
Diffstat (limited to 'themes/default/js/user.js')
-rw-r--r-- | themes/default/js/user.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/themes/default/js/user.js b/themes/default/js/user.js new file mode 100644 index 00000000..5acc711f --- /dev/null +++ b/themes/default/js/user.js @@ -0,0 +1,69 @@ +$(document).ready(function() { + $("#gLoginForm").submit(function() { + process_login(); + return false; + }); + $("#gLogoutLink").click(function() { + process_logout(); + return false; + }); +}); + +function show_login() { + $("#gLoginLink").css({display: "none"}); + $("#gLoginClose").css({display: "inline"}); + var url = $("#gLoginForm").attr("formSrc"); + $.get(url, null, function(data, textStatus) { + $("#gLoginForm").html(data); + $("#gLoginForm").css({display: "block"}); + }); +} + +function close_login() { + $("#gLoginLink").css({display: "inline"}); + $("#gLoginForm").css({display: "none"}); + $("#gLoginForm").html(""); + $("#gLoginClose").css({display: "none"}); + $("input#gUsername").val(""); + $("input#gPassword").val(""); +} + +function process_login() { + var username = $("input#gUsername").val(); + var password = $("input#gPassword").val(); + var data = 'username=' + username + '&password=' + password; + $.ajax({ + url: $("#gLogin").attr("action"), + type: "POST", + data: data, + dataType: "json", + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("textStatus: " + textStatus + "\nerrorThrown: " + errorThrown); + }, + success: function(data, textStatus) { + if (data.error_message != "") { + $("#gLoginMessage").html(data.error_message); + $("#gLoginMessage").css({display: "block"}); + $("#gLogin").addClass("gError"); + } else { + window.location.reload(); + } + } + }); +} + +function process_logout() { + $.ajax({ + url: $("#gLogoutLink").attr("href"), + type: "GET", + dataType: "json", + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("textStatus: " + textStatus + "\nerrorThrown: " + errorThrown); + }, + success: function(data, textStatus) { + if (data.logout) { + window.location.reload(); + } + } + }); +}
\ No newline at end of file |