Mercurial > bugzilla-dashboard
diff js/modules/app.js @ 68:6f5b5b404066
added a refresh button.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 25 Apr 2010 10:58:25 -0700 |
parents | d0f5f87e0b0a |
children | 4ec651cc606e |
line wrap: on
line diff
--- a/js/modules/app.js Sun Apr 25 09:26:13 2010 -0700 +++ b/js/modules/app.js Sun Apr 25 10:58:25 2010 -0700 @@ -60,6 +60,22 @@ }; }; +Require.modules["app/commands"] = function(exports, require) { + var commands = {}; + + exports.get = function get(name) { + if (!(name in commands)) + throw new Error("command not found: " + name); + return commands[name]; + }; + + exports.register = function(options) { + if (options.name in commands) + throw new Error("command already registered: " + options.name); + commands[options.name] = options; + }; +}; + Require.modules["app/ui/login-form"] = function(exports, require) { var $ = require("jQuery"); var cachedUsername = $("#login .username").val(); @@ -246,8 +262,12 @@ }); $("#header .menu li").click( - function openDialogForMenuItem(event) { - openDialog(this.getAttribute("data-dialog")); + function onMenuItemClick(event) { + if (this.hasAttribute("data-command")) { + var cmdName = this.getAttribute("data-command"); + require("app/commands").get(cmdName).execute(); + } else + openDialog(this.getAttribute("data-dialog")); }); $(".dialog").click( @@ -531,7 +551,17 @@ email2_reporter: 1}); }; + var refreshCommand = { + name: "refresh-dashboard", + execute: function execute() { + var user = require("app/login").get(); + if (user.isLoggedIn) + update(user.username); + } + }; + exports.init = function init() { + require("app/commands").register(refreshCommand); require("app/login").whenChanged( function changeSearchCriteria(user) { if (user.isLoggedIn) {