From 2414eb30ccb7a5f52d58d527d6db395c5fd2cb54 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 1 May 2009 03:02:48 +0000 Subject: [PATCH] ENHANCEMENT: Added page location fields in the behaviour tab, as an alternative to drag and drop git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@75815 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/LeftAndMain.php | 5 +++++ javascript/CMSMain_right.js | 30 +++++++++++++++++++++++++----- javascript/LeftAndMain_left.js | 9 +++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 293d9f58..626c7d00 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -593,6 +593,7 @@ JS; // HACK: This should be turned into something more general $originalClass = $record->ClassName; $originalStatus = $record->Status; + $originalParentID = $record->ParentID; $record->HasBrokenLink = 0; $record->HasBrokenFile = 0; @@ -659,6 +660,10 @@ JS; if($originalStatus != $record->Status) { $message .= sprintf(_t('LeftAndMain.STATUSTO'," Status changed to '%s'"),$record->Status); } + + if($originalParentID != $record->ParentID) { + FormResponse::add("if(\$('sitetree').setNodeParentID) \$('sitetree').setNodeParentID($record->ID, $record->ParentID);"); + } $record->write(); diff --git a/javascript/CMSMain_right.js b/javascript/CMSMain_right.js index b26e2e2c..de246c55 100755 --- a/javascript/CMSMain_right.js +++ b/javascript/CMSMain_right.js @@ -85,14 +85,34 @@ Behaviour.register({ onchange: function() { alert('The page type will be updated after the page is saved'); } - } -}); + }, -Behaviour.register({ '#Form_EditForm' : { changeDetection_fieldsToIgnore : { 'restricted-chars[Form_EditForm_URLSegment]' : true, 'Sort' : true } - } -}); + }, + + // ParentType / ParentID field combination + '#Form_EditForm_ParentType' : { + initialize : function() { + $('Form_EditForm_ParentType_root').onclick = this.rootClick.bind(this); + $('Form_EditForm_ParentType_subpage').onclick = this.showHide; + this.showHide(); + }, + + rootClick : function() { + $('Form_EditForm_ParentID').setValue(0); + this.showHide(); + }, + + showHide : function() { + if($('Form_EditForm_ParentType_root').checked) { + Element.hide('ParentID'); + } else { + Element.show('ParentID'); + } + } + } +}); \ No newline at end of file diff --git a/javascript/LeftAndMain_left.js b/javascript/LeftAndMain_left.js index 8ec1b7a9..bba33a72 100755 --- a/javascript/LeftAndMain_left.js +++ b/javascript/LeftAndMain_left.js @@ -102,6 +102,15 @@ TreeAPI.prototype = { }); }, + /** + * Set the parent ID of a tree node + */ + setNodeParentID: function (idx, parentID) { + var treeNode = this.getTreeNodeByIdx(idx); + var parentNode = this.getTreeNodeByIdx(parentID); + parentNode.appendTreeNode(treeNode); + }, + setCurrentByIdx : function(idx) { if(this.selected) { var i,item;