Skip to content
This repository
Browse code

MINOR Fixed controller contexts in LeftAndMain->SiteTreeAsUL() - need…

…s different context for edit links and determining "current page" (not applicable for CMSPagesController)
  • Loading branch information...
commit 473d3a66b8be0540bcf92fb1e879a1c1d90ae05d 1 parent 761bae3
Ingo Schommer authored April 17, 2012
25  admin/code/LeftAndMain.php
@@ -624,19 +624,22 @@ function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $num
624 624
 		}
625 625
 
626 626
 		// getChildrenAsUL is a flexible and complex way of traversing the tree
627  
-		$titleEval = '
628  
-			"<li id=\"record-$child->ID\" data-id=\"$child->ID\" data-ssclass=\"$child->ClassName\" class=\"" . $child->CMSTreeClasses($extraArg) . "\">" .
629  
-			"<ins class=\"jstree-icon\">&nbsp;</ins>" .
630  
-			"<a href=\"" . Controller::join_links($extraArg->Link("show"), $child->ID) . "\" title=\"' 
631  
-			. _t('LeftAndMain.PAGETYPE','Page type: ') 
632  
-			. '".$child->class."\" ><ins class=\"jstree-icon\">&nbsp;</ins><span class=\"text\">" . ($child->TreeTitle) . 
633  
-			"</span></a>"
634  
-		';
635  
-
  627
+		$controller = $this;
  628
+		$recordController = ($this->stat('tree_class') == 'SiteTree') ?  singleton('CMSPageEditController') : $this;
  629
+		$titleFn = function(&$child) use(&$controller, &$recordController) {
  630
+			$classes = $child->CMSTreeClasses();
  631
+			if($controller->isCurrentPage($child)) $classes .= " current";
  632
+			return "<li id=\"record-$child->ID\" data-id=\"$child->ID\" data-ssclass=\"$child->ClassName\" class=\"" . $classes . "\">" .
  633
+				"<ins class=\"jstree-icon\">&nbsp;</ins>" .
  634
+				"<a href=\"" . Controller::join_links($recordController->Link("show"), $child->ID) . "\" title=\"' 
  635
+				. _t('LeftAndMain.PAGETYPE','Page type: ') 
  636
+				. '".$child->class."\" ><ins class=\"jstree-icon\">&nbsp;</ins><span class=\"text\">" . ($child->TreeTitle) . 
  637
+				"</span></a>";
  638
+		};
636 639
 		$html = $obj->getChildrenAsUL(
637 640
 			"", 
638  
-			$titleEval,
639  
-			singleton('CMSPageEditController'), 
  641
+			$titleFn,
  642
+			singleton('CMSPagesController'), 
640 643
 			true, 
641 644
 			$childrenMethod,
642 645
 			$numChildrenMethod,
4  admin/css/screen.css
@@ -263,8 +263,8 @@ body.cms { overflow: hidden; }
263 263
 .cms-content-header h2 { padding: 8px 8px 0 8px; font-size: 14px; line-height: 24px; font-weight: bold; text-shadow: #bfcad2 1px 1px 0; margin: 0; display: table-cell; vertical-align: top; width: 100%; }
264 264
 .cms-content-header h2 .breadcrumbs-wrapper { display: table-row; }
265 265
 .cms-content-header h2 .breadcrumbs-wrapper .crumb { display: table-cell; line-height: 26px; }
266  
-.cms-content-header div { display: table-row; }
267  
-.cms-content-header div .cms_backlink { display: table-cell; vertical-align: middle; width: auto; }
  266
+.cms-content-header > div { display: table; }
  267
+.cms-content-header > div .cms_backlink { display: table-cell; vertical-align: middle; width: auto; }
268 268
 .cms-content-header .cms-content-header-tabs { display: table-cell; white-space: nowrap; width: 100%; }
269 269
 .cms-content-header .cms-content-header-tabs .ui-tabs-nav { float: right; margin-right: 32px; }
270 270
 .cms-content-header .cms-content-header-tabs .ui-tabs-nav li a { font-weight: bold; line-height: 16px; padding: 12px 20px 12px; }
15  admin/javascript/LeftAndMain.Content.js
@@ -222,21 +222,20 @@
222 222
 				var url = $(node).find('a:first').attr('href');
223 223
 				if(url && url != '#') {
224 224
 
  225
+					// Ensure URL is absolute (important for IE)
225 226
 					if($.path.isExternal($(node).find('a:first'))) url = url = $.path.makeUrlAbsolute(url, $('base').attr('href'));
226  
-					// Reload only edit form if it exists (side-by-side view of tree and edit view), otherwise reload whole panel
227  
-					if(container.find('.cms-edit-form').length) {
228  
-						container.entwine('ss').loadPanel(url, null, {selector: '.cms-edit-form', pjax: 'CurrentForm'});
229  
-					} else {
230  
-						container.entwine('ss').loadPanel(url);	
231  
-					}
  227
+					// Retain search parameters
  228
+					if(document.location.search) url = $.path.addSearchParams(url, document.location.search.replace(/^\?/, ''));
  229
+					// Load new page
  230
+					container.entwine('ss').loadPanel(url);	
232 231
 				} else {
233 232
 					self.removeForm();
234 233
 				}
235 234
 			});
