Consolidate window logic in panel controller
Previously the conversation window would query the background page for a model id and then fetch the conversation. Instead, we can fetch the conversation before opening the window, which simplifies the front end scripts and avoids creating multiple copies of the same model.
This commit is contained in:
parent
90140556e4
commit
3279dddcc3
4 changed files with 81 additions and 90 deletions
|
@ -19,28 +19,12 @@
|
|||
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
function loadConversation (id) {
|
||||
var conversation = new Whisper.Conversation({ id: id });
|
||||
conversation.fetch().then(function () {
|
||||
window.document.title = conversation.getTitle();
|
||||
new Whisper.ConversationView({
|
||||
model: conversation
|
||||
}).render().$el.prependTo($('body'));
|
||||
window.conversation = conversation;
|
||||
});
|
||||
};
|
||||
|
||||
var bg = extension.windows.getBackground();
|
||||
|
||||
extension.windows.getCurrent(function (windowInfo) {
|
||||
var windowId = windowInfo.id;
|
||||
|
||||
// close the panel if background.html is refreshed
|
||||
bg.addEventListener('beforeunload', function () {
|
||||
// TODO: reattach after reload instead of closing.
|
||||
extension.windows.remove(windowId);
|
||||
});
|
||||
|
||||
loadConversation(bg.Whisper.windowMap.modelIdFrom(windowId));
|
||||
var bg = extension.windows.getBackground();
|
||||
var conversation = bg.getConversationForWindow(windowInfo.id);
|
||||
window.document.title = conversation.getTitle();
|
||||
new Whisper.ConversationView({
|
||||
model: conversation
|
||||
}).render().$el.prependTo($('body'));
|
||||
});
|
||||
}());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue