[Zope-CVS] CVS: Packages/Moztop/moztop/content/Explorer - Explorer.js:1.12 ExplorerOverlay.xul:1.6
Stephan Richter
srichter@cbu.edu
Sat, 15 Mar 2003 17:25:16 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/Explorer
In directory cvs.zope.org:/tmp/cvs-serv22749/moztop/content/Explorer
Modified Files:
Explorer.js ExplorerOverlay.xul
Log Message:
Fixed openSelectedResource code and removed all of the hacked in hardwired
code, so that we should be able to to open every thing generically now.
Also, you cannot open a resource twice anymore.
In order to make it work for all content types we need to get a more
complete resource type RDF graph.
=== Packages/Moztop/moztop/content/Explorer/Explorer.js 1.11 => 1.12 ===
--- Packages/Moztop/moztop/content/Explorer/Explorer.js:1.11 Sat Mar 15 11:28:23 2003
+++ Packages/Moztop/moztop/content/Explorer/Explorer.js Sat Mar 15 17:24:45 2003
@@ -13,78 +13,83 @@
******************************************************************************
Explorer library; here to manage Content Object Tree.
+
+SitesManager API Methods:
+
+ * getSelectedResource - Get the in the tree selected resource.
+
+ * openSelectedResource - Open resource views.
+
$Id$
******************************************************************************/
-
/* Some regular expressions to fix the case-sensitivity of Moz RDF */
var fixer1 = /rdf:rdf/g;
var fixer2 = /rdf:description/g;
var fixer3 = /rdf:seq/g;
function SitesManager () {
+ /* A prototype to manage the sites database and datasources */
- /* A prototype to manage the sites database and datasources */
- if( !(this instanceof SitesManager) ) return new SitesManager( );
- DataSourceManager.call(this);
-
- this.ds = new RDFDataSource(this.profileurl + "/moztop.rdf",null);
- this.commontypesds = new RDFDataSource();
- this.commontypesds.parseFromString(commontypes_data,
- "http://www.zope.org/rdf");
- this.elementid = 'explorertree';
-
- this.sitedatasources = new Array();
-
- /* Attach these (potentially empty) datasources */
- var tree=document.getElementById(this.elementid);
- tree.database.AddDataSource(this.ds.getRawDataSource());
- tree.database.AddDataSource(this.commontypesds.getRawDataSource());
- tree.builder.rebuild();
+ // Initialization
+ if( !(this instanceof SitesManager) )
+ return new SitesManager( );
+ DataSourceManager.call(this);
+
+ // Grab appropriate Content Tree RDF datasource
+ this.ds = new RDFDataSource(this.profileurl + "/moztop.rdf",null);
+
+ // Define Content Type RDF datasource
+ this.commontypesds = new RDFDataSource();
+ this.commontypesds.parseFromString(commontypes_data,
+ "http://www.zope.org/rdf");
+
+ // DOM element id of the Explorer tree
+ this.elementid = 'explorertree';
+
+ // An array of all datasources that describe the content of a site.
+ this.sitedatasources = new Array();
+
+ /* Attach these (potentially empty) datasources */
+ var tree = document.getElementById(this.elementid);
+ tree.database.AddDataSource(this.ds.getRawDataSource());
+ tree.database.AddDataSource(this.commontypesds.getRawDataSource());
+ tree.builder.rebuild();
}
-
/* Now subclass, then add methods */
SitesManager.prototype = new DataSourceManager();
/* Detect if this is an initial install. If so, initialize. */
-SitesManager.prototype.initializeProfileDatabases=
- function ()
-{
-
- /* Are there databases in profile dir? If so, log a message and return */
- var allres = this.ds.getAllResources();
- if (allres.hasMoreElements()) {
- logmanager.addMessage('Found existing moztop databases',
- 'Explorer.js, initExplorer',
- this.ds.serializeToString());
- return;
- }
+SitesManager.prototype.initializeProfileDatabases = function() {
+ /* Are there databases in profile dir? If so, log a message and return */
+ var allres = this.ds.getAllResources();
+ if (allres.hasMoreElements()) {
+ logmanager.addMessage('Found existing moztop databases',
+ 'Explorer.js, initExplorer',
+ this.ds.serializeToString());
+ return;
+ }
+ /* If we make it here, it means we need to create moztop databases */
+ var rootnode = this.ds.getNode("urn:moztop:sites");
+ var subitems = this.ds.getNode("urn:moztop:sites:subitems");
+ subitems.makeSeq();
+ rootnode.addTarget(this.subitemsprop,subitems);
- /* If we make it here, it means we need to create moztop databases */
- var rootnode = this.ds.getNode("urn:moztop:sites");
- var subitems = this.ds.getNode("urn:moztop:sites:subitems");
- subitems.makeSeq();
- rootnode.addTarget(this.subitemsprop,subitems);
-
- this.ds.save();
- logmanager.addMessage("Initialized moztop.rdf","Explorer.js, initExplorer",
- this.ds.serializeToString());
+ this.ds.save();
+ logmanager.addMessage("Initialized moztop.rdf","Explorer.js, initExplorer",
+ this.ds.serializeToString());
- return;
+ return;
}
-SitesManager.prototype.toggleNoSites=
- function ()
-{
- return;
+SitesManager.prototype.toggleNoSites = function() {
+ return;
}
-SitesManager.prototype.connectSelectedSite=
- function ()
-{
+SitesManager.prototype.connectSelectedSite = function() {
var selectedsite = this.getSelectedResource();
if (! selectedsite) {
@@ -106,9 +111,7 @@
}
-SitesManager.prototype.retrieveSiteContents=
- function (siteurl,ds)
-{
+SitesManager.prototype.retrieveSiteContents = function(siteurl, ds) {
/* Given a URL, retrieve the RDF and add it to the passed-in datasource */
function handleError() {
@@ -123,38 +126,37 @@
}
}
- function serializeResponse(e)
- {
+ function serializeResponse(e) {
/* Local anonymous function for handling the async data */
if (p.statusText) {
dump("\nhere\n");
-
+
/* If p.ds is empty, we'll have to attach and rebuild */
var needsReload = false;
if (! p.ds.getAllResources()) {
var needsReload = false;
}
-
+
p.ds.refresh(true);
-
+
var newrdf = p.responseText;
var newrdf = newrdf.replace(fixer1,"rdf:RDF");
var newrdf = newrdf.replace(fixer2,"rdf:Description");
var newrdf = newrdf.replace(fixer3,"rdf:Seq");
dump("\ngoober is " + newrdf);
-
+
p.ds.parseFromString(newrdf,siteurl);
logmanager.addMessage("Retrieved remote contents.rdf",
"Explorer.js, retrieveSiteContents",
p.ds.serializeToString());
-
+
/* todo: don't rebuild tree if you don't have to */
var tree=document.getElementById("explorertree");
tree.database.AddDataSource(p.ds.getRawDataSource());
tree.builder.rebuild();
}
}
-
+
var p = new XMLHttpRequest();
p.ds = ds;
// p.onreadystatechange = handleError;
@@ -164,8 +166,7 @@
}
-SitesManager.prototype.DELETE=function (puturl, putcontent)
-{
+SitesManager.prototype.DELETE = function(puturl, putcontent) {
var p = new XMLHttpRequest();
function myfunc (e) {
@@ -189,10 +190,9 @@
}
-SitesManager.prototype.addSite=
- function (site_name, site_realm, site_url,
- site_username, site_password)
-{
+SitesManager.prototype.addSite = function(site_name, site_realm, site_url,
+ site_username, site_password) {
+
/* The realm is used in URNs while the name is for the display */
var sc=this.ds.getNode("urn:moztop:sites")
.getTarget(this.subitemsprop);
@@ -247,76 +247,76 @@
return;
}
-SitesManager.prototype.openSelectedResource=
- function () {
- var rdf = this.getSelectedResource();
- var resourcetitle = rdf.getTarget(this.titleprop).getValue();
-
- // todo: stop hard coding sitetabpanel'
- // var resourcetype = rdf.getTarget(this.resourcetypeprop);
- //var resourcetypetitle = resourcetype.getTarget(this.titleprop).getValue();
-
- logmanager.addMessage("Open selected resource");
- dump("\n in openSelectedResource\n");
- var resourcetype = "site";
- var tp = document.createElement("folderviewer");
- tp.id = "127";
- tp.setAttribute("urn","124");
- tp.setAttribute("resourcetitle", resourcetitle);
- var outter = document.getElementById("active-contents-tabpanels");
- outter.appendChild(tp);
+SitesManager.prototype.openSelectedResource = function() {
+ /* Opens the tab views for the selected resource */
+
+ // Grab the selected resource and its title
+ var rdf = this.getSelectedResource();
+ var resourcetitle = rdf.getTarget(this.titleprop).getValue();
+
+ // Find viewer container
+ var outter = document.getElementById("active-contents-tabpanels");
+
+ // Do not open resource if already opened.
+ for (var i = 0; i < outter.childNodes.length; i++) {
+ if (outter.childNodes[i].getAttribute('urn') == rdf.getValue())
+ return;
+ }
+
+ // Make an appropriate log entry
+ logmanager.addMessage("Opening " + resourcetitle);
+
+ // Retrieving resource type
+ typeURN = rdf.getTarget(this.resourcetypeprop).getValue();
+ type = this.commontypesds.getNode(typeURN);
+ // XXX: The type registry should really have an attribute for this.
+ typeViewerName = type.getTarget(
+ "http://www.zope.org/rdf#styleid").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);
+
+ // Add new viewer to opened resources tabs
+ outter.appendChild(viewer);
+}
- dump("\n out of openSelectedResource\n");
- return;
- }
-SitesManager.prototype.addResource=
- function ()
-{
+SitesManager.prototype.addResource = function(type, name) {
return;
}
-SitesManager.prototype.deleteResource=
- function ()
-{
+SitesManager.prototype.deleteResource = function() {
var urn = this.getSelectedResource();
-
+
if (! urn) {
alert("Please select a resource to delete.");
return;
}
-
+
var urn = urn.getValue();
var selectedsite = this.ds.getNode(urn);
- var resourcetype = selectedsite.getTarget(this.resourcetypeprop).getValue();
+ var resourcetype = selectedsite.getTarget(
+ this.resourcetypeprop).getValue();
if (resourcetype != "urn:moztop:resourcetypes:site") {
alert("You cannot delete a " + resourcetype);
return;
}
-
+
/* Only delete if you get a valid response back from the server */
- /* todo: remove from array */
+ /* XXX: remove from array */
this.ds.deleteRecursive(urn);
this.ds.save();
return;
}
-
-/* Initialize the Explorer datasource */
-function initExplorer() {
- sitesmanager = SitesManager();
- sitesmanager.initializeProfileDatabases();
- return;
-}
-
-
-
-
-SitesManager.prototype.PUT=function ()
-{
+SitesManager.prototype.PUT = function () {
var puturl = "http://localhost:9700/fooboy3";
var putcontent = "";
@@ -337,7 +337,8 @@
var x = document.implementation.createDocument("", "test", null);
x.documentElement.appendChild(document.createElement("Foo"));
x.documentElement.appendChild(document.createElement("Bar"));
- x.documentElement.firstChild.appendChild(document.createTextNode("My Stuff\nYeah"));
+ x.documentElement.firstChild.appendChild(
+ document.createTextNode("My Stuff\nYeah"));
var s = new XMLSerializer();
str = s.serializeToString(x);
@@ -352,7 +353,12 @@
return;
}
-
+/* Initialize the Explorer datasource */
+function initExplorer() {
+ sitesmanager = SitesManager();
+ sitesmanager.initializeProfileDatabases();
+ return;
+}
/* Everything after this will be replaced by everything above this */
=== Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul 1.5 => 1.6 ===
--- Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul:1.5 Sat Feb 15 06:02:00 2003
+++ Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul Sat Mar 15 17:24:45 2003
@@ -11,7 +11,7 @@
<tree flex="1" hidden="false"
id="explorertree" ref="urn:moztop:sites"
datasources="rdf:null"
- ondblclick="sitesmanager.openSelectedResource();"
+ ondblclick="sitesmanager.openSelectedResource();"
containment="http://home.netscape.com/NC-rdf#subitems">
<treecols>
<treecol id="ResourceNameColumn" label="Name" primary="true" flex="1"/>