Bug 968188 - Introduce 'action' option in Home.panels.add() API (r=margaret)

This commit is contained in:
Lucas Rocha 2014-02-13 11:19:57 +00:00
parent ce061be925
commit ec8f86e09c

View File

@ -163,6 +163,12 @@ let HomePanels = Object.freeze({
GRID: "grid"
}),
// Valid actions for a panel.
Action: Object.freeze({
INSTALL: "install",
REFRESH: "refresh"
}),
// Holds the currrent set of registered panels.
_panels: {},
@ -202,8 +208,11 @@ let HomePanels = Object.freeze({
throw "Home.panels: Can't create a home panel without an id and title!";
}
// Bail if the panel already exists
if (panel.id in this._panels) {
let action = options.action;
// Bail if the panel already exists, except when we're refreshing
// an existing panel instance.
if (panel.id in this._panels && action != this.Action.REFRESH) {
throw "Home.panels: Panel already exists: id = " + panel.id;
}
@ -223,9 +232,24 @@ let HomePanels = Object.freeze({
this._panels[panel.id] = panel;
if (options.autoInstall) {
if (action) {
let messageType;
switch(action) {
case this.Action.INSTALL:
messageType = "HomePanels:Install";
break;
case this.Action.REFRESH:
messageType = "HomePanels:Refresh";
break;
default:
throw "Home.panels: Invalid action for panel: panel.id = " + panel.id + ", action = " + action;
}
sendMessageToJava({
type: "HomePanels:Install",
type: messageType,
panel: this._panelToJSON(panel)
});
}