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

@ -241,7 +241,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
* @return String Serialized JSON
*/
public function SiteTreeHints() {
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
$def['Root'] = array();
$def['Root']['disallowedParents'] = array();
@ -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'
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));
if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren;
@ -264,6 +284,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$def[$class]['defaultChild'] = $defaultChild;
$defaultParent = $obj->defaultParent();
$parent = SiteTree::get_by_link($defaultParent);
$id = $parent ? $parent->id : null;
@ -368,7 +389,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
$result->sort('AddAction');
return $result;
}

View File

@ -16,6 +16,18 @@ class CMSPageAddController extends CMSPageEditController {
* @return Form
*/
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();
$pageTypes = array();
@ -89,7 +101,7 @@ class CMSPageAddController extends CMSPageEditController {
if($parentID = $this->request->getVar('ParentID')) {
$form->Fields()->dataFieldByName('ParentID')->setValue((int)$parentID);
}
return $form;
}

View File

@ -22,6 +22,8 @@ class ErrorPage extends Page {
"ShowInSearch" => 0
);
static $allowed_children = array();
static $description = 'Custom content for different error cases (e.g. "Page not found")';
protected static $static_filepath = ASSETS_PATH;
@ -50,7 +52,7 @@ class ErrorPage extends Page {
$response = new SS_HTTPResponse();
$response->setStatusCode($statusCode);
$response->setBody(file_get_contents($cachedPath));
$response->setBody(file_get_contents($cachedPath));
return $response;
}

View File

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

View File

@ -1,35 +1,57 @@
(function($) {
$.entwine('ss', function($){
$('.cms-tree').entwine({
getTreeConfig: function() {
var config = this._super();
var hints = this.getHints();
config.plugins.push('contextmenu');
config.contextmenu = {
'items': {
'create': null,
"rename": null,
"remove": null,
"ccp": null,
'edit': {
'label': ss.i18n._t('Tree.EditPage'),
'action': function(obj) {
// TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/edit/show/' + obj.data('id'));
'items': function(node) {
// Build a list for allowed children as submenu entries
var ssclass = node.data('ssclass');
var id = node.data('id');
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);
}
};
}
},
'addsubpage': {
'label': ss.i18n._t('Tree.AddSubPage'),
'action': function(obj) {
// TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/add/?ParentID=' + obj.data('id'));
}
}
}
);
var menuitems =
{
'edit': {
'label': ss.i18n._t('Tree.EditPage'),
'action': function(obj) {
// TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/add/show/' + obj.data('id'));
}
}
};
// 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'),
'action': function(obj) {
// TODO Fix hardcoding of link
$('.cms-container').loadPanel('admin/page/add/?ParentID=' + obj.data('id'));
},
'submenu': allowedChildren
};
}
return menuitems;
}
};
return config;
}
});
});
}(jQuery));

View File

@ -4,7 +4,7 @@
</div>
<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
</div>
</div>