From 1bac2dc4aaf3510ad6d4a95adb42fdd1801060d8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 02:39:18 +0000 Subject: [PATCH] BUGFIX Fixed ParentType selector javascript in SiteTree->getCMSFields() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92676 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- css/cms_right.css | 4 ++++ javascript/CMSMain.js | 41 ++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/css/cms_right.css b/css/cms_right.css index 8a775ab4..e6d9f2ef 100644 --- a/css/cms_right.css +++ b/css/cms_right.css @@ -67,6 +67,10 @@ border: none; padding: 0; } + + .right form .parentTypeSelector { + margin-left: 0; + } .right form .dropdown, .right form .countrydropdown { diff --git a/javascript/CMSMain.js b/javascript/CMSMain.js index 304b0509..432d9a20 100644 --- a/javascript/CMSMain.js +++ b/javascript/CMSMain.js @@ -139,34 +139,25 @@ var ss_MainLayout; /** * @class ParentID field combination - mostly toggling between * the two radiobuttons and setting the hidden "ParentID" field - * @name ss.EditForm.ParentType + * @name ss.EditForm.parentTypeSelector */ - $('#Form_EditForm_ParentType').concrete('ss', function($){ - return/** @lends ss.EditForm.ParentType */{ + $('#Form_EditForm .parentTypeSelector').concrete('ss', function($){ + return/** @lends ss.EditForm.parentTypeSelector */{ onmatch : function() { - var parentTypeRootEl = $('#Form_EditForm_ParentType_root'); - var parentTypeSubpageEl = $('#Form_EditForm_ParentType_subpage'); - if(parentTypeRootEl) { - parentTypeRootEl.onclick = this._rootClick.bind(this); - } - if(parentTypeSubpageEl) { - parentTypeSubpageEl.onclick = this.showHide; - } - this.showHide(); + var self = this; + + this.find(':input[name=ParentType]').bind('click', function(e) {self._toggleSelection(e);}); + + this._toggleSelection(); }, - - _rootClick : function() { - $('#Form_EditForm_ParentID').val(0); - this.showHide(); - }, - - showHide : function() { - var parentTypeRootEl = $('#Form_EditForm_ParentType_root'); - if(parentTypeRootEl && parentTypeRootEl.checked) { - $('#ParentID').hide(); - } else { - $('#ParentID').show(); - } + + _toggleSelection: function(e) { + var selected = this.find(':input[name=ParentType]:checked').val(); + // reset parent id if 'root' radiobutton is selected + if(selected == 'root') this.find(':input[name=ParentID]').val(0); + console.debug(selected); + // toggle tree dropdown based on selection + this.find('#ParentID').toggle(selected != 'root'); } }; });