From d12d08e2f3553b06df6371535f971c9f193bd388 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Fri, 29 Jul 2011 19:38:01 +0200
Subject: [PATCH] some more changes for navigation subentries

---
 core/css/styles.css             |  1 +
 core/templates/layout.admin.php | 11 ++++++----
 core/templates/layout.user.php  | 15 ++++++++------
 lib/app.php                     | 36 ++++++++++++++++++++++++---------
 4 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/core/css/styles.css b/core/css/styles.css
index 99090b9171..00433979d2 100644
--- a/core/css/styles.css
+++ b/core/css/styles.css
@@ -89,6 +89,7 @@ input[type="search"] { font-size:1em; padding-left:2em; background:#eee url('../
 #plugins a:active { outline:0; }
 #plugins .subentry { background-color:#ddd; border-top:1px solid #aaa; border-bottom:1px solid #ccc; color:#000; outline:0; }
 #plugins .subentry.active { background-color:#bbb; border-top:1px solid #aaa; border-bottom:1px solid #ccc; color:#000; outline:0; }
+#plugins li.subentry a {padding-left:4em;}
 
 /* CONTENT ------------------------------------------------------------------ */
 #content { margin:3.5em 0 0 15.7em; }
diff --git a/core/templates/layout.admin.php b/core/templates/layout.admin.php
index 8077fd304f..3aac4c98ac 100644
--- a/core/templates/layout.admin.php
+++ b/core/templates/layout.admin.php
@@ -48,12 +48,15 @@
 					<?php endforeach; ?>
 					<?php if(isset($_['adminnavigation'])):?>
 						<?php foreach($_['adminnavigation'] as $entry):?>
-							<li><a style="background-image:url(<?php echo $entry['icon']; ?>)" href="<?php echo $entry['href']; ?>" title="" <?php if( $entry["active"] ): ?> class="active"<?php endif; ?>><?php echo $entry['name'] ?></a></li>
+							<li><a style="background-image:url(<?php echo $entry['icon']; ?>)" href="<?php echo $entry['href']; ?>" title="" <?php if( $entry["active"] ): ?> class="active"<?php endif; ?>><?php echo $entry['name'] ?></a>
 							<?php if( sizeof( $entry["subnavigation"] )): ?>
-								<?php foreach($entry["subnavigation"] as $subentry):?>
-									<li><a class="subentry<?php if( $subentry['active'] ): ?> active<?php endif; ?>" href="<?php echo $subentry['href']; ?>" title=""><?php echo $subentry['name'] ?></a></li>
-								<?php endforeach; ?>
+								<ul>
+									<?php foreach($entry["subnavigation"] as $subentry):?>
+										<li class="subentry"><a class="subentry<?php if( $subentry['active'] ): ?> active<?php endif; ?>" href="<?php echo $subentry['href']; ?>" title=""><?php echo $subentry['name'] ?></a></li>
+									<?php endforeach; ?>
+								</ul>
 							<?php endif; ?>
+							</li>
 						<?php endforeach; ?>
 					<?php endif; ?>
 				</ul>
diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php
index 4440ae28b2..8f073914a1 100644
--- a/core/templates/layout.user.php
+++ b/core/templates/layout.user.php
@@ -43,12 +43,15 @@
 			<div id="plugins">
 				<ul>
 					<?php foreach($_['navigation'] as $entry): ?>
-						<li><a style="background-image:url(<?php echo $entry['icon']; ?>)" href="<?php echo $entry['href']; ?>" title="" <?php if( $entry['active'] ): ?> class="active"<?php endif; ?>><?php echo $entry['name']; ?></a></li>
-						<?php if( sizeof( $entry["subnavigation"] )): ?>
-							<?php foreach($entry["subnavigation"] as $subentry):?>
-								<li><a style="background-image:url(<?php echo $subentry['icon']; ?>)" href="<?php echo $subentry['href']; ?>" title="" <?php if( $subentry['active'] ): ?>class="active"<?php endif; ?>><?php echo $subentry['name'] ?></a></li>
-							<?php endforeach; ?>
-						<?php endif; ?>
+						<li><a style="background-image:url(<?php echo $entry['icon']; ?>)" href="<?php echo $entry['href']; ?>" title="" <?php if( $entry['active'] ): ?> class="active"<?php endif; ?>><?php echo $entry['name']; ?></a>
+							<?php if( sizeof( $entry["subnavigation"] )): ?>
+								<ul>
+									<?php foreach($entry["subnavigation"] as $subentry):?>
+										<li class="subentry"><a style="background-image:url(<?php echo $subentry['icon']; ?>)" href="<?php echo $subentry['href']; ?>" title="" <?php if( $subentry['active'] ): ?>class="active"<?php endif; ?>><?php echo $subentry['name'] ?></a></li>
+									<?php endforeach; ?>
+								</ul>
+							<?php endif; ?>
+						</li>
 					<?php endforeach; ?>
 				</ul>
 			</div>
diff --git a/lib/app.php b/lib/app.php
index bccd0c665f..b6c2512e79 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -158,7 +158,10 @@ class OC_APP{
 	 *     the navigation. Lower values come first.
 	 */
 	public static function addNavigationEntry( $data ){
-		// TODO: write function
+		$data['active']=false;
+		if(!isset($data['icon'])){
+			$data['icon']='';
+		}
 		OC_APP::$navigation[] = $data;
 		return true;
 	}
@@ -184,6 +187,10 @@ class OC_APP{
 	 *     the navigation. Lower values come first.
 	 */
 	public static function addNavigationSubEntry( $parent, $data ){
+		$data['active']=false;
+		if(!isset($data['icon'])){
+			$data['icon']='';
+		}
 		if( !array_key_exists( $parent, self::$subnavigation )){
 			self::$subnavigation[$parent] = array();
 		}
@@ -318,16 +325,25 @@ class OC_APP{
 					$naventry['subnavigation'] = $subNav;
 				}
 			}
-		}
-
-		// Mark subentry as active
-		foreach( $list as &$naventry ){
-			if( $naventry['active'] ){
-				foreach( $naventry['subnavigation'] as &$subnaventry ){
-					$subnaventry['active'] = $subnaventry['id'] == self::$activeapp? true : false;
-				} unset( $subnaventry );
+		}else{
+			foreach(self::$subnavigation as $parent=>$entries){
+				$activeParent=false;
+				foreach($entries as &$subNav){
+					$subNav['active']=$subNav['id'] == self::$activeapp;
+					if($subNav['active']){
+						$activeParent=true;
+					}
+				}
+				if($activeParent){
+					foreach( $list as &$naventry ){
+						if( $naventry['id'] == $parent ){
+							$naventry['active'] = true;
+							$naventry['subnavigation'] = $entries;
+						}
+					}
+				}
 			}
-		} unset( $naventry );
+		}
 
 		return $list;
 	}
-- 
GitLab