mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
NEW Restored duplicate and duplicated with children functionality, as in 2.4 See ticket #7602
Conflicts: javascript/CMSMain.Tree.js templates/Includes/CMSMain_TreeView.ss
This commit is contained in:
parent
37bb86a927
commit
2dd0e3f02e
@ -1277,24 +1277,34 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
$newPage = $page->duplicate();
|
$newPage = $page->duplicate();
|
||||||
|
|
||||||
// ParentID can be hard-set in the URL. This is useful for pages with multiple parents
|
// 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->ParentID = $_GET['parentID'];
|
||||||
$newPage->write();
|
$newPage->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload form, data and actions might have changed
|
$this->response->addHeader(
|
||||||
$form = $this->getEditForm($newPage->ID);
|
'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 {
|
} 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) {
|
public function duplicatewithchildren($request) {
|
||||||
// Protect against CSRF on destructive action
|
// Protect against CSRF on destructive action
|
||||||
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
|
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
|
||||||
|
increase_time_limit_to();
|
||||||
if(($id = $this->urlParams['ID']) && is_numeric($id)) {
|
if(($id = $this->urlParams['ID']) && is_numeric($id)) {
|
||||||
$page = DataObject::get_by_id("SiteTree", $id);
|
$page = DataObject::get_by_id("SiteTree", $id);
|
||||||
if($page && (!$page->canEdit() || !$page->canCreate())) return Security::permissionFailure($this);
|
if($page && (!$page->canEdit() || !$page->canCreate())) return Security::permissionFailure($this);
|
||||||
@ -1302,12 +1312,22 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
|
|
||||||
$newPage = $page->duplicateWithChildren();
|
$newPage = $page->duplicateWithChildren();
|
||||||
|
|
||||||
// Reload form, data and actions might have changed
|
$this->response->addHeader(
|
||||||
$form = $this->getEditForm($newPage->ID);
|
'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 {
|
} else {
|
||||||
user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING);
|
return new SS_HTTPResponse("CMSMain::duplicatewithchildren() Bad ID: '$id'", 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,27 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return menuitems;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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?',
|
'AssetAdmin.ConfirmDelete': 'Do you really want to delete this folder and all contained files?',
|
||||||
'Folder.Name': 'Folder name',
|
'Folder.Name': 'Folder name',
|
||||||
'Tree.AddSubPage': 'Add new page here',
|
'Tree.AddSubPage': 'Add new page here',
|
||||||
|
'Tree.Duplicate': 'Duplicate',
|
||||||
'Tree.EditPage': 'Edit',
|
'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.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?",
|
'CMSMain.RollbackToVersion': "Do you really want to roll back to version #%s of this page?",
|
||||||
'URLSEGMENT.Edit': 'Edit',
|
'URLSEGMENT.Edit': 'Edit',
|
||||||
|
@ -80,6 +80,8 @@ en:
|
|||||||
DELETE: 'Delete draft'
|
DELETE: 'Delete draft'
|
||||||
DELETEFP: Delete
|
DELETEFP: Delete
|
||||||
DESCREMOVED: 'and {count} descendants'
|
DESCREMOVED: 'and {count} descendants'
|
||||||
|
DUPLICATED: 'Duplicated ''{title}'' successfully'
|
||||||
|
DUPLICATEDWITHCHILDREN: 'Duplicated ''{title}'' and children successfully'
|
||||||
EMAIL: Email
|
EMAIL: Email
|
||||||
EditTree: 'Edit Tree'
|
EditTree: 'Edit Tree'
|
||||||
ListFiltered: 'Filtered list.'
|
ListFiltered: 'Filtered list.'
|
||||||
|
@ -82,6 +82,8 @@ en_GB:
|
|||||||
DELETE: 'Delete from the draft site'
|
DELETE: 'Delete from the draft site'
|
||||||
DELETEFP: 'Delete from the published site'
|
DELETEFP: 'Delete from the published site'
|
||||||
DESCREMOVED: 'and {count} descendants'
|
DESCREMOVED: 'and {count} descendants'
|
||||||
|
DUPLICATED: 'Duplicated ''{title}'' successfully'
|
||||||
|
DUPLICATEDWITHCHILDREN: 'Duplicated ''{title}'' and children successfully'
|
||||||
EMAIL: Email
|
EMAIL: Email
|
||||||
EditTree: 'Edit Tree'
|
EditTree: 'Edit Tree'
|
||||||
ListFiltered: 'Filtered list.'
|
ListFiltered: 'Filtered list.'
|
||||||
|
@ -19,7 +19,7 @@ $ExtraTreeTools
|
|||||||
</div>
|
</div>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
|
||||||
<div class="cms-tree" data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)" data-url-updatetreenodes="$Link(updatetreenodes)" data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1')}&ParentID=%s&PageType=%s&SecurityID=$SecurityID" data-url-editpage="$LinkPageEdit('%s')" data-hints="$SiteTreeHints.XML">
|
<div class="cms-tree" data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)" data-url-updatetreenodes="$Link(updatetreenodes)" data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1')}&ParentID=%s&PageType=%s&SecurityID=$SecurityID" data-url-editpage="$LinkPageEdit('%s')" data-url-duplicate="{$Link('duplicate/%s')}?SecurityID=$SecurityID" data-url-duplicatewithchildren="{$Link('duplicatewithchildren/%s')}?SecurityID=$SecurityID" data-hints="$SiteTreeHints.XML">
|
||||||
$SiteTreeAsUL
|
$SiteTreeAsUL
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user