[Zope-CVS] CVS: Packages/Moztop/moztop/content/toolbar - toolbar.js:1.1 toolbaroverlay.xul:1.1

Stephan Richter srichter@cbu.edu
Thu, 20 Mar 2003 11:38:31 -0500


Update of /cvs-repository/Packages/Moztop/moztop/content/toolbar
In directory cvs.zope.org:/tmp/cvs-serv7755/toolbar

Added Files:
	toolbar.js toolbaroverlay.xul 
Log Message:
Created new toolbar directory and moved toolbar code to it.

Note that we try to match the directory hierarchy to the UI layout now.


=== Added File Packages/Moztop/moztop/content/toolbar/toolbar.js ===
/*****************************************************************************
*
* Copyright (c) 2002, 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
What a mess! All these functions do not belong here.

$Id: toolbar.js,v 1.1 2003/03/20 16:38:30 srichter Exp $

******************************************************************************/

/* Remove the Welcome tab. */
function _removeWelcome() {
    var tabs = document.getElementById("active-contents-tabs");
    var tabpanels = document.getElementById("active-contents-tabpanels");
    if (tabs.firstChild.label == "Welcome") {
	tabs.removeChild(tabs.firstChild);
	tabpanels.removeChild(tabpanels.firstChild);
    }
}

/* Open selected content object. */
function openContentObject() {
    var tree = document.getElementById("navigationtree");
    var tabs = document.getElementById("active-contents-tabs");
    var tabpanels = document.getElementById("active-contents-tabpanels");
    index = tree.view.selection.currentIndex;
    rdf = tree.view.getItemAtIndex(index).resource;

    var ds = new RDFDataSource();
    var sources = tree.database.GetDataSources();
    sources.getNext()
    ds.Init(sources.getNext().QueryInterface(
		Components.interfaces.nsIRDFDataSource));
    
    /* Get type of object */
    node = ds.getNode(rdf.Value);
    node = node.getTarget("http://home.netscape.com/NC-rdf#resourcetype");
    var type = node.getValue();
    type = type.split('#')[1];

    var parent = rdf.Value.replace('urn:navigation:data', '');
    while (parent.indexOf(":") > -1)
	parent = parent.replace(":", "/");

    // Unselect selected item; we have a new one
    tabs.selectedItem.setAttribute('selected', false);

    if (document.getElementById(parent+"-tab") != null) {
	document.getElementById(parent+"-tab").setAttribute(
	    'selected', true);
	tabpanels.selectedPanel = document.getElementById(parent+"-tabpanel");
	return;
    }

    var newtab = document.createElement("tab");
    newtab.setAttribute('id', parent+'-tab');
    newtab.setAttribute('label', parent);
    newtab.setAttribute('selected', true);
    tabs.appendChild(newtab);

    var newtabpanel = document.createElement("tabpanel");
    newtabpanel.setAttribute('id', parent+'-tabpanel');
    tabpanels.appendChild(newtabpanel);

    createViewTabs(type, parent, newtabpanel);
    _removeWelcome();
    tabpanels.selectedPanel = newtabpanel;
}


/* Create all view tabs for a content object of the specified type */
function createViewTabs(type, name, parent_tabpanel) {

    TypeRegistry = {"Folder": 
		    ["Content", "Preview", "MetaData", "Security"],
		    "File":
		    ["Upload", "Preview", "MetaData", "Security"],
		    "Image":
		    ["Upload", "Preview", "MetaData", "Security"],
		    "ZPTPage":
		    ["Content", "Preview", "MetaData", "Security"],
		    "DTMLPage":
		    ["Content", "Preview", "MetaData", "Security"],
		    "SQLScript":
		    ["Source", "Test", "Cache", "MetaData", "Security"]
    }

    var tabbox = document.createElement("tabbox");
    tabbox.setAttribute('id', name+'-tabbox');
    tabbox.setAttribute('orient', 'vertical');
    tabbox.setAttribute('flex', '1');
    parent_tabpanel.appendChild(tabbox);
    
    var tabs = document.createElement("tabs");
    tabs.setAttribute('orient', 'horizontal');
    tabbox.appendChild(tabs);

    var tabpanels = document.createElement("tabpanels");
    tabpanels.setAttribute('flex', '100%');
    tabbox.appendChild(tabpanels);
     
    for (var index = 0; index < 4; index++) {
	var tab = document.createElement("tab");
	tab.setAttribute("label", TypeRegistry[type][index]);
	tabs.appendChild(tab);

	var tabpanel = document.createElement("tabpanel");
	tabpanels.appendChild(tabpanel);

	var iframe = document.createElement("iframe");
	iframe.setAttribute('src', 
	   'chrome://moztop/content/ContentObjects/' + type + '/' +
           TypeRegistry[type][index] + '.xul');
	iframe.setAttribute('flex', '1');
	tabpanel.appendChild(iframe);
    }

    tabs.firstChild.setAttribute("selected", true);
}

function removeActiveContentTab() {
    var tabs = document.getElementById("active-contents-tabs");
    var tabpanels = document.getElementById("active-contents-tabpanels");
    tabs.removeChild(tabs.selectedItem);
    tabpanels.removeChild(tabpanels.selectedPanel);
    tabs.firstChild.setAttribute("selected", "true");
    tabelpanels.selectedPanel = tabelpanels.firstChild;
}


=== Added File Packages/Moztop/moztop/content/toolbar/toolbaroverlay.xul ===
<?xml version="1.0"?>

<overlay id="ToolBarOverlay"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script src="chrome://moztop/content/toolbar/toolbar.js"/>

  <toolbar id="moztop-toolbar">
    <button label="New Site" command="menu-file-new-site:command" />
    <button oncommand="sitesmanager.deleteResource();" 
	    label="Delete" tooltiptext="Delete selected resource"/>
    <button oncommand="sitesmanager.connectSelectedSite();" 
	    label="Connect" tooltiptext="Connect or reload selected site"/>
    <button oncommand="removeActiveContentTab();" 
            label="Remove Tab" />
    <button oncommand="sitesmanager.PUT();" 
            label="PUT" />
    <button oncommand="sitesmanager.DELETE('http://localhost:8000/somefolder',
                                           'foo');" 
            label="Delete Foo" />
    <spring flex="100%" />
    <image src="chrome://moztop/skin/moztop.png" height="50" />

  </toolbar>

</overlay>