2000-03-21 03:16:39 +00:00
|
|
|
var gSubscribeTree = null;
|
2000-03-17 23:08:51 +00:00
|
|
|
var okCallback = null;
|
2000-03-21 03:16:39 +00:00
|
|
|
var gChangeTable = {};
|
|
|
|
var gServerURI = null;
|
2000-06-01 02:41:03 +00:00
|
|
|
var gSubscribableServer = null;
|
2000-05-05 07:25:16 +00:00
|
|
|
var gStatusBar = null;
|
2000-05-05 07:40:33 +00:00
|
|
|
var gNameField = null;
|
2000-05-12 06:43:11 +00:00
|
|
|
var gFolderDelimiter = ".";
|
2000-08-14 21:43:19 +00:00
|
|
|
var gStatusFeedback = new nsMsgStatusFeedback;
|
2000-03-17 18:28:31 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
// the rdf service
|
|
|
|
var RDF = '@mozilla.org/rdf/rdf-service;1'
|
|
|
|
RDF = Components.classes[RDF].getService();
|
|
|
|
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
|
|
|
var subscribeDS = RDF.GetDataSource("rdf:subscribe");
|
|
|
|
|
2000-09-18 21:49:17 +00:00
|
|
|
// used for caching the tree children (in typedown)
|
|
|
|
var lastTreeChildrenValue = null;
|
|
|
|
var lastTreeChildren = null;
|
|
|
|
|
2001-01-06 06:11:15 +00:00
|
|
|
function goDoCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-04-02 19:58:09 +00:00
|
|
|
function Stop()
|
|
|
|
{
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("Stop()\n")
|
2001-01-19 22:04:06 +00:00
|
|
|
if (gSubscribableServer) {
|
|
|
|
gSubscribableServer.stopPopulating(msgWindow);
|
|
|
|
}
|
2000-04-02 19:58:09 +00:00
|
|
|
}
|
|
|
|
|
2000-04-25 01:30:30 +00:00
|
|
|
var Bundle = srGetStrBundle("chrome://messenger/locale/subscribe.properties");
|
|
|
|
|
|
|
|
function SetServerTypeSpecificTextValues()
|
|
|
|
{
|
2000-05-20 01:25:27 +00:00
|
|
|
if (!gServerURI) return;
|
|
|
|
|
2000-04-25 01:30:30 +00:00
|
|
|
var serverType = GetMsgFolderFromUri(gServerURI).server.type;
|
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
//set the server specific ui elements
|
|
|
|
|
2000-04-25 01:30:30 +00:00
|
|
|
var element = document.getElementById("foldertextlabel");
|
|
|
|
var stringName = "foldertextfor-" + serverType;
|
|
|
|
var stringval = Bundle.GetStringFromName(stringName);
|
|
|
|
element.setAttribute('value',stringval);
|
|
|
|
|
|
|
|
stringName = "foldersheaderfor-" + serverType;
|
|
|
|
stringval = Bundle.GetStringFromName(stringName);
|
|
|
|
element = document.getElementById("foldersheaderlabel");
|
|
|
|
element.setAttribute('value',stringval);
|
2000-05-13 00:47:47 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
//set the delimiter
|
|
|
|
try {
|
|
|
|
gFolderDelimiter = gSubscribableServer.delimiter;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
//dump(ex + "\n");
|
|
|
|
gFolderDelimiter = ".";
|
|
|
|
}
|
2000-04-25 01:30:30 +00:00
|
|
|
}
|
|
|
|
|
2000-04-20 03:41:30 +00:00
|
|
|
function onServerClick(event)
|
|
|
|
{
|
|
|
|
var item = event.target;
|
|
|
|
gServerURI = item.id;
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("gServerURI="+gServerURI+"\n");
|
2000-04-20 03:41:30 +00:00
|
|
|
|
2000-05-17 05:27:04 +00:00
|
|
|
SetUpTree(false);
|
2000-11-17 20:47:31 +00:00
|
|
|
|
|
|
|
SetServerTypeSpecificTextValues();
|
2000-04-20 03:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetUpServerMenu()
|
|
|
|
{
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("SetUpServerMenu()\n");
|
2000-04-20 03:41:30 +00:00
|
|
|
|
|
|
|
var serverMenu = document.getElementById("serverMenu");
|
|
|
|
var menuitems = serverMenu.getElementsByAttribute("id", gServerURI);
|
2000-04-25 01:30:30 +00:00
|
|
|
|
2000-05-15 21:44:34 +00:00
|
|
|
try {
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("gServerURI="+gServerURI+"\n");
|
|
|
|
//dump("menuitems="+menuitems+"\n");
|
|
|
|
//dump("menuitems[0]="+menuitems[0]+"\n");
|
|
|
|
//dump("serverMenu="+serverMenu+"\n");
|
2000-05-15 21:44:34 +00:00
|
|
|
serverMenu.selectedItem = menuitems[0];
|
|
|
|
}
|
|
|
|
catch (ex) {
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("failed to set the selected server: " + ex + "\n");
|
2000-05-15 21:44:34 +00:00
|
|
|
}
|
2000-04-25 01:30:30 +00:00
|
|
|
|
|
|
|
SetServerTypeSpecificTextValues();
|
2000-04-20 03:41:30 +00:00
|
|
|
}
|
|
|
|
|
2000-04-23 05:18:23 +00:00
|
|
|
var MySubscribeListener = {
|
2000-11-17 20:47:31 +00:00
|
|
|
OnDonePopulating: function() {
|
2001-01-08 22:50:00 +00:00
|
|
|
gStatusFeedback.showProgress(100);
|
|
|
|
gStatusFeedback.showStatusString(Bundle.GetStringFromName("doneString"));
|
2000-08-14 21:43:19 +00:00
|
|
|
gStatusBar.setAttribute("mode","normal");
|
2000-11-17 20:47:31 +00:00
|
|
|
|
|
|
|
// only re-root the tree, if it is null.
|
|
|
|
// otherwise, we are in here because we are populating
|
|
|
|
// a part of the tree
|
|
|
|
|
|
|
|
var refValue = gSubscribeTree.getAttribute('ref');
|
|
|
|
//dump("ref = " + refValue + refValue.length + "\n");
|
|
|
|
if (refValue == "null") {
|
|
|
|
//dump("root subscribe tree at: "+ gServerURI +"\n");
|
|
|
|
gSubscribeTree.database.AddDataSource(subscribeDS);
|
|
|
|
gSubscribeTree.setAttribute('ref',gServerURI);
|
|
|
|
}
|
2000-04-23 05:18:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2000-05-17 05:27:04 +00:00
|
|
|
function SetUpTree(forceToServer)
|
2000-03-28 04:03:25 +00:00
|
|
|
{
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("SetUpTree()\n");
|
2000-09-18 21:49:17 +00:00
|
|
|
|
|
|
|
// forget the cached tree children
|
|
|
|
lastTreeChildrenValue = null;
|
|
|
|
lastTreeChildren = null;
|
|
|
|
|
2000-08-14 21:43:19 +00:00
|
|
|
gStatusBar = document.getElementById('statusbar-icon');
|
2000-05-20 01:25:27 +00:00
|
|
|
if (!gServerURI) return;
|
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
|
2000-04-20 03:41:30 +00:00
|
|
|
var folder = GetMsgFolderFromUri(gServerURI);
|
|
|
|
var server = folder.server;
|
|
|
|
|
2000-04-23 01:19:51 +00:00
|
|
|
try {
|
2000-06-01 02:41:03 +00:00
|
|
|
gSubscribableServer = server.QueryInterface(Components.interfaces.nsISubscribableServer);
|
2000-11-17 20:47:31 +00:00
|
|
|
gSubscribeTree.setAttribute('ref',null);
|
2000-03-28 04:03:25 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
// clear out the text field when switching server
|
|
|
|
gNameField.setAttribute('value',"");
|
|
|
|
|
|
|
|
gSubscribeTree.database.RemoveDataSource(subscribeDS);
|
2000-06-01 02:41:03 +00:00
|
|
|
gSubscribableServer.subscribeListener = MySubscribeListener;
|
2000-04-23 05:18:23 +00:00
|
|
|
|
2001-01-08 22:50:00 +00:00
|
|
|
gStatusFeedback.showProgress(0);
|
|
|
|
gStatusFeedback.showStatusString(Bundle.GetStringFromName("pleaseWaitString"));
|
2000-08-14 21:43:19 +00:00
|
|
|
gStatusBar.setAttribute("mode","undetermined");
|
2000-05-09 02:48:25 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
gSubscribableServer.startPopulating(msgWindow, forceToServer);
|
2000-04-23 01:19:51 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("failed to populate subscribe ds: " + ex + "\n");
|
2000-04-23 01:19:51 +00:00
|
|
|
}
|
2000-03-28 04:03:25 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 21:43:19 +00:00
|
|
|
|
2000-03-17 18:28:31 +00:00
|
|
|
function SubscribeOnLoad()
|
|
|
|
{
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("SubscribeOnLoad()\n");
|
2000-03-28 04:03:25 +00:00
|
|
|
|
2000-06-01 02:41:03 +00:00
|
|
|
gSubscribeTree = document.getElementById('subscribetree');
|
2000-05-05 07:40:33 +00:00
|
|
|
gNameField = document.getElementById('namefield');
|
2000-03-17 18:28:31 +00:00
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
msgWindow = Components.classes[msgWindowContractID].createInstance(Components.interfaces.nsIMsgWindow);
|
2000-08-14 21:43:19 +00:00
|
|
|
msgWindow.statusFeedback = gStatusFeedback;
|
|
|
|
msgWindow.SetDOMWindow(window);
|
|
|
|
|
2000-03-17 23:08:51 +00:00
|
|
|
doSetOKCancel(subscribeOK,subscribeCancel);
|
|
|
|
|
|
|
|
// look in arguments[0] for parameters
|
|
|
|
if (window.arguments && window.arguments[0]) {
|
|
|
|
if ( window.arguments[0].okCallback ) {
|
|
|
|
top.okCallback = window.arguments[0].okCallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-20 01:25:27 +00:00
|
|
|
gServerURI = null;
|
2000-03-17 23:08:51 +00:00
|
|
|
if (window.arguments[0].preselectedURI) {
|
2000-04-20 03:41:30 +00:00
|
|
|
var uri = window.arguments[0].preselectedURI;
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("subscribe: got a uri," + uri + "\n");
|
2000-09-18 21:44:54 +00:00
|
|
|
var folder = GetMsgFolderFromUri(uri);
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("folder="+folder+"\n");
|
|
|
|
//dump("folder.server="+folder.server+"\n");
|
2000-05-20 01:25:27 +00:00
|
|
|
try {
|
2000-06-01 02:41:03 +00:00
|
|
|
gSubscribableServer = folder.server.QueryInterface(Components.interfaces.nsISubscribableServer);
|
2000-05-20 01:25:27 +00:00
|
|
|
gServerURI = folder.server.serverURI;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("not a subscribable server\n");
|
2000-06-01 02:41:03 +00:00
|
|
|
gSubscribableServer = null;
|
2000-05-20 01:25:27 +00:00
|
|
|
gServerURI = null;
|
|
|
|
}
|
2000-03-17 23:08:51 +00:00
|
|
|
}
|
2000-05-20 01:25:27 +00:00
|
|
|
|
|
|
|
if (!gServerURI) {
|
|
|
|
//dump("subscribe: no uri\n");
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("xxx todo: use the default news server. right now, I'm just using the first server\n");
|
2000-04-20 03:41:30 +00:00
|
|
|
var serverMenu = document.getElementById("serverMenu");
|
|
|
|
var menuitems = serverMenu.getElementsByTagName("menuitem");
|
2000-05-20 01:25:27 +00:00
|
|
|
|
|
|
|
if (menuitems.length > 1) {
|
|
|
|
gServerURI = menuitems[1].id;
|
|
|
|
}
|
|
|
|
else {
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("xxx todo none of your servers are subscribable\n");
|
|
|
|
//dump("xxx todo fix this by disabling subscribe if no subscribable server or, add a CREATE SERVER button, like in 4.x\n");
|
2000-05-20 01:25:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-04-13 21:56:28 +00:00
|
|
|
}
|
2000-04-20 03:41:30 +00:00
|
|
|
|
|
|
|
SetUpServerMenu();
|
2000-11-17 20:47:31 +00:00
|
|
|
|
2000-05-17 05:27:04 +00:00
|
|
|
SetUpTree(false);
|
2000-04-20 03:41:30 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
gNameField.focus();
|
2000-03-17 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function subscribeOK()
|
|
|
|
{
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("in subscribeOK()\n")
|
2000-03-17 23:08:51 +00:00
|
|
|
if (top.okCallback) {
|
2000-11-17 20:47:31 +00:00
|
|
|
top.okCallback(top.gChangeTable);
|
2000-03-17 23:08:51 +00:00
|
|
|
}
|
2000-11-17 20:47:31 +00:00
|
|
|
Stop();
|
2000-06-01 02:41:03 +00:00
|
|
|
if (gSubscribableServer) {
|
|
|
|
gSubscribableServer.subscribeCleanup();
|
|
|
|
}
|
2000-03-17 23:08:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function subscribeCancel()
|
|
|
|
{
|
2000-05-16 21:40:32 +00:00
|
|
|
//dump("in subscribeCancel()\n");
|
2000-04-02 19:58:09 +00:00
|
|
|
Stop();
|
2000-06-01 02:41:03 +00:00
|
|
|
if (gSubscribableServer) {
|
|
|
|
gSubscribableServer.subscribeCleanup();
|
|
|
|
}
|
2000-03-17 23:08:51 +00:00
|
|
|
return true;
|
2000-03-17 18:28:31 +00:00
|
|
|
}
|
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
function SetState(name,state)
|
2000-03-17 18:28:31 +00:00
|
|
|
{
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("SetState(" + name + "," + state + ")\n");
|
2000-04-01 01:56:16 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
var changed = gSubscribableServer.setState(name, state);
|
|
|
|
if (changed) {
|
|
|
|
StateChanged(name,state);
|
2000-03-21 01:03:25 +00:00
|
|
|
}
|
2000-03-17 18:28:31 +00:00
|
|
|
}
|
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
function changeTableRecord(server, name, state) {
|
|
|
|
this.server = server;
|
|
|
|
this.name = name;
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
2000-04-14 05:34:49 +00:00
|
|
|
function StateChanged(name,state)
|
2000-03-21 03:16:39 +00:00
|
|
|
{
|
2001-01-31 03:00:56 +00:00
|
|
|
if (gServerURI in gChangeTable) {
|
|
|
|
if (name in gChangeTable[gServerURI]) {
|
|
|
|
var oldValue = gChangeTable[gServerURI][name];
|
|
|
|
if (oldValue != state)
|
|
|
|
delete gChangeTable[gServerURI][name];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gChangeTable[gServerURI][name] = state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gChangeTable[gServerURI] = {};
|
|
|
|
gChangeTable[gServerURI][name] = state;
|
|
|
|
}
|
2000-03-21 03:16:39 +00:00
|
|
|
}
|
|
|
|
|
2000-03-21 01:03:25 +00:00
|
|
|
function SetSubscribeState(state)
|
2000-03-17 18:28:31 +00:00
|
|
|
{
|
2000-04-01 01:56:16 +00:00
|
|
|
try {
|
2000-03-21 03:16:39 +00:00
|
|
|
var groupList = gSubscribeTree.selectedItems;
|
2001-01-31 03:00:56 +00:00
|
|
|
for (var i=0;i<groupList.length;i++) {
|
|
|
|
var group = groupList[i];
|
|
|
|
var name = group.getAttribute('name');
|
2000-11-17 20:47:31 +00:00
|
|
|
SetState(name,state);
|
2000-03-21 01:03:25 +00:00
|
|
|
}
|
2000-04-01 01:56:16 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("SetSubscribedState failed: " + ex + "\n");
|
2000-04-01 01:56:16 +00:00
|
|
|
}
|
2000-03-17 18:28:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-20 06:59:43 +00:00
|
|
|
function ReverseStateFromNode(node)
|
|
|
|
{
|
|
|
|
var state;
|
|
|
|
|
|
|
|
if (node.getAttribute('Subscribed') == "true") {
|
|
|
|
state = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var uri = node.getAttribute('id');
|
2000-04-20 07:11:27 +00:00
|
|
|
var name = node.getAttribute('name');
|
2000-11-17 20:47:31 +00:00
|
|
|
SetState(name, state);
|
2000-04-20 03:41:30 +00:00
|
|
|
}
|
|
|
|
|
2000-12-14 21:43:51 +00:00
|
|
|
|
2000-03-17 18:28:31 +00:00
|
|
|
function SubscribeOnClick(event)
|
|
|
|
{
|
2000-12-14 21:43:51 +00:00
|
|
|
var t = event.originalTarget;
|
2000-09-07 08:17:32 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (event.detail == 2) {
|
2000-09-07 08:17:32 +00:00
|
|
|
ReverseStateFromNode(t.parentNode.parentNode);
|
2000-04-20 03:41:30 +00:00
|
|
|
}
|
2000-05-05 07:40:33 +00:00
|
|
|
else {
|
2000-09-07 08:17:32 +00:00
|
|
|
if (t.getAttribute('twisty') == 'true') {
|
|
|
|
var treeitem = t.parentNode.parentNode.parentNode;
|
2000-06-01 02:41:03 +00:00
|
|
|
var open = treeitem.getAttribute('open');
|
|
|
|
if(open == "true") {
|
2000-06-01 03:59:14 +00:00
|
|
|
var uri = treeitem.getAttribute("id");
|
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
//dump("do twisty for " + uri + "\n");
|
2000-06-01 02:41:03 +00:00
|
|
|
|
2001-01-08 22:50:00 +00:00
|
|
|
gStatusFeedback.showProgress(0);
|
|
|
|
gStatusFeedback.showStatusString(Bundle.GetStringFromName("pleaseWaitString"));
|
2000-08-14 21:43:19 +00:00
|
|
|
gStatusBar.setAttribute("mode","undetermined");
|
2000-06-01 02:41:03 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
gSubscribableServer.startPopulatingWithUri(msgWindow, true /* force to server */, uri);
|
2000-06-01 02:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-12-14 21:43:51 +00:00
|
|
|
// if the user clicks on the subscribe check box, we handle it here
|
|
|
|
if (t.localName == "image") {
|
|
|
|
ReverseStateFromNode(t.parentNode.parentNode.parentNode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-09-07 08:17:32 +00:00
|
|
|
var name = t.parentNode.parentNode.getAttribute('name');
|
2000-06-09 22:14:23 +00:00
|
|
|
if (name && (name.length > 0)) {
|
|
|
|
gNameField.setAttribute('value',name);
|
|
|
|
}
|
2000-05-05 07:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
2000-03-17 18:28:31 +00:00
|
|
|
}
|
2000-03-28 04:03:25 +00:00
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
function Refresh()
|
2000-03-28 04:03:25 +00:00
|
|
|
{
|
2000-05-17 05:27:04 +00:00
|
|
|
// force it to talk to the server
|
|
|
|
SetUpTree(true);
|
2000-03-28 04:03:25 +00:00
|
|
|
}
|
2000-04-02 19:58:09 +00:00
|
|
|
|
2000-05-12 06:43:11 +00:00
|
|
|
function trackGroupInTree()
|
|
|
|
{
|
|
|
|
var portion = gNameField.value;
|
|
|
|
selectNodeByName( portion );
|
|
|
|
}
|
|
|
|
|
2000-09-18 21:44:54 +00:00
|
|
|
|
2000-05-12 06:43:11 +00:00
|
|
|
function selectNodeByName( aMatchString )
|
|
|
|
{
|
|
|
|
var lastDot = aMatchString.lastIndexOf(gFolderDelimiter);
|
|
|
|
var nodeValue = lastDot != -1 ? aMatchString.substring(0, lastDot) : aMatchString;
|
|
|
|
|
|
|
|
var chain = aMatchString.split(gFolderDelimiter);
|
2000-09-18 21:44:54 +00:00
|
|
|
var node;
|
2000-05-12 06:43:11 +00:00
|
|
|
if( chain.length == 1 ) {
|
2000-09-18 21:44:54 +00:00
|
|
|
if (lastTreeChildrenValue != "") {
|
|
|
|
node = getTreechildren(gSubscribeTree);
|
|
|
|
if( !node ) return;
|
|
|
|
lastTreeChildrenValue = "";
|
|
|
|
lastTreeChildren = node;
|
|
|
|
//dump("cache miss!\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node = lastTreeChildren;
|
|
|
|
//dump("cache hit!\n");
|
|
|
|
}
|
2000-05-12 06:43:11 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-09-18 21:44:54 +00:00
|
|
|
// if we can, use the cached tree children
|
|
|
|
if (nodeValue != lastTreeChildrenValue) {
|
|
|
|
node = gSubscribeTree.getElementsByAttribute("name",nodeValue)[0];
|
|
|
|
|
|
|
|
// expand the node, if we need to
|
|
|
|
if( node.getAttribute("container") == "true" &&
|
|
|
|
node.getAttribute("open") != "true" ) {
|
|
|
|
node.setAttribute("open","true");
|
|
|
|
}
|
|
|
|
node = getTreechildren(node);
|
|
|
|
//dump("*** node = " + node.localName + "\n");
|
|
|
|
|
|
|
|
lastTreeChildren = node;
|
|
|
|
lastTreeChildrenValue = nodeValue;
|
|
|
|
//dump("cache miss!\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//dump("cache hit!\n");
|
|
|
|
node = lastTreeChildren;
|
|
|
|
}
|
2000-05-12 06:43:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 21:44:54 +00:00
|
|
|
// find the match, using a binary search.
|
|
|
|
var totalItems = node.childNodes.length;
|
|
|
|
if (totalItems == 0) return;
|
|
|
|
var lastLow = 0;
|
|
|
|
var lastHigh = totalItems;
|
|
|
|
while (true) {
|
|
|
|
var i = Math.floor((lastHigh + lastLow) / 2);
|
|
|
|
//dump(i+","+lastLow+","+lastHigh+"\n");
|
|
|
|
var currItem = node.childNodes[i];
|
|
|
|
var currValue = (currItem.getAttribute("name")).substring(0,aMatchString.length);
|
|
|
|
//dump(currValue+" vs "+aMatchString+"\n");
|
|
|
|
if (currValue > aMatchString) {
|
|
|
|
if (lastHigh == i) return;
|
|
|
|
lastHigh = i;
|
|
|
|
}
|
|
|
|
else if (currValue < aMatchString) {
|
|
|
|
if (lastLow == i) return;
|
|
|
|
lastLow = i;
|
|
|
|
}
|
|
|
|
else {
|
2000-11-17 20:47:31 +00:00
|
|
|
SelectFirstMatch(lastLow, i, node.childNodes, aMatchString);
|
|
|
|
return;
|
2000-09-18 21:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-12 06:43:11 +00:00
|
|
|
}
|
|
|
|
|
2000-11-17 20:47:31 +00:00
|
|
|
function SelectFirstMatch(startNode, endNode, nodes, matchStr)
|
|
|
|
{
|
|
|
|
// this code is to make sure we select the alphabetically first match
|
|
|
|
// not just any match (see bug #60242)
|
|
|
|
|
|
|
|
// find the match, using a binary search.
|
|
|
|
|
|
|
|
var lastMatch = nodes[endNode];
|
|
|
|
var totalItems = endNode - startNode;
|
|
|
|
if (totalItems == 0) {
|
|
|
|
gSubscribeTree.selectItem( lastMatch );
|
|
|
|
gSubscribeTree.ensureElementIsVisible( lastMatch );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var lastLow = startNode;
|
|
|
|
var lastHigh = endNode;
|
|
|
|
while (true) {
|
|
|
|
var i = Math.floor((lastHigh + lastLow) / 2);
|
|
|
|
//dump(i+","+lastLow+","+lastHigh+"\n");
|
|
|
|
var currItem = nodes[i];
|
|
|
|
var currValue = (currItem.getAttribute("name")).substring(0,matchStr.length);
|
|
|
|
//dump(currValue+" vs "+matchStr+"\n");
|
|
|
|
if (currValue > matchStr) {
|
|
|
|
gSubscribeTree.selectItem( lastMatch );
|
|
|
|
gSubscribeTree.ensureElementIsVisible( lastMatch );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (currValue < matchStr) {
|
|
|
|
if (lastLow == i) {
|
|
|
|
gSubscribeTree.selectItem( lastMatch );
|
|
|
|
gSubscribeTree.ensureElementIsVisible( lastMatch );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastLow = i;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastMatch = currItem;
|
|
|
|
if (lastHigh == i) {
|
|
|
|
gSubscribeTree.selectItem( lastMatch );
|
|
|
|
gSubscribeTree.ensureElementIsVisible( lastMatch );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastHigh = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-12 06:43:11 +00:00
|
|
|
function getTreechildren( aTreeNode )
|
|
|
|
{
|
|
|
|
if( aTreeNode.childNodes )
|
|
|
|
{
|
|
|
|
for( var i = 0; i < aTreeNode.childNodes.length; i++ )
|
|
|
|
{
|
2000-06-07 01:05:50 +00:00
|
|
|
if( aTreeNode.childNodes[i].localName.toLowerCase() == "treechildren" )
|
2000-05-12 06:43:11 +00:00
|
|
|
return aTreeNode.childNodes[i];
|
|
|
|
}
|
|
|
|
return aTreeNode;
|
|
|
|
}
|
|
|
|
return null;
|
2000-05-13 00:47:47 +00:00
|
|
|
}
|