ENHANCEMENT: Flyout menu to directly choose the pagetype one wants to add.

This commit is contained in:
Wolf Vollprecht 2012-03-19 02:05:09 +01:00 committed by Ingo Schommer
parent 4524d1c594
commit a18b9bd85e
6 changed files with 83 additions and 25 deletions

View File

@ -255,6 +255,26 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none' // SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
if($allowedChildren == null) $allowedChildren = array(); if($allowedChildren == null) $allowedChildren = array();
// Exclude SiteTree from possible Children
$possibleChildren = array_diff($allowedChildren, array("SiteTree"));
// Find i18n - names and build allowed children array
foreach($possibleChildren as $child) {
$instance = singleton($child);
if($instance instanceof HiddenClass) continue;
if(!$instance->canCreate()) continue;
// skip this type if it is restricted
if($instance->stat('need_permission') && !$this->can(singleton($class)->stat('need_permission'))) continue;
$title = $instance->i18n_singular_name();
$def[$class]['allowedChildren'][] = array("ssclass" => $child, "ssname" => $title);
}
$allowedChildren = array_keys(array_diff($classes, $allowedChildren)); $allowedChildren = array_keys(array_diff($classes, $allowedChildren));
if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren; if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren;
@ -264,6 +284,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$def[$class]['defaultChild'] = $defaultChild; $def[$class]['defaultChild'] = $defaultChild;
$defaultParent = $obj->defaultParent(); $defaultParent = $obj->defaultParent();
$parent = SiteTree::get_by_link($defaultParent); $parent = SiteTree::get_by_link($defaultParent);
$id = $parent ? $parent->id : null; $id = $parent ? $parent->id : null;
@ -368,7 +389,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} }
$result->sort('AddAction'); $result->sort('AddAction');
return $result; return $result;
} }

View File

@ -16,6 +16,18 @@ class CMSPageAddController extends CMSPageEditController {
* @return Form * @return Form
*/ */
function AddForm() { function AddForm() {
// If request send from rightclick-submenu, directly add Page
if(($pageType = $this->request->getVar('Type')) && ($parentID = $this->request->getVar('ParentID'))) {
$data = array(
"PageType" => (string)$pageType,
"ParentID" => $parentID,
"ParentModeField" => "child"
);
$this->doAdd($data, null);
return;
}
$record = $this->currentPage(); $record = $this->currentPage();
$pageTypes = array(); $pageTypes = array();

View File

@ -22,6 +22,8 @@ class ErrorPage extends Page {
"ShowInSearch" => 0 "ShowInSearch" => 0
); );
static $allowed_children = array();
static $description = 'Custom content for different error cases (e.g. "Page not found")'; static $description = 'Custom content for different error cases (e.g. "Page not found")';
protected static $static_filepath = ASSETS_PATH; protected static $static_filepath = ASSETS_PATH;

View File

@ -27,6 +27,8 @@ class RedirectorPage extends Page {
static $many_many = array( static $many_many = array(
); );
static $allowed_children = array();
/** /**
* Returns this page if the redirect is external, otherwise * Returns this page if the redirect is external, otherwise
* returns the target page. * returns the target page.

View File

@ -1,35 +1,57 @@
(function($) { (function($) {
$.entwine('ss', function($){ $.entwine('ss', function($){
$('.cms-tree').entwine({ $('.cms-tree').entwine({
getTreeConfig: function() { getTreeConfig: function() {
var config = this._super(); var config = this._super();
var hints = this.getHints();
config.plugins.push('contextmenu'); config.plugins.push('contextmenu');
config.contextmenu = { config.contextmenu = {
'items': { 'items': function(node) {
'create': null, // Build a list for allowed children as submenu entries
"rename": null, var ssclass = node.data('ssclass');
"remove": null, var id = node.data('id');
"ccp": null,
var allowedChildren = new Object;
$(hints[ssclass].allowedChildren).each(
function(key, val){
allowedChildren["allowedchildren-" + key ] = {
'label': '<span class="jstree-pageicon"></span>' + val.ssname,
'_class': 'class-' + val.ssclass,
'action': function(obj) {
// TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/add/?ParentID=' + id + '&Type=' + val.ssclass);
}
};
}
);
var menuitems =
{
'edit': { 'edit': {
'label': ss.i18n._t('Tree.EditPage'), 'label': ss.i18n._t('Tree.EditPage'),
'action': function(obj) { 'action': function(obj) {
// TODO Fix hardcoding of link // TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/edit/show/' + obj.data('id')); $('.cms-container').loadPanel('admin/page/add/show/' + obj.data('id'));
} }
}, }
'addsubpage': { };
// Test if there are any allowed Children and thus the possibility of adding some
if(allowedChildren.hasOwnProperty('allowedchildren-0')) {
menuitems['addsubpage'] = {
'label': ss.i18n._t('Tree.AddSubPage'), 'label': ss.i18n._t('Tree.AddSubPage'),
'action': function(obj) { 'action': function(obj) {
// TODO Fix hardcoding of link // TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/add/?ParentID=' + obj.data('id')); $('.cms-container').loadPanel('admin/page/add/?ParentID=' + obj.data('id'));
},
'submenu': allowedChildren
};
} }
} return menuitems;
} }
}; };
return config; return config;
} }
}); });
}); });
}(jQuery)); }(jQuery));

View File

@ -4,7 +4,7 @@
</div> </div>
<div class="cms-panel-content center"> <div class="cms-panel-content center">
<div class="cms-tree" data-url-tree="$Link(getsubtree)"> <div class="cms-tree" data-url-tree="$Link(getsubtree)" data-hints="$SiteTreeHints">
$SiteTreeAsUL $SiteTreeAsUL
</div> </div>
</div> </div>