236 235
 		}
237 236
 	});
238  
-	
239  
-	$('.cms-content.loading,.cms-edit-form.loading').entwine({
  237
+
  238
+	$('.cms-content.loading,.cms-edit-form.loading,.cms-content-fields.loading,.cms-content-view.loading').entwine({
240 239
 		onmatch: function() {
241 240
 			this.append('<div class="cms-content-loading-overlay ui-widget-overlay-light"></div><div class="cms-content-loading-spinner"></div>');
242 241
 		},
49  admin/javascript/LeftAndMain.js
@@ -610,6 +610,55 @@ jQuery.noConflict();
610 610
 			}
611 611
 		}
612 612
 	});
  613
+
  614
+	/**
  615
+	 * Lightweight wrapper around jQuery UI tabs.
  616
+	 * Ensures that anchor links are set properly,
  617
+	 * and any nested tabs are scrolled if they have
  618
+	 * their height explicitly set. This is important
  619
+	 * for forms inside the CMS layout.
  620
+	 */
  621
+	$('.cms-tabset').entwine({
  622
+		onmatch: function() {
  623
+			// Can't name redraw() as it clashes with other CMS entwine classes
  624
+			this.redrawTabs();
  625
+			this._super();
  626
+		},
  627
+		
  628
+		redrawTabs: function() {
  629
+			this.rewriteHashlinks();
  630
+
  631
+			var id = this.attr('id'), cookieId = 'ui-tabs-' + id, 
  632
+				selectedTab = this.find('ul:first .ui-state-selected');
  633
+
  634
+			// Fix for wrong cookie storage of deselected tabs
  635
+			if($.cookie && id && $.cookie(cookieId) == -1) $.cookie(cookieId, 0);
  636
+			this.tabs({
  637
+				cookie: ($.cookie && id) ? { expires: 30, path: '/', name: cookieId } : false,
  638
+				ajaxOptions: {
  639
+					// Overwrite ajax loading to use CMS logic instead
  640
+					beforeSend: function(xhr, settings) {
  641
+						$('.cms-container').entwine('ss').loadPanel(settings.url);
  642
+						return false;
  643
+					}
  644
+				},
  645
+				selected: (selectedTab.index() != -1) ? selectedTab.index() : 0
  646
+			});
  647
+		},
  648
+	
  649
+		/**
  650
+		 * Replace prefixes for all hashlinks in tabs.
  651
+		 * SSViewer rewrites them from "#Root_MyTab" to
  652
+		 * e.g. "/admin/#Root_MyTab" which makes them
  653
+		 * unusable for jQuery UI.
  654
+		 */
  655
+		rewriteHashlinks: function() {
  656
+			$(this).find('ul a').each(function() {
  657
+				var href = $(this).attr('href').replace(/.*(#.*)/, '$1');
  658
+				if(href) $(this).attr('href', href);
  659
+			});
  660
+		}
  661
+	});
613 662
 	
614 663
 }(jQuery));
615 664
 
6  admin/scss/_style.scss
@@ -126,9 +126,9 @@ body.cms {
126 126
 		}
127 127
 	}
128 128
 
129  
-	& div {
130  
-		display:table-row;
131  
-		& .cms_backlink {
  129
+	& > div {
  130
+		display:table;
  131
+		.cms_backlink {
132 132
 			display:table-cell;
133 133
 			vertical-align:middle;
134 134
 			width:auto;
1  admin/scss/_uitheme.scss
@@ -39,7 +39,6 @@
39 39
 		
40 40
 		.ui-tabs-panel {
41 41
 			background: transparent; // default it's white
42  
-			padding: 0;
43 42
 		}
44 43
 	}
45 44
 
5  filesystem/Folder.php
@@ -433,15 +433,12 @@ function ChildFolders() {
433 433
 	/**
434 434
 	 * @return String
435 435
 	 */
436  
-	function CMSTreeClasses($controller) {
  436
+	function CMSTreeClasses() {
437 437
 		$classes = sprintf('class-%s', $this->class);
438 438
 
439 439
 		if(!$this->canDelete())
440 440
 			$classes .= " nodelete";
441 441
 
442  
-		if($controller->isCurrentPage($this))
443  
-			$classes .= " current";
444  
-
445 442
 		if(!$this->canEdit()) 
446 443
 			$classes .= " disabled";
447 444
 			

0 notes on commit 473d3a6

Please sign in to comment.
Something went wrong with that request. Please try again.