[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - datasourcemanager.js:1.14 jsdav.js:1.13 sitesmanager.js:1.16
Paul Everitt
paul@zope.com
Wed, 2 Apr 2003 16:33:59 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/lib
In directory cvs.zope.org:/tmp/cvs-serv14779
Modified Files:
datasourcemanager.js jsdav.js sitesmanager.js
Log Message:
Merged in Stephan's improvements to jsdav, eliminated the silly callbacks.
=== Packages/Moztop/moztop/content/lib/datasourcemanager.js 1.13 => 1.14 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.13 Wed Mar 26 05:57:13 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js Wed Apr 2 16:33:58 2003
@@ -161,18 +161,55 @@
// serialized data.
var tree = document.getElementById(this.treeId);
var sources = tree.database.GetDataSources();
+ sources.getNext(); // Skip first Mozilla-internal datasource
while (sources.hasMoreElements()) {
ds = new RDFDataSource();
ds.Init(sources.getNext());
- logmanager.addMessage('DS: ' + ds.getRawDataSource().URI,
- 'Tree: ' + this.treeId + ', dumpDataSources',
- ds.serializeToString());
+ dump("\n\n--- DS: " + ds.getRawDataSource().URI + " ------\n" +
+ ds.serializeToString());
+// logmanager.addMessage('DS: ' + ds.getRawDataSource().URI,
+// 'Tree: ' + this.treeId + ', dumpDataSources',
+// ds.serializeToString());
}
return true;
}
-DataSourceManager.prototype.getSelectedResource = function() {
+
+DataSourceManager.prototype.getCompositeDS = function ()
+{
+ /* We need to work with the composite DS on the navigator tree */
+ var tree = document.getElementById(this.treeId);
+ var treedb = tree.database;
+ var compositeds = new RDFDataSource();
+ compositeds.Init(treedb);
+ return compositeds;
+}
+
+
+
+DataSourceManager.prototype.getSelectedResource = function ()
+{
+ /* For all trees, this returns a selected resource as an RDFNode */
+ var tree = document.getElementById(this.treeId);
+ var index = tree.view.selection.currentIndex;
+
+ var compositeds = this.getCompositeDS();
+ if (index == -1) return false;
+
+ /* Switching to flags="dont-build-content" solved a lot of the */
+ /* tree flashing and rebuilding problems, but made grabbing the */
+ /* current selected resource a bit harder. */
+ currindex = tree.view.selection.currentIndex;
+ builder = tree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
+ r = builder.getResourceAtIndex(currindex);
+ return compositeds.getNode(r.Value);
+}
+
+
+
+
+DataSourceManager.prototype.OOOOLLLLLDDDDgetSelectedResource = function() {
/* Return the resource that is currently selected in the tree. */
// get index of tree
=== Packages/Moztop/moztop/content/lib/jsdav.js 1.12 => 1.13 ===
--- Packages/Moztop/moztop/content/lib/jsdav.js:1.12 Tue Apr 1 08:02:06 2003
+++ Packages/Moztop/moztop/content/lib/jsdav.js Wed Apr 2 16:33:58 2003
@@ -162,15 +162,6 @@
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.6
*/
- /* Callbacks are passed to the various DAV methods for handling */
- /* the server results from your application. These callback */
- /* functions sometimes need to be called in the context and n */
- /* scope of an object. Thus, the application can assign the */
- /* object as a property of this object. Here we set null as */
- /* the default, which will tell all the DAV methods here to use */
- /* the callback function as a function, not a method. */
-
- this.callbackObj = null;
}
@@ -187,9 +178,9 @@
/* The DavClient is stashed in request.thisobject and the */
/* widget is in DavClient.callbackObj */
// Parse the resulting XML for successful return
- stat = new MultiStatus();
+ stat = new DavMultiStatus();
stat.parseXML(request.responseXML.documentElement)
- request.callback(stat, request.thisobj.callbackObj);
+ callback(request);
}
return;
};
@@ -202,8 +193,6 @@
// Prepare the request
request.onload = handleResponse;
- request.callback = callback;
- request.thisobj = this;
request.open("PROPFIND", url);
request.setRequestHeader("Content-Type", "text/xml");
@@ -214,7 +203,7 @@
if (!propfind)
request.send("");
else
- request.send(propfind.serialize());
+ request.send(propfind.createXML());
return;
}
@@ -283,8 +272,10 @@
function handleResponse(error) {
/* The DavClient is stashed in request.thisobject and the */
/* widget is in DavClient.callbackObj */
- var thisobj = request.thisobj;
- request.callback(request.responseText);
+
+ if (request.responseText) {
+ callback(request);
+ }
};
// Make sure we have a URL
@@ -295,8 +286,6 @@
// Prepare request
request.onload = handleResponse;
- request.callback = callback;
- request.thisobj = this;
request.open("GET", url);
request.setRequestHeader("Content-type", "text/plain");
// Send request
@@ -352,12 +341,10 @@
function handleResponse(error) {
if (request.responseXML) {
// error handeling
- stat = new MultiStatus();
+ stat = new DavMultiStatus();
stat.parseXML(request.responseXML.documentElement);
- request.callback(stat);
+ callback(stat);
}
- request.callback(request.statusText);
-
}
// Make sure we have a URL
@@ -368,7 +355,6 @@
// Prepare request
request.onload = handleResponse;
- request.callback = callback;
request.open("DELETE", url);
request.setRequestHeader("Content-type", "text/plain");
// Send request
@@ -378,7 +364,7 @@
}
-DavClient.prototype.PUT = function(url, headers) {
+DavClient.prototype.PUT = function(url, content, headers) {
/* Implementation of WebDAV command PUT.
See http://asg.web.cmu.edu/rfc/rfc2518.html#sec-8.7
@@ -386,34 +372,33 @@
*/
var request = new XMLHttpRequest();
- var typeheader = "X-Zope-Type-Name"
+ var typeheader = "X-Zope-Type-Name";
function handleResponse(error) {
if (request.responseXML) {
+ dump("\nin PUT handler\n" + response_str + "\n");
var serializer = new XMLSerializer();
var response = request.responseXML;
var response_str = serializer.serializeToString(response);
-
- dump("\nmade it in PUT\n" + response_str + "\n");
+ dump("\nleaving PUT handler\n" + response_str + "\n");
}
}
- 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"));
+// 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"));
- var s = new XMLSerializer();
- str = xml_decl + s.serializeToString(x);
+// var s = new XMLSerializer();
+// str = xml_decl + s.serializeToString(x);
request.onload = handleResponse;
request.open("PUT", url);
request.setRequestHeader("Content-type", "text/xml");
- request.setRequestHeader("Host","localhost");
request.setRequestHeader(typeheader, "PageTemplate");
- request.send(x);
+ request.send(content);
return;
}
@@ -430,7 +415,7 @@
function handleResponse(error) {
if (request.responseXML) {
// error handeling
- stat = new MultiStatus();
+ stat = new DavMultiStatus();
stat.parseXML(request.responseXML.documentElement);
request.callback(stat);
}
@@ -481,7 +466,7 @@
function handleResponse(error) {
if (request.responseXML) {
// error handeling
- stat = new MultiStatus();
+ stat = new DavMultiStatus();
stat.parseXML(request.responseXML.documentElement);
request.callback(stat);
}
=== Packages/Moztop/moztop/content/lib/sitesmanager.js 1.15 => 1.16 ===
--- Packages/Moztop/moztop/content/lib/sitesmanager.js:1.15 Wed Mar 26 05:57:13 2003
+++ Packages/Moztop/moztop/content/lib/sitesmanager.js Wed Apr 2 16:33:58 2003
@@ -17,6 +17,7 @@
******************************************************************************/
+
function SitesManager() {
// Initialization
@@ -33,9 +34,11 @@
this.contentsurlprop = this.oscomrdfns + "contentsurl";
this.resourcetypesurlprop = this.oscomrdfns + "resourcetypesurl";
- // Local Sites RDF file
- this.sitesurl = getProfileDirURL() + '/moztop_sites.rdf';
+ // Local Sites and localsite RDF files
+ this.sitesurl = getProfileDirURL() + 'moztop_sites.rdf';
this.sitesurn = 'urn:moztop:sites'
+ this.localsiteurl = getProfileDirURL() + 'moztop_localsite.rdf';
+ this.localsiteurn = 'urn:moztop:sites:localsite';
}
@@ -62,14 +65,34 @@
}
/* If we make it here, it means we need to create moztop databases */
- sitesds = this.addDataSource(this.sitesurl);
+ sitesds = this.addDataSource(this.sitesurl, true);
var rootnode = sitesds.getNode(this.sitesurn);
- var subitems = sitesds.getNode(this.sitesurn+":subitems");
- subitems.makeSeq();
- rootnode.addTarget(this.subitemsprop, subitems);
+ var sitessubitems = sitesds.getNode(this.sitesurn+":subitems");
+ sitessubitems.makeSeq();
+ rootnode.addTarget(this.subitemsprop, sitessubitems);
+
+ /* Now create the localsite database for storing Drafts*/
+ localsiteds = this.addDataSource(this.localsiteurl, true);
+
+ /* Add an entry in the sites database */
+ // XXX: This doesn't need to be recorded as an entry in moztop_sites.
+ // Instead, we should copy an RDF file over to the profile dir and
+ // let the moztop_localsites make an assertion about containment in sites.
+ var newsite = sitesds.getNode(this.localsiteurn);
+ newsite.addTarget(this.titleprop, "Drafts");
+ newsite.addTarget(this.resourcetypeprop,
+ 'urn:moztop:resourcetypes:site');
+ sitessubitems.addChild(newsite);
+
+ /* Put a container under "Drafts" */
+ var newsite = localsiteds.getNode(this.localsiteurn);
+ var localsitesubitems = localsiteds.getNode(this.localsiteurn+":subitems");
+ localsitesubitems.makeSeq();
+ newsite.addTarget(this.subitemsprop, localsitesubitems);
+ localsiteds.save();
sitesds.save();
- logmanager.addMessage("Initialized moztop.rdf",
+ logmanager.addMessage("Initialized profile databases",
"navigation.js, initNavigation",
sitesds.serializeToString());
@@ -84,13 +107,20 @@
tree */
// Get the sites resource from the data source
sitesds = this.addDataSource(this.sitesurl, true);
+
+ /* Add localsite, which is NOT recorded as a site in the sitesdb */
+ localsite = this.addDataSource(this.localsiteurl, true);
+
var sites_node = sitesds.getNode(this.sitesurn).getTarget(
this.subitemsprop);
var sites = sites_node.getChildren();
while (sites.hasMoreElements()) {
site = sites.getNext();
- this.loadSite(site.getValue());
+ dump("\nin initializeSites " + site.getValue());
+ if (site.getValue() != this.localsiteurn) {
+ this.loadSite(site.getValue());
+ }
}
return true;
}
@@ -242,18 +272,30 @@
// Make the new tab/panel the active one
tabs.selectedItem = tab;
panels.selectedPanel = viewer;
+
+ // Allow the event to keep bubbling by returning false
+ return false;
}
SitesManager.prototype.createResource = function(newtypeurn) {
+ /* Create a resource in Drafts and open it */
- /* This function "opens" the selected Tree resource. */
- var rdf = this.getSelectedResource();
+ // First grab the drafts folder
+ // localsiteds = this.getDataSource(this.localsiteurl);
+ var localsiteds = new RDFDataSource(this.localsiteurl);
+ drafts = localsiteds.getNode(this.localsiteurn).getTarget(this.subitemsprop);
// We're going to make up a URN, it doesn't get set until the user
- // saves it. todo: save this in a temp datasource, like Drafts
+ // saves it. Then we create a resource in Drafts.
var resourcetitle = "Untitled-1";
- var urn = "urn:localsite:drafts:untitled1";
+ var urn = "urn:moztop:sites:localsite:drafts:untitled1";
+
+ // Create a new site and add it to the sites resource
+ var newresource = localsiteds.getNode(urn);
+ newresource.addTarget(this.titleprop, resourcetitle);
+ newresource.addTarget(this.resourcetypeprop,newtypeurn);
+ drafts.addChild(newresource);
// Find viewer containers
var tabs = document.getElementById("active-contents-tabs");
@@ -262,14 +304,10 @@
// Do not open resource if already opened.
for (var i = 0; i < panels.childNodes.length; i++) {
if (panels.childNodes[i].getAttribute('urn') == urn)
+ alert(resourcetitle + " is already open");
return;
}
- // Make an appropriate log entry
- logmanager.addMessage("Opening " + resourcetitle,
- 'SiteManager.openSelectedResource',
- "Opening " + resourcetitle);
-
// Retrieving resource type resource for chosen resource type
type = this.getResource(newtypeurn);
// XXX: The type registry should really have an attribute for this.
@@ -302,7 +340,9 @@
DataSourceManager.prototype.removeSelectedResource = function() {
/* This function deletes the selected Tree resource. */
+
resource = this.getSelectedResource();
+ resourceurn = resource.getValue();
type = resource.getTarget(this.resourcetypeprop).getValue();
if (type == 'urn:moztop:resourcetypes:site') {
@@ -318,13 +358,51 @@
return true;
}
+ // XXX: ok this is a hack too. If we are deleting a draft, don't
+ // issue the DavClient call.
+ if (resourceurn =="urn:moztop:sites:localsite:drafts:untitled1") {
+ rootnode = this.getResource(this.localsiteurn);
+ container = rootnode.getTarget(this.subitemsprop);
+ container.makeSeq();
+ container.removeChild(resourceurn);
+ // XXX: Need to save the datasource
+ return;
+ }
+
+
// Deleting item from server
- dav = new DavClient('localhost');
- dav.DELETE(resource.getValue());
+ var dav = new DavClient();
+ //dav.DELETE(resource.getValue());
// Update RDF
- resource.datasource.Refresh(0);
+ /* Hard wired for now to a certain container */
+// rdfseqprop = "http://www.w3.org/1999/02/22-rdf-syntax-ns#_1";
+// rdfseq = resource.getSource(rdfseqprop);
+// rdfseq.makeSeq();
+// rdfseq.removeChild(resourceurn);
+// var tree = document.getElementById(this.treeId);
+// tree.builder.rebuild();
+// return;
+
+/*
+
+rdfseq = resource.getTarget(this.subitemsprop)
+rdfseq.getSource(this.subitemsprop).getValue()
+
+*/
+
+
+// rooturn = "http://127.0.0.1:8380/"
+// rootnode = this.getResource(rooturn);
+// container = rootnode.getTarget(this.subitemsprop);
+
+ container = resource.getTarget(this.subitemsprop);
+ container.makecontain();
+ container.removeChild(resourceurn);
+ var tree = document.getElementById(this.treeId);
+ tree.builder.rebuild();
+ return;
}