diff --git a/suite/common/sidebar/customize.js b/suite/common/sidebar/customize.js index 6c35ac6cd50..026a5d187ad 100644 --- a/suite/common/sidebar/customize.js +++ b/suite/common/sidebar/customize.js @@ -27,21 +27,22 @@ RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService); var NC = "http://home.netscape.com/NC-rdf#"; var sidebar = new Object; +var original_panels = new Array(); function debug(msg) { - //dump(msg); + //dump(msg+"\n"); } function Init() { - sidebar.db = window.arguments[0]; - sidebar.resource = window.arguments[1]; - debug("sidebar.db = " + sidebar.db + "\n"); - debug("sidebar.resource = " + sidebar.resource + "\n"); + sidebar.datasource_uri = window.arguments[0]; + sidebar.resource = window.arguments[1]; + debug("sidebar.datasource_uri = " + sidebar.datasource_uri); + debug("sidebar.resource = " + sidebar.resource); // This will load the datasource, if it isn't already. - sidebar.datasource = RDF.GetDataSource(sidebar.db); + sidebar.datasource = RDF.GetDataSource(sidebar.datasource_uri); // Add the necessary datasources to the select list var select_list = document.getElementById('selected-panels'); @@ -50,12 +51,21 @@ function Init() // Root the customize dialog at the correct place. select_list.setAttribute('ref', sidebar.resource); + saveInitialPanels(); enableButtons(); } +function saveInitialPanels() +{ + var root = document.getElementById('selected-panels-root'); + for (var node = root.firstChild; node != null; node = node.nextSibling) { + original_panels[original_panels.length] = node.getAttribute('id'); + } +} + function addOption(registry, service, selectIt) { - dump("Adding "+service.Value+"\n"); + debug("Adding "+service.Value); var option_title = getAttr(registry, service, 'title'); var option_customize = getAttr(registry, service, 'customize'); var option_content = getAttr(registry, service, 'content'); @@ -87,7 +97,7 @@ function addOption(registry, service, selectIt) treeroot.appendChild(item); if (selectIt) { - dump("Selecting new item\n"); + debug("Selecting new item"); tree.selectItem(item) } } @@ -126,6 +136,7 @@ function moveUp() { } } enableButtons(); + enableSave(); } function moveDown() { @@ -143,6 +154,7 @@ function moveDown() { } } enableButtons(); + enableSave(); } function enableButtons() { @@ -153,6 +165,7 @@ function enableButtons() { var remove = document.getElementById('remove-button'); var numSelected = tree.selectedItems.length; + var noneSelected, isFirst, isLast, selectedNode if (numSelected > 0) { @@ -233,10 +246,7 @@ function RemovePanel() enableSave(); } -// Note that there is a bug with resource: URLs right now. -var FileURL = "file:////u/slamm/tt/sidebar-browser.rdf"; -// var the "NC" namespace. Used to construct resources function Save() { // Iterate through the 'selected-panels' tree to collect the panels @@ -251,20 +261,20 @@ function Save() // Now remove all the current panels from the datasource. - // Create a "container" wrapper around the "NC:BrowserSidebarRoot" + // Create a "container" wrapper around the "urn:sidebar:ccurent-panel-list" // object. This makes it easier to manipulate the RDF:Seq correctly. var container = Components.classes["component://netscape/rdf/container"].createInstance(); container = container.QueryInterface(Components.interfaces.nsIRDFContainer); container.Init(sidebar.datasource, RDF.GetResource(sidebar.resource)); for (var ii = container.GetCount(); ii >= 1; --ii) { - dump('removing panel ' + ii + '\n'); + debug('removing panel ' + ii); container.RemoveElementAt(ii, true); } // Now iterate through the panels, and re-add them to the datasource for (var ii = 0; ii < panels.length; ++ii) { - debug('adding ' + panels[ii] + '\n'); + debug('adding ' + panels[ii]); container.AppendElement(RDF.GetResource(panels[ii])); } @@ -274,20 +284,38 @@ function Save() window.close(); } -function otherPanelSelected() +function otherPanelSelected(event, target) { - var add_button = document.getElementById('add_button'); - var preview_button = document.getElementById('preview_button'); - var other_panels = document.getElementById('other-panels'); + if (target.getAttribute('container') == 'true') { + if (target.getAttribute('open') == 'true') { + target.removeAttribute('open'); + } else { + target.setAttribute('open','true'); + } + return; + } - if (other_panels.selectedItems.length > 0) { - add_button.setAttribute('disabled',''); - preview_button.setAttribute('disabled',''); - } - else { - add_button.setAttribute('disabled','true'); - preview_button.setAttribute('disabled','true'); - } + var add_button = document.getElementById('add_button'); + var preview_button = document.getElementById('preview_button'); + var other_panels = document.getElementById('other-panels'); + + var num_selected = 0; + // Only count non-folders as selected for button enabling + for (var ii=0; ii 0) { + add_button.setAttribute('disabled',''); + preview_button.setAttribute('disabled',''); + } + else { + add_button.setAttribute('disabled','true'); + preview_button.setAttribute('disabled','true'); + } } function AddPanel() @@ -299,6 +327,10 @@ function AddPanel() for (var nodeIndex=0; nodeIndex 0) { @@ -233,10 +246,7 @@ function RemovePanel() enableSave(); } -// Note that there is a bug with resource: URLs right now. -var FileURL = "file:////u/slamm/tt/sidebar-browser.rdf"; -// var the "NC" namespace. Used to construct resources function Save() { // Iterate through the 'selected-panels' tree to collect the panels @@ -251,20 +261,20 @@ function Save() // Now remove all the current panels from the datasource. - // Create a "container" wrapper around the "NC:BrowserSidebarRoot" + // Create a "container" wrapper around the "urn:sidebar:ccurent-panel-list" // object. This makes it easier to manipulate the RDF:Seq correctly. var container = Components.classes["component://netscape/rdf/container"].createInstance(); container = container.QueryInterface(Components.interfaces.nsIRDFContainer); container.Init(sidebar.datasource, RDF.GetResource(sidebar.resource)); for (var ii = container.GetCount(); ii >= 1; --ii) { - dump('removing panel ' + ii + '\n'); + debug('removing panel ' + ii); container.RemoveElementAt(ii, true); } // Now iterate through the panels, and re-add them to the datasource for (var ii = 0; ii < panels.length; ++ii) { - debug('adding ' + panels[ii] + '\n'); + debug('adding ' + panels[ii]); container.AppendElement(RDF.GetResource(panels[ii])); } @@ -274,20 +284,38 @@ function Save() window.close(); } -function otherPanelSelected() +function otherPanelSelected(event, target) { - var add_button = document.getElementById('add_button'); - var preview_button = document.getElementById('preview_button'); - var other_panels = document.getElementById('other-panels'); + if (target.getAttribute('container') == 'true') { + if (target.getAttribute('open') == 'true') { + target.removeAttribute('open'); + } else { + target.setAttribute('open','true'); + } + return; + } - if (other_panels.selectedItems.length > 0) { - add_button.setAttribute('disabled',''); - preview_button.setAttribute('disabled',''); - } - else { - add_button.setAttribute('disabled','true'); - preview_button.setAttribute('disabled','true'); - } + var add_button = document.getElementById('add_button'); + var preview_button = document.getElementById('preview_button'); + var other_panels = document.getElementById('other-panels'); + + var num_selected = 0; + // Only count non-folders as selected for button enabling + for (var ii=0; ii 0) { + add_button.setAttribute('disabled',''); + preview_button.setAttribute('disabled',''); + } + else { + add_button.setAttribute('disabled','true'); + preview_button.setAttribute('disabled','true'); + } } function AddPanel() @@ -299,6 +327,10 @@ function AddPanel() for (var nodeIndex=0; nodeIndex