[Zope-CVS] CVS: Packages/Moztop/moztop/content/Explorer - Explorer.js:1.6 ExplorerOverlay.xul:1.5
Paul Everitt
paul@zope.com
Sat, 15 Feb 2003 06:02:01 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/Explorer
In directory cvs.zope.org:/tmp/cvs-serv19080/Explorer
Modified Files:
Explorer.js ExplorerOverlay.xul
Log Message:
Rewrite finished.
=== Packages/Moztop/moztop/content/Explorer/Explorer.js 1.5 => 1.6 ===
--- Packages/Moztop/moztop/content/Explorer/Explorer.js:1.5 Fri Feb 7 10:28:43 2003
+++ Packages/Moztop/moztop/content/Explorer/Explorer.js Sat Feb 15 06:02:00 2003
@@ -17,6 +17,261 @@
******************************************************************************/
+function SitesManager () {
+
+ /* 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();
+}
+
+
+/* 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;
+ }
+
+
+ /* 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());
+
+ return;
+}
+
+SitesManager.prototype.toggleNoSites=
+ function ()
+{
+ return;
+}
+
+SitesManager.prototype.connectSelectedSite=
+ function ()
+{
+ var selectedsite = this.getSelectedResource();
+
+ if (! selectedsite) {
+ alert("Please select a site to connect to.");
+ return;
+ }
+
+ var siteurl = selectedsite.getTarget(this.urlprop).getValue();
+
+ /* If the site isn't already in the array, create a ds */
+ var ds = this.sitedatasources[siteurl];
+ if (! ds) {
+ var ds = new RDFDataSource();
+ this.sitedatasources[siteurl] = ds;
+ }
+ this.retrieveSiteContents(siteurl,ds);
+
+ return;
+}
+
+
+SitesManager.prototype.retrieveSiteContents=
+ function (siteurl,ds)
+{
+ /* Given a URL, retrieve the RDF and add it to the passed-in datasource */
+
+ function handleError() {
+ dump("\n in handleError");
+ if (p.readyState == 2) {
+ if (p.status) {
+ if (p.status== "401") {
+ alert("Invalid URL");
+ return;
+ }
+ }
+ }
+ }
+
+ function serializeResponse(e)
+ {
+ /* Local anonymous function for handling the async data */
+ if (p.statusText) {
+
+ /* 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);
+ p.ds.parseFromString(p.responseText,siteurl);
+ logmanager.addMessage("Retrieved remote contents.rdf",
+ "Explorer.js, retrieveSiteContents",
+ p.ds.serializeToString());
+
+ /* todo: don't rebuild tree if you don't have to */
+ if (1 == 1) {
+ dump("1==1 " + p.ds.serializeToString());
+ var tree=document.getElementById("explorertree");
+ tree.database.AddDataSource(p.ds.getRawDataSource());
+ tree.builder.rebuild();
+ }
+ }
+ }
+
+ var p = new XMLHttpRequest();
+ p.ds = ds;
+ // p.onreadystatechange = handleError;
+ p.onload = serializeResponse;
+ p.open("GET", siteurl + "contents.rdf", false);
+ p.send(null);
+}
+
+
+SitesManager.prototype.addSite=
+ function (site_name, site_url, site_username, site_password)
+{
+ var sc=this.ds.getNode("urn:moztop:sites")
+ .getTarget(this.subitemsprop);
+ var newsite=this.ds.getNode("urn:moztop:sites:" + site_name);
+ var siteres = this.ds.getNode("urn:moztop:resourcetypes:site");
+ sc.addChild(newsite);
+
+
+ // Now fill in the data for the new site
+ newsite.addTarget(this.titleprop,site_name);
+ newsite.addTarget(this.urlprop,site_url);
+ newsite.addTarget(this.usernameprop,site_username);
+ newsite.addTarget(this.passwordprop,site_password);
+ newsite.addTarget(this.resourcetypeprop,siteres);
+
+ // Prepare the area for psuedo-folders (Configurations, Content, etc.)
+ var subitemsurn = "urn:moztop:sites:" + site_name + ":subitems";
+ var subitems = this.ds.getNode(subitemsurn);
+ subitems.makeSeq();
+ newsite.addTarget(this.subitemsprop,subitems);
+
+ /* Now add the virtual folders which arc to this.commontypesds */
+ var vfs = new Array ('Views','Configurations','Content','Bundles','Packages');
+ for (var i = 0; i < vfs.length; i++) {
+
+ /* vf is the current virtual folder */
+ var vf = vfs[i];
+ var vfurn = "urn:moztop:sites:" + site_name + ":" + vf.toLowerCase();
+
+ /* Create a new node for this virtual folder and append to subitems */
+ var newvf = this.ds.getNode(vfurn);
+ subitems.addChild(newvf);
+ newvf.addTarget(this.titleprop,vf);
+
+ /* Fill in the rest of the info for the virtual folder */
+ newvf.addTarget(this.resourcetypeprop,
+ "urn:moztop:resourcetypes:" + vf.toLowerCase());
+ }
+
+ /* Finally, create a site datasource and load the contents for this site */
+ var ds = this.sitedatasources[site_url];
+ if (! ds) {
+ var ds = new RDFDataSource();
+ this.sitedatasources[site_url] = ds;
+ }
+ this.retrieveSiteContents(site_url,ds);
+
+ this.ds.save();
+ return;
+}
+
+SitesManager.prototype.openSelectedResource=
+ function () {
+ var rdf = this.getSelectedResource();
+ var resourcetitle = rdf.getTarget(this.titleprop).getValue();
+
+ // todo: stop hardcoding the element to 'sitetabpanel'
+ // var resourcetype = rdf.getTarget(this.resourcetypeprop);
+ //var resourcetypetitle = resourcetype.getTarget(this.titleprop).getValue();
+
+ var resourcetype = "site";
+ var tp = document.createElement("sitetabpanel");
+ tp.id = "127";
+ tp.setAttribute("urn","124");
+ tp.setAttribute("resourcetitle",resourcetitle);
+
+ var outter = document.getElementById("active-contents-tabpanels");
+ outter.appendChild(tp);
+ return;
+ }
+
+SitesManager.prototype.addResource=
+ function ()
+{
+ return;
+}
+
+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();
+
+ 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 */
+ this.ds.deleteRecursive(urn);
+ this.ds.save();
+
+ return;
+}
+
+
+/* Initialize the Explorer datasource */
+function initExplorer() {
+ sitesmanager = SitesManager();
+ sitesmanager.initializeProfileDatabases();
+ return;
+}
+
+
+
+
+
+
+/* Everything after this will be replaced by everything above this */
/* XML-RPC client setup. */
function getClient() {
@@ -151,196 +406,3 @@
return obj_name
}
-function addSite(site_name, site_url, site_username, site_password) {
-
- // First some constants for RDF property names
- var dctitle = "http://www.purl.org/dc/1.1#title";
- var sitert = "http://www.zope.org/rdf/site#resourcetype";
- var siteurl = "http://www.zope.org/rdf/site#url";
- var siteusername = "http://www.zope.org/rdf/site#username";
- var sitepassword = "http://www.zope.org/rdf/site#password";
-
-// Grab the datasources
-// var prefsdir = getProfileURL();
-// var sitesds = new RDFDataSource(prefsdir + "/moztop_sites.rdf");
-// var typesds = new RDFDataSource(prefsdir + "/moztop_types.rdf");
-
- // Create a new node for the new site, attached to the sites list
- var sc=sitesds.getNode("urn:moztop:sites")
- .getTarget("http://home.netscape.com/NC-rdf#subitems");
- var newsite=sitesds.getNode("urn:moztop:sites:" + site_name);
- var siteres = typesds.getNode("urn:moztop:resourcetypes:site");
- sc.addChild(newsite);
-
- // Now fill in the data for the new site
- newsite.addTarget(dctitle,site_name);
- newsite.addTarget(siteurl,site_url);
- newsite.addTarget(siteusername,site_username);
- newsite.addTarget(sitepassword,site_password);
- newsite.addTarget(sitert,siteres);
-
- // Prepare the area for psuedo-folders (Configurations, Content, etc.)
- var urn = "urn:moztop:sites:" + site_name + ":subitems";
- var subitems = sitesds.getNode(urn);
- subitems.makeSeq();
- newsite.addTarget("http://home.netscape.com/NC-rdf#subitems",subitems);
-
- // Now add the psuedo folders
- var pfs = new Array ('Views','Configurations','Content','Bundles','Packages');
- for (var i = 0; i < pfs.length; i++) {
- var rt = pfs[i];
- var urn = "urn:moztop:sites:" + site_name + ":" + rt.toLowerCase();
- var newpf = sitesds.getNode(urn);
- subitems.addChild(newpf);
- newpf.addTarget(dctitle,rt);
- }
-
- // Now we can hide the "no sites defined" label and turn on the tree
- doc = getDocumentOfWindowWithId("moztop-main-window");
-
- doc.getElementById("explorer-ishidden").setAttribute("hidden",true);
- doc.getElementById("explorertree").setAttribute("hidden",false);
- doc.getElementById("explorer-buttons").setAttribute("hidden",false);
- sitesds.save();
-
-}
-
-
-/* Delete a site from the datasource. */
-function deleteSelectedSite() {
-
- // First find out which site should be deleted
- var tree = document.getElementById("explorertree");
- var index = tree.view.selection.currentIndex;
- var rdf = tree.view.getItemAtIndex(index).resource;
-
- // Grab the datasources
- var prefsdir = getProfileURL();
- var sitesds = new RDFDataSource(prefsdir + "/moztop_sites.rdf");
- sitesds.deleteRecursive(rdf.Value);
- sitesds.save()
- return;
-}
-
-
-/* Initialize the Explorer datasource */
-function initExplorer() {
- // var ds = RDF.GetDataSource(RDF_BASE + '@@contents.rdf');
- // var tree = document.getElementById('navigationtree');
- // tree.database.AddDataSource(ds);
- // tree.setAttribute("ref", "urn:explorer:data");
-
- var prefsdir = getProfileURL();
- sitesds = new RDFDataSource(prefsdir + "/moztop_sites.rdf");
- typesds = new RDFDataSource(prefsdir + "/moztop_types.rdf");
-
- var explorer=document.getElementById("explorertree");
- explorer.database.AddDataSource(sitesds.getRawDataSource());
- explorer.database.AddDataSource(typesds.getRawDataSource());
- explorer.builder.rebuild();
-}
-
-/* Reload Explorer datasource */
-function reloadContentData() {
- var tree = document.getElementById('navigationtree');
- var sources = tree.database.GetDataSources();
- sources.getNext(); // Hack, we should find this out in a better way.
- var ds = sources.getNext();
- ds = ds.QueryInterface(
- Components.interfaces.nsIRDFRemoteDataSource);
- ds.Refresh(false);
- /* We need this alert, so the RDF has time to load, otherwise the tree
- will be empty. We have find a better way of doing this.
-
- This happens because the DS is loaded asynchronically.
- */
- alert('Done reloading Content Tree.');
- tree.builder.rebuild();
-}
-
-
-/* Initialize the Explorer datasource */
-function initExplorer() {
-
- // var ds = RDF.GetDataSource(RDF_BASE + '@@contents.rdf');
- // var tree = document.getElementById('navigationtree');
- // tree.database.AddDataSource(ds);
- // tree.setAttribute("ref", "urn:explorer:data");
-
- var prefsdir = getProfileURL();
- var sitesds = new RDFDataSource(prefsdir + "/moztop_sites.rdf");
- var typesds = new RDFDataSource(prefsdir + "/moztop_types.rdf");
-
- // Are these datasource empty? If so, this means this is a first-startup
- var allres = sitesds.getAllResources();
- if (! allres.hasMoreElements()) {
- logmanager.addMessage('First time installation',
- 'Explorer.js, initExplorer',
- sitesds.serializeToString());
-
- // First create moztop_sites.rdf in the profile dir
- var dcref = "http://www.purl.org/dc/1.1#";
- var siteref = "http://www.zope.org/rdf/site#";
- var ncref ="http://home.netscape.com/NC-rdf#";
- var rootnode = sitesds.getNode("urn:moztop:sites");
- var subitems = sitesds.getNode("urn:moztop:sites:subitems");
- subitems.makeSeq();
- rootnode.addTarget("http://home.netscape.com/NC-rdf#subitems",subitems);
- sitesds.save();
-
- // Now create moztop_types.rdf in the profile dir
- var sitetypenode = typesds.getNode("urn:moztop:resourcetypes:site");
- sitetypenode.addTarget(dcref + "title","Site");
- sitetypenode.addTarget(siteref + "styleid", "site");
- typesds.save();
-
- }
-
- var explorer=document.getElementById("explorertree");
- explorer.database.AddDataSource(sitesds.getRawDataSource());
- explorer.database.AddDataSource(typesds.getRawDataSource());
- explorer.builder.rebuild();
-}
-
-/* Reload Explorer datasource */
-function reloadContentData() {
- var tree = document.getElementById('navigationtree');
- var sources = tree.database.GetDataSources();
- sources.getNext(); // Hack, we should find this out in a better way.
- var ds = sources.getNext();
- ds = ds.QueryInterface(
- Components.interfaces.nsIRDFRemoteDataSource);
- ds.Refresh(false);
- /* We need this alert, so the RDF has time to load, otherwise the tree
- will be empty. We have find a better way of doing this.
-
- This happens because the DS is loaded asynchronically.
- */
- alert('Done reloading Content Tree.');
- tree.builder.rebuild();
-}
-
-var p = new XMLHttpRequest();
-
-function serializeResponse(e)
-{
- alert('bla');
- if (p.responseXML) {
- //var s = new XMLSerializer();
- var d = p.responseXML;
- ///var str = s.serializeToString(d);
- }
-}
-
-function openResource() {
- p.onload = serializeResponse;
- p.open("GET", "http://localhost:8080/Plone/contents.rdf", false);
- p.send(null);
-
- //var localhostds = new RDFDataSource();
- //localhostds.loadFromString('')
-
- //var explorer=document.getElementById("explorertree");
- //explorer.database.AddDataSource(localhostds.getRawDataSource());
- //explorer.builder.rebuild();
-}
=== Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul 1.4 => 1.5 ===
--- Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul:1.4 Fri Feb 7 10:28:43 2003
+++ Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul Sat Feb 15 06:02:00 2003
@@ -1,17 +1,17 @@
<?xml version="1.0"?>
<overlay id="ExplorerOverlay"
- xmlns:z="http://www.zope.org/rdf/content#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="Explorer.js"/>
-<vbox id="explorer">
+<vbox id="explorer" flex="3">
<label flex="1" id="explorer-ishidden"
value="No sites defined in this Moztop" hidden="true"/>
<tree flex="1" hidden="false"
id="explorertree" ref="urn:moztop:sites"
- datasources="rdf:null" ondblclick="openResource();"
+ datasources="rdf:null"
+ ondblclick="sitesmanager.openSelectedResource();"
containment="http://home.netscape.com/NC-rdf#subitems">
<treecols>
<treecol id="ResourceNameColumn" label="Name" primary="true" flex="1"/>
@@ -30,18 +30,18 @@
</conditions>
<bindings>
- <binding subject="?subitem"
- predicate="http://www.purl.org/dc/1.1#title"
- object="?name" />
<binding subject="?subitem"
- predicate="http://www.zope.org/rdf/site#resourcetype"
+ predicate="http://www.zope.org/rdf#resourcetype"
object="?resourcetype" />
- <binding subject="?resourcetype"
- predicate="http://www.purl.org/dc/1.1#title"
- object="?resourcetypetitle"/>
- <binding subject="?resourcetype"
- predicate="http://www.zope.org/rdf/site#styleid"
- object="?styleid"/>
+ <binding subject="?subitem"
+ predicate="http://www.purl.org/dc/1.1#title"
+ object="?name" />
+ <binding subject="?resourcetype"
+ predicate="http://www.purl.org/dc/1.1#title"
+ object="?resourcetypetitle"/>
+ <binding subject="?resourcetype"
+ predicate="http://www.zope.org/rdf#styleid"
+ object="?styleid"/>
</bindings>
<action>
@@ -55,63 +55,9 @@
</treechildren>
</action>
</rule>
+
</template>
</tree>
-
-<box id="explorer-buttons" orient="vertical" hidden="false">
- <box orient="horizontal">
- <menulist id="field_obj_type" label="Type">
- <menupopup>
- <menuitem label="Folder" />
- <menuitem label="File" />
- <menuitem label="Image" />
- <menuitem label="ZPTPage" />
- <menuitem label="DTMLPage" />
- <menuitem label="SQLScript" />
- </menupopup>
- </menulist>
- <textbox id="field_obj_name" value="Name" flex="1" />
- </box>
- <box orient="horizontal">
-<button label="Delete Site" oncommand="deleteSelectedSite();" />
- <button command="explorer-add:command" label="Add" />
- <button command="explorer-delete:command" label="Delete" />
- <button command="explorer-rename:command" label="Rename" />
- <!--
- XXX lets replace those buttons by icons. They are too wide and boring.
-
- <button command="explorer-cut:command" label="Cut" />
- <button command="explorer-copy:command" label="Copy" />
- <button command="explorer-paste:command" label="Paste" />
- -->
- </box>
-</box>
-
-<commandset id="explorercommands">
- <command id="explorer-add:command"
- oncommand="window.openDialog('Inspector/AddDialog.xul',
- 'Add', 'chrome,modal,centerscreen,width=300,height=100');"/>
- <command id="explorer-delete:command" oncommand="deleteContentObject();"/>
- <command id="explorer-rename:command"
- oncommand="window.openDialog('Inspector/RenameDialog.xul',
- 'Rename', 'chrome,modal,centerscreen,width=300,height=100');"/>
- <command id="explorer-cut:command" oncommand="cutContentObject();"/>
- <command id="explorer-copy:command" oncommand="copyContentObject();"/>
- <command id="explorer-paste:command" oncommand="pasteContentObject();"/>
-</commandset>
-
-<popupset>
- <popup id="explorermenu">
- <menuitem label="Add" command="explorer-add:command" />
- <menuitem label="Delete" command="explorer-delete:command" />
- <menuitem label="Rename" command="explorer-rename:command" />
- <menuseparator/>
- <menuitem label="Cut" command="explorer-cut:command" />
- <menuitem label="Copy" command="explorer-copy:command" />
- <menuitem label="Paste" command="explorer-paste:command" />
- </popup>
-</popupset>
-
</vbox>
</overlay>