[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - datasourcemanager.js:1.10 sitesmanager.js:1.9
Stephan Richter
srichter@cbu.edu
Sat, 22 Mar 2003 20:34:29 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/lib
In directory cvs.zope.org:/tmp/cvs-serv18063/moztop/content/lib
Modified Files:
datasourcemanager.js sitesmanager.js
Log Message:
Okay, this is a good checkpoint.
- I hooked up the XBL for the Folder again.
- Improved the Folder Viewer constructors.
- Implemented Folder Preview.
- Only the Folder's actual content is shown now in content.
=== Packages/Moztop/moztop/content/lib/datasourcemanager.js 1.9 => 1.10 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.9 Sat Mar 22 14:36:31 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js Sat Mar 22 20:33:58 2003
@@ -58,8 +58,12 @@
}
-DataSourceManager.prototype.addDataSource = function(rdfurl) {
- /* Add a new datasource to the tree. */
+DataSourceManager.prototype.addDataSource = function(rdfurl, blocked) {
+ /* Add a new datasource to the tree.
+
+ While we are trying to load data sources in blocked mode, it is
+ sometimes necessary to do so.
+ */
// Allowing the Data Source Manager namespace to be present in onFullLoad()
dsm = this;
@@ -71,15 +75,18 @@
tree.builder.rebuild();
};
-
// Get the RDF from the specified URL and creata a RDFDataSource
- if (rdfurl == null) {
- var ds = new RDFDataSource();
+ if ((rdfurl == null) || (blocked == true)) {
+ if (rdfurl == null) {
+ var ds = new RDFDataSource();
+ } else {
+ // Load data source in blocked mode
+ var ds = new RDFDataSource(rdfurl);
+ }
// Calling onFullLoad manually, since it does not do remote things
onFullLoad(ds);
} else {
- // For some reason getDataSourceBlocked is not part of the API
- // anymore, so that we need to use getDataSource
+ // Loading and adding the datasource in async (non-blocking) mode.
var ds = new RDFDataSource(rdfurl, onFullLoad);
}
@@ -150,8 +157,8 @@
/* Dump a serialized representation of all data sources into a meaningful
medium, such as the LogManager */
- // XXX: Iterate through all datasources in the tree database and dump
- // their serialized data.
+ // Iterate through all datasources in the tree database and dump their
+ // serialized data.
var tree = document.getElementById(this.treeId);
var sources = tree.database.GetDataSources();
while (sources.hasMoreElements()) {
@@ -177,6 +184,8 @@
return false;
var res = tree.view.getItemAtIndex(index).resource;
+ // XXX: All of the following code should be eventually replaced by the
+ // getNode() method.
sources = tree.database.GetDataSources();
// the first source is always Mozilla internal
sources.getNext();
@@ -195,6 +204,24 @@
}
+DataSourceManager.prototype.getNode = function(urn) {
+ /* Grab a resource using its urn. This method looks through all
+ datasources to find the resource. */
+ var tree = document.getElementById(this.treeId);
+ var sources = tree.database.GetDataSources();
+ // The first datasource is Mozilla internal
+ sources.getNext();
+ while (sources.hasMoreElements()) {
+ ds = new RDFDataSource();
+ ds.Init(sources.getNext());
+ resource = ds.getNode(urn);
+ if (resource.getProperties().hasMoreElements())
+ return resource;
+ }
+ return null;
+}
+
+
DataSourceManager.prototype.openSelectedResource = function() {
/* This function "opens" the selected Tree resource.
@@ -203,3 +230,4 @@
return true;
}
+
=== Packages/Moztop/moztop/content/lib/sitesmanager.js 1.8 => 1.9 ===
--- Packages/Moztop/moztop/content/lib/sitesmanager.js:1.8 Sat Mar 22 15:09:19 2003
+++ Packages/Moztop/moztop/content/lib/sitesmanager.js Sat Mar 22 20:33:58 2003
@@ -11,19 +11,7 @@
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
-SitesManager API Methods:
-
- * connectSelectedSite - Connect to the selected site.
-
- * addSite - Add a site to the tree.
-
- * getSelectedResource - Get the in the tree selected resource.
-
- * openSelectedResource - Open resource views.
-
- * addResource - Add a resource to the selected container object.
-
- * deleteResource - Delete the selected resource.
+Defines the SitesManager, which handles the navigation tree.
$Id$
@@ -38,11 +26,13 @@
this.treeId = 'navigationtree';
// Sites-specific RDF properties
- this.resourcetypeprop = this.oscomrdfns + "resourcetypes";
- this.contentsurlprop = this.oscomrdfns + "contentsurl";
+ this.resourcetypeprop = this.oscomrdfns + "resourcetype";
this.sitetypeprop = this.oscomrdfns + "sitetype";
this.styleidprop = this.oscomrdfns + "styleid";
+ this.contentsurlprop = this.oscomrdfns + "contentsurl";
+ this.resourcetypesurlprop = this.oscomrdfns + "resourcetypesurl";
+
// Local Sites RDF file
this.sitesurl = getProfileDirURL() + '/moztop_sites.rdf';
this.sitesurn = 'urn:moztop:sites'
@@ -100,32 +90,50 @@
while (sites.hasMoreElements()) {
site = sites.getNext();
- this.loadSite(site.getValue());
+ this.loadSite(site.getValue(), sitesds);
}
return true;
}
-SitesManager.prototype.loadSite = function(rsdurl) {
- /* Load a site by grabbing its contents and types. */
+SitesManager.prototype.loadSite = function(rsdurl, sitesds) {
+ /* Load a site by grabbing its contents and types.
+
+ Why do we allow an optional sitesds to be passed?
+ Rememeber async? During initialization we are not ensured that the
+ sites RDF data was already added to the tree, therefore we might
+ not be able to get to it using getDataSource(). Passing it explicitly
+ solves the problem during initialization.
+ */
// Allowing the Sites Manager namespace to be present in loadThisSite()
sm = this;
+ if (!sitesds)
+ sitesds = sm.getDataSource(sm.sitesurl);
+
function loadThisSite(error) {
if (request.statusText) {
var response = request.responseXML;
-
+
+ // Get the site resource
+ var site = sitesds.getNode(rsdurl);
+
// Retrieve site content URL from response (XML)
var holder = response.getElementsByTagNameNS(
sm.oscomrdfns, "contentsurl")[0];
var contenturl = holder.firstChild.nodeValue;
-
+ site.addTarget(sm.contentsurlprop, contenturl);
+
// Retrieve site resource types URL from response (XML)
var holder = response.getElementsByTagNameNS(
sm.oscomrdfns, "resourcetypesurl")[0];
var typesurl = holder.firstChild.nodeValue;
+ site.addTarget(sm.resourcetypesurlprop, typesurl);
+ // Save the changes
+ sitesds.save();
+
// Get the tree
var tree = document.getElementById(sm.treeId);
@@ -163,7 +171,7 @@
sites.addChild(newsite);
// Save the changes
- this.sitesds.save();
+ sitesds.save();
// Load the site
this.loadSite(rsdurl)
@@ -177,6 +185,59 @@
return true;
}
+
+
+SitesManager.prototype.openSelectedResource = function() {
+ /* This function "opens" the selected Tree resource. */
+ var rdf = this.getSelectedResource();
+
+ // Grab the selected resource and its title
+ resourcetitle = rdf.getTarget(this.titleprop).getValue();
+ urn = rdf.getValue();
+
+ // Find viewer containers
+ var tabs = document.getElementById("active-contents-tabs");
+ var panels = document.getElementById("active-contents-tabpanels");
+
+ // Do not open resource if already opened.
+ for (var i = 0; i < panels.childNodes.length; i++) {
+ if (panels.childNodes[i].getAttribute('urn') == rdf.getValue())
+ return;
+ }
+
+ // Make an appropriate log entry
+ logmanager.addMessage("Opening " + resourcetitle,
+ 'SiteManager.openSelectedResource',
+ "Opening " + resourcetitle);
+
+ // Retrieving resource type
+ typeURN = rdf.getTarget(this.resourcetypeprop).getValue();
+ type = this.getNode(typeURN);
+ // XXX: The type registry should really have an attribute for this.
+ typeViewerName = type.getTarget(this.styleidprop).getValue() + "viewer";
+
+ // Creating resource viewer
+ var viewer = document.createElement(typeViewerName);
+
+ // Setting initialization attributes
+ viewer.id = typeViewerName + "-" + new Date().getTime();
+ viewer.setAttribute("urn", rdf.getValue());
+ viewer.setAttribute("resourcetitle", resourcetitle);
+
+ // Prepare tabs
+ var tab = document.createElement("tab");
+ tab.setAttribute("label", resourcetitle);
+ tab.setAttribute("id", resourcetitle + "-tab");
+
+ // Add new viewer to opened resources tabs
+ tabs.appendChild(tab);
+ panels.appendChild(viewer);
+
+ // Make the new tab/panel the active one
+ tabs.selectedItem = tab;
+ panels.selectedPanel = viewer;
+}
+
/* Initialize the Sites Manager */
function initSitesManager() {