MINOR Fixed controller contexts in LeftAndMain->SiteTreeAsUL() - needs different context for edit links and determining "current page" (not applicable for CMSPagesController)

This commit is contained in:
Ingo Schommer 2012-04-17 22:29:45 +02:00
parent 761bae3418
commit 473d3a66b8
7 changed files with 76 additions and 29 deletions

View File

@ -624,19 +624,22 @@ class LeftAndMain extends Controller implements PermissionProvider {
}
// getChildrenAsUL is a flexible and complex way of traversing the tree
$titleEval = '
"<li id=\"record-$child->ID\" data-id=\"$child->ID\" data-ssclass=\"$child->ClassName\" class=\"" . $child->CMSTreeClasses($extraArg) . "\">" .
"<ins class=\"jstree-icon\">&nbsp;</ins>" .
"<a href=\"" . Controller::join_links($extraArg->Link("show"), $child->ID) . "\" title=\"'
. _t('LeftAndMain.PAGETYPE','Page type: ')
. '".$child->class."\" ><ins class=\"jstree-icon\">&nbsp;</ins><span class=\"text\">" . ($child->TreeTitle) .
"</span></a>"
';
$controller = $this;
$recordController = ($this->stat('tree_class') == 'SiteTree') ? singleton('CMSPageEditController') : $this;
$titleFn = function(&$child) use(&$controller, &$recordController) {
$classes = $child->CMSTreeClasses();
if($controller->isCurrentPage($child)) $classes .= " current";
return "<li id=\"record-$child->ID\" data-id=\"$child->ID\" data-ssclass=\"$child->ClassName\" class=\"" . $classes . "\">" .
"<ins class=\"jstree-icon\">&nbsp;</ins>" .
"<a href=\"" . Controller::join_links($recordController->Link("show"), $child->ID) . "\" title=\"'
. _t('LeftAndMain.PAGETYPE','Page type: ')
. '".$child->class."\" ><ins class=\"jstree-icon\">&nbsp;</ins><span class=\"text\">" . ($child->TreeTitle) .
"</span></a>";
};
$html = $obj->getChildrenAsUL(
"",
$titleEval,
singleton('CMSPageEditController'),
$titleFn,
singleton('CMSPagesController'),
true,
$childrenMethod,
$numChildrenMethod,

View File

@ -263,8 +263,8 @@ body.cms { overflow: hidden; }
.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%; }
.cms-content-header h2 .breadcrumbs-wrapper { display: table-row; }
.cms-content-header h2 .breadcrumbs-wrapper .crumb { display: table-cell; line-height: 26px; }
.cms-content-header div { display: table-row; }
.cms-content-header div .cms_backlink { display: table-cell; vertical-align: middle; width: auto; }
.cms-content-header > div { display: table; }
.cms-content-header > div .cms_backlink { display: table-cell; vertical-align: middle; width: auto; }
.cms-content-header .cms-content-header-tabs { display: table-cell; white-space: nowrap; width: 100%; }
.cms-content-header .cms-content-header-tabs .ui-tabs-nav { float: right; margin-right: 32px; }
.cms-content-header .cms-content-header-tabs .ui-tabs-nav li a { font-weight: bold; line-height: 16px; padding: 12px 20px 12px; }

View File

@ -222,13 +222,12 @@
var url = $(node).find('a:first').attr('href');
if(url && url != '#') {
// Ensure URL is absolute (important for IE)
if($.path.isExternal($(node).find('a:first'))) url = url = $.path.makeUrlAbsolute(url, $('base').attr('href'));
// Reload only edit form if it exists (side-by-side view of tree and edit view), otherwise reload whole panel
if(container.find('.cms-edit-form').length) {
container.entwine('ss').loadPanel(url, null, {selector: '.cms-edit-form', pjax: 'CurrentForm'});
} else {
container.entwine('ss').loadPanel(url);
}
// Retain search parameters
if(document.location.search) url = $.path.addSearchParams(url, document.location.search.replace(/^\?/, ''));
// Load new page
container.entwine('ss').loadPanel(url);
} else {
self.removeForm();
}
@ -236,7 +235,7 @@
}
});
$('.cms-content.loading,.cms-edit-form.loading').entwine({
$('.cms-content.loading,.cms-edit-form.loading,.cms-content-fields.loading,.cms-content-view.loading').entwine({
onmatch: function() {
this.append('<div class="cms-content-loading-overlay ui-widget-overlay-light"></div><div class="cms-content-loading-spinner"></div>');
},

View File

@ -611,6 +611,55 @@ jQuery.noConflict();
}
});
/**
* Lightweight wrapper around jQuery UI tabs.
* Ensures that anchor links are set properly,
* and any nested tabs are scrolled if they have
* their height explicitly set. This is important
* for forms inside the CMS layout.
*/
$('.cms-tabset').entwine({
onmatch: function() {
// Can't name redraw() as it clashes with other CMS entwine classes
this.redrawTabs();
this._super();
},
redrawTabs: function() {
this.rewriteHashlinks();
var id = this.attr('id'), cookieId = 'ui-tabs-' + id,
selectedTab = this.find('ul:first .ui-state-selected');
// Fix for wrong cookie storage of deselected tabs
if($.cookie && id && $.cookie(cookieId) == -1) $.cookie(cookieId, 0);
this.tabs({
cookie: ($.cookie && id) ? { expires: 30, path: '/', name: cookieId } : false,
ajaxOptions: {
// Overwrite ajax loading to use CMS logic instead
beforeSend: function(xhr, settings) {
$('.cms-container').entwine('ss').loadPanel(settings.url);
return false;
}
},
selected: (selectedTab.index() != -1) ? selectedTab.index() : 0
});
},
/**
* Replace prefixes for all hashlinks in tabs.
* SSViewer rewrites them from "#Root_MyTab" to
* e.g. "/admin/#Root_MyTab" which makes them
* unusable for jQuery UI.
*/
rewriteHashlinks: function() {
$(this).find('ul a').each(function() {
var href = $(this).attr('href').replace(/.*(#.*)/, '$1');
if(href) $(this).attr('href', href);
});
}
});
}(jQuery));
var statusMessage = function(text, type) {

View File

@ -126,9 +126,9 @@ body.cms {
}
}
& div {
display:table-row;
& .cms_backlink {
& > div {
display:table;
.cms_backlink {
display:table-cell;
vertical-align:middle;
width:auto;

View File

@ -39,7 +39,6 @@
.ui-tabs-panel {
background: transparent; // default it's white
padding: 0;
}
}

View File

@ -433,15 +433,12 @@ class Folder extends File {
/**
* @return String
*/
function CMSTreeClasses($controller) {
function CMSTreeClasses() {
$classes = sprintf('class-%s', $this->class);
if(!$this->canDelete())
$classes .= " nodelete";
if($controller->isCurrentPage($this))
$classes .= " current";
if(!$this->canEdit())
$classes .= " disabled";