Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT: Flyout menu to directly choose the pagetype one wants to…

… add.
  • Loading branch information...
commit a18b9bd85e78028bf458fc97c5d21e8aecee408d 1 parent 4524d1c
Wolf Vollprecht wolfv authored chillu committed
24 code/controllers/CMSMain.php
View
@@ -241,7 +241,7 @@ public function Breadcrumbs($unlinked = false) {
* @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 @@ public function SiteTreeHints() {
// 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 @@ public function SiteTreeHints() {
$def[$class]['defaultChild'] = $defaultChild;
$defaultParent = $obj->defaultParent();
+
$parent = SiteTree::get_by_link($defaultParent);
$id = $parent ? $parent->id : null;
@@ -368,7 +389,6 @@ public function PageTypes() {
}
$result->sort('AddAction');
-
return $result;
}
14 code/controllers/CMSPageAddController.php
View
@@ -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 @@ function AddForm() {
if($parentID = $this->request->getVar('ParentID')) {
$form->Fields()->dataFieldByName('ParentID')->setValue((int)$parentID);
}
-
+
return $form;
}
4 code/model/ErrorPage.php
View
@@ -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_exists('Translatable') ? Translatable::get_current_locale() : null
$response = new SS_HTTPResponse();
$response->setStatusCode($statusCode);
- $response->setBody(file_get_contents($cachedPath));
+ $response->setBody(file_get_contents($cachedPath));
return $response;
}
2  code/model/RedirectorPage.php
View
@@ -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.
62 javascript/CMSMain.Tree.js
View
@@ -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'));
- }
- },
- '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'));
+ '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);
+ }
+ };
}
- }
- }
+ );
+ 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));
2  templates/CMSPageEditController_Tools.ss
View
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.