diff --git a/code/CMSMain.php b/code/CMSMain.php index f6ce4d68..523c55d1 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -13,7 +13,7 @@ * @todo Create some base classes to contain the generic functionality that will be replicated. */ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionProvider { - + static $tree_class = "SiteTree"; static $subitem_class = "Member"; @@ -1202,6 +1202,18 @@ HTML; user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING); } } + + function duplicatewithchildren() { + if(($id = $this->urlParams['ID']) && is_numeric($id)) { + $page = DataObject::get_by_id("SiteTree", $id); + + $newPage = $page->duplicateWithChildren(); + + return $this->returnItemToUser($newPage); + } else { + user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING); + } + } /** * Switch the cms language and reload the site tree diff --git a/javascript/CMSMain_left.js b/javascript/CMSMain_left.js index e0c251cd..301cffd5 100755 --- a/javascript/CMSMain_left.js +++ b/javascript/CMSMain_left.js @@ -371,7 +371,11 @@ TreeContextMenu = { 'Edit this page' : function(treeNode) { treeNode.selectTreeNode(); }, - 'Duplicate this page' : function(treeNode) { + 'Duplicate page and children' : function(treeNode) { + // First save the page silently (without confirmation) and then duplicate the page. + autoSave(false, treeNode.duplicatePageWithChildren.bind(treeNode)); + }, + 'Duplicate just this page' : function(treeNode) { // First save the page silently (without confirmation) and then duplicate the page. autoSave(false, treeNode.duplicatePage.bind(treeNode)); }, diff --git a/javascript/LeftAndMain_left.js b/javascript/LeftAndMain_left.js index 82f508d4..2d5707de 100755 --- a/javascript/LeftAndMain_left.js +++ b/javascript/LeftAndMain_left.js @@ -203,6 +203,15 @@ TreeNodeAPI.prototype = { errorMessage('Error: ', response); } }); + }, + duplicatePageWithChildren: function() { + new Ajax.Request(baseHref() + 'admin/duplicatewithchildren/' + this.getIdx() + '?ajax=1', { + method : 'get', + onSuccess : Ajax.Evaluator, + onFailure : function(response) { + errorMessage('Error: ', response); + } + }); } }