2006-07-27 14:54:23 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2006-07-27 14:58:22 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2006-07-27 14:49:29 +00:00
|
|
|
*
|
2006-07-27 14:58:22 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2006-07-27 14:49:29 +00:00
|
|
|
*
|
2006-07-27 14:54:23 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2006-07-27 14:49:29 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2006-07-27 14:58:22 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2006-07-27 14:54:23 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2006-07-27 14:49:29 +00:00
|
|
|
*
|
2006-07-27 14:53:34 +00:00
|
|
|
* Contributor(s):
|
2006-07-27 14:58:22 +00:00
|
|
|
* Robert John Churchill <rjc@netscape.com>
|
|
|
|
* Blake Ross <BlakeR1234@aol.com>
|
2006-07-27 14:54:23 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2006-07-27 14:58:22 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2006-07-27 14:54:23 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2006-07-27 14:58:22 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2006-07-27 14:54:23 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2006-07-27 14:58:22 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2006-07-27 14:54:23 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-07-27 14:49:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// global(s)
|
2006-07-27 14:49:41 +00:00
|
|
|
var bundle = srGetStrBundle("chrome://communicator/locale/search/search-editor.properties");
|
2006-07-27 14:53:43 +00:00
|
|
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
|
|
|
|
promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
|
2006-07-27 14:49:29 +00:00
|
|
|
var pref = null;
|
2006-07-27 14:49:35 +00:00
|
|
|
var RDF = null;
|
|
|
|
var RDFC = null;
|
2006-07-27 14:49:38 +00:00
|
|
|
var RDFCUtils = null;
|
2006-07-27 14:49:35 +00:00
|
|
|
var catDS = null;
|
2006-07-27 14:50:53 +00:00
|
|
|
var internetSearchDS = null;
|
2006-07-27 14:49:35 +00:00
|
|
|
|
2006-07-27 14:49:29 +00:00
|
|
|
try
|
|
|
|
{
|
2006-07-27 14:54:50 +00:00
|
|
|
pref = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2006-07-27 14:49:35 +00:00
|
|
|
|
2006-07-27 14:58:32 +00:00
|
|
|
RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
|
2006-07-27 14:49:35 +00:00
|
|
|
|
2006-07-27 14:58:32 +00:00
|
|
|
RDFC = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:58:32 +00:00
|
|
|
RDFCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
pref = null;
|
|
|
|
RDF = null;
|
|
|
|
RDFC = null;
|
|
|
|
RDFCUtils = null;
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function debug(msg)
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
// uncomment for noise
|
|
|
|
// dump(msg+"\n");
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function doLoad()
|
|
|
|
{
|
2006-07-27 14:58:41 +00:00
|
|
|
var categoryList = document.getElementById("categoryList");
|
2006-07-27 14:50:46 +00:00
|
|
|
// adjust category popup
|
2006-07-27 14:53:34 +00:00
|
|
|
var internetSearch = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"].getService();
|
|
|
|
if (internetSearch) internetSearch = internetSearch.QueryInterface(Components.interfaces.nsIInternetSearchService);
|
|
|
|
if (internetSearch)
|
|
|
|
{
|
|
|
|
internetSearchDS = internetSearch.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
|
|
|
|
catDS = internetSearch.GetCategoryDataSource();
|
|
|
|
if (catDS) catDS = catDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
if (catDS)
|
|
|
|
{
|
|
|
|
if (categoryList)
|
|
|
|
{
|
|
|
|
categoryList.database.AddDataSource(catDS);
|
2006-07-27 14:57:39 +00:00
|
|
|
categoryList.builder.rebuild();
|
2006-07-27 14:53:34 +00:00
|
|
|
}
|
|
|
|
var engineList = document.getElementById("engineList");
|
|
|
|
if (engineList)
|
|
|
|
{
|
|
|
|
engineList.database.AddDataSource(catDS);
|
2006-07-27 14:57:39 +00:00
|
|
|
engineList.builder.rebuild();
|
2006-07-27 14:53:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try and determine last category name used
|
|
|
|
var lastCategoryName = "";
|
|
|
|
try
|
|
|
|
{
|
2006-07-27 14:54:50 +00:00
|
|
|
var pref = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
lastCategoryName = pref.getCharPref( "browser.search.last_search_category" );
|
2006-07-27 14:53:34 +00:00
|
|
|
|
|
|
|
if (lastCategoryName != "")
|
|
|
|
{
|
|
|
|
// strip off the prefix if necessary
|
|
|
|
var prefix="NC:SearchCategory?category=";
|
|
|
|
if (lastCategoryName.indexOf(prefix) == 0)
|
|
|
|
{
|
|
|
|
lastCategoryName = lastCategoryName.substr(prefix.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch( e )
|
|
|
|
{
|
|
|
|
debug("Exception in SearchPanelStartup\n");
|
|
|
|
lastCategoryName = "";
|
|
|
|
}
|
|
|
|
debug("\nSearchPanelStartup: lastCategoryName = '" + lastCategoryName + "'\n");
|
|
|
|
|
|
|
|
// select the appropriate category
|
|
|
|
var categoryPopup = document.getElementById( "categoryPopup" );
|
|
|
|
if( categoryList && categoryPopup )
|
|
|
|
{
|
|
|
|
var found = false;
|
|
|
|
for( var i = 0; i < categoryPopup.childNodes.length; i++ )
|
|
|
|
{
|
|
|
|
if( ( lastCategoryName == "" && categoryPopup.childNodes[i].getAttribute("value") == "NC:SearchEngineRoot" ) ||
|
|
|
|
( categoryPopup.childNodes[i].getAttribute("id") == lastCategoryName ) )
|
|
|
|
{
|
|
|
|
categoryList.selectedItem = categoryPopup.childNodes[i];
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (categoryPopup.childNodes.length > 0)
|
|
|
|
{
|
|
|
|
if (found == false)
|
|
|
|
{
|
|
|
|
categoryList.selectedItem = categoryPopup.childNodes[0];
|
|
|
|
}
|
|
|
|
chooseCategory(categoryList.selectedItem);
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 14:49:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Commit()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
// flush
|
|
|
|
if (catDS)
|
|
|
|
{
|
|
|
|
var flushableDS = catDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
|
|
|
if (flushableDS)
|
|
|
|
{
|
|
|
|
flushableDS.Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-27 14:55:12 +00:00
|
|
|
return true;
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function doUnload()
|
|
|
|
{
|
|
|
|
// Get the current window position/size.
|
|
|
|
var x = window.screenX;
|
|
|
|
var y = window.screenY;
|
|
|
|
var h = window.outerHeight;
|
|
|
|
var w = window.outerWidth;
|
|
|
|
|
|
|
|
// Store these into the window attributes (for persistence).
|
|
|
|
var win = document.getElementById( "search-editor-window" );
|
|
|
|
win.setAttribute( "x", x );
|
|
|
|
win.setAttribute( "y", y );
|
|
|
|
win.setAttribute( "height", h );
|
|
|
|
win.setAttribute( "width", w );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Note: doSort() does NOT support natural order sorting, unless naturalOrderResource is valid,
|
|
|
|
in which case we sort ascending on naturalOrderResource
|
|
|
|
*/
|
|
|
|
function doSort(sortColName, naturalOrderResource)
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
var node = document.getElementById(sortColName);
|
|
|
|
// determine column resource to sort on
|
|
|
|
var sortResource = node.getAttribute('resource');
|
|
|
|
if (!sortResource) return(false);
|
|
|
|
|
|
|
|
var sortDirection="ascending";
|
|
|
|
var isSortActive = node.getAttribute('sortActive');
|
|
|
|
if (isSortActive == "true")
|
|
|
|
{
|
|
|
|
sortDirection = "ascending";
|
|
|
|
|
|
|
|
var currentDirection = node.getAttribute('sortDirection');
|
|
|
|
if (currentDirection == "ascending")
|
|
|
|
{
|
|
|
|
if (sortResource != naturalOrderResource)
|
|
|
|
{
|
|
|
|
sortDirection = "descending";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (currentDirection == "descending")
|
|
|
|
{
|
|
|
|
if (naturalOrderResource != null && naturalOrderResource != "")
|
|
|
|
{
|
|
|
|
sortResource = naturalOrderResource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var isupports = Components.classes["@mozilla.org/xul/xul-sort-service;1"].getService();
|
|
|
|
if (!isupports) return(false);
|
|
|
|
var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService);
|
|
|
|
if (!xulSortService) return(false);
|
|
|
|
try
|
|
|
|
{
|
2006-07-27 14:55:56 +00:00
|
|
|
xulSortService.sort(node, sortResource, sortDirection);
|
2006-07-27 14:53:34 +00:00
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
2006-07-27 14:55:56 +00:00
|
|
|
debug("Exception calling xulSortService.sort()");
|
2006-07-27 14:53:34 +00:00
|
|
|
}
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function chooseCategory( aNode )
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
var category = "NC:SearchCategory?category=" + aNode.getAttribute("id");
|
|
|
|
debug("chooseCategory: '" + category + "'\n");
|
|
|
|
|
|
|
|
var treeNode = document.getElementById("engineList");
|
|
|
|
if (treeNode)
|
|
|
|
{
|
|
|
|
dump("*** Set search engine list to category=" + category + "\n");
|
|
|
|
treeNode.setAttribute( "ref", category );
|
2006-07-27 14:52:49 +00:00
|
|
|
treeNode.builder.rebuild();
|
2006-07-27 14:53:34 +00:00
|
|
|
}
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function AddEngine()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
var allenginesList = document.getElementById("allengines");
|
|
|
|
if (!allenginesList) return(false);
|
|
|
|
var select_list = allenginesList.selectedItems;
|
|
|
|
if (!select_list) return(false)
|
|
|
|
if (select_list.length < 1) return(false);
|
|
|
|
|
|
|
|
// make sure we have at least one category to add engine into
|
|
|
|
var categoryPopup = document.getElementById( "categoryPopup" );
|
|
|
|
if (!categoryPopup) return(false);
|
|
|
|
if (categoryPopup.childNodes.length < 1)
|
|
|
|
{
|
|
|
|
if (NewCategory() == false) return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
var engineList = document.getElementById("engineList");
|
|
|
|
if (!engineList) return(false);
|
|
|
|
|
|
|
|
var ref = engineList.getAttribute("ref");
|
|
|
|
if ((!ref) || (ref == "")) return(false);
|
|
|
|
|
|
|
|
var categoryRes = RDF.GetResource(ref);
|
|
|
|
if (!categoryRes) return(false);
|
|
|
|
|
|
|
|
RDFCUtils.MakeSeq(catDS, categoryRes);
|
|
|
|
|
|
|
|
RDFC.Init(catDS, categoryRes);
|
|
|
|
|
|
|
|
var urlRes = RDF.GetResource("http://home.netscape.com/NC-rdf#URL");
|
|
|
|
if (!urlRes) return(false);
|
|
|
|
var typeRes = RDF.GetResource("http://home.netscape.com/NC-rdf#searchtype");
|
|
|
|
if (!typeRes) return(false);
|
|
|
|
var engineRes = RDF.GetResource("http://home.netscape.com/NC-rdf#Engine");
|
|
|
|
if (!engineRes) return(false);
|
|
|
|
|
|
|
|
for (var x = 0; x < select_list.length; x++)
|
|
|
|
{
|
|
|
|
var id = select_list[x].getAttribute("id");
|
|
|
|
if ((!id) || (id == "")) return(false);
|
|
|
|
var idRes = RDF.GetResource(id);
|
|
|
|
if (!idRes) return(false);
|
|
|
|
|
|
|
|
// try and find/use alias to search engine
|
|
|
|
var privateEngineFlag = internetSearchDS.HasAssertion(idRes, typeRes, engineRes, true);
|
|
|
|
if (privateEngineFlag == true)
|
|
|
|
{
|
|
|
|
var node = internetSearchDS.GetTarget(idRes, urlRes, true);
|
|
|
|
if (node) node = node.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
if (node.Value)
|
|
|
|
{
|
|
|
|
id = node.Value;
|
|
|
|
idRes = RDF.GetResource(id);
|
|
|
|
if (!idRes) return(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var nodeIndex = RDFC.IndexOf(idRes);
|
|
|
|
if (nodeIndex < 1)
|
|
|
|
{
|
|
|
|
RDFC.AppendElement(idRes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function RemoveEngine()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
var engineList = document.getElementById("engineList");
|
|
|
|
if (!engineList) return(false);
|
|
|
|
var select_list = engineList.selectedItems;
|
|
|
|
if (!select_list) return(false)
|
|
|
|
if (select_list.length < 1) return(false);
|
|
|
|
|
|
|
|
var ref = engineList.getAttribute("ref");
|
|
|
|
if ((!ref) || (ref == "")) return(false);
|
|
|
|
var categoryRes = RDF.GetResource(ref);
|
|
|
|
if (!categoryRes) return(false);
|
|
|
|
|
|
|
|
RDFC.Init(catDS, categoryRes);
|
|
|
|
|
|
|
|
// Note: walk backwards to make deletion easier
|
|
|
|
for (var x = select_list.length - 1; x >= 0; x--)
|
|
|
|
{
|
|
|
|
var id = select_list[x].getAttribute("id");
|
|
|
|
if ((!id) || (id == "")) return(false);
|
|
|
|
var idRes = RDF.GetResource(id);
|
|
|
|
if (!idRes) return(false);
|
|
|
|
|
|
|
|
var nodeIndex = RDFC.IndexOf(idRes);
|
|
|
|
if (nodeIndex > 0)
|
|
|
|
{
|
|
|
|
RDFC.RemoveElementAt(nodeIndex, true, idRes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MoveUp()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
return MoveDelta(-1);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MoveDown()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
return MoveDelta(1);
|
2006-07-27 14:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MoveDelta(delta)
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
var engineList = document.getElementById("engineList");
|
|
|
|
if (!engineList) return(false);
|
|
|
|
var select_list = engineList.selectedItems;
|
|
|
|
if (!select_list) return(false)
|
|
|
|
if (select_list.length != 1) return(false);
|
|
|
|
|
|
|
|
var ref = engineList.getAttribute("ref");
|
|
|
|
if (!ref) return(false);
|
|
|
|
var categoryRes = RDF.GetResource(ref);
|
|
|
|
if (!categoryRes) return(false);
|
|
|
|
|
|
|
|
var id = select_list[0].id;
|
|
|
|
if (!id) return(false);
|
|
|
|
var idRes = RDF.GetResource(id);
|
|
|
|
if (!idRes) return(false);
|
|
|
|
|
|
|
|
RDFC.Init(catDS, categoryRes);
|
|
|
|
|
|
|
|
var nodeIndex = RDFC.IndexOf(idRes);
|
|
|
|
if (nodeIndex < 1) return(false); // how did that happen?
|
|
|
|
|
|
|
|
var numItems = RDFC.GetCount();
|
|
|
|
|
|
|
|
var newPos = -1;
|
|
|
|
if (((delta == -1) && (nodeIndex > 1)) ||
|
|
|
|
((delta == 1) && (nodeIndex < numItems)))
|
|
|
|
{
|
|
|
|
newPos = nodeIndex + delta;
|
|
|
|
RDFC.RemoveElementAt(nodeIndex, true, idRes);
|
|
|
|
}
|
|
|
|
if (newPos > 0)
|
|
|
|
{
|
|
|
|
RDFC.InsertElementAt(idRes, newPos, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
selectItems(engineList, ref, id);
|
|
|
|
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
2006-07-27 14:52:49 +00:00
|
|
|
function doMoveDirectionEnabling()
|
|
|
|
{
|
2006-07-27 14:55:43 +00:00
|
|
|
var engineList = document.getElementById("engineList")
|
|
|
|
var selectedItems = engineList.selectedItems;
|
|
|
|
var nodeIndex = -1;
|
|
|
|
if (selectedItems && selectedItems.length == 1) {
|
|
|
|
var ref = engineList.getAttribute("ref");
|
|
|
|
var categoryResource = RDF.GetResource(ref);
|
|
|
|
var elementResource = RDF.GetResource(selectedItems[0].id);
|
|
|
|
RDFC.Init(catDS, categoryResource);
|
|
|
|
nodeIndex = RDFC.IndexOf(elementResource);
|
|
|
|
}
|
|
|
|
|
2006-07-27 14:52:49 +00:00
|
|
|
var moveUpButton = document.getElementById("up");
|
|
|
|
var moveDownButton = document.getElementById("down");
|
2006-07-27 14:55:43 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
if (nodeIndex <= 1)
|
2006-07-27 14:52:49 +00:00
|
|
|
moveUpButton.setAttribute("disabled", "true");
|
2006-07-27 14:55:43 +00:00
|
|
|
else
|
|
|
|
moveUpButton.removeAttribute("disabled");
|
|
|
|
|
|
|
|
if (nodeIndex < 0 || nodeIndex >= RDFC.GetCount())
|
2006-07-27 14:52:49 +00:00
|
|
|
moveDownButton.setAttribute("disabled", "true");
|
2006-07-27 14:55:43 +00:00
|
|
|
else
|
|
|
|
moveDownButton.removeAttribute("disabled");
|
2006-07-27 14:52:49 +00:00
|
|
|
}
|
2006-07-27 14:49:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
function NewCategory()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
var promptStr = bundle.GetStringFromName("NewCategoryPrompt");
|
|
|
|
var newTitle = bundle.GetStringFromName("NewCategoryTitle");
|
2006-07-27 14:53:48 +00:00
|
|
|
var result = {value:null};
|
|
|
|
var confirmed = promptService.prompt(window, newTitle, promptStr, result, null, {value:0});
|
|
|
|
if (!confirmed || (!result.value) || result.value == "") return(false);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
var newName = RDF.GetLiteral(result.value);
|
|
|
|
if (!newName) return(false);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
var categoryRes = RDF.GetResource("NC:SearchCategoryRoot");
|
|
|
|
if (!categoryRes) return(false);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
RDFC.Init(catDS, categoryRes);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
var randomID = Math.random();
|
|
|
|
var categoryID = "NC:SearchCategory?category=urn:search:category:" + randomID.toString();
|
|
|
|
var currentCatRes = RDF.GetResource(categoryID);
|
|
|
|
if (!currentCatRes) return(false);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
var titleRes = RDF.GetResource("http://home.netscape.com/NC-rdf#title");
|
|
|
|
if (!titleRes) return(false);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
// set the category's name
|
|
|
|
catDS.Assert(currentCatRes, titleRes, newName, true);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
// and insert the category
|
|
|
|
RDFC.AppendElement(currentCatRes);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
RDFCUtils.MakeSeq(catDS, currentCatRes);
|
2006-07-27 14:49:38 +00:00
|
|
|
|
2006-07-27 14:53:34 +00:00
|
|
|
// try and select the new category
|
|
|
|
var categoryList = document.getElementById( "categoryList" );
|
|
|
|
var select_list = categoryList.getElementsByAttribute("id", categoryID);
|
2006-07-27 14:57:41 +00:00
|
|
|
if (select_list && select_list.item(0))
|
2006-07-27 14:53:34 +00:00
|
|
|
{
|
|
|
|
categoryList.selectedItem = select_list[0];
|
|
|
|
chooseCategory(categoryList.selectedItem);
|
|
|
|
}
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function RenameCategory()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
// make sure we have at least one category
|
|
|
|
var categoryPopup = document.getElementById( "categoryPopup" );
|
|
|
|
if (!categoryPopup) return(false);
|
|
|
|
if (categoryPopup.childNodes.length < 1) return(false);
|
|
|
|
|
|
|
|
var categoryList = document.getElementById( "categoryList" );
|
|
|
|
var currentName = categoryList.selectedItem.getAttribute("label");
|
|
|
|
var promptStr = bundle.GetStringFromName("RenameCategoryPrompt");
|
|
|
|
var renameTitle = bundle.GetStringFromName("RenameCategoryTitle");
|
2006-07-27 14:53:47 +00:00
|
|
|
var result = {value:currentName};
|
2006-07-27 14:53:48 +00:00
|
|
|
var confirmed = promptService.prompt(window,renameTitle,promptStr,result,null,{value:0});
|
|
|
|
if (!confirmed || (!result.value) || (result.value == "") || result.value == currentName) return(false);
|
2006-07-27 14:53:34 +00:00
|
|
|
|
|
|
|
var currentCatID = categoryList.selectedItem.getAttribute("id");
|
|
|
|
var currentCatRes = RDF.GetResource(currentCatID);
|
|
|
|
if (!currentCatRes) return(false);
|
|
|
|
|
|
|
|
var titleRes = RDF.GetResource("http://home.netscape.com/NC-rdf#title");
|
|
|
|
if (!titleRes) return(false);
|
|
|
|
|
|
|
|
var newName = RDF.GetLiteral(result.value);
|
|
|
|
if (!newName) return(false);
|
|
|
|
|
|
|
|
var oldName = catDS.GetTarget(currentCatRes, titleRes, true);
|
|
|
|
if (oldName) oldName = oldName.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (oldName)
|
|
|
|
{
|
|
|
|
catDS.Change(currentCatRes, titleRes, oldName, newName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
catDS.Assert(currentCatRes, titleRes, newName, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// force popup to update
|
|
|
|
chooseCategory(categoryList.selectedItem);
|
|
|
|
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function RemoveCategory()
|
|
|
|
{
|
2006-07-27 14:53:34 +00:00
|
|
|
// make sure we have at least one category
|
|
|
|
var categoryPopup = document.getElementById( "categoryPopup" );
|
|
|
|
if (!categoryPopup) return(false);
|
|
|
|
if (categoryPopup.childNodes.length < 1) return(false);
|
|
|
|
|
|
|
|
var promptStr = bundle.GetStringFromName("RemoveCategoryPrompt");
|
|
|
|
if (!confirm(promptStr)) return(false);
|
|
|
|
|
|
|
|
var categoryRes = RDF.GetResource("NC:SearchCategoryRoot");
|
|
|
|
if (!categoryRes) return(false);
|
|
|
|
|
|
|
|
var categoryList = document.getElementById( "categoryList" );
|
|
|
|
if (!categoryList) return(false);
|
|
|
|
|
|
|
|
var idNum = categoryList.selectedIndex;
|
|
|
|
|
|
|
|
var id = categoryList.selectedItem.getAttribute("id");
|
|
|
|
if ((!id) || (id == "")) return(false);
|
|
|
|
|
|
|
|
var idRes = RDF.GetResource(id);
|
|
|
|
if (!idRes) return(false);
|
|
|
|
|
|
|
|
RDFC.Init(catDS, categoryRes);
|
|
|
|
|
|
|
|
var nodeIndex = RDFC.IndexOf(idRes);
|
|
|
|
if (nodeIndex < 1) return(false); // how did that happen?
|
|
|
|
|
|
|
|
RDFC.RemoveElementAt(nodeIndex, true, idRes);
|
|
|
|
|
|
|
|
// try and select another category
|
|
|
|
if (idNum > 0) --idNum;
|
|
|
|
else idNum = 0;
|
|
|
|
|
|
|
|
if (categoryPopup.childNodes.length > 0)
|
|
|
|
{
|
|
|
|
categoryList.selectedItem = categoryPopup.childNodes[idNum];
|
|
|
|
chooseCategory(categoryList.selectedItem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// last category was deleted, so empty out engine list
|
|
|
|
var treeNode = document.getElementById("engineList");
|
|
|
|
if (treeNode)
|
|
|
|
{
|
|
|
|
treeNode.setAttribute( "ref", "" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(true);
|
2006-07-27 14:49:29 +00:00
|
|
|
}
|
2006-07-27 14:49:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-27 14:55:43 +00:00
|
|
|
function selectItems(listbox, containerID, targetID)
|
2006-07-27 14:49:35 +00:00
|
|
|
{
|
2006-07-27 14:55:43 +00:00
|
|
|
var select_list = listbox.getElementsByAttribute("id", targetID);
|
2006-07-27 14:53:34 +00:00
|
|
|
for (var x=0; x<select_list.length; x++)
|
|
|
|
{
|
|
|
|
var node = select_list[x];
|
|
|
|
if (!node) continue;
|
|
|
|
|
2006-07-27 14:55:43 +00:00
|
|
|
var parent = node.parentNode;
|
2006-07-27 14:53:34 +00:00
|
|
|
if (!parent) continue;
|
|
|
|
|
|
|
|
var id = parent.getAttribute("ref");
|
|
|
|
if (!id || id=="")
|
|
|
|
{
|
|
|
|
id = parent.getAttribute("id");
|
|
|
|
}
|
|
|
|
if (!id || id=="") continue;
|
|
|
|
|
|
|
|
if (id == containerID)
|
|
|
|
{
|
2006-07-27 14:55:43 +00:00
|
|
|
listbox.selectItem(node);
|
2006-07-27 14:53:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 14:49:35 +00:00
|
|
|
}
|