Index: trunk/grails-app/taglib/AssetTreeTagLib.groovy
===================================================================
--- trunk/grails-app/taglib/AssetTreeTagLib.groovy	(revision 306)
+++ trunk/grails-app/taglib/AssetTreeTagLib.groovy	(revision 307)
@@ -24,4 +24,20 @@
         def sites = Site.list()
 
+        def visibleBranches = session.assetTreeVisibleBranches ? session.assetTreeVisibleBranches.tokenize(',') : []
+
+        def branchStyle = { branchId ->
+            if(visibleBranches.contains(branchId))
+                ''
+            else
+                'display:none;'
+        }
+
+        def branchImg = { branchId ->
+            if(visibleBranches.contains(branchId))
+                bulletTreeMinusImg()
+            else
+                bulletTreePlusImg()
+        }
+
         def divIdCount = 0
         def divId = ''
@@ -36,5 +52,5 @@
         /// @todo: use a loop for the subItem levels.
         mkp.div(class: 'overlayPane', id: 'assetTreePane', style: 'display:none;') {
-            div(class: 'tree') {
+            div(class: 'tree', id: 'assetTreeTable') {
                 table() {
                     tr() {
@@ -46,32 +62,32 @@
                                         if(site.sections) {
                                             a(href: toggleBranch(nextDivId()) ) {
-                                                img( src: bulletTreePlusImg(), id: divId+'img' )
+                                                img( src: branchImg(divId), id: divId+'img' )
                                             }
                                         }
                                         else
                                             img(src: dashImg())
-                                        a( href: siteShowLink(site.id) ) {
+                                        a( href: siteShowLink(site.id), onclick: hideAssetTreePane() ) {
                                             yieldUnescaped( site.encodeAsHTML() )
                                         }
-                                        a(href: sectionCreateLink(site.id)) {
+                                        a(href: sectionCreateLink(site.id), onclick: hideAssetTreePane()) {
                                             img(src: addImg(), alt: 'Add', title: 'Add Section')
                                         }
                                     }
                                     if(site.sections) {
-                                        div(id: divId, style: 'display:none;') {
+                                        div( id: divId, style: branchStyle(divId) ) {
                                             ul() {
                                                 for(section in site.sections.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) {
                                                     li() {
                                                         if(section.assets) {
-                                                            a(href: toggleBranch(nextDivId()) ) {
-                                                                img(src: bulletTreePlusImg(), id: divId+'img' )
+                                                            a( href: toggleBranch(nextDivId()) ) {
+                                                                img(src: branchImg(divId), id: divId+'img' )
                                                             }
                                                         }
                                                         else
                                                             img(src: dashImg())
-                                                        a( href: sectionShowLink(section.id) ) {
+                                                        a( href: sectionShowLink(section.id), onclick: hideAssetTreePane() ) {
                                                             yieldUnescaped( section.encodeAsHTML() )
                                                         }
-                                                        a(href: assetCreateLink(section.id)) {
+                                                        a(href: assetCreateLink(section.id), onclick: hideAssetTreePane()) {
                                                             img(src: addImg(), alt: 'Add', title: 'Add Asset')
                                                         }
@@ -79,22 +95,22 @@
 
                                                     if(section.assets) {
-                                                        div(id: divId, style: 'display:none;') {
+                                                        div( id: divId, style: branchStyle(divId) ) {
                                                             ul() {
                                                                 for(asset in section.assets.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) {
                                                                     li() {
                                                                         if(asset.assetSubItems) {
-                                                                            a(href: toggleBranch(nextDivId()) ) {
-                                                                                img(src: bulletTreePlusImg(), id: divId+'img' )
+                                                                            a( href: toggleBranch(nextDivId()) ) {
+                                                                                img(src: branchImg(divId), id: divId+'img' )
                                                                             }
                                                                         }
                                                                         else
                                                                             img(src: dashImg())
-                                                                        a( href: assetShowLink(asset.id) ) {
+                                                                        a( href: assetShowLink(asset.id), onclick: hideAssetTreePane() ) {
                                                                             yieldUnescaped( asset.encodeAsHTML() )
                                                                         }
-                                                                        a(href: assetSubItemCreateLink(asset.id)) {
+                                                                        a(href: assetSubItemCreateLink(asset.id), onclick: hideAssetTreePane()) {
                                                                             img(src: addImg(), alt: 'Add', title: 'Add Sub Item')
                                                                         }
-                                                                        a(href: assetCopyLink(asset.id)) {
+                                                                        a(href: assetCopyLink(asset.id), onclick: hideAssetTreePane()) {
                                                                             img(src: copyImg(), alt: 'Add', title: 'Copy Asset')
                                                                         }
@@ -102,19 +118,19 @@
 
                                                                     if(asset.assetSubItems) {
-                                                                        div(id: divId, style: 'display:none;') {
+                                                                        div( id: divId, style: branchStyle(divId) ) {
                                                                             ul() {
                                                                                 for(assetSubItemL1 in asset.assetSubItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) {
                                                                                     li() {
                                                                                         if(assetSubItemL1.subItems) {
-                                                                                            a(href: toggleBranch(nextDivId()) ) {
-                                                                                                img(src: bulletTreePlusImg(), id: divId+'img' )
+                                                                                            a( href: toggleBranch(nextDivId()) ) {
+                                                                                                img(src: branchImg(divId), id: divId+'img' )
                                                                                             }
                                                                                         }
                                                                                         else
                                                                                             img(src: dashImg())
-                                                                                        a( href: assetSubItemShowLink(assetSubItemL1.id) ) {
+                                                                                        a( href: assetSubItemShowLink(assetSubItemL1.id), onclick: hideAssetTreePane() ) {
                                                                                             yieldUnescaped( assetSubItemL1.encodeAsHTML() )
                                                                                         }
-                                                                                        a(href: assetSubItemCreateWithParentLink(assetSubItemL1.id)) {
+                                                                                        a(href: assetSubItemCreateWithParentLink(assetSubItemL1.id), onclick: hideAssetTreePane()) {
                                                                                             img(src: addImg(), alt: 'Add', title: 'Add Sub Item')
                                                                                         }
@@ -122,19 +138,19 @@
 
                                                                                     if(assetSubItemL1.subItems) {
-                                                                                        div(id: divId, style: 'display:none;') {
+                                                                                        div( id: divId, style: branchStyle(divId) ) {
                                                                                             ul() {
                                                                                                 for(assetSubItemL2 in assetSubItemL1.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) {
                                                                                                     li() {
                                                                                                         if(assetSubItemL2.subItems) {
-                                                                                                            a(href: toggleBranch(nextDivId()) ) {
-                                                                                                                img( src: bulletTreePlusImg(), id: divId+'img' )
+                                                                                                            a( href: toggleBranch(nextDivId()) ) {
+                                                                                                                img( src: branchImg(divId), id: divId+'img' )
                                                                                                             }
                                                                                                         }
                                                                                                         else
                                                                                                             img(src: dashImg())
-                                                                                                        a( href: assetSubItemShowLink(assetSubItemL2.id) ) {
+                                                                                                        a( href: assetSubItemShowLink(assetSubItemL2.id), onclick: hideAssetTreePane() ) {
                                                                                                             yieldUnescaped( assetSubItemL2.encodeAsHTML() )
                                                                                                         }
-                                                                                                        a(href: assetSubItemCreateWithParentLink(assetSubItemL2.id)) {
+                                                                                                        a(href: assetSubItemCreateWithParentLink(assetSubItemL2.id), onclick: hideAssetTreePane()) {
                                                                                                             img(src: addImg(), alt: 'Add', title: 'Add Sub Item')
                                                                                                         }
@@ -142,19 +158,19 @@
 
                                                                                                     if(assetSubItemL2.subItems) {
-                                                                                                        div(id: divId, style: 'display:none;') {
+                                                                                                        div( id: divId, style: branchStyle(divId) ) {
                                                                                                             ul() {
                                                                                                                 for(assetSubItemL3 in assetSubItemL2.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) {
                                                                                                                     li() {
                                                                                                                         if(assetSubItemL3.subItems) {
-                                                                                                                            a(href: toggleBranch(nextDivId()) ) {
-                                                                                                                                img( src: bulletTreePlusImg(), id: divId+'img' )
+                                                                                                                            a( href: toggleBranch(nextDivId()) ) {
+                                                                                                                                img( src: branchImg(divId), id: divId+'img' )
                                                                                                                             }
                                                                                                                         }
                                                                                                                         else
                                                                                                                             img(src: dashImg())
-                                                                                                                        a( href: assetSubItemShowLink(assetSubItemL3.id) ) {
+                                                                                                                        a( href: assetSubItemShowLink(assetSubItemL3.id), onclick: hideAssetTreePane() ) {
                                                                                                                             yieldUnescaped( assetSubItemL3.encodeAsHTML() )
                                                                                                                         }
-                                                                                                                        a(href: assetSubItemCreateWithParentLink(assetSubItemL3.id)) {
+                                                                                                                        a(href: assetSubItemCreateWithParentLink(assetSubItemL3.id), onclick: hideAssetTreePane()) {
                                                                                                                             img(src: addImg(), alt: 'Add', title: 'Add Sub Item')
                                                                                                                         }
@@ -162,19 +178,19 @@
 
                                                                                                                     if(assetSubItemL3.subItems) {
-                                                                                                                        div(id: divId, style: 'display:none;') {
+                                                                                                                        div( id: divId, style: branchStyle(divId) ) {
                                                                                                                             ul() {
                                                                                                                                 for(assetSubItemL4 in assetSubItemL3.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) {
                                                                                                                                     li() {
                 //                                                                                                                         if(assetSubItemL4.subItems) {
-                //                                                                                                                             a(href: toggleBranch(nextDivId()) ) {
-                //                                                                                                                                 img( src: bulletTreePlusImg(), id: divId+'img' )
+                //                                                                                                                             a( href: toggleBranch(nextDivId()) ) {
+                //                                                                                                                                 img( src: branchImg(divId), id: divId+'img' )
                 //                                                                                                                             }
                 //                                                                                                                         }
                 //                                                                                                                         else
                                                                                                                                         img(src: dashImg())
-                                                                                                                                        a( href: assetSubItemShowLink(assetSubItemL4.id) ) {
+                                                                                                                                        a( href: assetSubItemShowLink(assetSubItemL4.id), onclick: hideAssetTreePane() ) {
                                                                                                                                             yieldUnescaped( assetSubItemL4.encodeAsHTML() )
                                                                                                                                         }
-                //                                                                                                                         a(href: assetSubItemCreateWithParentLink(assetSubItemL4.id)) {
+                //                                                                                                                         a(href: assetSubItemCreateWithParentLink(assetSubItemL4.id), onclick: hideAssetTreePane()) {
                 //                                                                                                                             img(src: addImg(), alt: 'Add', title: 'Add Sub Item')
                 //                                                                                                                         }
@@ -220,5 +236,5 @@
             div( class: 'buttons') {
                 span(class: 'button') {
-                    input(type: 'button', value: 'Close', onclick: 'return hideElement("assetTreePane");')
+                    input( type: 'button', value: 'Close', onclick: hideAssetTreePane() )
                 }
             }
@@ -227,5 +243,4 @@
 
     } // assetTree
-
 
 
@@ -258,4 +273,9 @@
     }
 
+    def hideAssetTreePane() {
+        def saveUrl = createLink(controller: 'appCore', action: 'saveAssetTreeStatus').toString()
+        'return hideAssetTreePane(\"assetTreePane\", \"assetTreeTable' + '\", \"' + saveUrl + '\");'
+    }
+
     def toggleBranch(divId) {
         /// @todo: toggleBranch is in overlayPane.js and should be moved to tree.js
