annotate extension/content/sidebar.js @ 11:40c49a0e9e34

update the list of sources when the user unsubscribes from one
author Myk Melez <myk@mozilla.org>
date Fri, 11 Apr 2008 15:08:33 -0700
parents 64defcf896f1
children dfd64db41b8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
1 var gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
2 getInterface(Ci.nsIWebNavigation).
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
3 QueryInterface(Ci.nsIDocShellTreeItem).
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
4 rootTreeItem.
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
5 QueryInterface(Ci.nsIInterfaceRequestor).
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
6 getInterface(Ci.nsIDOMWindow);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
7
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
8 SourcesView = {
10
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
9 // Observer Service
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
10 get _obsSvc() {
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
11 let obsSvc = Cc["@mozilla.org/observer-service;1"].
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
12 getService(Ci.nsIObserverService);
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
13 delete this._obsSvc;
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
14 this._obsSvc = obsSvc;
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
15 return this._obsSvc;
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
16 },
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
17
8
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
18 get _tree() {
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
19 let tree = document.getElementById("sourcesView");
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
20 delete this._tree;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
21 this._tree = tree;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
22 return this._tree;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
23 },
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
24
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
25 get _children() {
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
26 let children = this._tree.getElementsByTagName("treechildren")[0];
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
27 delete this._children;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
28 this._children = children;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
29 return this._children;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
30 },
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
31
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
32 init: function() {
10
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
33 this._obsSvc.addObserver(this, "sources:changed", true);
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
34 this._rebuildView();
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
35 },
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
36
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
37 //**************************************************************************//
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
38 // XPCOM Interface Implementations
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
39
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
40 // nsISupports
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
41 QueryInterface: function(aIID) {
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
42 if (aIID.equals(Ci.nsIObserver) ||
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
43 aIID.equals(Ci.nsISupportsWeakReference) ||
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
44 aIID.equals(Ci.nsISupports))
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
45 return this;
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
46
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
47 throw Cr.NS_ERROR_NO_INTERFACE;
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
48 },
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
49
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
50 // nsIObserver
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
51 observe: function(subject, topic, data) {
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
52 switch (topic) {
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
53 case "sources:changed":
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
54 this._rebuildView();
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
55 break;
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
56 }
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
57 },
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
58
64defcf896f1 update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents: 9
diff changeset
59 _rebuildView: function() {
8
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
60 let statementString = "SELECT title, id FROM sources ORDER BY title";
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
61
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
62 let statement = SnowlDatastore.createStatement(statementString);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
63
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
64 // Empty the view.
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
65 while (this._children.hasChildNodes())
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
66 this._children.removeChild(this._children.lastChild);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
67
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
68 // Rebuild the view.
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
69 this._addItem(null, "All");
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
70 while (statement.step())
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
71 this._addItem(statement.row.id, statement.row.title);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
72
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
73 // Select the subscription that the messages view is currently displaying.
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
74 for (let i = 0; i < this._children.childNodes.length; i++) {
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
75 let item = this._children.childNodes[i];
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
76 if (item.sourceID == gBrowserWindow.SnowlView.sourceID) {
9
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
77 this._tree.view.selection.select(i);
8
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
78 break;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
79 }
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
80 }
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
81 },
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
82
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
83 _addItem: function(aSourceID, aTitle) {
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
84 let item = document.createElement("treeitem");
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
85 item.sourceID = aSourceID;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
86 let row = document.createElement("treerow");
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
87
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
88 let titleCell = document.createElement("treecell");
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
89 titleCell.setAttribute("label", aTitle);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
90
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
91 row.appendChild(titleCell);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
92 item.appendChild(row);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
93 this._children.appendChild(item);
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
94 },
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
95
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
96 onSelect: function(aEvent) {
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
97 if (this._tree.currentIndex == -1)
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
98 return;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
99 let sourceID = this._children.childNodes[this._tree.currentIndex].sourceID;
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
100 gBrowserWindow.SnowlView.setSource(sourceID);
9
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
101 },
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
102
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
103 onUnsubscribe: function(aEvent) {
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
104 let sourceID = this._tree.view.getItemAtIndex(this._tree.currentIndex).sourceID;
11
40c49a0e9e34 update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents: 10
diff changeset
105
9
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
106 SnowlDatastore.dbConnection.beginTransaction();
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
107 try {
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
108 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM metadata WHERE messageID IN (SELECT id FROM messages WHERE sourceID = " + sourceID + ")");
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
109 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM parts WHERE messageID IN (SELECT id FROM messages WHERE sourceID = " + sourceID + ")");
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
110 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM messages WHERE sourceID = " + sourceID);
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
111 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM sources WHERE id = " + sourceID);
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
112 SnowlDatastore.dbConnection.commitTransaction();
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
113 }
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
114 catch(ex) {
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
115 SnowlDatastore.dbConnection.rollbackTransaction();
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
116 throw ex;
d8abd85fc94d implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents: 8
diff changeset
117 }
11
40c49a0e9e34 update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents: 10
diff changeset
118
40c49a0e9e34 update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents: 10
diff changeset
119 this._rebuildView();
8
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
120 }
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
121
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
122 };
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
123
87c6af76db52 add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff changeset
124 window.addEventListener("load", function() { SourcesView.init() }, false);