diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index b90a45cc..9298b81d 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -757,6 +757,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'), ); $gridField->getConfig()->getComponentByType('GridFieldSortableHeader')->setFieldSorting(array('getTreeTitle' => 'Title')); + $gridField->getState()->ParentID = $parentID; if(!$params) { $fields = array_merge(array('listChildrenLink' => ''), $fields); @@ -1277,24 +1278,34 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $newPage = $page->duplicate(); // ParentID can be hard-set in the URL. This is useful for pages with multiple parents - if($_GET['parentID'] && is_numeric($_GET['parentID'])) { + if(isset($_GET['parentID']) && is_numeric($_GET['parentID'])) { $newPage->ParentID = $_GET['parentID']; $newPage->write(); } - // Reload form, data and actions might have changed - $form = $this->getEditForm($newPage->ID); + $this->response->addHeader( + 'X-Status', + rawurlencode(_t( + 'CMSMain.DUPLICATED', + "Duplicated '{title}' successfully", + array('title' => $newPage->Title) + )) + ); + $url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $newPage->ID); + $this->response->addHeader('X-ControllerURL', $url); + $this->request->addHeader('X-Pjax', 'Content'); + $this->response->addHeader('X-Pjax', 'Content'); - return $form->forTemplate(); + return $this->getResponseNegotiator()->respond($this->request); } else { - user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING); + return new SS_HTTPResponse("CMSMain::duplicate() Bad ID: '$id'", 400); } } public function duplicatewithchildren($request) { // Protect against CSRF on destructive action if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400); - + increase_time_limit_to(); if(($id = $this->urlParams['ID']) && is_numeric($id)) { $page = DataObject::get_by_id("SiteTree", $id); if($page && (!$page->canEdit() || !$page->canCreate())) return Security::permissionFailure($this); @@ -1302,36 +1313,25 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $newPage = $page->duplicateWithChildren(); - // Reload form, data and actions might have changed - $form = $this->getEditForm($newPage->ID); + $this->response->addHeader( + 'X-Status', + rawurlencode(_t( + 'CMSMain.DUPLICATEDWITHCHILDREN', + "Duplicated '{title}' and children successfully", + array('title' => $newPage->Title) + )) + ); + $url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $newPage->ID); + $this->response->addHeader('X-ControllerURL', $url); + $this->request->addHeader('X-Pjax', 'Content'); + $this->response->addHeader('X-Pjax', 'Content'); - return $form->forTemplate(); + return $this->getResponseNegotiator()->respond($this->request); } else { - user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING); + return new SS_HTTPResponse("CMSMain::duplicatewithchildren() Bad ID: '$id'", 400); } } - /** - * Return the version number of this application. - * Uses the subversion path information in /silverstripe_version - * (automacially replaced by build scripts). - * - * @return string - */ - public function CMSVersion() { - $cmsVersion = file_get_contents(CMS_PATH . '/silverstripe_version'); - if(!$cmsVersion) $cmsVersion = _t('LeftAndMain.VersionUnknown', 'Unknown'); - - $frameworkVersion = file_get_contents(FRAMEWORK_PATH . '/silverstripe_version'); - if(!$frameworkVersion) $frameworkVersion = _t('LeftAndMain.VersionUnknown', 'Unknown'); - - return sprintf( - "CMS: %s Framework: %s", - $cmsVersion, - $frameworkVersion - ); - } - public function providePermissions() { $title = _t("CMSPagesController.MENUTITLE", LeftAndMain::menu_title_for_class('CMSPagesController')); return array( diff --git a/code/controllers/RootURLController.php b/code/controllers/RootURLController.php index f59d3559..e13e419f 100644 --- a/code/controllers/RootURLController.php +++ b/code/controllers/RootURLController.php @@ -117,12 +117,10 @@ class RootURLController extends Controller { return $this->response; } - $request = new SS_HTTPRequest ( - $request->httpMethod(), self::get_homepage_link() . '/', $request->getVars(), $request->postVars() - ); + $request->setUrl(self::get_homepage_link() . '/'); $request->match('$URLSegment//$Action', true); - $controller = new ModelAsController(); + $result = $controller->handleRequest($request, $model); $this->popCurrent(); diff --git a/javascript/CMSMain.AddForm.js b/javascript/CMSMain.AddForm.js index c1a9511b..5d65067a 100644 --- a/javascript/CMSMain.AddForm.js +++ b/javascript/CMSMain.AddForm.js @@ -70,7 +70,8 @@ }); $(".cms-add-form #PageType li").entwine({ - onclick: function() { + onclick: function(e) { + e.preventDefault(); this.setSelected(true); }, setSelected: function(bool) { @@ -90,9 +91,18 @@ $(".cms-page-add-button").entwine({ onclick: function(e) { - var selected = $('.cms-tree').jstree('get_selected'), - parentId = selected ? $(selected[0]).data('id') : null, - data = {selector: this.data('targetPanel'),pjax: this.data('pjax')}, + var tree = $('.cms-tree'), list = $('.cms-list'), parentId = 0; + + // Choose parent ID either from tree or list view, depending which is visible + if(tree.is(':visible')) { + var selected = tree.jstree('get_selected'); + parentId = selected ? $(selected[0]).data('id') : null; + } else { + var state = list.find('input[name="Page[GridState]"]').val(); + if(state) parentId = parseInt(JSON.parse(state).ParentID, 10); + } + + var data = {selector: this.data('targetPanel'),pjax: this.data('pjax')}, url = parentId ? ss.i18n.sprintf(this.data('urlAddpage'), parentId) : this.attr('href'); $('.cms-container').loadPanel(url, null, data); diff --git a/javascript/CMSMain.Tree.js b/javascript/CMSMain.Tree.js index 285f82fc..cbd56f91 100644 --- a/javascript/CMSMain.Tree.js +++ b/javascript/CMSMain.Tree.js @@ -7,12 +7,12 @@ config.plugins.push('contextmenu'); config.contextmenu = { 'items': function(node) { - + var menuitems = { 'edit': { 'label': ss.i18n._t('Tree.EditPage'), 'action': function(obj) { - $('.cms-container').entwine('.ss').loadPanel(ss.i18n.sprintf( + $('.cms-container').entwine('.ss').loadPanel(ss.i18n.sprintf( self.data('urlEditpage'), obj.data('id') )); } @@ -34,7 +34,7 @@ disallowedClass = disallowedChildren[i]; if(allowedChildren[disallowedClass]) { delete allowedChildren[disallowedClass]; - } + } } } @@ -46,7 +46,7 @@ '_class': 'class-' + klass, 'action': function(obj) { $('.cms-container').entwine('.ss').loadPanel(ss.i18n.sprintf( - self.data('urlAddpage'), id, klass + self.data('urlAddpage'), id, klass )); } }; @@ -57,7 +57,28 @@ 'label': ss.i18n._t('Tree.AddSubPage'), 'submenu': menuAllowedChildren }; - } + } + + menuitems['duplicate'] = { + 'label': ss.i18n._t('Tree.Duplicate'), + 'submenu': [ + { + 'label': ss.i18n._t('Tree.ThisPageOnly'), + 'action': function(obj) { + $('.cms-container').entwine('.ss').loadPanel(ss.i18n.sprintf( + self.data('urlDuplicate'), obj.data('id') + )); + } + },{ + 'label': ss.i18n._t('Tree.ThisPageAndSubpages'), + 'action': function(obj) { + $('.cms-container').entwine('.ss').loadPanel(ss.i18n.sprintf( + self.data('urlDuplicatewithchildren'), obj.data('id') + )); + } + } + ] + }; return menuitems; } diff --git a/javascript/lang/en_US.js b/javascript/lang/en_US.js index 7e5952f5..667c15e6 100644 --- a/javascript/lang/en_US.js +++ b/javascript/lang/en_US.js @@ -29,7 +29,10 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') { 'AssetAdmin.ConfirmDelete': 'Do you really want to delete this folder and all contained files?', 'Folder.Name': 'Folder name', 'Tree.AddSubPage': 'Add new page here', + 'Tree.Duplicate': 'Duplicate', 'Tree.EditPage': 'Edit', + 'Tree.ThisPageOnly': 'This page only', + 'Tree.ThisPageAndSubpages': 'This page and subpages', 'CMSMain.ConfirmRestoreFromLive': "Do you really want to copy the published content to the draft site?", 'CMSMain.RollbackToVersion': "Do you really want to roll back to version #%s of this page?", 'URLSEGMENT.Edit': 'Edit', diff --git a/lang/en.yml b/lang/en.yml index 7c539828..acf244fe 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -80,6 +80,8 @@ en: DELETE: 'Delete draft' DELETEFP: Delete DESCREMOVED: 'and {count} descendants' + DUPLICATED: 'Duplicated ''{title}'' successfully' + DUPLICATEDWITHCHILDREN: 'Duplicated ''{title}'' and children successfully' EMAIL: Email EditTree: 'Edit Tree' ListFiltered: 'Filtered list.' diff --git a/lang/en_GB.yml b/lang/en_GB.yml index e95b794f..32f8d7fe 100644 --- a/lang/en_GB.yml +++ b/lang/en_GB.yml @@ -82,6 +82,8 @@ en_GB: DELETE: 'Delete from the draft site' DELETEFP: 'Delete from the published site' DESCREMOVED: 'and {count} descendants' + DUPLICATED: 'Duplicated ''{title}'' successfully' + DUPLICATEDWITHCHILDREN: 'Duplicated ''{title}'' and children successfully' EMAIL: Email EditTree: 'Edit Tree' ListFiltered: 'Filtered list.' diff --git a/templates/Includes/CMSMain_TreeView.ss b/templates/Includes/CMSMain_TreeView.ss index 081caafa..83cec419 100644 --- a/templates/Includes/CMSMain_TreeView.ss +++ b/templates/Includes/CMSMain_TreeView.ss @@ -19,7 +19,7 @@ $ExtraTreeTools <% end_if %> -
+
$SiteTreeAsUL