Permalink
Browse files

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
  • Loading branch information...
patbolo authored and chillu committed Mar 11, 2013
1 parent 37bb86a commit 2dd0e3f02efe64b595b4610c3a28ae9feaed58ed
Showing with 64 additions and 16 deletions.
  1. +30 −10 code/controllers/CMSMain.php
  2. +26 −5 javascript/CMSMain.Tree.js
  3. +3 −0 javascript/lang/en_US.js
  4. +2 −0 lang/en.yml
  5. +2 −0 lang/en_GB.yml
  6. +1 −1 templates/Includes/CMSMain_TreeView.ss
@@ -1277,37 +1277,57 @@ public function duplicate($request) {
$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);
if(!$page || !$page->ID) throw new SS_HTTPResponse_Exception("Bad record ID #$id", 404);
$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);
}
}
View
@@ -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;
}
View
@@ -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',
View
@@ -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.'
View
@@ -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.'
@@ -19,7 +19,7 @@ $ExtraTreeTools
</div>
<% 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')}&amp;ParentID=%s&amp;PageType=%s&amp;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')}&amp;ParentID=%s&amp;PageType=%s&amp;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
</div>
</div>

3 comments on commit 2dd0e3f

@yunusaslam

This comment has been minimized.

Show comment Hide comment
@yunusaslam

yunusaslam Apr 30, 2013

Duplicate this page only is creating a duplicate along with a blank page.. And Duplicate this page and sub pages also have the same problem. While duplicating sub pages, the sub page is not created under the new parent created but they are created under the parent from which we have chosen to duplicate..

Duplicate this page only is creating a duplicate along with a blank page.. And Duplicate this page and sub pages also have the same problem. While duplicating sub pages, the sub page is not created under the new parent created but they are created under the parent from which we have chosen to duplicate..

@chillu

This comment has been minimized.

Show comment Hide comment
@chillu

chillu Apr 30, 2013

Owner

See #689

Owner

chillu replied Apr 30, 2013

See #689

@yunusaslam

This comment has been minimized.

Show comment Hide comment
@yunusaslam

yunusaslam May 1, 2013

I referred #689 and implemented the duplicate functionality. But still i am having the issue of generating duplicate blank page. Also duplicate this page and sub pages do not work properly. While duplicating sub page the sub page is created as the child of the original page from which we are duplicating and not as the child of new duplicated parent page. When duplicating the page goes blank and the console have this error

SSERROR has this -
Error at framework/core/Object.php line 633: Uncaught Exception: Object->__call(): the method 'setvalue' does not exist on 'Image' (http://hf-dev.com/admin/pages/duplicatewithchildren/9?SecurityID=d47b89eb3b94c0506bca46a239483e300aaced97)

The console has this -

GET http://hf-dev.com/admin/pages/duplicatewithchild...urityID=03a6a8c0f018f8e6380761916b8565bfa8e080ce 200 OK 1.58s

Response : -
There has been an error

HTML :-
There has been an error

Parameters:-
SecurityID 03a6a8c0f018f8e6380761916b8565bfa8e080ce

Have attached few images below-
duplicate1
duplicate2
duplicate3

Please help me..!!!!!

I referred #689 and implemented the duplicate functionality. But still i am having the issue of generating duplicate blank page. Also duplicate this page and sub pages do not work properly. While duplicating sub page the sub page is created as the child of the original page from which we are duplicating and not as the child of new duplicated parent page. When duplicating the page goes blank and the console have this error

SSERROR has this -
Error at framework/core/Object.php line 633: Uncaught Exception: Object->__call(): the method 'setvalue' does not exist on 'Image' (http://hf-dev.com/admin/pages/duplicatewithchildren/9?SecurityID=d47b89eb3b94c0506bca46a239483e300aaced97)

The console has this -

GET http://hf-dev.com/admin/pages/duplicatewithchild...urityID=03a6a8c0f018f8e6380761916b8565bfa8e080ce 200 OK 1.58s

Response : -
There has been an error

HTML :-
There has been an error

Parameters:-
SecurityID 03a6a8c0f018f8e6380761916b8565bfa8e080ce

Have attached few images below-
duplicate1
duplicate2
duplicate3

Please help me..!!!!!

Please sign in to comment.