Mercurial > bugzilla-dashboard
diff js/main.js @ 41:7a1162b1b7e7
Added app module
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sat, 24 Apr 2010 17:56:20 -0700 |
parents | 1cf0cdbc18cc |
children | 0a1c7fec0af2 |
line wrap: on
line diff
--- a/js/main.js Sat Apr 24 15:16:02 2010 -0700 +++ b/js/main.js Sat Apr 24 17:56:20 2010 -0700 @@ -2,53 +2,62 @@ function() { const BASE_TITLE = document.title; - function onLoginChange() { - var username = $("#login-username").val(); - var password = $("#login-password").val(); - var title = BASE_TITLE; + var require = Require.build(); + + require("app/login").whenChanged( + function changeTitle(user) { + var title = BASE_TITLE; + + if (user.isLoggedIn) + title = user.username + "'s " + BASE_TITLE; - if (username) { - $("#login").fadeOut(); - title = username + "'s " + BASE_TITLE; + if (document.title != title) { + document.title = title; + $("#header .title").text(title); + } + }); - $(".requires-no-login").hide(); - $(".requires-login").show(); - if (password) { - $(".requires-auth-login").show(); + require("app/login").whenChanged( + function changeUI(user) { + if (user.isLoggedIn) { + $(".requires-no-login").hide(); + $(".requires-login").show(); + if (user.isAuthenticated) { + $(".requires-auth-login").show(); + } else { + $(".requires-auth-login").hide(); + } } else { + $(".requires-no-login").show(); + $(".requires-login").hide(); $(".requires-auth-login").hide(); } - } else { - $("#login").fadeIn(); - $(".requires-no-login").show(); - $(".requires-login").hide(); - $(".requires-auth-login").hide(); - } - - if (document.title != title) { - document.title = title; - $("#header .title").text(title); - } - } + }); $("#header .menu li").click( - function(event) { + function openDialog(event) { var dialog = $("#" + this.title); if (dialog.length == 0) throw new Error("dialog not found: " + this.title); dialog.fadeIn(); }); + $(".dialog").click( + function dismissDialogOnOutsideClick(event) { + if (event.target == this) + $(this).fadeOut(); + }); + $("#login-form").submit( function(event) { event.preventDefault(); - onLoginChange(); + require("app/login").set($("#login-username").val(), + $("#login-password").val()); + $("#login").fadeOut(); }); - $(".dialog").click( - function(event) { - if (event.target == this) - $(this).fadeOut(); - }); - onLoginChange(); + require("app/login").set($("#login-username").val(), + $("#login-password").val()); + if (!require("app/login").isLoggedIn()) + $("#login").fadeIn(); });